@Overwrite for variables?

Hello, I was thinking of working on the CommandBlock implementation. I have a temporary solution set up, but it only works for Vanilla Minecraft commands. I found the issue but I don’t know how to fix it considering that as of right now, the @Overwrite annotation only works on methods as far as I know. Therefore I have a couple of questions:
A.) Does @Overwrite support variables?
B.) If not, then how can I fix that?
C.) If I need to edit an anonymous inner class, how do I do that? (P.S. This is basically what this entire post is about.)
D.) How do I use said edited anonymous inner class to access private variables from class to be added to?

Thank you for your time and patience.

EDIT: I have made a solution, but it is very ugly and involves ignoring about 20 errors. I need a way to access/overwrite constructors of the class to be mixed WITHOUT errors. Can anyone help?

The @Overwrite annotation is used by the annotation processor, which is currently under development.

@Mumfrey will be able to tell you more.

Okay, thank you!

Okay, I’m not really sure where to start here, I’ll start by saying that it’s imperative that you properly understand mixins before attempting to implement anything using them. Please read all the examples present in the /src/example/java folder in the source tree.

To answer your questions:

  • A - No, there is no purpose for @Overwrite to support fields. There are only two types of field in a mixin, shadowed fields and member fields, so having @Overwrite on them makes no sense at all because they would only support a fictitious third class of field which doesn’t exist.
  • B - You can’t fix that because it doesn’t make any sense.
  • C - Whilst it’s technically possible, I’d strongly recommend against it, but I don’t really see what it has to do with @Overwrite either since you talk about fields in the first instance and now you’re talking about anonymous classes? If you need to edit an anonymous inner class then it’s very possible that a different approach is more appropriate.
  • D - You don’t, you’d just use an AT for that.

Whilst you can @Inject into a ctor, you cannot overwrite a ctor or otherwise modify it, this is a deliberate choice because the functionality of ctors in bytecode also includes any field initialisers for the class and must call the superclass ctor and so none of the mixin functionality allows ctors to be manipulated other than using @Inject to place a callback at the RETURN opcode.

I suggest you get on IRC in #spongedev to actually discuss this, because the forums are not an ideal medium, I’m not really sure what you’re trying to achieve and I think it will be easier to establish that via IRC.

Okay, I can see what you are saying. But the way that I have it set up DOES overwrite a constructor and actually works (I believe that this is because the class TileEntityCommandBlock uses the default empty constructor). The only problem is that I have to ignore about 20 errors, as I said above. As of right now, I have created a new variable so that I can use it like the inner class was used and overwritten the methods that refer to that variable. I want a solution that doesn’t look so ugly (That @Inject thing seems nice… I hadn’t thought of that before.) TileEntityCommandBlock uses the way of making an interface “instance” and I need to overwrite that. Is an AT an access transformer, and if so, how do I use them?

@mumfrey, Okay, now I am using @Inject instead of @Overwrite for the constructor. HOWEVER, I still need to ignore the 9 leftover errors. If, as I asked above, an AT is an access transformer, how do I use it?

Never mind, I got on the IRC and talked to a bunch of people. I don’t actually need to do this. :expressionless: Oh well, I guess I will just get onto the counting and output. :smile:

P.S. You can track my changes at github.com/piepie62/Sponge