Hi! I'm trying to find a method to override in order for my block to have grass-like spreading capabilities. I was looking through the classes of different types of block that have timing in them, and they've either used the randomTick() method or the tick() method. However, it's deprecated! So is there any other alternative solution to my problem or the tick method in general? I've heard something about block ticks being called in BlockState now or something, but I've tried looking into that and I don't know what it means.
Here's my code that would've probably worked if tick wasn't deprecated, simply spreading to a random surrounding block of a type every two seconds, code was pretty much ripped from:
private int defaultTimer = 40; //2 seconds
private int timer = defaultTimer;
//Constructor, other overriden methods, yada yada
@Override
public void tick(BlockState state, ServerWorld worldIn, BlockPos pos, Random rand) {
super.tick(state, worldIn, pos, rand);
if(timer < defaultTimer)
{
for(int i = 0; i < 4; ++i) {
BlockPos blockpos = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1);
if (worldIn.getBlockState(blockpos).isIn(RegistryHandler.BLOCK_TO_SPREAD_ONTO.get())) {
worldIn.setBlockState(blockpos, RegistryHandler.THIS_BLOCK.get().getDefaultState());
}
}
timer = defaultTimer;
}
else
{
timer --;
}
}
Thanks everyone for the help,
Cheers.