better entity events, untested
This commit is contained in:
1 parent
32dc6b17e8
commit
6505afdfdb
6 files changed
+100
-25
No files matched your search
@@ -5,14 +5,26 @@ import carpet.fakes.EntityInterface;
|
||||
import carpet.script.CarpetContext;
|
||||
import carpet.script.CarpetEventServer;
|
||||
import carpet.script.ScriptHost;
|
||||
import carpet.script.value.Value;
|
||||
import carpet.settings.CarpetSettings;
|
||||
import net.minecraft.entity.Entity;
|
||||
import org.lwjgl.system.CallbackI;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(Entity.class)
|
||||
public abstract class Entity_scarpetEventsMixin implements EntityInterface
|
||||
{
|
||||
@Shadow public boolean removed;
|
||||
private CarpetEventServer.ScheduledCall deathCall;
|
||||
private CarpetEventServer.ScheduledCall removeCall;
|
||||
|
||||
|
||||
@Override
|
||||
public void onDeathCallback(String reason)
|
||||
{
|
||||
@@ -23,8 +35,24 @@ public abstract class Entity_scarpetEventsMixin implements EntityInterface
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDeathCallback(CarpetContext cc, String function)
|
||||
public void setDeathCallback(CarpetContext cc, String function, List<Value> extraArgs)
|
||||
{
|
||||
deathCall = CarpetServer.scriptServer.events.makeDeathCall(cc, function);
|
||||
deathCall = CarpetServer.scriptServer.events.makeDeathCall(cc, function, extraArgs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRemovedCallback(CarpetContext cc, String function, List<Value> extraArgs)
|
||||
{
|
||||
removeCall = CarpetServer.scriptServer.events.makeRemovedCall(cc, function, extraArgs);
|
||||
}
|
||||
|
||||
|
||||
@Inject(method = "remove", at = @At("HEAD"))
|
||||
private void onRemove(CallbackInfo ci)
|
||||
{
|
||||
if (!removed && removeCall != null)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onEntityRemoved(removeCall, (Entity)(Object)this);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user