gegy1000 Posted August 9, 2015 Share Posted August 9, 2015 I am currently making a block similar to a mob spawner, it renders an entity inside it. I am using a TESR, just like the mob spawner and everything renders fine. However, I want it to save the entity that is inside it, and still render it while it is an ItemStack. I looked through the MC code and found that mob spawners actually use an ItemBlock. So I have set my block to use an ItemBlock too. This didn't change anything, not that I expected it to. So I looked some more into the MC code and I can't find anything that may be of use to this, so I've come here. Here is some of my code: package net.timeless.jurassicraft.common.block; import net.minecraft.block.material.Material; import net.minecraft.item.ItemBlock; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumWorldBlockLayer; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import net.timeless.jurassicraft.common.api.ISubBlocksBlock; import net.timeless.jurassicraft.common.creativetab.JCCreativeTabs; import net.timeless.jurassicraft.common.item.ItemCage; import net.timeless.jurassicraft.common.tileentity.TileCage; public class BlockCage extends BlockOriented { public BlockCage() { super(Material.iron); this.setUnlocalizedName("cage_small"); this.setHardness(1.0F); this.setResistance(1.0F); this.setCreativeTab(JCCreativeTabs.blocks); } @SideOnly(Side.CLIENT) public EnumWorldBlockLayer getBlockLayer() { return EnumWorldBlockLayer.CUTOUT; } @Override public boolean isOpaqueCube() { return false; } @Override public boolean isFullCube() { return false; } @SideOnly(Side.CLIENT) public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side) { return true; } @Override public TileEntity createNewTileEntity(World world, int meta) { return new TileCage(); } } BlockRegistry: GameRegistry.registerBlock(cage_small, ItemCage.class, "cage_small"); GameRegistry.registerTileEntity(TileCage.class, "cage_small"); ItemCage: package net.timeless.jurassicraft.common.item; import net.minecraft.block.Block; import net.minecraft.item.ItemBlock; public class ItemCage extends ItemBlock { public ItemCage(Block block) { super(block); this.setUnlocalizedName("cage_small"); } } TileCage: package net.timeless.jurassicraft.common.tileentity; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; public class TileCage extends TileEntity { private Entity entity; public void setEntity(Entity entity) { this.entity = entity; } public Entity getEntity() { return entity; } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); int entityID = compound.getInteger("EntityID"); if(entityID != -1) { NBTTagCompound entityTag = compound.getCompoundTag("Entity"); entity = EntityList.createEntityByID(entityID, worldObj); entity.readFromNBT(entityTag); } } @Override public void writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); NBTTagCompound entityTag = new NBTTagCompound(); if(entity != null) { entity.writeToNBT(entityTag); compound.setInteger("EntityID", EntityList.getEntityID(entity)); } else { compound.setInteger("EntityID", -1); } compound.setTag("Entity", entityTag); } } TESR: package net.timeless.jurassicraft.client.render.tileentity; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.entity.Entity; import net.minecraft.entity.passive.EntityCow; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.timeless.jurassicraft.common.entity.*; import net.timeless.jurassicraft.common.tileentity.TileCage; public class TileEntityRendererCage extends TileEntitySpecialRenderer { private static final Minecraft mc = Minecraft.getMinecraft(); @Override public void renderTileEntityAt(TileEntity tile, double posX, double posY, double posZ, float partialTicks, int p_180535_9_) { GlStateManager.pushMatrix(); TileCage cage = (TileCage) tile; Entity entity = cage.getEntity(); if(entity == null) { entity = new EntityGallimimus(tile.getWorld()); cage.setEntity(entity); } GlStateManager.translate((float)posX + 0.5F, (float)posY, (float)posZ + 0.5F); float f1 = 0.5F; GlStateManager.translate(0.0F, 0.4F, 0.0F); EnumFacing front = EnumFacing.getFront(tile.getBlockMetadata()); if(front == EnumFacing.EAST) front = EnumFacing.WEST; else if(front == EnumFacing.WEST) front = EnumFacing.EAST; GlStateManager.rotate((front.getHorizontalIndex()) * 90, 0, 1, 0); GlStateManager.translate(0.0F, -0.4F, 0.0F); entity.setLocationAndAngles(posX, posY, posZ, 0.0F, 0.0F); mc.getRenderManager().renderEntityWithPosYaw(entity, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F); GlStateManager.popMatrix(); } } RenderingRegistry: ClientRegistry.bindTileEntitySpecialRenderer(TileCage.class, new TileEntityRendererCage()); Thanks - gegy1000 Quote Link to comment Share on other sites More sharing options...
gegy1000 Posted August 10, 2015 Author Share Posted August 10, 2015 In 1.7.10 you would solve this using IItemRenderer. In 1.8 there is currently no way to do this as far as I'm aware. Okay, I'll leave out the rendering for now. But I still need to keep the data in the ItemStack NBT from the TileEntity. Quote Link to comment Share on other sites More sharing options...
TheGreyGhost Posted August 10, 2015 Share Posted August 10, 2015 In 1.7.10 you would solve this using IItemRenderer. In 1.8 there is currently no way to do this as far as I'm aware. There is a way, but the Forge Code Purity Police censor it out every time it gets mentioned on this forum A google on TileEntityItemStackRenderer.instance may show it up. -TGG Quote Link to comment Share on other sites More sharing options...
delpi Posted August 10, 2015 Share Posted August 10, 2015 There is an another way (probably will be disliked). 1st person view is a bit ugly, still working on that part. Create the render for the item as a modelbiped Extend a livingrender event (or whichever one you like) and only override the gettexture part In the json item model, set the scale for 3rd person to 0,0,0. (for a piece of armor, provide a texture that is empty) Watch the event for playerrender post If the player has the item in hand, pass the render details to your custom render above. Bam, item in hand. Full model. No need to figure out angles, ect. It just works. Can use this for armor, ect. I actually created a how render manager class of my own to track all this just for simplicity but overkill if doing one item. Now, should you do this if don't have a fair amount of experience? no. Quote Long time Bukkit & Forge Programmer Happy to try and help Link to comment Share on other sites More sharing options...
gegy1000 Posted August 10, 2015 Author Share Posted August 10, 2015 ItemStack.getStackTagCompound gives you an NBTTagCompound where you can put your data. Yes - I know that, but I was wondering if Minecraft had something built into it that copies data from tileentity to itemstack. Anyway, I'll just write that code manually then. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.