Jump to content

Recommended Posts

Posted

I am using the code

        			worldIn.destroyBlock(pos.add(0, 0, i), false);

(i being a variable) to destroy multiple blocks at once. The blocks are being removed but aren't updating, still showing as what they were before until I relog. How can I force a block update at the location?

Posted

I am using the code

        			worldIn.destroyBlock(pos.add(0, 0, i), false);

(i being a variable) to destroy multiple blocks at once. The blocks are being removed but aren't updating, still showing as what they were before until I relog. How can I force a block update at the location?

Posted

Are you calling this ONLY (!world.isRemote) server side?

Yes, here is my whole code for the action.

    public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
        if (!worldIn.isRemote) {
        	for (int i = 0; i < 2; i++){
        			if (worldIn.getBlockState(pos.add(0, 0, i)).getBlock().equals(Blocks.STONE) && playerIn.canPlayerEdit(pos.add(0, 0, i), facing, stack)){
        			worldIn.destroyBlock(pos.add(0, 0, i), false);
            			//worldIn.getBlockState(pos.add(0,0,i)).getBlock().removedByPlayer(worldIn.getBlockState(pos.add(0,0,i)),
            					//worldIn, pos.add(0,0,i), playerIn, true);
        			worldIn.scheduleBlockUpdate(pos, worldIn.getBlockState(pos.add(0,0,i)).getBlock(), 1, 100);
        			}
        	}
        }

The first block is the only one that actually gets updated and is shown breaking. The second one does not update.

Posted

Are you calling this ONLY (!world.isRemote) server side?

Yes, here is my whole code for the action.

    public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
        if (!worldIn.isRemote) {
        	for (int i = 0; i < 2; i++){
        			if (worldIn.getBlockState(pos.add(0, 0, i)).getBlock().equals(Blocks.STONE) && playerIn.canPlayerEdit(pos.add(0, 0, i), facing, stack)){
        			worldIn.destroyBlock(pos.add(0, 0, i), false);
            			//worldIn.getBlockState(pos.add(0,0,i)).getBlock().removedByPlayer(worldIn.getBlockState(pos.add(0,0,i)),
            					//worldIn, pos.add(0,0,i), playerIn, true);
        			worldIn.scheduleBlockUpdate(pos, worldIn.getBlockState(pos.add(0,0,i)).getBlock(), 1, 100);
        			}
        	}
        }

The first block is the only one that actually gets updated and is shown breaking. The second one does not update.

Posted

Why are you calling scheduleBlockUpdate?

To attempt to update the block since it is broken but doesn't update until relog. Is there another thing I could use?

Posted

Why are you calling scheduleBlockUpdate?

To attempt to update the block since it is broken but doesn't update until relog. Is there another thing I could use?

Posted

Just tried it, works just fine with just

destroyBlock

:

 

Mine's done on right click, if that changes anything.

   
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
        if (!worldIn.isRemote) {
        	int dir = MathHelper.floor_double((double)((playerIn.rotationYaw * 4F) / 360F) + 0.5D) & 3;
    		if (dir == 0){
        	for (int i = 0; i < 2; i++){
        			if (worldIn.getBlockState(pos.add(0, 0, i)).getBlock().equals(Blocks.STONE)){
        			worldIn.destroyBlock(pos.add(0, 0, i), false);
        			}
        			if (worldIn.getBlockState(pos.add(1, 0, i)).getBlock().equals(Blocks.STONE)){
        			worldIn.destroyBlock(pos.add(1, 0, i), false);
        			}        			if (worldIn.getBlockState(pos.add(-1, 0, i)).getBlock().equals(Blocks.STONE)){
        			worldIn.destroyBlock(pos.add(-1, 0, i), false);

        			}
        		}
    		}
        }
	return null;
    }

Full code

EDIT: Longer gif

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.