Jump to content

[1.10.2] Set Block Break State


Gaprosys

Recommended Posts

I've tried to set the block break state and it functions really good, but the state doesn't reset, if I destroy the block or set it with the World::setBlockToAir to air.

 

How can I reset the block break state?

worldIn.sendBlockBreakProgress(player.getEntityId(), pos, 0) doesnt function.

 

 - Gaprosys

Link to comment
Share on other sites

This is my actual code. I've messed a little bit with it and this is the code for my breaker(for with I need the breaking method(instant mining is not so balanced)).

Quote

@Override
    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
        super.updateTick(worldIn, pos, state, rand);
        
        BlockPos harvestPos = null;
        BlockPos oldHarvestPos = null;
        IBlockState block = null;
        List<ItemStack> drops = new ArrayList<ItemStack>();
        ItemTool tool = null;
        TileEntityBreaker te = (TileEntityBreaker) worldIn.getTileEntity(pos);
        InMFakePlayer player = new InMFakePlayer(worldIn);
        
        if(worldIn.isBlockPowered(pos)) {
            te.progress = -1;
            worldIn.scheduleBlockUpdate(pos, this, this.timeSpan, 0);
            return;
        }
        
        if(!(worldIn.isRemote)) {
            if(!(IEMNetwork.canSubstrateCurrentEM(Crystal.getOwner(te.getStackInSlot(0)), this.EM))) {
                te.progress = -1;
                worldIn.scheduleBlockUpdate(pos, this, this.timeSpan, 0);
                return;
            }
            this.consumeEM(worldIn, pos);
        }
        
        switch (this.getMetaFromState(state)) {
            case 2: harvestPos = pos.north(); break;
            case 3: harvestPos = pos.south(); break;
            case 4: harvestPos = pos.west(); break;
            case 5: harvestPos = pos.east(); break;
        }
        
        if(harvestPos == null) {
            te.progress = -1;
            worldIn.scheduleBlockUpdate(pos, this, this.timeSpan, 0);
            return;
        }
        
        if(worldIn.isAirBlock(harvestPos)) {
            te.progress = -1;
            worldIn.sendBlockBreakProgress(player.getEntityId(), harvestPos, te.progress);
            worldIn.scheduleBlockUpdate(pos, this, this.timeSpan, 0);
            return;
        }
        
        worldIn.sendBlockBreakProgress(player.getEntityId(), harvestPos, te.progress);
        
        if(worldIn.isRemote) {
            return;
        }
                
        block = worldIn.getBlockState(harvestPos);
        
        if(block.getBlockHardness(worldIn, harvestPos) < 0 || block.getBlock() instanceof BlockDynamicLiquid || block.getBlock() instanceof BlockStaticLiquid ) {
            te.progress = -1;
            worldIn.scheduleBlockUpdate(pos, this, this.timeSpan, 0);
            return;
        }
        
        if(!(StackUtils.isEmpty(te.getStackInSlot(16)))) {
            if(te.getStackInSlot(16).getItem() instanceof ItemTool) {
                tool = (ItemTool) te.getStackInSlot(16).getItem();
            }
        }
        
        if(tool == null) {
            tool = new EmptyHandTool();
        }
        
        if(!(tool.getStrVsBlock(new ItemStack(tool), block) > 1.0 || block.getMaterial().isToolNotRequired())) {
            te.progress = -1;
            worldIn.scheduleBlockUpdate(pos, this, this.timeSpan, 0);
            return;
        }
        
        worldIn.sendBlockBreakProgress(player.getEntityId(), harvestPos, te.progress);
        
        if(te.progress < 9) {
            te.progress++;
            worldIn.scheduleBlockUpdate(pos, this, this.timeSpan, 0);
            return;
        } else {
            te.progress = -1;
        }
        
        if(tool.onBlockStartBreak(new ItemStack(tool, 1), harvestPos, player)) {
            List<EntityItem> list = worldIn.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(harvestPos));
            for(EntityItem item : list) {
                drops.add(item.getEntityItem().copy());
                item.setDead();
            }
        } else {
            drops = worldIn.getBlockState(harvestPos).getBlock().getDrops(worldIn, harvestPos, worldIn.getBlockState(harvestPos), 0);
        }
        
        worldIn.setBlockToAir(harvestPos);
        worldIn.playSound(null, harvestPos, block.getBlock().getSoundType(block, worldIn, harvestPos, null).getBreakSound(), SoundCategory.BLOCKS, 1, 1);
        
        if(drops.isEmpty()) {
            worldIn.scheduleBlockUpdate(pos, this, this.timeSpan, 0);
            return;
        }
        if(!(this.hasInventoryPlace(drops, te))) {
            for(int i = 0; i < drops.size(); i++) {
                worldIn.spawnEntityInWorld(new EntityItem(worldIn, harvestPos.getX()+0.5, harvestPos.getY()+0.5, harvestPos.getZ()+0.5, drops.get(i)));
            }
        } else {
            this.setStackInInventory(drops, te);
        }
        if(!(StackUtils.isEmpty(te.getStackInSlot(16)))) {
            if((te.getStackInSlot(16).getItemDamage() + 1) <= te.getStackInSlot(16).getMaxDamage())
                te.setInventorySlotContents(16, new ItemStack(tool, 1, (te.getStackInSlot(16).getItemDamage()+1)));
            else
                te.setInventorySlotContents(16, StackUtils.None);
        }
        worldIn.sendBlockBreakProgress(player.getEntityId(), harvestPos, te.progress);
    }

Link to comment
Share on other sites

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.