private boolean shouldMineBlock(Block block, int x, int y, int z) { if (block instanceof BlockOre || block instanceof BlockRedstoneOre) { InventoryBasic minerInventory = this.miner.inventory; if (InventoryUtils.hasRoomInInventory(minerInventory)) { return true; } else { World world = this.miner.worldObj; ArrayList<ItemStack> items = block.getDrops(world, x, y, z, world.getBlockMetadata(x, y, z), 0); for (ItemStack item : items) { if (InventoryUtils.canFitItem(item, minerInventory)) { return true; } } } } return false; }
private void breaking(ItemStack stack, BlockPos pos, EntityPlayerMP playermp) { World world = playermp.worldObj; IBlockState state = world.getBlockState(pos); Block block = state.getBlock(); if (!world.isRemote) { if (!world.isAirBlock(pos)) { block.onBlockHarvested(world, pos, state, playermp); if (block.removedByPlayer(world, pos, playermp, true)) { block.onBlockDestroyedByPlayer(world, pos, state); if (!playermp.capabilities.isCreativeMode) { block.harvestBlock(world, playermp, pos, state, world.getTileEntity(pos)); block.dropXpOnBlockBreak(world, pos, block.getExpDrop(world, pos, 0)); stack.damageItem(1, playermp); } } playermp.playerNetServerHandler.sendPacket(new S23PacketBlockChange(world, pos)); } } if (block instanceof BlockRedstoneOre || block instanceof BlockOre || blocks.contains(block)) { if (playermp.worldObj.getBlockState(pos.up()).getBlock() instanceof BlockRedstoneOre || playermp.worldObj.getBlockState(pos.up()).getBlock() instanceof BlockOre || blocks.contains(playermp.worldObj.getBlockState(pos.up()).getBlock())) { this.breaking(stack, pos.up(), playermp); } if (playermp.worldObj.getBlockState(pos.down()).getBlock() instanceof BlockRedstoneOre || playermp.worldObj.getBlockState(pos.down()).getBlock() instanceof BlockOre || blocks.contains(playermp.worldObj.getBlockState(pos.down()).getBlock())) { this.breaking(stack, pos.down(), playermp); } if (playermp.worldObj.getBlockState(pos.north()).getBlock() instanceof BlockRedstoneOre || playermp.worldObj.getBlockState(pos.north()).getBlock() instanceof BlockOre || blocks.contains(playermp.worldObj.getBlockState(pos.north()).getBlock())) { this.breaking(stack, pos.north(), playermp); } if (playermp.worldObj.getBlockState(pos.south()).getBlock() instanceof BlockRedstoneOre || playermp.worldObj.getBlockState(pos.south()).getBlock() instanceof BlockOre || blocks.contains(playermp.worldObj.getBlockState(pos.south()).getBlock())) { this.breaking(stack, pos.south(), playermp); } if (playermp.worldObj.getBlockState(pos.west()).getBlock() instanceof BlockRedstoneOre || playermp.worldObj.getBlockState(pos.west()).getBlock() instanceof BlockOre || blocks.contains(playermp.worldObj.getBlockState(pos.west()).getBlock())) { this.breaking(stack, pos.west(), playermp); } if (playermp.worldObj.getBlockState(pos.east()).getBlock() instanceof BlockRedstoneOre || playermp.worldObj.getBlockState(pos.east()).getBlock() instanceof BlockOre || blocks.contains(playermp.worldObj.getBlockState(pos.east()).getBlock())) { this.breaking(stack, pos.east(), playermp); } } }
private void placeBlock(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side) { if (!checkUsage(stack, player, 1.0f)) { return; } NBTTagCompound tagCompound = stack.getTagCompound(); if (tagCompound == null) { Tools.error(player, "First select a block by sneaking"); return; } int id = tagCompound.getInteger("block"); Block block = (Block) Block.blockRegistry.getObjectById(id); int meta = tagCompound.getInteger("meta"); float hardness = tagCompound.getFloat("hardness"); IBlockState oldState = world.getBlockState(pos); Block oldblock = oldState.getBlock(); int oldmeta = oldblock.getMetaFromState(oldState); float blockHardness = oldblock.getBlockHardness(world, pos); if (block == oldblock && meta == oldmeta) { // The same, nothing happens. return; } if (blockHardness < -0.1f) { Tools.error(player, "This block cannot be swapped!"); return; } if (Math.abs(hardness-blockHardness) >= hardnessDistance) { Tools.error(player, "The hardness of this blocks differs too much to swap!"); return; } ProtectedBlocks protectedBlocks = ProtectedBlocks.getProtectedBlocks(world); if (protectedBlocks.isProtected(world, pos)) { Tools.error(player, "This block is protected. You cannot replace it!"); return; } Set<BlockPos> coordinates = findSuitableBlocks(stack, world, side, pos, oldblock, oldmeta); boolean notenough = false; for (BlockPos coordinate : coordinates) { if (!checkUsage(stack, player, 1.0f)) { return; } if (Tools.consumeInventoryItem(Item.getItemFromBlock(block), meta, player.inventory, player)) { if (!player.capabilities.isCreativeMode) { ItemStack itemStack = null; if (oldblock instanceof BlockRedstoneOre) { itemStack = new ItemStack(Blocks.redstone_ore); } else { Item item = oldblock.getItem(world, pos); if (item != null) { itemStack = new ItemStack(item, 1, oldblock.getDamageValue(world, pos)); } } if (itemStack != null) { Tools.giveItem(world, player, pos, itemStack); } } Tools.playSound(world, block.stepSound.getBreakSound(), coordinate.getX(), coordinate.getY(), coordinate.getZ(), 1.0f, 1.0f); world.setBlockState(coordinate, block.getStateFromMeta(meta), 2); player.openContainer.detectAndSendChanges(); registerUsage(stack, player, 1.0f); } else { notenough = true; } } if (notenough) { Tools.error(player, "You don't have the right block"); } }