refactor entity events. Allow multiple hosts have events on things

This commit is contained in:
gnembon committed 2019-11-29 10:34:13 -04:00
1 parent 1c35f5b6a9
commit afd7952a62
11 files changed
+190 -186

No files matched your search

@@ -1,23 +1,28 @@
package carpet.mixins;
import carpet.CarpetServer;
import carpet.fakes.EntityInterface;
import carpet.script.EntityEventsGroup;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.FallingBlockEntity;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(FallingBlockEntity.class)
public class FallingBlockEntity_scarpetEventsMixin
public abstract class FallingBlockEntity_scarpetEventsMixin extends Entity
{
public FallingBlockEntity_scarpetEventsMixin(EntityType<?> type, World world)
{
super(type, world);
}
@Inject(method = "tick", at = @At("HEAD"))
private void onTickCall(CallbackInfo ci)
{
if (((EntityInterface)this).getTickCallback() != null)
{
CarpetServer.scriptServer.events.onEntityTick(((EntityInterface)this).getTickCallback(), (Entity) (Object) this);
}
// calling extra on_tick because falling blocks do not fall back to super tick call
((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.EntityEventType.ON_TICK, this);
}
}