diff --git a/src/main/java/com/simibubi/create/AllEntityTypes.java b/src/main/java/com/simibubi/create/AllEntityTypes.java index 7711a6500..80e5bbf50 100644 --- a/src/main/java/com/simibubi/create/AllEntityTypes.java +++ b/src/main/java/com/simibubi/create/AllEntityTypes.java @@ -1,75 +1,49 @@ package com.simibubi.create; -import java.util.function.Function; - import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity; import com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueRenderer; import com.simibubi.create.foundation.utility.Lang; +import com.tterrag.registrate.util.entry.RegistryEntry; +import com.tterrag.registrate.util.nullness.NonNullConsumer; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityClassification; import net.minecraft.entity.EntityType; -import net.minecraft.entity.EntityType.Builder; import net.minecraft.entity.EntityType.IFactory; -import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.fml.client.registry.RenderingRegistry; -public enum AllEntityTypes { +public class AllEntityTypes { - CONTRAPTION(ContraptionEntity::new, EntityClassification.MISC, 5, 3, true, ContraptionEntity::build), - STATIONARY_CONTRAPTION(ContraptionEntity::new, EntityClassification.MISC, 20, 40, false, ContraptionEntity::build), - SUPER_GLUE(SuperGlueEntity::new, EntityClassification.MISC, 10, Integer.MAX_VALUE, false, SuperGlueEntity::build), + public static final RegistryEntry> CONTRAPTION = + register("contraption", ContraptionEntity::new, EntityClassification.MISC, 5, 3, true, ContraptionEntity::build); + public static final RegistryEntry> STATIONARY_CONTRAPTION = + register("stationary_contraption", ContraptionEntity::new, EntityClassification.MISC, 20, 40, false, ContraptionEntity::build); + public static final RegistryEntry> SUPER_GLUE = + register("super_glue", SuperGlueEntity::new, EntityClassification.MISC, 10, Integer.MAX_VALUE, false, SuperGlueEntity::build); - ; - - private IFactory factory; - private int range; - private int updateFrequency; - private Function, EntityType.Builder> propertyBuilder; - private EntityClassification group; - private boolean sendVelocity; - - public EntityType type; - - private AllEntityTypes(IFactory factory, EntityClassification group, int range, int updateFrequency, - boolean sendVelocity, - Function, EntityType.Builder> propertyBuilder) { - this.factory = factory; - this.group = group; - this.range = range; - this.updateFrequency = updateFrequency; - this.sendVelocity = sendVelocity; - this.propertyBuilder = propertyBuilder; + private static RegistryEntry> register(String name, IFactory factory, + EntityClassification group, int range, int updateFrequency, boolean sendVelocity, + NonNullConsumer> propertyBuilder) { + String id = Lang.asId(name); + return Create.registrate().entity(id, factory, group) + .properties(b -> b + .setTrackingRange(range) + .setUpdateInterval(updateFrequency) + .setShouldReceiveVelocityUpdates(sendVelocity)) + .properties(propertyBuilder) + .register(); } + + public static void register() {} - public static void register(final RegistryEvent.Register> event) { - for (AllEntityTypes entity : values()) { - String id = Lang.asId(entity.name()); - ResourceLocation resourceLocation = new ResourceLocation(Create.ID, id); - Builder builder = EntityType.Builder - .create(entity.factory, entity.group) - .setTrackingRange(entity.range) - .setUpdateInterval(entity.updateFrequency) - .setShouldReceiveVelocityUpdates(entity.sendVelocity); - if (entity.propertyBuilder != null) - builder = entity.propertyBuilder.apply(builder); - entity.type = builder.build(id).setRegistryName(resourceLocation); - event.getRegistry().register(entity.type); - } - - } - - @SuppressWarnings("unchecked") // TODO 1.15 this generic stuff is incompatible with the enum system - need strong types @OnlyIn(value = Dist.CLIENT) public static void registerRenderers() { - RenderingRegistry.registerEntityRenderingHandler((EntityType) STATIONARY_CONTRAPTION.type, ContraptionEntityRenderer::new); - RenderingRegistry.registerEntityRenderingHandler((EntityType) CONTRAPTION.type, ContraptionEntityRenderer::new); - RenderingRegistry.registerEntityRenderingHandler((EntityType) SUPER_GLUE.type, SuperGlueRenderer::new); + RenderingRegistry.registerEntityRenderingHandler(STATIONARY_CONTRAPTION.get(), ContraptionEntityRenderer::new); + RenderingRegistry.registerEntityRenderingHandler(CONTRAPTION.get(), ContraptionEntityRenderer::new); + RenderingRegistry.registerEntityRenderingHandler(SUPER_GLUE.get(), SuperGlueRenderer::new); } - } diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java index 7fa85b6b7..7cf99d912 100644 --- a/src/main/java/com/simibubi/create/Create.java +++ b/src/main/java/com/simibubi/create/Create.java @@ -20,7 +20,6 @@ import com.simibubi.create.foundation.worldgen.AllWorldFeatures; import com.tterrag.registrate.util.NonNullLazyValue; import net.minecraft.data.DataGenerator; -import net.minecraft.entity.EntityType; import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemGroup; import net.minecraft.item.crafting.IRecipeSerializer; @@ -61,11 +60,11 @@ public class Create { AllBlocks.register(); AllItems.register(); AllPaletteBlocks.register(); + AllEntityTypes.register(); modEventBus.addGenericListener(IRecipeSerializer.class, AllRecipeTypes::register); modEventBus.addGenericListener(TileEntityType.class, AllTileEntities::register); modEventBus.addGenericListener(ContainerType.class, AllContainerTypes::register); - modEventBus.addGenericListener(EntityType.class, AllEntityTypes::register); modEventBus.addGenericListener(ParticleType.class, AllParticleTypes::register); modEventBus.addGenericListener(SoundEvent.class, AllSoundEvents::register); modEventBus.addListener(AllConfigs::onLoad); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionEntity.java index bf36fac2d..27e8cd5ae 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionEntity.java @@ -89,12 +89,12 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD public ContraptionEntity(EntityType entityTypeIn, World worldIn) { super(entityTypeIn, worldIn); motionBeforeStall = Vec3d.ZERO; - stationary = entityTypeIn == AllEntityTypes.STATIONARY_CONTRAPTION.type; + stationary = entityTypeIn == AllEntityTypes.STATIONARY_CONTRAPTION.get(); forcedAngle = -1; } public static ContraptionEntity createMounted(World world, Contraption contraption, float initialAngle) { - ContraptionEntity entity = new ContraptionEntity(AllEntityTypes.CONTRAPTION.type, world); + ContraptionEntity entity = new ContraptionEntity(AllEntityTypes.CONTRAPTION.get(), world); entity.contraption = contraption; entity.initialAngle = initialAngle; entity.forceYaw(initialAngle); @@ -112,7 +112,7 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD } public static ContraptionEntity createStationary(World world, Contraption contraption) { - ContraptionEntity entity = new ContraptionEntity(AllEntityTypes.STATIONARY_CONTRAPTION.type, world); + ContraptionEntity entity = new ContraptionEntity(AllEntityTypes.STATIONARY_CONTRAPTION.get(), world); entity.contraption = contraption; if (contraption != null) contraption.gatherStoredItems(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java index 56199fb23..aedad7870 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java @@ -62,7 +62,7 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat } public SuperGlueEntity(World world, BlockPos pos, Direction direction) { - this(AllEntityTypes.SUPER_GLUE.type, world); + this(AllEntityTypes.SUPER_GLUE.get(), world); hangingPosition = pos; facingDirection = direction; updateFacingWithBoundingBox();