Posted December 17, 20177 yr Hey everyone, So, I have a block that has a Tile Entity. When I right click this block with one of my items, I check if this block that was right clicked is an instanceof this Tile Entity. If it is, I run a getWorld().setBlockState() method inside of the Tile Entities code. All the code runs, except, as soon as it changes the block, it INSTANTLY REVERTS back to the old block. I feel this may be because the Tile Entity might still be there, or something? Anyways, here's my code. (NOTE: I have shortened this code on purpose in the Tile Entity. PlaceNewModBlock actually has a bunch of other conditions in it to change the block into others. I removed these other conditions in my code to test if it was the others interfering, but they weren't.) TILE ENTITY CLASS: public class TileEntityModBlock extends TileEntity { public int carveAmount = 0; public void placeNewModBlock() { Block mod_block = getWorld().getBlockState(getPos()).getBlock(); Utils.getLogger().info(mod_block.getUnlocalizedName()); if(mod_block == ModBlocks.new_mod_block) { getWorld().setBlockState(getPos(), ModBlocks.new_mod_block.getDefaultState()); } } } ITEM CLASS: @Override public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if(worldIn.isRemote) { if (worldIn.getTileEntity(pos) != null) { if (worldIn.getTileEntity(pos) instanceof TileEntityModBlock) { TileEntityModBlock modBlock = (TileEntityModBlock) worldIn.getTileEntity(pos); modBlock.carveAmount++; if(modBlock.carveAmount >= 3){ modBlock.placeNewModBlock(); } } } } return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ); } So, when the carveAmount is greater than 3 (R-Click block 3 times) The block should change to the new one, based on whatever block you're right clicking is. It does change, but REVERTS back immediately. Again, I think it may be something to do with the Tile Entity still being there... anways, help is appreciated! Thanks! Edited December 17, 20177 yr by MSpace-Dev Solved the problem
December 17, 20177 yr Author UPDATE: I've also tried adding getWorld().removeTileEntity(getPos()); just before the code that sets the block state. Still reverts back immediately. I should also mention that a lot of different blocks use this Tile Entity when registered through overriding createTileEntity() in each block's class.
December 17, 20177 yr Author I have found the problem. So obvious. During trying to make sound and particles work, I changed !worldIn.isRemote to worldIn.isRemote! Changed that back, and now all's working fine! Just need to figure out how I can do particles and sound for the block and the logic server side, without having to duplicate the function
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.