move ITrinketItem to the API and add ITESRProvider to the mod

This commit is contained in:
Ellpeck 2018-11-21 20:36:55 +01:00
parent 6275a326de
commit bb0263bbd8
13 changed files with 95 additions and 45 deletions

View file

@ -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);
}

View file

@ -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<Class, TileEntitySpecialRenderer> getTESR() {
return new Tuple<>(TileEntityNatureAltar.class, new RenderNatureAltar());
}
}

View file

@ -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<Class, TileEntitySpecialRenderer> getTESR() {
return new Tuple<>(TileEntityOfferingTable.class, new RenderOfferingTable());
}
}

View file

@ -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<Class, TileEntitySpecialRenderer> getTESR() {
return new Tuple<>(TileEntityWoodStand.class, new RenderWoodStand());
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -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<String, RenderPlayer> 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<Class, TileEntitySpecialRenderer> 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,

View file

@ -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);

View file

@ -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) {

View file

@ -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<Class, TileEntitySpecialRenderer> getTESR();
}

View file

@ -29,12 +29,11 @@ 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) {
block.setTranslationKey(NaturesAura.MOD_ID + "." + name);
@ -45,37 +44,33 @@ 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<ItemStack, ModelResourceLocation> 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);
}

View file

@ -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<EntityPlayer> {
public boolean shouldCombineTextures() {
return false;
}
public enum RenderType {
HEAD, BODY
}
}