changes to entity load handler keeping it backwards compatible

This commit is contained in:
gnembon committed 2021-06-25 20:09:15 -03:00
1 parent 85d60b283f
commit 448fde1f36
4 files changed
+83 -13

No files matched your search

@@ -926,18 +926,20 @@ public class CarpetEventServer
}
};
@Deprecated
public static String getEntityLoadEventName(EntityType<? extends Entity> et)
{
return "entity_loaded_" + ValueConversions.of(Registry.ENTITY_TYPE.getId(et)).getString();
}
@Deprecated
public static final Map<EntityType<? extends Entity>, Event> ENTITY_LOAD= new HashMap<EntityType<? extends Entity>, Event>() {{
EntityType.get("zombie");
Registry.ENTITY_TYPE.forEach(et -> {
put(et, new Event(getEntityLoadEventName(et), 1, true, false)
{
@Override
public void onEntityAction(Entity entity)
public void onEntityAction(Entity entity, boolean created)
{
handler.call(
() -> Collections.singletonList(new EntityValue(entity)),
@@ -948,6 +950,28 @@ public class CarpetEventServer
});
}};
public static String getEntityHandlerEventName(EntityType<? extends Entity> et)
{
return "entity_handler_" + ValueConversions.of(Registry.ENTITY_TYPE.getId(et)).getString();
}
public static final Map<EntityType<? extends Entity>, Event> ENTITY_HANDLER= new HashMap<EntityType<? extends Entity>, Event>() {{
EntityType.get("zombie");
Registry.ENTITY_TYPE.forEach(et -> {
put(et, new Event(getEntityHandlerEventName(et), 2, true, false)
{
@Override
public void onEntityAction(Entity entity, boolean created)
{
handler.call(
() -> Arrays.asList(new EntityValue(entity), BooleanValue.of(created)),
() -> CarpetServer.minecraft_server.getCommandSource().withWorld((ServerWorld) entity.world).withLevel(CarpetSettings.runPermissionLevel)
);
}
});
});
}};
// on projectile thrown (arrow from bows, crossbows, tridents, snoballs, e-pearls
public final String name;
@@ -1038,7 +1062,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) {}