Jump to content

Recommended Posts

Posted (edited)

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.

Edited by CommandCore
Posted

Deprecation of randomTick and tick have nothing to do with overriding the methods. The deprecation is for usage. When calling those methods, you should call them through BlockState rather than through Block.

 

As for why it won't work, you probably didn't add tickRandomly() to your block's properties. Deprecated methods will still work regardless.

Posted
6 hours ago, ChampionAsh5357 said:

Deprecation of randomTick and tick have nothing to do with overriding the methods. The deprecation is for usage. When calling those methods, you should call them through BlockState rather than through Block.

 

As for why it won't work, you probably didn't add tickRandomly() to your block's properties. Deprecated methods will still work regardless.

Gotcha, I was able to utilize this and use tick() to check for surrounding blocks.

 

5 hours ago, poopoodice said:

use


worldIn.getPendingBlockTicks().scheduleTick

to tick

This method is definitely a way to go for some actions, but unfortunately it didn't work for me,

 

By putting this in onBlockPlace() and also putting it in tick(), I was able to make someone of a consistent tick loop that ran for every interval that the tick scheduler was set at. However, it was inconsistent as random ticks would overlap it and start new tick loops. Removing  the tickRandomly() also wouldn't work for natural block appearances.

 

Basically any solution using this was going to lag out my game or just be straight up inconsistent. I really appreciate you showing me how to schedule a tick though, it is what I asked to do in the first place after all.

 

End Result:

I ended up using tickRandomly() and tick() like so:

 

public MyBlock() {
    super(Properties.create(Material.ROCK)
    .harvestTool(ToolType.PICKAXE)
    .harvestLevel(2)
    .hardnessAndResistance(2.5f, 7f)
    .sound(SoundType.field_235583_E_)
    .func_235861_h_()
                    .tickRandomly()
    );
}

@Override
public void tick(BlockState state, ServerWorld worldIn, BlockPos pos, Random rand) {
    super.tick(state, worldIn, pos, rand);

    if(JavaStuff.randomPercentChance(100))
    {
        

 

Thanks guys for the help!! 😄

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.