changes to entity load handler keeping it backwards compatible
This commit is contained in:
1 parent
85d60b283f
commit
448fde1f36
4 files changed
+83
-13
No files matched your search
@@ -23,6 +23,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
import static carpet.script.CarpetEventServer.Event.ENTITY_HANDLER;
|
||||
import static carpet.script.CarpetEventServer.Event.ENTITY_LOAD;
|
||||
import static carpet.script.CarpetEventServer.Event.EXPLOSION;
|
||||
import static carpet.script.CarpetEventServer.Event.LIGHTNING;
|
||||
@@ -43,24 +44,50 @@ public class ServerWorld_scarpetMixin implements ServerWorldInterface
|
||||
if (LIGHTNING.isNeeded()) LIGHTNING.onWorldEventFlag((ServerWorld) (Object)this, blockPos, bl2?1:0);
|
||||
}
|
||||
|
||||
|
||||
private ThreadLocal<Boolean> entityJustLoaded = ThreadLocal.withInitial(() -> false);
|
||||
|
||||
@Inject(method = "loadEntityUnchecked", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/world/ServerChunkManager;loadEntity(Lnet/minecraft/entity/Entity;)V"
|
||||
))
|
||||
private void onEntityAddedToWorld(Entity entity, CallbackInfo ci)
|
||||
{
|
||||
CarpetEventServer.Event event = ENTITY_LOAD.get(entity.getType());
|
||||
boolean justLoaded = entityJustLoaded.get();
|
||||
entityJustLoaded.set(false);
|
||||
CarpetEventServer.Event event = ENTITY_HANDLER.get(entity.getType());
|
||||
if (event != null)
|
||||
{
|
||||
if (event.isNeeded())
|
||||
{
|
||||
event.onEntityAction(entity);
|
||||
event.onEntityAction(entity, !justLoaded);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CarpetSettings.LOG.error("Failed to handle entity "+entity.getType().getTranslationKey());
|
||||
}
|
||||
|
||||
// deprecated usage
|
||||
event = ENTITY_LOAD.get(entity.getType());
|
||||
if (event != null)
|
||||
{
|
||||
if (event.isNeeded())
|
||||
{
|
||||
event.onEntityAction(entity, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CarpetSettings.LOG.error("Failed to handle entity "+entity.getType().getTranslationKey());
|
||||
}
|
||||
}
|
||||
|
||||
// 1.16only
|
||||
@Inject(method = "loadEntity", at= @At("HEAD"))
|
||||
private void onSideLoaded(Entity entity, CallbackInfoReturnable<Boolean> cir)
|
||||
{
|
||||
entityJustLoaded.set(true);
|
||||
}
|
||||
|
||||
@Inject(method = "createExplosion", at = @At("HEAD"))
|
||||
|
||||
Reference in new issue
Block a user