I was wondering if someone could explain how the forge to sponge event mapping worked? I’m looking to write in some event handling code for the chat event handler. But the implementation seems to use ASM quite a bit and I’m having trouble figuring out how the code works.
So if someone could both explain exactly what ASM is doing and how the implementation maps events that’s what I need.
Note: Perhaps this was unclear, but I’m looking for details about the current Sponge implementation, not how a plugin would do it.
I’m not talking about for making a plugin, that event can’t register yet because the current Sponge implementation doesn’t handle a forge chat event. I’m looking at how the current Sponge implementation can be extended to map the forge event.
Oh got ya,
Well I did it before, you need something like this:
Basicly you say what class the forge event has to implement. But don’t be surprised if you get abstractmethodexception because most of the methods aren’t created yet. You could use mixings to make them work.
Can you explain that a bit more? I’m pretty new to low level java like this, so I’m trying to learn it. What are mixins exactly? I’ve looked at that file before, but I’m not sure what exactly it’s doing. How do I match up the arguments for the events?
Mixins make it possible to change minecraft base classes without writing the bytecode. Sponge uses mixins because managing bytecode is not funny and maintainable. Also you will have to change brand if you want to use them.
I just started messing around with the pre-existing event mapping stuff, but lets say I wanted to make a command listening event that just forwarded the whole string to the event handler. How would I map the methods to the forge event? Sorry about all the questions, I’ve never really looked into this class mapping and ASM stuff.
Seems you are unaware of the selection ability of gist xD. What is fine it also took me a while to notice it. If you click the link you will see that line 70 is selected .
Yes for the methods you need a mixin I guess. I wrote a mixin class to explain (not tested, but this is as it should work). Be aware that you don’t need to implement methods from the Event class. The event transformer already implement those.
package org.spongepowered.mixin.impl;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.event.ServerChatEvent;
import org.spongepowered.api.entity.Player;
import org.spongepowered.api.event.player.AsyncPlayerChatEvent;
import org.spongepowered.mod.mixin.Mixin;
import org.spongepowered.mod.mixin.Shadow;
@Mixin(ServerChatEvent.class)
public abstract class MixinServerChatEvent implements AsyncPlayerChatEvent {
@Shadow public String message;
@Shadow public EntityPlayerMP player;
@Override
public String getMessage() {
return message; //this will work
}
@Override
public Player getPlayer() {
return (Player) player; //This will crash until Player has a mixin
}
}