mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-26 06:57:02 +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;
|
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.ContraptionEntity;
|
||||||
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionEntityRenderer;
|
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.SuperGlueEntity;
|
||||||
import com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueRenderer;
|
import com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueRenderer;
|
||||||
import com.simibubi.create.foundation.utility.Lang;
|
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.Entity;
|
||||||
import net.minecraft.entity.EntityClassification;
|
import net.minecraft.entity.EntityClassification;
|
||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.entity.EntityType;
|
||||||
import net.minecraft.entity.EntityType.Builder;
|
|
||||||
import net.minecraft.entity.EntityType.IFactory;
|
import net.minecraft.entity.EntityType.IFactory;
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import net.minecraftforge.event.RegistryEvent;
|
|
||||||
import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
||||||
|
|
||||||
public enum AllEntityTypes {
|
public class AllEntityTypes {
|
||||||
|
|
||||||
CONTRAPTION(ContraptionEntity::new, EntityClassification.MISC, 5, 3, true, ContraptionEntity::build),
|
public static final RegistryEntry<EntityType<ContraptionEntity>> CONTRAPTION =
|
||||||
STATIONARY_CONTRAPTION(ContraptionEntity::new, EntityClassification.MISC, 20, 40, false, ContraptionEntity::build),
|
register("contraption", ContraptionEntity::new, EntityClassification.MISC, 5, 3, true, ContraptionEntity::build);
|
||||||
SUPER_GLUE(SuperGlueEntity::new, EntityClassification.MISC, 10, Integer.MAX_VALUE, false, SuperGlueEntity::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 static <T extends Entity> RegistryEntry<EntityType<T>> register(String name, IFactory<T> factory,
|
||||||
|
EntityClassification group, int range, int updateFrequency, boolean sendVelocity,
|
||||||
private IFactory<?> factory;
|
NonNullConsumer<EntityType.Builder<T>> propertyBuilder) {
|
||||||
private int range;
|
String id = Lang.asId(name);
|
||||||
private int updateFrequency;
|
return Create.registrate().entity(id, factory, group)
|
||||||
private Function<EntityType.Builder<? extends Entity>, EntityType.Builder<? extends Entity>> propertyBuilder;
|
.properties(b -> b
|
||||||
private EntityClassification group;
|
.setTrackingRange(range)
|
||||||
private boolean sendVelocity;
|
.setUpdateInterval(updateFrequency)
|
||||||
|
.setShouldReceiveVelocityUpdates(sendVelocity))
|
||||||
public EntityType<? extends Entity> type;
|
.properties(propertyBuilder)
|
||||||
|
.register();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void register(final RegistryEvent.Register<EntityType<?>> event) {
|
public static void register() {}
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked") // TODO 1.15 this generic stuff is incompatible with the enum system - need strong types
|
|
||||||
@OnlyIn(value = Dist.CLIENT)
|
@OnlyIn(value = Dist.CLIENT)
|
||||||
public static void registerRenderers() {
|
public static void registerRenderers() {
|
||||||
RenderingRegistry.registerEntityRenderingHandler((EntityType<ContraptionEntity>) STATIONARY_CONTRAPTION.type, ContraptionEntityRenderer::new);
|
RenderingRegistry.registerEntityRenderingHandler(STATIONARY_CONTRAPTION.get(), ContraptionEntityRenderer::new);
|
||||||
RenderingRegistry.registerEntityRenderingHandler((EntityType<ContraptionEntity>) CONTRAPTION.type, ContraptionEntityRenderer::new);
|
RenderingRegistry.registerEntityRenderingHandler(CONTRAPTION.get(), ContraptionEntityRenderer::new);
|
||||||
RenderingRegistry.registerEntityRenderingHandler((EntityType<SuperGlueEntity>) SUPER_GLUE.type, SuperGlueRenderer::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 com.tterrag.registrate.util.NonNullLazyValue;
|
||||||
|
|
||||||
import net.minecraft.data.DataGenerator;
|
import net.minecraft.data.DataGenerator;
|
||||||
import net.minecraft.entity.EntityType;
|
|
||||||
import net.minecraft.inventory.container.ContainerType;
|
import net.minecraft.inventory.container.ContainerType;
|
||||||
import net.minecraft.item.ItemGroup;
|
import net.minecraft.item.ItemGroup;
|
||||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||||
|
@ -61,11 +60,11 @@ public class Create {
|
||||||
AllBlocks.register();
|
AllBlocks.register();
|
||||||
AllItems.register();
|
AllItems.register();
|
||||||
AllPaletteBlocks.register();
|
AllPaletteBlocks.register();
|
||||||
|
AllEntityTypes.register();
|
||||||
|
|
||||||
modEventBus.addGenericListener(IRecipeSerializer.class, AllRecipeTypes::register);
|
modEventBus.addGenericListener(IRecipeSerializer.class, AllRecipeTypes::register);
|
||||||
modEventBus.addGenericListener(TileEntityType.class, AllTileEntities::register);
|
modEventBus.addGenericListener(TileEntityType.class, AllTileEntities::register);
|
||||||
modEventBus.addGenericListener(ContainerType.class, AllContainerTypes::register);
|
modEventBus.addGenericListener(ContainerType.class, AllContainerTypes::register);
|
||||||
modEventBus.addGenericListener(EntityType.class, AllEntityTypes::register);
|
|
||||||
modEventBus.addGenericListener(ParticleType.class, AllParticleTypes::register);
|
modEventBus.addGenericListener(ParticleType.class, AllParticleTypes::register);
|
||||||
modEventBus.addGenericListener(SoundEvent.class, AllSoundEvents::register);
|
modEventBus.addGenericListener(SoundEvent.class, AllSoundEvents::register);
|
||||||
modEventBus.addListener(AllConfigs::onLoad);
|
modEventBus.addListener(AllConfigs::onLoad);
|
||||||
|
|
|
@ -89,12 +89,12 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD
|
||||||
public ContraptionEntity(EntityType<?> entityTypeIn, World worldIn) {
|
public ContraptionEntity(EntityType<?> entityTypeIn, World worldIn) {
|
||||||
super(entityTypeIn, worldIn);
|
super(entityTypeIn, worldIn);
|
||||||
motionBeforeStall = Vec3d.ZERO;
|
motionBeforeStall = Vec3d.ZERO;
|
||||||
stationary = entityTypeIn == AllEntityTypes.STATIONARY_CONTRAPTION.type;
|
stationary = entityTypeIn == AllEntityTypes.STATIONARY_CONTRAPTION.get();
|
||||||
forcedAngle = -1;
|
forcedAngle = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ContraptionEntity createMounted(World world, Contraption contraption, float initialAngle) {
|
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.contraption = contraption;
|
||||||
entity.initialAngle = initialAngle;
|
entity.initialAngle = initialAngle;
|
||||||
entity.forceYaw(initialAngle);
|
entity.forceYaw(initialAngle);
|
||||||
|
@ -112,7 +112,7 @@ public class ContraptionEntity extends Entity implements IEntityAdditionalSpawnD
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ContraptionEntity createStationary(World world, Contraption contraption) {
|
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;
|
entity.contraption = contraption;
|
||||||
if (contraption != null)
|
if (contraption != null)
|
||||||
contraption.gatherStoredItems();
|
contraption.gatherStoredItems();
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat
|
||||||
}
|
}
|
||||||
|
|
||||||
public SuperGlueEntity(World world, BlockPos pos, Direction direction) {
|
public SuperGlueEntity(World world, BlockPos pos, Direction direction) {
|
||||||
this(AllEntityTypes.SUPER_GLUE.type, world);
|
this(AllEntityTypes.SUPER_GLUE.get(), world);
|
||||||
hangingPosition = pos;
|
hangingPosition = pos;
|
||||||
facingDirection = direction;
|
facingDirection = direction;
|
||||||
updateFacingWithBoundingBox();
|
updateFacingWithBoundingBox();
|
||||||
|
|
Loading…
Reference in a new issue