Posted July 2, 20196 yr Hey all, I'm trying to make the code in onBlockActivated to only run when a cooldown reaches 0. I've seen there is randomTick, updateTick, etc. However, I cannot get them to work. public class BlockMod extends ModBlock implements ITileEntityProvider{ public BlockMod(String name, Material materialIn) { super(name, materialIn); this.setTickRandomly(false); } @Nullable @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityBlockMod(); } @Override public int tickRate(World worldIn) { return 1; } @Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random random) { Utils.getLogger().info("tick"); super.randomTick(worldIn, pos, state, random); } } Edited July 2, 20196 yr by MSpace-Dev Solved
July 2, 20196 yr Author Solved it. Had to scheduleUpdate(). Here is the revised code: public class BlockExample extends BlockMod implements ITileEntityProvider{ // For testing purposes private int i; public BlockExample(String name, Material materialIn) { super(name, materialIn); } @Nullable @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityBlockExample(); } @Override public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) { this.updateTick(worldIn, pos, state, worldIn.rand); super.onBlockAdded(worldIn, pos, state); } @Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { Utils.getLogger().info(++i); worldIn.scheduleUpdate(pos, this, 1); // <<-- This is important! super.updateTick(worldIn, pos, state, rand); } }
July 2, 20196 yr Author I already stated that int i was for testing purposes in the code. I am not storing the cooldown in the block class. I understand they are singleton-like. The int was just to confirm it was working. As for the tile entity creation, I will apply that.
July 2, 20196 yr Author Yeah, I will use the tile entity for that too, thanks. Btw, trying the new TileEntity init method. This isn't working. How would I do this exactly? @Nullable @Override public TileEntity createTileEntity(World world, IBlockState state) { return new TileEntityBlock(); } @Override public boolean hasTileEntity() { return true; } Also tried to call createTileEnity() in the onBlockAdded() method. Edited July 2, 20196 yr by MSpace-Dev Other methods
July 2, 20196 yr Author Ah, that worked. Thanks for the improvements. TileEntity init works and cooldown is now running using getTotalWorldTime() on the TileEntity.
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.