Posted May 25, 20178 yr Hello, how can I set the block break state? I need this for a breaker. - Gaprosys
May 25, 20178 yr Author Thx. You saved me the day. I'm searching since yesterday and befor after a solution to this. Thank you.
May 25, 20178 yr 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
May 25, 20178 yr 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); }
May 26, 20178 yr Author Thanks. Now it does work good. not perfect but good and thats ok. Very thanks to you.
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.