From ae14dd18e79accaad89da9c93d9a2d3b9e23845a Mon Sep 17 00:00:00 2001 From: Adubbz Date: Sat, 25 May 2019 11:09:26 +1000 Subject: [PATCH] Fixed entities --- .../client/render/RenderMudball.java | 12 ++++ .../biomesoplenty/core/BiomesOPlenty.java | 7 +- .../java/biomesoplenty/core/ClientProxy.java | 12 +--- .../java/biomesoplenty/core/CommonProxy.java | 1 - .../java/biomesoplenty/init/ModEntities.java | 68 ++++--------------- 5 files changed, 33 insertions(+), 67 deletions(-) create mode 100644 src/main/java/biomesoplenty/client/render/RenderMudball.java diff --git a/src/main/java/biomesoplenty/client/render/RenderMudball.java b/src/main/java/biomesoplenty/client/render/RenderMudball.java new file mode 100644 index 000000000..0e441ae90 --- /dev/null +++ b/src/main/java/biomesoplenty/client/render/RenderMudball.java @@ -0,0 +1,12 @@ +/******************************************************************************* + * Copyright 2014-2019, the Biomes O' Plenty Team + * + * This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License. + * + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. + ******************************************************************************/ +package biomesoplenty.client.render; + +public class RenderMudball +{ +} diff --git a/src/main/java/biomesoplenty/core/BiomesOPlenty.java b/src/main/java/biomesoplenty/core/BiomesOPlenty.java index 9bf1c1ca3..4a3cb99cb 100644 --- a/src/main/java/biomesoplenty/core/BiomesOPlenty.java +++ b/src/main/java/biomesoplenty/core/BiomesOPlenty.java @@ -9,9 +9,14 @@ package biomesoplenty.core; import biomesoplenty.common.command.BOPCommand; +import biomesoplenty.common.entity.projectile.EntityMudball; import biomesoplenty.init.*; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.entity.RenderSprite; +import net.minecraft.init.Items; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.DistExecutor; +import net.minecraftforge.fml.client.registry.RenderingRegistry; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent; @@ -47,7 +52,7 @@ public class BiomesOPlenty private void clientSetup(final FMLClientSetupEvent event) { - proxy.registerRenderers(); + ModEntities.registerRendering(); } private void loadComplete(final FMLLoadCompleteEvent event) // PostRegistrationEven diff --git a/src/main/java/biomesoplenty/core/ClientProxy.java b/src/main/java/biomesoplenty/core/ClientProxy.java index b8ce65359..6243f3656 100644 --- a/src/main/java/biomesoplenty/core/ClientProxy.java +++ b/src/main/java/biomesoplenty/core/ClientProxy.java @@ -18,6 +18,7 @@ import net.minecraft.client.renderer.color.BlockColors; import net.minecraft.client.renderer.color.ItemColors; import net.minecraft.client.renderer.entity.RenderSprite; import net.minecraft.entity.Entity; +import net.minecraft.init.Items; import net.minecraft.init.Particles; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; @@ -37,17 +38,6 @@ public class ClientProxy extends CommonProxy } - @Override - public void registerRenderers() - { - RenderingRegistry.registerEntityRenderingHandler(EntityMudball.class, manager -> - { - BiomesOPlenty.logger.info("Creating sprite renderer"); - BiomesOPlenty.logger.info(Minecraft.getInstance().getItemRenderer() == null); - return new RenderSprite(manager, BOPItems.mudball, Minecraft.getInstance().getItemRenderer()); - }); - } - @Override public void init() { diff --git a/src/main/java/biomesoplenty/core/CommonProxy.java b/src/main/java/biomesoplenty/core/CommonProxy.java index 038ac3452..3b8ca7279 100644 --- a/src/main/java/biomesoplenty/core/CommonProxy.java +++ b/src/main/java/biomesoplenty/core/CommonProxy.java @@ -17,7 +17,6 @@ public class CommonProxy } - public void registerRenderers() {} public void init() {} public void spawnParticle(BOPParticleTypes type, World parWorld, double x, double y, double z, Object... info) {} diff --git a/src/main/java/biomesoplenty/init/ModEntities.java b/src/main/java/biomesoplenty/init/ModEntities.java index 7c024725e..4260d099e 100644 --- a/src/main/java/biomesoplenty/init/ModEntities.java +++ b/src/main/java/biomesoplenty/init/ModEntities.java @@ -11,84 +11,44 @@ import static biomesoplenty.api.entity.BOPEntities.*; import java.util.function.Function; +import biomesoplenty.api.item.BOPItems; +import biomesoplenty.core.BiomesOPlenty; import com.mojang.datafixers.DataFixUtils; import com.mojang.datafixers.types.Type; import biomesoplenty.common.entity.item.EntityBoatBOP; import biomesoplenty.common.entity.projectile.EntityMudball; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.entity.RenderSprite; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; +import net.minecraft.init.Items; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.datafix.DataFixesManager; import net.minecraft.util.datafix.TypeReferences; import net.minecraft.world.World; +import net.minecraftforge.fml.client.registry.RenderingRegistry; import net.minecraftforge.registries.ForgeRegistries; public class ModEntities { public static void init() { - mudball = registerEntity(FixedEntityTypeBuilder.create(EntityMudball.class, EntityMudball::new), "mudball"); - boat_bop = registerEntity(FixedEntityTypeBuilder.create(EntityBoatBOP.class, EntityBoatBOP::new), "boat_bop"); + mudball = createEntity(EntityMudball.class, EntityMudball::new, "mudball", 64, 10, true); + boat_bop = createEntity(EntityBoatBOP.class, EntityBoatBOP::new, "boat_bop", 80, 3, true); } - public static EntityType registerEntity(FixedEntityTypeBuilder typeBuilder, String name) + public static EntityType createEntity(Class entityClass, Function entityInstance, String name, int trackingRange, int updateFrequency, boolean sendsVelocityUpdates) { - EntityType type = typeBuilder.build("biomesoplenty:" + name); + ResourceLocation location = new ResourceLocation("biomesoplenty", name); + EntityType type = EntityType.Builder.create(entityClass, entityInstance).tracker(trackingRange, updateFrequency, sendsVelocityUpdates).build(location.toString()); type.setRegistryName(name); ForgeRegistries.ENTITIES.register(type); return type; } - // TODO: Remove this once Forge has fixed the bugs with calling build in - // EntityType.Builder, causing an exception when registering entities - public static class FixedEntityTypeBuilder + public static void registerRendering() { - private final Class entityClass; - private final Function factory; - private boolean serializable = true; - private boolean summonable = true; - - private FixedEntityTypeBuilder(Class entityClassIn, Function factoryIn) - { - this.entityClass = entityClassIn; - this.factory = factoryIn; - } - - public static FixedEntityTypeBuilder create(Class entityClassIn, Function factoryIn) - { - return new FixedEntityTypeBuilder(entityClassIn, factoryIn); - } - - public static FixedEntityTypeBuilder createNothing(Class entityClassIn) - { - return new FixedEntityTypeBuilder(entityClassIn, (p_200708_0_) -> { - return null; - }); - } - - public FixedEntityTypeBuilder disableSummoning() - { - this.summonable = false; - return this; - } - - public FixedEntityTypeBuilder disableSerialization() - { - this.serializable = false; - return this; - } - - public EntityType build(String id) { - Type type = null; - if (this.serializable) { - try { - type = DataFixesManager.getDataFixer().getSchema(DataFixUtils.makeKey(1519)).getChoiceType(TypeReferences.ENTITY_TYPE, id); - } catch (IllegalArgumentException e) { - // Ignore, we don't care - } - } - - return new EntityType(this.entityClass, this.factory, this.serializable, this.summonable, type); - } + RenderingRegistry.registerEntityRenderingHandler(EntityMudball.class, manager -> new RenderSprite<>(manager, BOPItems.mudball, Minecraft.getInstance().getItemRenderer())); } }