changes to entity load handler / not backwards compatible
This commit is contained in:
1 parent
f2aae4ec92
commit
481fc97545
4 files changed
+48
-6
No files matched your search
@@ -0,0 +1,38 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.script.CarpetEventServer;
|
||||
import carpet.script.CarpetScriptServer;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.world.ServerEntityManager;
|
||||
import net.minecraft.world.entity.EntityLike;
|
||||
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.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ServerEntityManager.class)
|
||||
public class ServerEntityManager_scarpetMixin
|
||||
{
|
||||
@Inject(method = "addEntity(Lnet/minecraft/world/entity/EntityLike;Z)Z", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/world/entity/EntityTrackingStatus;shouldTick()Z"
|
||||
))
|
||||
private void handleAddedEntity(EntityLike entityLike, boolean existing, CallbackInfoReturnable<Boolean> cir)
|
||||
{
|
||||
Entity entity = (Entity)entityLike;
|
||||
CarpetEventServer.Event event = CarpetEventServer.Event.ENTITY_LOAD.get(entity.getType());
|
||||
if (event != null)
|
||||
{
|
||||
if (event.isNeeded())
|
||||
{
|
||||
event.onEntityAction(entity, !existing);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CarpetScriptServer.LOG.error("Failed to handle entity type " + entity.getType().getTranslationKey());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,7 +26,6 @@ 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_LOAD;
|
||||
import static carpet.script.CarpetEventServer.Event.EXPLOSION;
|
||||
import static carpet.script.CarpetEventServer.Event.LIGHTNING;
|
||||
|
||||
@@ -46,6 +45,8 @@ public class ServerWorld_scarpetMixin implements ServerWorldInterface
|
||||
if (LIGHTNING.isNeeded()) LIGHTNING.onWorldEventFlag((ServerWorld) (Object)this, blockPos, bl2?1:0);
|
||||
}
|
||||
|
||||
/*
|
||||
moved to ServerEntityManager_scarpetMixin in 1.17
|
||||
@Redirect(method = "addEntity", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/world/ServerEntityManager;addEntity(Lnet/minecraft/world/entity/EntityLike;)Z"
|
||||
@@ -66,6 +67,7 @@ public class ServerWorld_scarpetMixin implements ServerWorldInterface
|
||||
};
|
||||
return success;
|
||||
}
|
||||
*/
|
||||
|
||||
@Inject(method = "createExplosion", at = @At("HEAD"))
|
||||
private void handleExplosion(/*@Nullable*/ Entity entity, /*@Nullable*/ DamageSource damageSource, /*@Nullable*/ ExplosionBehavior explosionBehavior, double d, double e, double f, float g, boolean bl, Explosion.DestructionType destructionType, CallbackInfoReturnable<Explosion> cir)
|
||||
|
||||
@@ -933,16 +933,17 @@ public class CarpetEventServer
|
||||
return "entity_loaded_" + ValueConversions.of(Registry.ENTITY_TYPE.getId(et)).getString();
|
||||
}
|
||||
|
||||
public static final Map<EntityType<? extends Entity>, Event> ENTITY_LOAD= new HashMap<EntityType<? extends Entity>, Event>() {{
|
||||
public static final Map<EntityType<? extends Entity>, Event> ENTITY_LOAD= new HashMap<>()
|
||||
{{
|
||||
EntityType.get("zombie");
|
||||
Registry.ENTITY_TYPE.forEach(et -> {
|
||||
put(et, new Event(getEntityLoadEventName(et), 1, true, false)
|
||||
put(et, new Event(getEntityLoadEventName(et), 2, true, false)
|
||||
{
|
||||
@Override
|
||||
public void onEntityAction(Entity entity)
|
||||
public void onEntityAction(Entity entity, boolean created)
|
||||
{
|
||||
handler.call(
|
||||
() -> Collections.singletonList(new EntityValue(entity)),
|
||||
() -> Arrays.asList(new EntityValue(entity), BooleanValue.of(created)),
|
||||
() -> CarpetServer.minecraft_server.getCommandSource().withWorld((ServerWorld) entity.world).withLevel(CarpetSettings.runPermissionLevel)
|
||||
);
|
||||
}
|
||||
@@ -1040,7 +1041,7 @@ public class CarpetEventServer
|
||||
public void onBlockPlaced(ServerPlayerEntity player, BlockPos pos, Hand enumhand, ItemStack itemstack) { }
|
||||
public void onEntityHandAction(ServerPlayerEntity player, Entity entity, Hand enumhand) { }
|
||||
public void onHandAction(ServerPlayerEntity player, Hand enumhand) { }
|
||||
public void onEntityAction(Entity entity) { }
|
||||
public void onEntityAction(Entity entity, boolean created) { }
|
||||
public void onDimensionChange(ServerPlayerEntity player, Vec3d from, Vec3d to, RegistryKey<World> fromDim, RegistryKey<World> dimTo) {}
|
||||
public void onDamage(Entity target, float amount, DamageSource source) { }
|
||||
public void onRecipeSelected(ServerPlayerEntity player, Identifier recipe, boolean fullStack) {}
|
||||
|
||||
@@ -188,6 +188,7 @@
|
||||
"StatType_scarpetMixin",
|
||||
"PointOfInterest_scarpetMixin",
|
||||
"ServerWorld_scarpetMixin",
|
||||
"ServerEntityManager_scarpetMixin",
|
||||
"HungerManagerMixin_scarpetEventsMixin",
|
||||
"ReloadCommand_reloadAppsMixin",
|
||||
"CrashReport_addScarpetAppsMixin",
|
||||
|
||||
Reference in new issue
Block a user