From 0db72764933298144ded524f7e0ff67b309a6a91 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 27 Jul 2015 08:26:13 +0200 Subject: [PATCH] Moved ItemDrill's tryHarvestBlock to WorldUtil, for future use probably --- .../config/values/ConfigBoolValues.java | 2 - .../actuallyadditions/items/ItemDrill.java | 46 +------- .../items/ItemLeafBlower.java | 13 +-- .../actuallyadditions/util/WorldUtil.java | 102 +++++++++++++++--- 4 files changed, 93 insertions(+), 70 deletions(-) diff --git a/src/main/java/ellpeck/actuallyadditions/config/values/ConfigBoolValues.java b/src/main/java/ellpeck/actuallyadditions/config/values/ConfigBoolValues.java index dcd28b1e5..d9e9cc3ad 100644 --- a/src/main/java/ellpeck/actuallyadditions/config/values/ConfigBoolValues.java +++ b/src/main/java/ellpeck/actuallyadditions/config/values/ConfigBoolValues.java @@ -5,8 +5,6 @@ import ellpeck.actuallyadditions.config.ConfigurationHandler; public enum ConfigBoolValues{ - LEAF_BLOWER_ITEMS("Leaf Blower: Drops Items", ConfigCategories.TOOL_VALUES, true, "If the Leaf Blower lets destroyed Blocks' Drops drop"), - LEAF_BLOWER_PARTICLES("Leaf Blower: Particles", ConfigCategories.TOOL_VALUES, true, "If the Leaf Blower lets destroyed Blocks have particles when getting destroyed"), LEAF_BLOWER_SOUND("Leaf Blower: Sound", ConfigCategories.TOOL_VALUES, true, "If the Leaf Blower makes Sounds"), JAM_VILLAGER_EXISTS("Jam Villager: Existence", ConfigCategories.WORLD_GEN, true, "If the Jam Villager and his House exist"), diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemDrill.java b/src/main/java/ellpeck/actuallyadditions/items/ItemDrill.java index 62fbacdc5..4e995d87f 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/ItemDrill.java +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemDrill.java @@ -13,24 +13,19 @@ import ellpeck.actuallyadditions.util.ModUtil; import ellpeck.actuallyadditions.util.WorldUtil; import net.minecraft.block.Block; import net.minecraft.block.material.Material; -import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.enchantment.Enchantment; -import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.EnumRarity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.network.play.client.C07PacketPlayerDigging; -import net.minecraft.network.play.server.S23PacketBlockChange; import net.minecraft.util.ChatComponentText; import net.minecraft.util.IIcon; import net.minecraft.util.MovingObjectPosition; @@ -343,45 +338,8 @@ public class ItemDrill extends ItemEnergy implements INameableItem{ boolean canHarvest = this.canHarvestBlock(block, stack) && (!isExtra || this.getDigSpeed(stack, block, meta) > 1.0F); if(hardness >= 0.0F && (!isExtra || (canHarvest && !block.hasTileEntity(meta)))){ this.extractEnergy(stack, use, false); - - if(!world.isRemote){ - //Server-Side only, special cases - block.onBlockHarvested(world, xPos, yPos, zPos, meta, player); - } - else{ - //Shows the Harvest Particles and plays the Block's Sound - world.playAuxSFX(2001, xPos, yPos, zPos, Block.getIdFromBlock(block)+(meta << 12)); - } - - //If the Block was actually "removed", meaning it will drop an Item - boolean removed = block.removedByPlayer(world, player, xPos, yPos, zPos, canHarvest); - //Actually removes the Block from the World - if(removed){ - //Before the Block is destroyed, special cases - block.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, meta); - - if(!world.isRemote && !player.capabilities.isCreativeMode){ - //Actually drops the Block's Items etc. - if(canHarvest){ - block.harvestBlock(world, player, xPos, yPos, zPos, meta); - } - //Only drop XP when no Silk Touch is applied - if(!EnchantmentHelper.getSilkTouchModifier(player)){ - //Drop XP depending on Fortune Level - block.dropXpOnBlockBreak(world, xPos, yPos, zPos, block.getExpDrop(world, meta, EnchantmentHelper.getFortuneModifier(player))); - } - } - } - - if(!world.isRemote){ - //Update the Client of a Block Change - ((EntityPlayerMP)player).playerNetServerHandler.sendPacket(new S23PacketBlockChange(xPos, yPos, zPos, world)); - } - else{ - //Check the Server if a Block that changed on the Client really changed, if not, revert the change - Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C07PacketPlayerDigging(2, xPos, yPos, zPos, Minecraft.getMinecraft().objectMouseOver.sideHit)); - } - return removed; + //Break the Block + return WorldUtil.playerHarvestBlock(world, xPos, yPos, zPos, player); } return false; } diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemLeafBlower.java b/src/main/java/ellpeck/actuallyadditions/items/ItemLeafBlower.java index 4f73ecaab..9007ca470 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/ItemLeafBlower.java +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemLeafBlower.java @@ -26,8 +26,6 @@ public class ItemLeafBlower extends Item implements INameableItem{ public final int range = ConfigIntValues.LEAF_BLOWER_RANGE_SIDES.getValue(); public final int rangeUp = ConfigIntValues.LEAF_BLOWER_RANGE_UP.getValue(); - public final boolean doesDrop = ConfigBoolValues.LEAF_BLOWER_ITEMS.isEnabled(); - public final boolean hasParticles = ConfigBoolValues.LEAF_BLOWER_PARTICLES.isEnabled(); public final boolean hasSound = ConfigBoolValues.LEAF_BLOWER_SOUND.isEnabled(); private final boolean isAdvanced; @@ -73,14 +71,13 @@ public class ItemLeafBlower extends Item implements INameableItem{ //Deletes the Block world.setBlockToAir(theCoord.getX(), theCoord.getY(), theCoord.getZ()); //Plays the Breaking Sound - if(this.hasParticles) world.playAuxSFX(2001, theCoord.getX(), theCoord.getY(), theCoord.getZ(), Block.getIdFromBlock(theBlock)+(meta << 12)); + world.playAuxSFX(2001, theCoord.getX(), theCoord.getY(), theCoord.getZ(), Block.getIdFromBlock(theBlock)+(meta << 12)); - if(this.doesDrop){ - for(ItemStack theDrop : drops){ - //Drops the Items into the World - world.spawnEntityInWorld(new EntityItem(world, theCoord.getX() + 0.5, theCoord.getY() + 0.5, theCoord.getZ() + 0.5, theDrop)); - } + for(ItemStack theDrop : drops){ + //Drops the Items into the World + world.spawnEntityInWorld(new EntityItem(world, theCoord.getX() + 0.5, theCoord.getY() + 0.5, theCoord.getZ() + 0.5, theDrop)); } + return; } } diff --git a/src/main/java/ellpeck/actuallyadditions/util/WorldUtil.java b/src/main/java/ellpeck/actuallyadditions/util/WorldUtil.java index 9746cb12c..ce4d7789a 100644 --- a/src/main/java/ellpeck/actuallyadditions/util/WorldUtil.java +++ b/src/main/java/ellpeck/actuallyadditions/util/WorldUtil.java @@ -4,11 +4,15 @@ import cofh.api.energy.EnergyStorage; import cofh.api.energy.IEnergyReceiver; import net.minecraft.block.Block; import net.minecraft.block.material.Material; +import net.minecraft.client.Minecraft; +import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; +import net.minecraft.network.play.client.C07PacketPlayerDigging; +import net.minecraft.network.play.server.S23PacketBlockChange; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; @@ -52,13 +56,14 @@ public class WorldUtil{ /** * Checks if a given Block with a given Meta is present in given Positions + * * @param positions The Positions, an array of {xCoord, yCoord, zCoord} arrays containing RELATIVE Positions - * @param block The Block - * @param meta The Meta - * @param world The World - * @param x The Start X Coord - * @param y The Start Y Coord - * @param z The Start Z Coord + * @param block The Block + * @param meta The Meta + * @param world The World + * @param x The Start X Coord + * @param y The Start Y Coord + * @param z The Start Z Coord * @return Is every block present? */ public static boolean hasBlocksInPlacesGiven(int[][] positions, Block block, int meta, World world, int x, int y, int z){ @@ -147,14 +152,15 @@ public class WorldUtil{ } return null; } - + public static void fillBucket(FluidTank tank, ItemStack[] slots, int inputSlot, int outputSlot){ if(slots[inputSlot] != null && tank.getFluid() != null){ ItemStack filled = FluidContainerRegistry.fillFluidContainer(tank.getFluid(), slots[inputSlot].copy()); if(filled != null && FluidContainerRegistry.isEmptyContainer(slots[inputSlot]) && (slots[outputSlot] == null || (slots[outputSlot].isItemEqual(filled) && slots[outputSlot].stackSize < slots[outputSlot].getMaxStackSize()))){ int cap = FluidContainerRegistry.getContainerCapacity(tank.getFluid(), slots[inputSlot]); if(cap > 0 && cap <= tank.getFluidAmount()){ - if(slots[outputSlot] == null) slots[outputSlot] = FluidContainerRegistry.fillFluidContainer(tank.getFluid(), slots[inputSlot].copy()); + if(slots[outputSlot] == null) + slots[outputSlot] = FluidContainerRegistry.fillFluidContainer(tank.getFluid(), slots[inputSlot].copy()); else slots[outputSlot].stackSize++; if(slots[outputSlot] != null){ @@ -175,7 +181,8 @@ public class WorldUtil{ if(slots[inputSlot] != null && FluidContainerRegistry.isFilledContainer(slots[inputSlot]) && (slots[outputSlot] == null || (slots[outputSlot].isItemEqual(FluidContainerRegistry.drainFluidContainer(slots[inputSlot].copy())) && slots[outputSlot].stackSize < slots[outputSlot].getMaxStackSize()))){ if(containedFluid == null || FluidContainerRegistry.containsFluid(slots[inputSlot], new FluidStack(containedFluid, 0))){ if((tank.getFluid() == null || FluidContainerRegistry.getFluidForFilledItem(slots[inputSlot]).isFluidEqual(tank.getFluid())) && tank.getCapacity()-tank.getFluidAmount() >= FluidContainerRegistry.getContainerCapacity(slots[inputSlot])){ - if(slots[outputSlot] == null) slots[outputSlot] = FluidContainerRegistry.drainFluidContainer(slots[inputSlot].copy()); + if(slots[outputSlot] == null) + slots[outputSlot] = FluidContainerRegistry.drainFluidContainer(slots[inputSlot].copy()); else slots[outputSlot].stackSize++; tank.fill(FluidContainerRegistry.getFluidForFilledItem(slots[inputSlot]), true); @@ -188,13 +195,20 @@ public class WorldUtil{ public static ForgeDirection getDirectionByRotatingSide(int side){ switch(side){ - case 0: return ForgeDirection.UP; - case 1: return ForgeDirection.DOWN; - case 2: return ForgeDirection.NORTH; - case 3: return ForgeDirection.EAST; - case 4: return ForgeDirection.SOUTH; - case 5: return ForgeDirection.WEST; - default: return ForgeDirection.UNKNOWN; + case 0: + return ForgeDirection.UP; + case 1: + return ForgeDirection.DOWN; + case 2: + return ForgeDirection.NORTH; + case 3: + return ForgeDirection.EAST; + case 4: + return ForgeDirection.SOUTH; + case 5: + return ForgeDirection.WEST; + default: + return ForgeDirection.UNKNOWN; } } @@ -259,4 +273,60 @@ public class WorldUtil{ Vec3 vec31 = vec3.addVector((double)f7*distance, (double)f6*distance, (double)f8*distance); return world.func_147447_a(vec3, vec31, p1, p2, p3); } + + /** + * Harvests a Block by a Player + * + * @param world The World + * @param xPos The X Coordinate + * @param yPos The Y Coordinate + * @param zPos The Z Coordinate + * @param player The Player + * @return If the Block could be harvested normally (so that it drops an item) + */ + public static boolean playerHarvestBlock(World world, int xPos, int yPos, int zPos, EntityPlayer player){ + Block block = world.getBlock(xPos, yPos, zPos); + int meta = world.getBlockMetadata(xPos, yPos, zPos); + //If the Block can be harvested or not + boolean canHarvest = block.canHarvestBlock(player, meta) && player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem().canHarvestBlock(block, player.getCurrentEquippedItem()); + + if(!world.isRemote){ + //Server-Side only, special cases + block.onBlockHarvested(world, xPos, yPos, zPos, meta, player); + } + else{ + //Shows the Harvest Particles and plays the Block's Sound + world.playAuxSFX(2001, xPos, yPos, zPos, Block.getIdFromBlock(block)+(meta << 12)); + } + + //If the Block was actually "removed", meaning it will drop an Item + boolean removed = block.removedByPlayer(world, player, xPos, yPos, zPos, canHarvest); + //Actually removes the Block from the World + if(removed){ + //Before the Block is destroyed, special cases + block.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, meta); + + if(!world.isRemote && !player.capabilities.isCreativeMode){ + //Actually drops the Block's Items etc. + if(canHarvest){ + block.harvestBlock(world, player, xPos, yPos, zPos, meta); + } + //Only drop XP when no Silk Touch is applied + if(!EnchantmentHelper.getSilkTouchModifier(player)){ + //Drop XP depending on Fortune Level + block.dropXpOnBlockBreak(world, xPos, yPos, zPos, block.getExpDrop(world, meta, EnchantmentHelper.getFortuneModifier(player))); + } + } + } + + if(!world.isRemote){ + //Update the Client of a Block Change + ((EntityPlayerMP)player).playerNetServerHandler.sendPacket(new S23PacketBlockChange(xPos, yPos, zPos, world)); + } + else{ + //Check the Server if a Block that changed on the Client really changed, if not, revert the change + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C07PacketPlayerDigging(2, xPos, yPos, zPos, Minecraft.getMinecraft().objectMouseOver.sideHit)); + } + return removed; + } }