Jump to content

Recommended Posts

Posted

Hi!

 

So I have this block, which the items you get from the block differs according to the pickaxe you use to mine it with. However, up to this point i have put dropBlockAsItem_do's in if statements checking the player.getCurrentItem() in a onBlockDestroyedByPlayer, but when making my mod multiplayer compatible the server crashes when its mined because the Minecraft.getMinecraft().thePlayer instance isnt recognized on server since it is a client side instance. But I cant figure out how to do it otherwise.

 

Solutions?

Posted

Use the harvestBlock method. It comes with an EntityPlayer instance which you can use instead of Minecraft.getMinecraft().thePlayer.

 

Here's the original code from the block:

public void harvestBlock(World par1World, EntityPlayer par2EntityPlayer, int par3, int par4, int par5, int par6)
    {
        par2EntityPlayer.addStat(StatList.mineBlockStatArray[this.blockID], 1);
        par2EntityPlayer.addExhaustion(0.025F);

        if (this.canSilkHarvest(par1World, par2EntityPlayer, par3, par4, par5, par6) && EnchantmentHelper.getSilkTouchModifier(par2EntityPlayer.inventory))
        {
            ItemStack var8 = this.createStackedBlock(par6);

            if (var8 != null)
            {
                this.dropBlockAsItem_do(par1World, par3, par4, par5, var8);
            }
        }
        else
        {
            int var7 = EnchantmentHelper.getFortuneModifier(par2EntityPlayer.inventory);
            this.dropBlockAsItem(par1World, par3, par4, par5, par6, var7);
        }
    }

You can put your code in the line where "this.dropBlockAsItem_do" is if the player has SilkTouch.

You can put your code in the line where "this.dropBlockAsItem" is if the player hasn't SilkTouch.

 

 

Or replace the entire code block:

if (this.canSilkHarvest(par1World, par2EntityPlayer, par3, par4, par5, par6) && EnchantmentHelper.getSilkTouchModifier(par2EntityPlayer.inventory))
        {
            ItemStack var8 = this.createStackedBlock(par6);

            if (var8 != null)
            {
                this.dropBlockAsItem_do(par1World, par3, par4, par5, var8);
            }
        }
        else
        {
            int var7 = EnchantmentHelper.getFortuneModifier(par2EntityPlayer.inventory);
            this.dropBlockAsItem(par1World, par3, par4, par5, par6, var7);
        }

and put your own code there if you don't need SilkTouch.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

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.