From bb0263bbd81ab07997fe3200f89cd1e06f3e3fe7 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 21 Nov 2018 20:36:55 +0100 Subject: [PATCH] move ITrinketItem to the API and add ITESRProvider to the mod --- .../render}/ITrinketItem.java | 7 ++-- .../naturesaura/blocks/BlockNatureAltar.java | 14 +++++++- .../blocks/BlockOfferingTable.java | 14 +++++++- .../naturesaura/blocks/BlockWoodStand.java | 14 +++++++- .../naturesaura/items/ItemAuraCache.java | 3 +- .../de/ellpeck/naturesaura/items/ItemEye.java | 3 +- .../items/ItemShockwaveCreator.java | 9 ++---- .../naturesaura/proxy/ClientProxy.java | 13 +++++--- .../de/ellpeck/naturesaura/proxy/IProxy.java | 5 +-- .../naturesaura/proxy/ServerProxy.java | 7 +++- .../naturesaura/reg/ITESRProvider.java | 13 ++++++++ .../ellpeck/naturesaura/reg/ModRegistry.java | 32 ++++++++----------- .../renderers/PlayerLayerTrinkets.java | 6 ++-- 13 files changed, 95 insertions(+), 45 deletions(-) rename src/main/java/de/ellpeck/naturesaura/{renderers => api/render}/ITrinketItem.java (74%) create mode 100644 src/main/java/de/ellpeck/naturesaura/reg/ITESRProvider.java diff --git a/src/main/java/de/ellpeck/naturesaura/renderers/ITrinketItem.java b/src/main/java/de/ellpeck/naturesaura/api/render/ITrinketItem.java similarity index 74% rename from src/main/java/de/ellpeck/naturesaura/renderers/ITrinketItem.java rename to src/main/java/de/ellpeck/naturesaura/api/render/ITrinketItem.java index d239f085..88d6635a 100644 --- a/src/main/java/de/ellpeck/naturesaura/renderers/ITrinketItem.java +++ b/src/main/java/de/ellpeck/naturesaura/api/render/ITrinketItem.java @@ -1,13 +1,16 @@ -package de.ellpeck.naturesaura.renderers; +package de.ellpeck.naturesaura.api.render; -import de.ellpeck.naturesaura.renderers.PlayerLayerTrinkets.RenderType; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public interface ITrinketItem { + enum RenderType { + HEAD, BODY + } @SideOnly(Side.CLIENT) void render(ItemStack stack, EntityPlayer player, RenderType type, boolean isHolding); + } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockNatureAltar.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockNatureAltar.java index 04633cdc..584d28cf 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockNatureAltar.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockNatureAltar.java @@ -2,18 +2,24 @@ package de.ellpeck.naturesaura.blocks; import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.blocks.tiles.TileEntityNatureAltar; +import de.ellpeck.naturesaura.blocks.tiles.render.RenderNatureAltar; +import de.ellpeck.naturesaura.reg.ITESRProvider; import net.minecraft.block.material.Material; import net.minecraft.block.state.BlockFaceShape; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; +import net.minecraft.util.Tuple; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; -public class BlockNatureAltar extends BlockContainerImpl { +public class BlockNatureAltar extends BlockContainerImpl implements ITESRProvider { private static final AxisAlignedBB BOUND_BOX = new AxisAlignedBB(0F, 0F, 0F, 1F, 12 / 16F, 1F); @@ -57,4 +63,10 @@ public class BlockNatureAltar extends BlockContainerImpl { public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face) { return BlockFaceShape.UNDEFINED; } + + @Override + @SideOnly(Side.CLIENT) + public Tuple getTESR() { + return new Tuple<>(TileEntityNatureAltar.class, new RenderNatureAltar()); + } } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockOfferingTable.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockOfferingTable.java index 431abaf2..e74b64cd 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockOfferingTable.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockOfferingTable.java @@ -2,19 +2,25 @@ package de.ellpeck.naturesaura.blocks; import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.blocks.tiles.TileEntityOfferingTable; +import de.ellpeck.naturesaura.blocks.tiles.render.RenderOfferingTable; +import de.ellpeck.naturesaura.reg.ITESRProvider; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.state.BlockFaceShape; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; +import net.minecraft.util.Tuple; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; -public class BlockOfferingTable extends BlockContainerImpl { +public class BlockOfferingTable extends BlockContainerImpl implements ITESRProvider { private static final AxisAlignedBB BOUND_BOX = new AxisAlignedBB(2 / 16F, 0F, 2 / 16F, 14 / 16F, 1F, 14 / 16F); @@ -58,4 +64,10 @@ public class BlockOfferingTable extends BlockContainerImpl { public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face) { return BlockFaceShape.UNDEFINED; } + + @Override + @SideOnly(Side.CLIENT) + public Tuple getTESR() { + return new Tuple<>(TileEntityOfferingTable.class, new RenderOfferingTable()); + } } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockWoodStand.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockWoodStand.java index 08cbfb9b..718b25af 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockWoodStand.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockWoodStand.java @@ -5,16 +5,20 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.recipes.TreeRitualRecipe; import de.ellpeck.naturesaura.blocks.multi.Multiblocks; import de.ellpeck.naturesaura.blocks.tiles.TileEntityWoodStand; +import de.ellpeck.naturesaura.blocks.tiles.render.RenderWoodStand; +import de.ellpeck.naturesaura.reg.ITESRProvider; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.state.BlockFaceShape; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.Ingredient; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; +import net.minecraft.util.Tuple; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; @@ -22,13 +26,15 @@ import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.terraingen.SaplingGrowTreeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; import org.apache.commons.lang3.mutable.MutableObject; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -public class BlockWoodStand extends BlockContainerImpl { +public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider { private static final AxisAlignedBB BOUND_BOX = new AxisAlignedBB(3 / 16F, 0F, 3 / 16F, 13 / 16F, 13 / 16F, 13 / 16F); @@ -123,4 +129,10 @@ public class BlockWoodStand extends BlockContainerImpl { public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face) { return BlockFaceShape.UNDEFINED; } + + @Override + @SideOnly(Side.CLIENT) + public Tuple getTESR() { + return new Tuple<>(TileEntityWoodStand.class, new RenderWoodStand()); + } } diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemAuraCache.java b/src/main/java/de/ellpeck/naturesaura/items/ItemAuraCache.java index e6b4be72..9a43d975 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ItemAuraCache.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemAuraCache.java @@ -4,8 +4,7 @@ import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.aura.container.IAuraContainer; import de.ellpeck.naturesaura.api.aura.container.ItemAuraContainer; -import de.ellpeck.naturesaura.renderers.ITrinketItem; -import de.ellpeck.naturesaura.renderers.PlayerLayerTrinkets.RenderType; +import de.ellpeck.naturesaura.api.render.ITrinketItem; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemEye.java b/src/main/java/de/ellpeck/naturesaura/items/ItemEye.java index 34a5c697..c0720035 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ItemEye.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemEye.java @@ -1,8 +1,7 @@ package de.ellpeck.naturesaura.items; import de.ellpeck.naturesaura.Helper; -import de.ellpeck.naturesaura.renderers.ITrinketItem; -import de.ellpeck.naturesaura.renderers.PlayerLayerTrinkets.RenderType; +import de.ellpeck.naturesaura.api.render.ITrinketItem; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.EntityEquipmentSlot; diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemShockwaveCreator.java b/src/main/java/de/ellpeck/naturesaura/items/ItemShockwaveCreator.java index 59781ab8..93a8019b 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ItemShockwaveCreator.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemShockwaveCreator.java @@ -1,12 +1,10 @@ package de.ellpeck.naturesaura.items; -import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.api.NaturesAuraAPI; +import de.ellpeck.naturesaura.api.render.ITrinketItem; import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketParticles; -import de.ellpeck.naturesaura.renderers.ITrinketItem; -import de.ellpeck.naturesaura.renderers.PlayerLayerTrinkets; import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; @@ -16,7 +14,6 @@ import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.EntityEquipmentSlot; @@ -115,8 +112,8 @@ public class ItemShockwaveCreator extends ItemImpl implements ITrinketItem { @Override @SideOnly(Side.CLIENT) - public void render(ItemStack stack, EntityPlayer player, PlayerLayerTrinkets.RenderType type, boolean isHolding) { - if (type == PlayerLayerTrinkets.RenderType.BODY && !isHolding) { + public void render(ItemStack stack, EntityPlayer player, RenderType type, boolean isHolding) { + if (type == RenderType.BODY && !isHolding) { boolean armor = !player.inventory.armorInventory.get(EntityEquipmentSlot.CHEST.getIndex()).isEmpty(); GlStateManager.translate(-0.1675F, -0.05F, armor ? -0.195F : -0.1475F); GlStateManager.scale(0.021F, 0.021F, 0.021F); diff --git a/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java b/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java index 3425b97b..0607a8aa 100644 --- a/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java +++ b/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java @@ -11,6 +11,7 @@ import de.ellpeck.naturesaura.particles.ParticleHandler; import de.ellpeck.naturesaura.particles.ParticleMagic; import de.ellpeck.naturesaura.reg.IColorProvidingBlock; import de.ellpeck.naturesaura.reg.IColorProvidingItem; +import de.ellpeck.naturesaura.reg.ITESRProvider; import de.ellpeck.naturesaura.renderers.PlayerLayerTrinkets; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; @@ -18,8 +19,10 @@ import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.color.IItemColor; import net.minecraft.client.renderer.color.ItemColors; import net.minecraft.client.renderer.entity.RenderPlayer; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.Tuple; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.client.registry.ClientRegistry; @@ -38,10 +41,6 @@ public class ClientProxy implements IProxy { @Override public void init(FMLInitializationEvent event) { - ClientRegistry.bindTileEntitySpecialRenderer(TileEntityWoodStand.class, new RenderWoodStand()); - ClientRegistry.bindTileEntitySpecialRenderer(TileEntityNatureAltar.class, new RenderNatureAltar()); - ClientRegistry.bindTileEntitySpecialRenderer(TileEntityOfferingTable.class, new RenderOfferingTable()); - Map skinMap = Minecraft.getMinecraft().getRenderManager().getSkinMap(); for (RenderPlayer render : new RenderPlayer[]{skinMap.get("default"), skinMap.get("slim")}) { render.addLayer(new PlayerLayerTrinkets()); @@ -77,6 +76,12 @@ public class ClientProxy implements IProxy { } } + @Override + public void registerTESR(ITESRProvider provider) { + Tuple tesr = provider.getTESR(); + ClientRegistry.bindTileEntitySpecialRenderer(tesr.getFirst(), tesr.getSecond()); + } + @Override public void spawnMagicParticle(double posX, double posY, double posZ, double motionX, double motionY, double motionZ, int color, float scale, int maxAge, float gravity, boolean collision, boolean fade) { ParticleHandler.spawnParticle(() -> new ParticleMagic(Minecraft.getMinecraft().world, diff --git a/src/main/java/de/ellpeck/naturesaura/proxy/IProxy.java b/src/main/java/de/ellpeck/naturesaura/proxy/IProxy.java index 31f4fbfc..0a4b2a9b 100644 --- a/src/main/java/de/ellpeck/naturesaura/proxy/IProxy.java +++ b/src/main/java/de/ellpeck/naturesaura/proxy/IProxy.java @@ -2,10 +2,9 @@ package de.ellpeck.naturesaura.proxy; import de.ellpeck.naturesaura.reg.IColorProvidingBlock; import de.ellpeck.naturesaura.reg.IColorProvidingItem; +import de.ellpeck.naturesaura.reg.ITESRProvider; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.World; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; @@ -23,6 +22,8 @@ public interface IProxy { void addColorProvidingBlock(IColorProvidingBlock block); + void registerTESR(ITESRProvider provider); + void spawnMagicParticle(double posX, double posY, double posZ, double motionX, double motionY, double motionZ, int color, float scale, int maxAge, float gravity, boolean collision, boolean fade); void scheduleTask(Runnable runnable); diff --git a/src/main/java/de/ellpeck/naturesaura/proxy/ServerProxy.java b/src/main/java/de/ellpeck/naturesaura/proxy/ServerProxy.java index 6ad77fd2..67c0b72e 100644 --- a/src/main/java/de/ellpeck/naturesaura/proxy/ServerProxy.java +++ b/src/main/java/de/ellpeck/naturesaura/proxy/ServerProxy.java @@ -2,9 +2,9 @@ package de.ellpeck.naturesaura.proxy; import de.ellpeck.naturesaura.reg.IColorProvidingBlock; import de.ellpeck.naturesaura.reg.IColorProvidingItem; +import de.ellpeck.naturesaura.reg.ITESRProvider; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.item.ItemStack; -import net.minecraft.world.World; import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; @@ -42,6 +42,11 @@ public class ServerProxy implements IProxy { } + @Override + public void registerTESR(ITESRProvider provider) { + + } + @Override public void spawnMagicParticle(double posX, double posY, double posZ, double motionX, double motionY, double motionZ, int color, float scale, int maxAge, float gravity, boolean collision, boolean fade) { diff --git a/src/main/java/de/ellpeck/naturesaura/reg/ITESRProvider.java b/src/main/java/de/ellpeck/naturesaura/reg/ITESRProvider.java new file mode 100644 index 00000000..2c150201 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/reg/ITESRProvider.java @@ -0,0 +1,13 @@ +package de.ellpeck.naturesaura.reg; + +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.util.Tuple; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public interface ITESRProvider { + + @SideOnly(Side.CLIENT) + Tuple getTESR(); + +} diff --git a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java index 8e627265..a9d4ea26 100644 --- a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java +++ b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java @@ -29,11 +29,10 @@ public final class ModRegistry { item.setRegistryName(NaturesAura.MOD_ID, name); ForgeRegistries.ITEMS.register(item); - if (addCreative) { + if (addCreative) item.setCreativeTab(NaturesAura.CREATIVE_TAB); - } else { + else item.setCreativeTab(null); - } } private static void registerBlock(Block block, String name, ItemBlock item, boolean addCreative) { @@ -45,36 +44,32 @@ public final class ModRegistry { item.setRegistryName(block.getRegistryName()); ForgeRegistries.ITEMS.register(item); - if (addCreative) { + if (addCreative) block.setCreativeTab(NaturesAura.CREATIVE_TAB); - } else { + else block.setCreativeTab(null); - } } public static void preInit(FMLPreInitializationEvent event) { for (IModItem item : ALL_ITEMS) { - if (item instanceof Item) { + if (item instanceof Item) registerItem((Item) item, item.getBaseName(), item.shouldAddCreative()); - } else if (item instanceof Block) { + else if (item instanceof Block) { Block block = (Block) item; ItemBlock itemBlock; - if (item instanceof ICustomItemBlockProvider) { + if (item instanceof ICustomItemBlockProvider) itemBlock = ((ICustomItemBlockProvider) item).getItemBlock(); - } else { + else itemBlock = new ItemBlock(block); - } registerBlock(block, item.getBaseName(), itemBlock, item.shouldAddCreative()); } if (item instanceof IModelProvider) { Map models = ((IModelProvider) item).getModelLocations(); - - for (ItemStack stack : models.keySet()) { + for (ItemStack stack : models.keySet()) NaturesAura.proxy.registerRenderer(stack, models.get(stack)); - } } item.onPreInit(event); @@ -83,13 +78,12 @@ public final class ModRegistry { public static void init(FMLInitializationEvent event) { for (IModItem item : ALL_ITEMS) { - if (item instanceof IColorProvidingBlock) { + if (item instanceof IColorProvidingBlock) NaturesAura.proxy.addColorProvidingBlock((IColorProvidingBlock) item); - } - - if (item instanceof IColorProvidingItem) { + if (item instanceof IColorProvidingItem) NaturesAura.proxy.addColorProvidingItem((IColorProvidingItem) item); - } + if (item instanceof ITESRProvider) + NaturesAura.proxy.registerTESR((ITESRProvider) item); item.onInit(event); } diff --git a/src/main/java/de/ellpeck/naturesaura/renderers/PlayerLayerTrinkets.java b/src/main/java/de/ellpeck/naturesaura/renderers/PlayerLayerTrinkets.java index be28ea61..e7536a53 100644 --- a/src/main/java/de/ellpeck/naturesaura/renderers/PlayerLayerTrinkets.java +++ b/src/main/java/de/ellpeck/naturesaura/renderers/PlayerLayerTrinkets.java @@ -1,6 +1,8 @@ package de.ellpeck.naturesaura.renderers; import baubles.api.BaublesApi; +import de.ellpeck.naturesaura.api.render.ITrinketItem; +import de.ellpeck.naturesaura.api.render.ITrinketItem.RenderType; import de.ellpeck.naturesaura.compat.Compat; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.entity.layers.LayerRenderer; @@ -76,8 +78,4 @@ public class PlayerLayerTrinkets implements LayerRenderer { public boolean shouldCombineTextures() { return false; } - - public enum RenderType { - HEAD, BODY - } } \ No newline at end of file