mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-25 14:36:18 +01:00
Convert AllEntityTypes to Registrate
This commit is contained in:
parent
33b5338828
commit
ea88e8fcf5
4 changed files with 30 additions and 57 deletions
|
@ -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<EntityType<ContraptionEntity>> CONTRAPTION =
|
||||
register("contraption", ContraptionEntity::new, EntityClassification.MISC, 5, 3, true, ContraptionEntity::build);
|
||||
public static final RegistryEntry<EntityType<ContraptionEntity>> STATIONARY_CONTRAPTION =
|
||||
register("stationary_contraption", ContraptionEntity::new, EntityClassification.MISC, 20, 40, false, ContraptionEntity::build);
|
||||
public static final RegistryEntry<EntityType<SuperGlueEntity>> 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<? extends Entity>, EntityType.Builder<? extends Entity>> propertyBuilder;
|
||||
private EntityClassification group;
|
||||
private boolean sendVelocity;
|
||||
|
||||
public EntityType<? extends Entity> type;
|
||||
|
||||
private AllEntityTypes(IFactory<?> factory, EntityClassification group, int range, int updateFrequency,
|
||||
boolean sendVelocity,
|
||||
Function<EntityType.Builder<? extends Entity>, EntityType.Builder<? extends Entity>> propertyBuilder) {
|
||||
this.factory = factory;
|
||||
this.group = group;
|
||||
this.range = range;
|
||||
this.updateFrequency = updateFrequency;
|
||||
this.sendVelocity = sendVelocity;
|
||||
this.propertyBuilder = propertyBuilder;
|
||||
private static <T extends Entity> RegistryEntry<EntityType<T>> register(String name, IFactory<T> factory,
|
||||
EntityClassification group, int range, int updateFrequency, boolean sendVelocity,
|
||||
NonNullConsumer<EntityType.Builder<T>> 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(final RegistryEvent.Register<EntityType<?>> event) {
|
||||
for (AllEntityTypes entity : values()) {
|
||||
String id = Lang.asId(entity.name());
|
||||
ResourceLocation resourceLocation = new ResourceLocation(Create.ID, id);
|
||||
Builder<? extends Entity> 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);
|
||||
}
|
||||
public static void register() {}
|
||||
|
||||
}
|
||||
|
||||
@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<ContraptionEntity>) STATIONARY_CONTRAPTION.type, ContraptionEntityRenderer::new);
|
||||
RenderingRegistry.registerEntityRenderingHandler((EntityType<ContraptionEntity>) CONTRAPTION.type, ContraptionEntityRenderer::new);
|
||||
RenderingRegistry.registerEntityRenderingHandler((EntityType<SuperGlueEntity>) 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue