Question on Mixins

I read through the Mixin documentation and understand most of it. I spent some time recently beating my head against ObjectWeb with Minecraft 1.7.10 and Forge so I think I have a pretty decent idea of what is going on. :smile:

Anyways, the question. Is there a way using Mixins to completely gut a Minecraft Vanilla class and replace it with new stuff? Obviously the method signatures and public/protected fields need to remain, so you can think of the class definition as being similar to an interface construct. I know I can do this pretty easily with Objectweb and Minecraft 1.7.10/Forge; my hope is to have be a bit less painful to accomplish with Mixins.

Yes, yes. I know - this would generally be discouraged because of compatibility and what not. But the classes where I want to do some pounding, er, tweaking are ones that no one would normally want to bother with. I should also point out this is at the experimental stage, and if things pan out I will more than likely have to approach this in a different way.

Thanks for reading if you managed to get this far. :slight_smile:

Yes you can do that, just use overwrites. Disclaimer bad idea, horrible doom, end of days, don’t blame me when hard drive formatted, etc. etc.

The basis of mixins is that you don’t need to gut entire methods (if you just @Overwrite, you reduce compatibility with most any mod that uses transformers). What you can do however is use @Redirect in a mixin to redirect methods entirely to yours (so you leave the original method relatively untouched, just redirect at the head). Also note that by targeting 1.7.10 you effectively just continue the spiral of being on an older version when mods are already working on targeting 1.8/1.8.8 (and likely sooner 1.9).

Having said all of that, Mixins will work for doing most of what you’re asking for, but I encourage you to look at how you are wanting the system to work with compatibility in mind (@Inject is your friend).

Yep. Understand. In the cases I am thinking I am not wanting to augment, extend, patch, etc the existing internal workings - I want to outright replace it. In the grand scheme of things the best approach may be to create a Forge patch and get it in via Forge.

Is there a way to erase a data member using overwrite? For example, the class may have a member using a TreeSet/TreeMap, and I may want to replace it with an entirely different collection type. I know I can introduce a new member and refer to that, but I don’t necessarily want to carry around the baggage of a dead field.

Mixins won’t do that, that’s something a patch/transformer would have to do.

Yeah, it was what I was thinking. I was hoping I missed something. Thanks for the info.

BTW, I really like the Mixin concept. It makes class tweaking a LOT easier and cleaner.

Hail @mumfrey, the great, the powerful, the eternal.