refactor entity events. Allow multiple hosts have events on things
This commit is contained in:
1 parent
1c35f5b6a9
commit
afd7952a62
11 files changed
+190
-186
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.EntityInterface;
|
||||
import carpet.script.EntityEventsGroup;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.damage.DamageTracker;
|
||||
@@ -19,6 +20,6 @@ public class DamageTracker_scarpetEventMixin
|
||||
@Inject(method = "onDamage", at = @At("HEAD"))
|
||||
private void onDamageTaken(DamageSource damageSource_1, float float_1, float float_2, CallbackInfo ci)
|
||||
{
|
||||
((EntityInterface)entity).onDamageCallback(float_2, damageSource_1);
|
||||
((EntityInterface)entity).getEventContainer().onEvent(EntityEventsGroup.EntityEventType.ON_DAMAGE, entity, float_2, damageSource_1);
|
||||
}
|
||||
}
|
||||
@@ -1,96 +1,37 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.CarpetServer;
|
||||
import carpet.fakes.EntityInterface;
|
||||
import carpet.script.CarpetContext;
|
||||
import carpet.script.CarpetEventServer;
|
||||
import carpet.script.value.FunctionValue;
|
||||
import carpet.script.value.Value;
|
||||
import carpet.script.EntityEventsGroup;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
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;
|
||||
private CarpetEventServer.ScheduledCall tickCall;
|
||||
private CarpetEventServer.ScheduledCall damageCall;
|
||||
|
||||
private EntityEventsGroup events = new EntityEventsGroup();
|
||||
|
||||
@Override
|
||||
public void setDeathCallback(CarpetContext cc, FunctionValue function, List<Value> extraArgs)
|
||||
public EntityEventsGroup getEventContainer()
|
||||
{
|
||||
deathCall = CarpetServer.scriptServer.events.makeDeathCall(cc, function, extraArgs);
|
||||
return events;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRemovedCallback(CarpetContext cc, FunctionValue function, List<Value> extraArgs)
|
||||
{
|
||||
removeCall = CarpetServer.scriptServer.events.makeRemovedCall(cc, function, extraArgs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTickCallback(CarpetContext cc, FunctionValue function, List<Value> extraArgs)
|
||||
{
|
||||
tickCall = CarpetServer.scriptServer.events.makeTickCall(cc, function, extraArgs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CarpetEventServer.ScheduledCall getTickCallback()
|
||||
{
|
||||
return tickCall;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDamageCallback(CarpetContext cc, FunctionValue function, List<Value> extraArgs)
|
||||
{
|
||||
damageCall = CarpetServer.scriptServer.events.makeDamageCall(cc, function, extraArgs);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDeathCallback(String reason)
|
||||
{
|
||||
if (deathCall != null)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onEntityDeath(deathCall, (Entity)(Object)this, reason);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDamageCallback(float amount, DamageSource source)
|
||||
{
|
||||
if (damageCall != null)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onEntityDamage(damageCall, (Entity)(Object)this, amount, source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Inject(method = "tick", at = @At("HEAD"))
|
||||
private void onTickCall(CallbackInfo ci)
|
||||
{
|
||||
if (tickCall != null)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onEntityTick(tickCall, (Entity) (Object) this);
|
||||
}
|
||||
events.onEvent(EntityEventsGroup.EntityEventType.ON_TICK, (Entity) (Object) this);
|
||||
}
|
||||
|
||||
|
||||
@Inject(method = "remove", at = @At("HEAD"))
|
||||
private void onRemove(CallbackInfo ci)
|
||||
{
|
||||
if (!removed && removeCall != null)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onEntityRemoved(removeCall, (Entity)(Object)this);
|
||||
}
|
||||
if (!removed) events.onEvent(EntityEventsGroup.EntityEventType.ON_REMOVED, (Entity) (Object) this);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.EntityInterface;
|
||||
import carpet.script.EntityEventsGroup;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
@@ -12,12 +13,17 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(LivingEntity.class)
|
||||
public abstract class LivingEntity_scarpetEventsMixin
|
||||
public abstract class LivingEntity_scarpetEventsMixin extends Entity
|
||||
{
|
||||
|
||||
public LivingEntity_scarpetEventsMixin(EntityType<?> type, World world)
|
||||
{
|
||||
super(type, world);
|
||||
}
|
||||
|
||||
@Inject(method = "onDeath", at = @At("HEAD"))
|
||||
private void onDeathCall(DamageSource damageSource_1, CallbackInfo ci)
|
||||
{
|
||||
((EntityInterface)this).onDeathCallback(damageSource_1.name);
|
||||
((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.EntityEventType.ON_DEATH, this, damageSource_1.name);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user