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

  • Author

Thx. You saved me the day. I'm searching since yesterday and befor after a solution to this.

 

Thank you.

  • Author

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

  • Author

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);
    }

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.