Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi,

 

I want to make my entity destroy blocks like a real player, meaning the damage state of the block should be computed the same way so the entity breaks block at the same speed a player would. How can i do it ?

 

From ItemInWorldManager.updateBlockRemoving() i tried to sum up the computation, leading to a result like :

 


onLivingUpdate()
{ 
    [some other entity updates];

    if(this.destroying_block)
    {
        ++this.curblockDamage;

        i = this.theWorld.getBlockId(this.partiallyDestroyedBlockX, this.partiallyDestroyedBlockY, this.partiallyDestroyedBlockZ);
        Block block = Block.blocksList[i];
        if (block == null)
        {
            this.theWorld.destroyBlockInWorldPartially(entityId, x,y,z, -1);
            this.destroying_block= false;
        }
        else
        {
            ItemStack items = inventory.getCurrentItem();
            float f = items.getItem().getStrVsBlock(items,block,world.getBlockMetadata(x,y,z));

            float hardness = block.getBlockHardness(world,x,y,z);

            int l = this.curBlockDamage;
            float f1 = f / hardness / 30F;
            float f2 = f1 * (l+1);
            float j = (int)( f2 * 10.0F );

            this.theWorld.destroyBlockInWorldPartially(entityId, x,y,z, j);
        }
    }
}

 

where curBlockDamage is initialised to 0 when destroying block is set to true. Is this correct ? I don't really understand why there are so many steps and factors when computing j so I'm absolutely not sure. Moreover, what's the limit to know when the block is destroyed ?

 

Thanks. :)

  • Author

I had a look, and there's the same call to destroyBlockInWorldPartially() but it's a special case where the computation seems different as it's not similar to breaking a block with a tool.

 

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.