Posted October 8, 201213 yr I have been creating a block that has a tile entity in it. The Gui shows, however what happens is when the world reloads, the block is no longer in it's place BlockFile package kintick.Minecraft.Ademantine.client; import cpw.mods.fml.common.Side; import cpw.mods.fml.common.asm.SideOnly; import java.io.Console; import java.util.List; import java.util.Random; import kintick.Minecraft.Ademantine.CommonProxy; import net.minecraft.src.Block; import net.minecraft.src.BlockBreakable; import net.minecraft.src.BlockContainer; import net.minecraft.src.CreativeTabs; import net.minecraft.src.Entity; import net.minecraft.src.EntityItem; import net.minecraft.src.EntityLiving; import net.minecraft.src.EntityPlayer; import net.minecraft.src.EntityTNTPrimed; import net.minecraft.src.IBlockAccess; import net.minecraft.src.IInventory; import net.minecraft.src.Item; import net.minecraft.src.ItemStack; import net.minecraft.src.Material; import net.minecraft.src.MathHelper; import net.minecraft.src.NBTTagCompound; import net.minecraft.src.TileEntity; import net.minecraft.src.TileEntityFurnace; import net.minecraft.src.TileEntityNote; import net.minecraft.src.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.UseHoeEvent; public class BlockFile extends BlockContainer { private boolean isActive = false; private boolean isOverheat = false; private int ticks = 0; private int overHeatVal = 100; private int overHeatTicking = 0; private int maxOverHeat = 50; private boolean hasFuel; protected BlockFile(int par1,int Texture, Material material) { super(par1, Texture, material); } @Override public String getTextureFile () { return CommonProxy.BLOCK_PNG; } /** * Returns the quantity of items to drop on block destruction. */ public int quantityDropped(Random par1Random) { return 1; } /** * Returns the ID of the items to drop on destruction. */ public int idDropped(int par1, Random par2Random, int par3) { return Generic.blockFile.blockID; } public int getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) { if (par5 == 1) { return 5; } else if (par5 == 0) { return 7; } else { return 6; } } public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random) { //updates ticks if (this.isActive) { ticks = ticks + 1; } else { ticks = ticks - 1; if(overHeatTicking > 0) { overHeatTicking = overHeatTicking - 1; } } //checking ticks if (ticks > overHeatVal) { this.isOverheat = true; } else { this.isOverheat = false; } //Overheat checking if (this.isOverheat) { overHeatTicking = overHeatTicking + 1; } if (overHeatTicking > maxOverHeat) { //Explode this.isActive = false; this.isOverheat = false; EntityblockfileExplode var6 = new EntityblockfileExplode(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F)); par1World.spawnEntityInWorld(var6); } //particle effetcs float var7 = (float)par2 + 2.0F * 6.0F / 16.0F; float var8 = (float)par3 + 1.5F * 6.0F / 16.0F; float var9 = (float)par4 + 2.0F * 6.0F / 16.0F; float var10 = (float)par2 + 0.7F * 6.0F / 16.0F; float var11 = (float)par3 + 1.5F * 6.0F / 16.0F; float var12 = (float)par4 + 2.0F * 6.0F / 16.0F; float var13 = (float)par2 + 0.5F; float var14 = (float)par3 + 0.5F; float var15 = (float)par4 + 0.5F; double yVelocity = 0.125D; double xVelocity = 0.125D; double zVelocity = 0.125D; double uxVelocity = -0.125D; double uzVelocity = -0.125D; if (this.isActive) { for (int n = 0; n < 8 ; n++) { par1World.playSoundEffect((double)par2 + 0.5D, (double)par3 + 0.5D, (double)par4 + 0.5D, "fire.ignite", 0.3F, 0.6F); par1World.spawnParticle("smoke", var7, var8, var9, 0.0D, yVelocity, 0.0D); par1World.spawnParticle("smoke", var7, var8, var9, 0.0D, yVelocity, 0.0D); par1World.spawnParticle("smoke", var7, var8, var9, 0.0D, yVelocity, 0.0D); par1World.spawnParticle("smoke", var10, var11, var12, 0.0D, yVelocity, 0.0D); par1World.spawnParticle("smoke", var10, var11, var12, 0.0D, yVelocity, 0.0D); par1World.spawnParticle("smoke", var10, var11, var12, 0.0D, yVelocity, 0.0D); } } if (this.isOverheat) { for (int n = 0; n < 10 ; n++) { par1World.playSoundEffect((double)par2 + 0.5D, (double)par3 + 0.5D, (double)par4 + 0.5D, "fire.ignite", 0.3F, 0.6F); par1World.spawnParticle("smoke", var13, var14, var15, xVelocity, 0.0D, 0.0D); par1World.spawnParticle("smoke", var13, var14, var15, 0.0D, 0.0D, zVelocity); par1World.spawnParticle("smoke", var13, var14, var15, uxVelocity, 0.0D, 0.0D); par1World.spawnParticle("smoke", var13, var14, var15, 0.0D, 0.0D, uzVelocity); par1World.spawnParticle("smoke", var13, var14, var15, xVelocity, 0.0D, 0.0D); par1World.spawnParticle("smoke", var13, var14, var15, 0.0D, 0.0D, zVelocity); par1World.spawnParticle("smoke", var13, var14, var15, uxVelocity, 0.0D, 0.0D); par1World.spawnParticle("smoke", var13, var14, var15, 0.0D, 0.0D, uzVelocity); par1World.spawnParticle("smoke", var13, var14, var15, xVelocity, 0.0D, 0.0D); par1World.spawnParticle("smoke", var13, var14, var15, 0.0D, 0.0D, zVelocity); par1World.spawnParticle("smoke", var13, var14, var15, uxVelocity, 0.0D, 0.0D); par1World.spawnParticle("smoke", var13, var14, var15, 0.0D, 0.0D, uzVelocity); } } } /** * Returns the block texture based on the side being looked at. Args: side */ public int getBlockTextureFromSide(int par1) { return par1 == 1 ? 5 : (par1 == 0 ? 7 : (par1 == 3 ? 6 : this.blockIndexInTexture)); } public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) { if (isPowered(par1World, par2, par3, par4, 1)) { par1World.setBlockWithNotify(par2, par3 - 1, par4, Block.dirt.blockID); } } /** * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are * their own) Args: x, y, z, neighbor blockID */ public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) { if (par5 > 0) { boolean var6 = isPowered(par1World, par2, par3, par4, par5); boolean var7 = getHasFuel(); if (var6 == true) { if (var7) { par1World.setBlockWithNotify(par2, par3 - 1, par4, Block.dirt.blockID); this.isActive = true; } else { this.isActive = false; } } else { this.isActive = false; } } } private boolean getHasFuel() { return hasFuel; } /** * checks the block to that side to see if it is powered. */ private boolean isPowered(World par1World, int par2, int par3, int par4, int par5) { return par5 != 0 && par1World.isBlockProvidingPowerTo(par2, par3 - 1, par4, 0) ? true : (par5 != 1 && par1World.isBlockProvidingPowerTo(par2, par3 + 1, par4, 1) ? true : (par5 != 2 && par1World.isBlockProvidingPowerTo(par2, par3, par4 - 1, 2) ? true : (par5 != 3 && par1World.isBlockProvidingPowerTo(par2, par3, par4 + 1, 3) ? true : (par5 != 5 && par1World.isBlockProvidingPowerTo(par2 + 1, par3, par4, 5) ? true : (par5 != 4 && par1World.isBlockProvidingPowerTo(par2 - 1, par3, par4, 4) ? true : (par1World.isBlockProvidingPowerTo(par2, par3, par4, 0) ? true : (par1World.isBlockProvidingPowerTo(par2, par3 + 2, par4, 1) ? true : (par1World.isBlockProvidingPowerTo(par2, par3 + 1, par4 - 1, 2) ? true : (par1World.isBlockProvidingPowerTo(par2, par3 + 1, par4 + 1, 3) ? true : (par1World.isBlockProvidingPowerTo(par2 - 1, par3 + 1, par4, 4) ? true : par1World.isBlockProvidingPowerTo(par2 + 1, par3 + 1, par4, 5))))))))))); } /** * Called upon block activation (right click on the block.) */ public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { if (par1World.isRemote) { return true; } else { TileEntity tileEntity = par1World.getBlockTileEntity(par2,par3,par4); if (tileEntity == null || par5EntityPlayer.isSneaking()) { } else { par5EntityPlayer.openGui(Generic.instance, 0, par1World, par2, par3, par4); } } return true; } @Override public void breakBlock(World world, int x, int y, int z, int par5, int par6) { dropItems(world, x, y, z); super.breakBlock(world, x, y, z, par5, par6); } private void dropItems(World world, int x, int y, int z){ Random rand = new Random(); TileEntity tileEntity = world.getBlockTileEntity(x, y, z); if (!(tileEntity instanceof IInventory)) { return; } IInventory inventory = (IInventory) tileEntity; for (int i = 0; i < inventory.getSizeInventory(); i++) { ItemStack item = inventory.getStackInSlot(i); if (item != null && item.stackSize > 0) { float rx = rand.nextFloat() * 0.8F + 0.1F; float ry = rand.nextFloat() * 0.8F + 0.1F; float rz = rand.nextFloat() * 0.8F + 0.1F; EntityItem entityItem = new EntityItem(world, x + rx, y + ry, z + rz, new ItemStack(item.itemID, item.stackSize, item.getItemDamage())); if (item.hasTagCompound()) { entityItem.item.setTagCompound((NBTTagCompound) item.getTagCompound().copy()); } float factor = 0.05F; entityItem.motionX = rand.nextGaussian() * factor; entityItem.motionY = rand.nextGaussian() * factor + 0.2F; entityItem.motionZ = rand.nextGaussian() * factor; world.spawnEntityInWorld(entityItem); item.stackSize = 0; } } } public TileEntity createNewTileEntity(World world) { return new TileEntityFile(); } } TileEntityFile package kintick.Minecraft.Ademantine.client; import net.minecraft.src.*; public class TileEntityFile extends TileEntity implements IInventory { private ItemStack[] inv; public TileEntityFile(){ inv = new ItemStack[1]; } @Override public int getSizeInventory() { return inv.length; } @Override public ItemStack getStackInSlot(int slot) { return inv[slot]; } @Override public void setInventorySlotContents(int slot, ItemStack stack) { inv[slot] = stack; if (stack != null && stack.stackSize > getInventoryStackLimit()) { stack.stackSize = getInventoryStackLimit(); } } @Override public ItemStack decrStackSize(int slot, int amt) { ItemStack stack = getStackInSlot(slot); if (stack != null) { if (stack.stackSize <= amt) { setInventorySlotContents(slot, null); } else { stack = stack.splitStack(amt); if (stack.stackSize == 0) { setInventorySlotContents(slot, null); } } } return stack; } @Override public ItemStack getStackInSlotOnClosing(int slot) { ItemStack stack = getStackInSlot(slot); if (stack != null) { setInventorySlotContents(slot, null); } return stack; } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64; } @Override public void openChest() {} @Override public void closeChest() {} @Override public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); NBTTagList tagList = tagCompound.getTagList("Inventory"); for (int i = 0; i < tagList.tagCount(); i++) { NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i); byte slot = tag.getByte("Slot"); if (slot >= 0 && slot < inv.length) { inv[slot] = ItemStack.loadItemStackFromNBT(tag); } } } @Override public void writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); NBTTagList itemList = new NBTTagList(); for (int i = 0; i < inv.length; i++) { ItemStack stack = inv; if (stack != null) { NBTTagCompound tag = new NBTTagCompound(); tag.setByte("Slot", (byte) i); stack.writeToNBT(tag); itemList.appendTag(tag); } } tagCompound.setTag("Inventory", itemList); } @Override public String getInvName() { // TODO Auto-generated method stub return null; } } ContainerFile package kintick.Minecraft.Ademantine; import kintick.Minecraft.Ademantine.client.TileEntityFile; import net.minecraft.src.*; public class ContainerFile extends Container { protected TileEntityFile tileEntity; public ContainerFile (InventoryPlayer inventoryPlayer, TileEntityFile te){ tileEntity = te; //the Slot constructor takes the IInventory and the slot number in that it binds to //and the x-y coordinates it resides on-screen addSlotToContainer(new Slot(tileEntity, 0, 76, 37)); //commonly used vanilla code that adds the player's inventory bindPlayerInventory(inventoryPlayer); } @Override public boolean canInteractWith(EntityPlayer player) { return tileEntity.isUseableByPlayer(player); } protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; j++) { addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } for (int i = 0; i < 9; i++) { addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142)); } } /** * @param itemStack ItemStack to merge into inventory * @param start minimum slot to attempt fill * @param end maximum slot to attempt fill * @param backwards go backwards * @return true if stacks merged successfully */ public boolean mergeItemStack(ItemStack itemStack, int start, int end, boolean backwards) { return true; } @Override public ItemStack transferStackInSlot(int slot) { ItemStack stack = null; Slot slotObject = (Slot) inventorySlots.get(slot); //null checks and checks if the item can be stacked (maxStackSize > 1) if (slotObject != null && slotObject.getHasStack()) { ItemStack stackInSlot = slotObject.getStack(); stack = stackInSlot.copy(); //merges the item into player inventory since its in the tileEntity if (slot == 0) { if (!mergeItemStack(stackInSlot, 1, inventorySlots.size(), true)) { return null; } //places it into the tileEntity is possible since its in the player inventory } else if (!mergeItemStack(stackInSlot, 0, 1, false)) { return null; } if (stackInSlot.stackSize == 0) { slotObject.putStack(null); } else { slotObject.onSlotChanged(); } } return stack; } } FileGui package kintick.Minecraft.Ademantine; import kintick.Minecraft.Ademantine.client.TileEntityFile; import cpw.mods.fml.common.network.IGuiHandler; import net.minecraft.src.EntityPlayer; import net.minecraft.src.TileEntity; import net.minecraft.src.World; public class FileGui implements IGuiHandler{ //returns an instance of the Container you made earlier @Override public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { TileEntityFile tileEntity = (TileEntityFile) world.getBlockTileEntity(x, y, z); if(tileEntity instanceof TileEntityFile){ return new ContainerFile(player.inventory, (TileEntityFile) tileEntity); } return null; } //returns an instance of the Gui you made earlier @Override public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { TileEntity tileEntity = world.getBlockTileEntity(x, y, z); if(tileEntity instanceof TileEntityFile){ return new GuiFile(player.inventory, (TileEntityFile) tileEntity); } return null; } } GuiFile package kintick.Minecraft.Ademantine; import kintick.Minecraft.Ademantine.client.TileEntityFile; import net.minecraft.src.*; import org.lwjgl.opengl.GL11; public class GuiFile extends GuiContainer { public GuiFile (InventoryPlayer inventoryPlayer, TileEntityFile tileEntity) { //the container is instanciated and passed to the superclass for handling super(new ContainerFile(inventoryPlayer, tileEntity)); } @Override protected void drawGuiContainerForegroundLayer() { //draw text and stuff here //the parameters for drawString are: string, x, y, color fontRenderer.drawString("Automatic File", 8, 6, 4210752); //draws "Inventory" or your regional equivalent fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, 4210752); } @Override protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { //draw your Gui here, only thing you need to change is the path int texture = mc.renderEngine.getTexture("/kintick/Minecraft/Ademantine/client/File.png"); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.renderEngine.bindTexture(texture); int x = (width - xSize) / 2; int y = (height - ySize) / 2; this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize); } } Before, I added the texture. This wasn't a problem... However at the time, the block just consumed items when the user logged out and back in again (Block was still in position). Even if i revert the code back it still removes the whole block. I hope you can help, Kintick I am new to modding Minecraft. I've tried for hours to find solutions before posting here, so I really need help.
October 11, 201213 yr Author It's now staying in position, however it doesn't save the block in the entity here's my error log as it also has something about a missing mapping, i have no idea what it is... 2012-10-11 09:58:03 [iNFO] [ForgeModLoader] Forge Mod Loader version 3.0.196.366 for Minecraft client:1.3.2, server:1.3.2 loading 2012-10-11 09:58:05 [iNFO] [sTDOUT] 27 achievements 2012-10-11 09:58:05 [iNFO] [sTDOUT] 195 recipes 2012-10-11 09:58:05 [iNFO] [sTDOUT] Setting user: Player465, - 2012-10-11 09:58:05 [iNFO] [sTDERR] Client asked for parameter: server 2012-10-11 09:58:05 [iNFO] [sTDOUT] LWJGL Version: 2.4.2 2012-10-11 09:58:06 [iNFO] [ForgeModLoader] Attempting early MinecraftForge initialization 2012-10-11 09:58:06 [iNFO] [ForgeModLoader] Completed early MinecraftForge initialization 2012-10-11 09:58:06 [iNFO] [ForgeModLoader] Searching C:\mcp\jars\mods for mods 2012-10-11 09:58:07 [iNFO] [ForgeModLoader] Forge Mod Loader has identified 3 mods to load 2012-10-11 09:58:08 [iNFO] [sTDOUT] Starting up SoundSystem... 2012-10-11 09:58:08 [iNFO] [sTDOUT] Initializing LWJGL OpenAL 2012-10-11 09:58:08 [iNFO] [sTDOUT] (The LWJGL binding of OpenAL. For more information, see http://www.lwjgl.org) 2012-10-11 09:58:08 [iNFO] [sTDOUT] OpenAL initialized. 2012-10-11 09:58:09 [iNFO] [ForgeModLoader] MinecraftForge v4.1.1.251 Initialized 2012-10-11 09:58:09 [iNFO] [ForgeModLoader] Forge Mod Loader has successfully loaded 3 mods 2012-10-11 09:58:14 [iNFO] [sTDOUT] MinecraftForge v4.1.1.251 Initialized Skipping TileEntity with id 2012-10-11 09:58:21 [iNFO] [sTDERR] java.lang.RuntimeException: class kintick.Minecraft.Ademantine.client.TileEntityFile is missing a mapping! This is a bug! 2012-10-11 09:58:21 [iNFO] [sTDERR] at net.minecraft.src.TileEntity.writeToNBT(TileEntity.java:88) 2012-10-11 09:58:21 [iNFO] [sTDERR] at kintick.Minecraft.Ademantine.client.TileEntityFile.writeToNBT(TileEntityFile.java:89) 2012-10-11 09:58:21 [iNFO] [sTDERR] at net.minecraft.src.AnvilChunkLoader.writeChunkToNBT(AnvilChunkLoader.java:276) 2012-10-11 09:58:21 [iNFO] [sTDERR] at net.minecraft.src.AnvilChunkLoader.saveChunk(AnvilChunkLoader.java:114) 2012-10-11 09:58:21 [iNFO] [sTDERR] at net.minecraft.src.ChunkProviderServer.safeSaveChunk(ChunkProviderServer.java:192) 2012-10-11 09:58:21 [iNFO] [sTDERR] at net.minecraft.src.ChunkProviderServer.saveChunks(ChunkProviderServer.java:245) 2012-10-11 09:58:21 [iNFO] [sTDERR] at net.minecraft.src.WorldServer.saveAllChunks(WorldServer.java:728) 2012-10-11 09:58:21 [iNFO] [sTDERR] at net.minecraft.server.MinecraftServer.saveAllDimensions(MinecraftServer.java:338) 2012-10-11 09:58:21 [iNFO] [sTDERR] at net.minecraft.src.IntegratedServer.tick(IntegratedServer.java:100) 2012-10-11 09:58:21 [iNFO] [sTDERR] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:453) 2012-10-11 09:58:21 [iNFO] [sTDERR] at net.minecraft.src.ThreadServerApplication.run(ThreadServerApplication.java:17) 2012-10-11 09:58:31 [iNFO] [sTDERR] Someone is closing me! here is my new tileentity package kintick.Minecraft.Ademantine.client; import net.minecraft.src.*; public class TileEntityFile extends TileEntity implements IInventory { private ItemStack[] inv; public TileEntityFile(){ inv = new ItemStack[1]; } @Override public int getSizeInventory() { return inv.length; } @Override public ItemStack getStackInSlot(int slot) { return inv[slot]; } @Override public void setInventorySlotContents(int slot, ItemStack stack) { inv[slot] = stack; if (stack != null && stack.stackSize > getInventoryStackLimit()) { stack.stackSize = getInventoryStackLimit(); } } @Override public ItemStack decrStackSize(int slot, int amt) { ItemStack stack = getStackInSlot(slot); if (stack != null) { if (stack.stackSize <= amt) { setInventorySlotContents(slot, null); } else { stack = stack.splitStack(amt); if (stack.stackSize == 0) { setInventorySlotContents(slot, null); } } } return stack; } @Override public ItemStack getStackInSlotOnClosing(int slot) { ItemStack stack = getStackInSlot(slot); if (stack != null) { setInventorySlotContents(slot, null); } return stack; } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64; } @Override public void openChest() {} @Override public void closeChest() {} @Override public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); NBTTagList tagList = tagCompound.getTagList("Inventory"); for (int i = 0; i < tagList.tagCount(); i++) { NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i); byte slot = tag.getByte("Slot"); if (slot >= 0 && slot < inv.length) { inv[slot] = ItemStack.loadItemStackFromNBT(tag); } } } @Override public void writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); NBTTagList itemList = new NBTTagList(); for (int i = 0; i < inv.length; i++) { ItemStack stack = inv; if (stack != null) { NBTTagCompound tag = new NBTTagCompound(); tag.setByte("Slot", (byte) i); stack.writeToNBT(tag); itemList.appendTag(tag); } } tagCompound.setTag("Inventory", itemList); } @Override public String getInvName() { return "File"; } } I am new to modding Minecraft. I've tried for hours to find solutions before posting here, so I really need help.
October 11, 201213 yr you need to register your tileentity in your @Init GameRegistry.registerTileEntity(TileEntityClass.class, "Name of your Container") http://i.imgur.com/Hppni.png[/img]
October 11, 201213 yr Author I did that, however i found a workaround that i'm happy with, but thanks for showing your interest I am new to modding Minecraft. I've tried for hours to find solutions before posting here, so I really need help.
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.