Posted October 16, 201411 yr Problem fixed by checking if !world.isRemote before running the onBlockActivated code (Thanks go to theEpicTekkit, and also SaoModder) I am currently working on my first mod. I have a block that is supposed to be destroyed in the onBlockActivated method and it appears that is does get destroyed but only for a split second. It seems as if the problem is in the block regenerating but in all my searching I could not find a reason for the regen. I am new to programming in general so I may have made a stupid mistake somewhere that I cannot see. The block has a tile entity that is successfully destroyed the first time by onBlockActivated. Also the items you get in onBlockActivated are only received the first time. The block in question is "TrapBuoy". You place it by using a BaitedLobsterTrap on the surface of the water. if the water is deep enough a trap will spawn on the sea floor. when right clicked after a delay the trap and buoy should disappear and the player receives the trap, buoy, rope, and fish. The trap disappears just fine however the buoy reappears immediately. Right clicking again will destroy the block(after a delay) without getting any items. Github: https://github.com/npomroy/MineHr Side Issue: If you have read this far I have another problem but I have not yet really worked on it. I have an issue with a tile entity. In the gui that I have made, the test slot is inaccessible for some reason(you can put items in but you cannot take them out). It seems like the slot isn't linking with the correct inventory. I have been unable to write the itemstack to the NBT as well. I greatly appreciate any and all help PS I am also happy to help anyone else if there is anything I can do with my so far limited knowledge.
October 16, 201411 yr why dont you try for removing the block public void breakBlock(World world, int x, int y, int z, int i, int j) { world.setBlockToAir(x, y, z); }
October 16, 201411 yr Author I have tried adding setBlockToAir to breakBlock but it had no effect. The problem doesn't seem to be with the block breaking(it appears to break for a split second) it seems that there is a bit of code causing it to return.
October 16, 201411 yr maybe try package com.kraz.minehr.blocks; import com.kraz.minehr.MineHr; import com.kraz.minehr.init.ItemInit; import com.kraz.minehr.reference.Reference; import com.kraz.minehr.tileentity.TileEntityTrapBuoy; import com.kraz.minehr.util.LogHelper; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import java.util.Random; public class TrapBuoy extends BlockContainer { private int haulTick; private int haulMax; private boolean caught = false; public TrapBuoy(Material material) { super(material); this.setHardness(3.0F); this.setResistance(5.0F); this.setStepSound(soundTypeCloth); this.setCreativeTab(MineHr.mineHrTab); this.setTickRandomly(true); haulMax = 20; haulTick = 0; } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister iconRegister) { this.blockIcon = iconRegister.registerIcon(Reference.MOD_ID + ":" + this.getUnlocalizedName().substring(5)); } public boolean onBlockActivated (World world, int x, int y, int z, EntityPlayer player, int q, float a, float b, float c) { TileEntityTrapBuoy tileentity = (TileEntityTrapBuoy)world.getTileEntity(x, y, z); //pull in trap if(tileentity != null) { if(haulTick == haulMax && haulMax != 0) { ItemStack buoyStack = new ItemStack(MineHr.blockTrapBuoy); ItemStack ropeStack = new ItemStack(ItemInit.itemRope, ; ItemStack trapStack = new ItemStack(MineHr.blockLobsterTrap); ItemStack fishStack = new ItemStack(ItemInit.itemRawLobster, tileentity.getFishAmount()); player.inventory.addItemStackToInventory(buoyStack); player.inventory.addItemStackToInventory(ropeStack); player.inventory.addItemStackToInventory(trapStack); player.inventory.addItemStackToInventory(fishStack); world.setBlockToAir(x, y, z); world.setBlock(x, y - tileentity.getDepth() - 1, z, Blocks.water); world.removeTileEntity(x, y, z); haulTick = 0; caught = true; }else{ haulTick++; caught = false; } return true; } else { return false; } } public TileEntity createNewTileEntity(World world, int metadata) { return new TileEntityTrapBuoy(); } public int quantityDropped() { return 0; } public void breakBlock(World world, int x, int y, int z, int i, int j) { world.removeTileEntity(x, y, z); world.setBlockToAir(x, y, z); } public void updateTick(World world, int x, int y, int z, Random random) { TileEntityTrapBuoy tileentity = (TileEntityTrapBuoy)world.getTileEntity(x, y, z); if(caught == true){ if (tileentity.getDepth() >= Reference.lobsterTrapMinDepth && tileentity.getDepth() < Reference.lobsterTrapBonusDepth) { int i1 = world.getBlockMetadata(x, y, z); Random random1 = new Random(); if (i1 == 15 && Math.floor(random1.nextInt(100)) <= Reference.lobsterTrapCatchChance) { tileentity.incrementFishAmount(); world.setBlockMetadataWithNotify(x, y, z, 0, 4); } else { world.setBlockMetadataWithNotify(x, y, z, i1 + 1, 4); } } else if (tileentity.getDepth() >= Reference.lobsterTrapBonusDepth) { int i1 = world.getBlockMetadata(x, y, z); Random random1 = new Random(); if (i1 == 15 && Math.floor(random1.nextInt(100 * Reference.lobsterTrapBonusFactor)) <= Reference.lobsterTrapCatchChance) { tileentity.incrementFishAmount(); world.setBlockMetadataWithNotify(x, y, z, 0, 4); } else { world.setBlockMetadataWithNotify(x, y, z, i1 + 1, 4); } } } } } youre updatetick may be setting the block back before the on activated deletes it or something
October 16, 201411 yr Maybe try adding in your onBlockActivated method: if (!world.isRemote) { //Only so this on the server. Not the client. //Then all your activation code here } else return true; //Always return true, otherwise there will be client - server sync issues. I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.
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.