2019-10-05 19:00:43 +02:00
|
|
|
package com.simibubi.create;
|
|
|
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
2020-02-15 18:54:23 +01:00
|
|
|
import com.simibubi.create.foundation.utility.Lang;
|
2019-12-12 11:58:29 +01:00
|
|
|
import com.simibubi.create.modules.contraptions.components.contraptions.ContraptionEntity;
|
|
|
|
import com.simibubi.create.modules.contraptions.components.contraptions.ContraptionEntityRenderer;
|
2019-10-05 19:00:43 +02:00
|
|
|
|
|
|
|
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 AllEntities {
|
|
|
|
|
2020-03-14 17:56:45 +01:00
|
|
|
CONTRAPTION(ContraptionEntity::new, EntityClassification.MISC, 30, 3, true,
|
|
|
|
ContraptionEntity::build),
|
|
|
|
STATIONARY_CONTRAPTION(ContraptionEntity::new, EntityClassification.MISC, 30, 40,
|
|
|
|
false, ContraptionEntity::build),
|
2019-10-05 19:00:43 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
private IFactory<?> factory;
|
|
|
|
private int range;
|
|
|
|
private int updateFrequency;
|
|
|
|
private Function<EntityType.Builder<? extends Entity>, EntityType.Builder<? extends Entity>> propertyBuilder;
|
|
|
|
private EntityClassification group;
|
2020-02-15 18:54:23 +01:00
|
|
|
private boolean sendVelocity;
|
2019-10-05 19:00:43 +02:00
|
|
|
|
|
|
|
public EntityType<? extends Entity> type;
|
|
|
|
|
2020-03-14 17:56:45 +01:00
|
|
|
private AllEntities(IFactory<?> factory, EntityClassification group, int range, int updateFrequency,
|
|
|
|
boolean sendVelocity,
|
2019-10-05 19:00:43 +02:00
|
|
|
Function<EntityType.Builder<? extends Entity>, EntityType.Builder<? extends Entity>> propertyBuilder) {
|
|
|
|
this.factory = factory;
|
2020-03-14 17:56:45 +01:00
|
|
|
this.group = group;
|
2019-10-05 19:00:43 +02:00
|
|
|
this.range = range;
|
|
|
|
this.updateFrequency = updateFrequency;
|
2020-02-15 18:54:23 +01:00
|
|
|
this.sendVelocity = sendVelocity;
|
2019-10-05 19:00:43 +02:00
|
|
|
this.propertyBuilder = propertyBuilder;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void register(final RegistryEvent.Register<EntityType<?>> event) {
|
|
|
|
for (AllEntities entity : values()) {
|
2020-02-15 18:54:23 +01:00
|
|
|
String id = Lang.asId(entity.name());
|
2019-10-05 19:00:43 +02:00
|
|
|
ResourceLocation resourceLocation = new ResourceLocation(Create.ID, id);
|
|
|
|
Builder<? extends Entity> builder = EntityType.Builder.create(entity.factory, entity.group)
|
|
|
|
.setTrackingRange(entity.range).setUpdateInterval(entity.updateFrequency)
|
2020-02-15 18:54:23 +01:00
|
|
|
.setShouldReceiveVelocityUpdates(entity.sendVelocity);
|
2019-10-05 19:00:43 +02:00
|
|
|
if (entity.propertyBuilder != null)
|
|
|
|
builder = entity.propertyBuilder.apply(builder);
|
|
|
|
entity.type = builder.build(id).setRegistryName(resourceLocation);
|
|
|
|
event.getRegistry().register(entity.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@OnlyIn(value = Dist.CLIENT)
|
|
|
|
public static void registerRenderers() {
|
2020-01-26 23:58:55 +01:00
|
|
|
// RenderingRegistry.registerEntityRenderingHandler(CardboardBoxEntity.class, CardboardBoxEntityRenderer::new);
|
2019-10-27 14:15:39 +01:00
|
|
|
RenderingRegistry.registerEntityRenderingHandler(ContraptionEntity.class, ContraptionEntityRenderer::new);
|
2019-10-05 19:00:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|