Posted November 16, 20168 yr Whenever I connect to the world, my item in my pan disappear. Block: package cz.grossik.farmcraft2.pan; import java.util.Random; import javax.annotation.Nullable; import cz.grossik.farmcraft2.Main; import cz.grossik.farmcraft2.handler.ItemHandler; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.math.BlockPos; import net.minecraft.world.EnumSkyBlock; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class BlockPan extends BlockContainer { public BlockPan() { super(Material.ROCK); setUnlocalizedName("pan"); setCreativeTab(Main.FarmCraft2Tab); setHardness(2f); setResistance(10f); } public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityPan(); } @SuppressWarnings("deprecation") @Override public boolean isOpaqueCube(IBlockState state) { return false; } public EnumBlockRenderType getRenderType(IBlockState state) { return EnumBlockRenderType.MODEL; } public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos) { TileEntityPan te = (TileEntityPan) world.getTileEntity(pos); return te == null || !te.isCooking() ? 0 : 14; } public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { TileEntityPan te = (TileEntityPan) world.getTileEntity(pos); if(heldItem != null && heldItem.getItem().equals(ItemHandler.DfPancakes) && !te.isCooking()) { if(te.putPancakes()) { heldItem.stackSize--; return true; } return false; } else if(te.isCooking()) { Item product = te.retrieveItem(); if(product != null && !world.isRemote) { BlockPos pPos = player.getPosition(); EntityItem itemDrop = new EntityItem(world, pPos.getX() + 0.5d, pPos.getY() + 0.5d, pPos.getZ() + 0.5d, new ItemStack(product)); itemDrop.setNoPickupDelay(); world.spawnEntityInWorld(itemDrop); return true; } } return false; } private void spawnParticle(World world, BlockPos pos, Random rand, boolean isFire) { double x = pos.getX() + 0.5F + (rand.nextFloat() * 0.6F -0.3F); double y = pos.getY() + 0.15F; double z = pos.getZ() + 0.5F + (rand.nextFloat() * -0.6F - -0.3F); EnumParticleTypes type; if(isFire) type = EnumParticleTypes.FLAME; else type = EnumParticleTypes.SMOKE_NORMAL; world.spawnParticle(type, x, y, z, 0, 0, 0, new int[0]); } @SideOnly(Side.CLIENT) public void randomDisplayTick(IBlockState state, World worldIn, BlockPos pos, Random rand) { worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn)); worldIn.checkLightFor(EnumSkyBlock.BLOCK, pos); boolean cooking = ((TileEntityPan) worldIn.getTileEntity(pos)).isCooking(); if(cooking) { for(int i = 0; i < rand.nextInt(10); i++) { spawnParticle(worldIn, pos, rand, true); } for(int i = 1; i < rand.nextInt(10); i++) { spawnParticle(worldIn, pos, rand, false); } } } } TileEntity: package cz.grossik.farmcraft2.pan; import cz.grossik.farmcraft2.handler.ItemHandler; import net.minecraft.item.Item; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ITickable; public class TileEntityPan extends TileEntity implements ITickable { private int cookTime = 0; private int TIME = 120; //6 sekund private boolean isCooking = false; private String KEY_TIME = "cookTime"; private String KEY_COOKING = "cooking"; public TileEntityPan() {} public boolean isCooking() { return isCooking; } public boolean putPancakes() { if(!isCooking) { isCooking = true; return true; } else { return false; } } public Item getPancakes() { if(!isCooking) return null; if(cookTime < TIME) return ItemHandler.DfPancakes; else return ItemHandler.Pancakes; } public int getCookingStage() { Item item = getPancakes(); if(item == null || item.equals(ItemHandler.DfPancakes)) return 0; else if(item.equals(ItemHandler.Pancakes)) return 1; else return 0; } public Item retrieveItem() { Item product = getPancakes(); isCooking = false; cookTime = 0; return product; } public void readFromNBT(NBTTagCompound tag) { super.readFromNBT(tag); isCooking = tag.getBoolean(KEY_COOKING); cookTime = tag.getInteger(KEY_TIME); } public NBTTagCompound writeToNBT(NBTTagCompound tag) { super.writeToNBT(tag); tag.setBoolean(KEY_COOKING, isCooking); tag.setInteger(KEY_TIME, cookTime); return tag; } public Packet getDescriptionPacket() { NBTTagCompound nbt = new NBTTagCompound(); writeToNBT(nbt); return new SPacketUpdateTileEntity(pos, 0, nbt); } public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { readFromNBT(pkt.getNbtCompound()); } @Override public void update() { if(isCooking) { cookTime++; } } } Model: package cz.grossik.farmcraft2.pan; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelRenderer; public class ModelPan extends ModelBase { private ModelRenderer pancakes; public ModelPan() { textureWidth = 128; textureHeight = 32; pancakes = new ModelRenderer(this, "pancakes"); setTextureOffset("pancakes.jedna", 0, 0); setTextureOffset("pancakes.dva", 32, 0); setTextureOffset("pancakes.tri", 0, 18); setTextureOffset("pancakes.ctyri", 0, 13); setTextureOffset("pancakes.pet", 56, 0); setTextureOffset("pancakes.sest", 18, 18); setTextureOffset("pancakes.sedum", 10, 13); pancakes.addBox("jedna", 6, -3, -6, 4, 1, 12); pancakes.addBox("dva", 4, -3, -5, 2, 1, 10); pancakes.addBox("tri", 3, -3, -4, 1, 1, ; pancakes.addBox("ctyri", 2, -3, -2, 1, 1, 4); pancakes.addBox("pet", 10, -3, -5, 2, 1, 10); pancakes.addBox("sest", 12, -3, -4, 1, 1, ; pancakes.addBox("sedum", 13, -3, -2, 1, 1, 4); } public void render() { pancakes.render(1f / 16f); } } Render: package cz.grossik.farmcraft2.pan; import cz.grossik.farmcraft2.Main; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class RendererPan extends TileEntitySpecialRenderer<TileEntityPan> { private static final ModelPan model = new ModelPan(); private static final ResourceLocation tAno = new ResourceLocation(Main.MODID + ":textures/models/neudelana.png"); private static final ResourceLocation tNe = new ResourceLocation(Main.MODID + ":textures/models/udelana.png"); @Override public void renderTileEntityAt(TileEntityPan te, double x, double y, double z, float partialTicks, int destroyStage) { if(te.isCooking()) { GlStateManager.pushMatrix(); GlStateManager.translate(x, y + 0.84375f, z + 0.5f); ResourceLocation texture; switch(te.getCookingStage()) { case 1: texture = tNe; break; case 0: default: texture = tAno; } bindTexture(texture); model.render(); GlStateManager.popMatrix(); } } }
November 16, 20168 yr Where is the object located that contains the items you want to save in the pan?
November 16, 20168 yr Author I saved everything you need, I just need to save item whether it is in the pan or not.
November 16, 20168 yr Author Perhaps this you wonder from ItemHandler. public static Item DfPancakes = new Item().setUnlocalizedName("dough_for_pancakes").setCreativeTab(Main.FarmCraft2Tab).setContainerItem(Items.BOWL); public static Item Pancakes = new ItemFood(4, false).setUnlocalizedName("pancakes").setCreativeTab(Main.FarmCraft2Tab);
November 16, 20168 yr I would suggest you to not do that the way you are doing it now, it just doesn't really make sense. You should instead create an internal inventory for your pan and use that to handle the stacks. This inventory can then be written to and read from NBT.
November 16, 20168 yr Author Yeah, I know it, too. But I do not know how to do that when you click on item with an item, the item is put into the slot.
November 16, 20168 yr Override the method onBlockActivated in your Block class and if the held item can be cooked in the pan get your TileEntity, get the inventory inside of it and place the ItemStack in the inventory.
November 16, 20168 yr Author public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { TileEntityPan te = (TileEntityPan) world.getTileEntity(pos); if(!world.isRemote){ if(heldItem != null && heldItem.getItem().equals(ItemHandler.DfPancakes) && !te.isBurning()) { heldItem.stackSize--; } else{ player.openGui(Main.MODID, FC2_GuiHandler.PANGUI, world, pos.getX(), pos.getY(), pos.getZ()); } } return true; } And now I'm finished. I do not know how to put the item into the slot.
November 16, 20168 yr Author public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { TileEntityPan te = (TileEntityPan) world.getTileEntity(pos); Container container = te.createContainer(player.inventory, player); Slot slot = (Slot)container.inventorySlots.get(0); if(!world.isRemote){ if(heldItem != null && heldItem.getItem().equals(ItemHandler.DfPancakes) && !te.isBurning()) { slot.putStack(heldItem); heldItem.stackSize--; } else{ player.openGui(Main.MODID, FC2_GuiHandler.PANGUI, world, pos.getX(), pos.getY(), pos.getZ()); } } return true; } But slot.putStack(heldItem); give me whole stack. But I only want one item, no stack.
November 16, 20168 yr You do know about stack splitting, yes? Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
November 16, 20168 yr ItemStack newstack = stack.split(1); Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
November 16, 20168 yr Author I figured it out myself. public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { TileEntityPan te = (TileEntityPan) world.getTileEntity(pos); Container container = te.createContainer(player.inventory, player); Slot slot = (Slot)container.inventorySlots.get(0); if(!world.isRemote){ if(heldItem != null && heldItem.getItem().equals(ItemHandler.DfPancakes) && !te.isBurning()) { ItemStack is = heldItem.splitStack(1); slot.putStack(is); } else{ player.openGui(Main.MODID, FC2_GuiHandler.PANGUI, world, pos.getX(), pos.getY(), pos.getZ()); } } return true; } Thanks. But I have a problem with the render pancakes. package cz.grossik.farmcraft2.pan; import cz.grossik.farmcraft2.Main; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class RendererPan extends TileEntitySpecialRenderer<TileEntityPan> { private static final ModelPan model = new ModelPan(); private static final ResourceLocation tAno = new ResourceLocation(Main.MODID + ":textures/models/neudelana.png"); private static final ResourceLocation tNe = new ResourceLocation(Main.MODID + ":textures/models/udelana.png"); @Override public void renderTileEntityAt(TileEntityPan te, double x, double y, double z, float partialTicks, int destroyStage) { if(te.isBurning()) { GlStateManager.pushMatrix(); GlStateManager.translate(x, y + 0.84375f, z + 0.5f); ResourceLocation texture = tAno; bindTexture(texture); model.render(); GlStateManager.popMatrix(); } } }
November 17, 20168 yr Author I have problem with render Pancakes. This code reports an error on if(furnaceItemStacks[2].getItem() == ItemHandler.Pancakes) package cz.grossik.farmcraft2.pan; import cz.grossik.farmcraft2.Main; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class RendererPan extends TileEntitySpecialRenderer<TileEntityPan> { private static final ModelPan model = new ModelPan(); private static final ResourceLocation tAno = new ResourceLocation(Main.MODID + ":textures/models/neudelana.png"); private static final ResourceLocation tNe = new ResourceLocation(Main.MODID + ":textures/models/udelana.png"); @Override public void renderTileEntityAt(TileEntityPan te, double x, double y, double z, float partialTicks, int destroyStage) { if(te.isBurning()) { GlStateManager.pushMatrix(); GlStateManager.translate(x, y + 0.84375f, z + 0.5f); ResourceLocation texture; if(te.Check()) { texture = tNe; } else { texture = tAno; } bindTexture(texture); model.render(); GlStateManager.popMatrix(); } } } public boolean Check(){ if(panItemStacks[2].getItem() == ItemHandler.Pancakes) { return true; } return false; }
November 17, 20168 yr "I have a problem with render" doesn't give us any clue about what's not working correctly? Is it not rendering? Is it rendering weird? Is it upside down? Please, be more specific. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
November 17, 20168 yr There's only 1 thing in the Check method that can be null (I'm guessing it's an NPE). Figure it out and do a proper null -check. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
November 17, 20168 yr Author public boolean Check(){ if(panItemStacks[2].getItem() == ItemHandler.Pancakes) { return true; } return false; } Tento kód nefunguje.
November 17, 20168 yr This is an English forum, let's keep it that way. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
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.