diff --git a/src/main/java/tconstruct/TConstruct.java b/src/main/java/tconstruct/TConstruct.java index 767be6caadc..5c072165d16 100644 --- a/src/main/java/tconstruct/TConstruct.java +++ b/src/main/java/tconstruct/TConstruct.java @@ -105,7 +105,6 @@ public TConstruct() } EnvironmentChecks.verifyEnvironmentSanity(); - MinecraftForge.EVENT_BUS.register(events = new TEventHandler()); PluginController.registerModules(); } diff --git a/src/main/java/tconstruct/items/tools/Battleaxe.java b/src/main/java/tconstruct/items/tools/Battleaxe.java index e4e4aca66b9..f5132fe796c 100644 --- a/src/main/java/tconstruct/items/tools/Battleaxe.java +++ b/src/main/java/tconstruct/items/tools/Battleaxe.java @@ -7,6 +7,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.EnumAction; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -247,56 +248,26 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl if (!stack.hasTagCompound()) return false; - World world = player.worldObj; - final Block wood = world.getBlock(x, y, z); - NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); - final int meta = world.getBlockMetadata(x, y, z); - for (int yPos = y + 1; yPos < y + 9; yPos++) + if (player instanceof EntityPlayerMP) { - Block block = world.getBlock(x, yPos, z); - if (!(tags.getBoolean("Broken")) && block != null && block.getMaterial() == Material.wood) + EntityPlayerMP mplayer = (EntityPlayerMP)player; + World world = player.worldObj; + NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); + if (!tags.hasKey("AOEBreaking") || !tags.getBoolean("AOEBreaking")) { - Block localblock = world.getBlock(x, yPos, z); - int localMeta = world.getBlockMetadata(x, yPos, z); - int hlvl = block.getHarvestLevel(meta); - - if (hlvl <= tags.getInteger("HarvestLevel")) + tags.setBoolean("AOEBreaking", true); + for (int yPos = y + 1; yPos < y + 9; yPos++) { - boolean cancelHarvest = false; - for (ActiveToolMod mod : TConstructRegistry.activeModifiers) - { - if (mod.beforeBlockBreak(this, stack, x, yPos, z, player)) - cancelHarvest = true; - } - - if (!cancelHarvest) - { - if (block != null && block.getMaterial() == Material.wood) - { - localMeta = world.getBlockMetadata(x, yPos, z); - if (!player.capabilities.isCreativeMode) - { - if (block.removedByPlayer(world, player, x, yPos, z)) - { - block.onBlockDestroyedByPlayer(world, x, yPos, z, localMeta); - } - block.harvestBlock(world, player, x, yPos, z, localMeta); - block.onBlockHarvested(world, x, yPos, z, localMeta, player); - onBlockDestroyed(stack, world, block, x, yPos, z, player); - } - else - { - WorldHelper.setBlockToAir(world, x, yPos, z); - } - } - } + Block block = world.getBlock(x, yPos, z); + if (block != null && block.getMaterial() == Material.wood + && block.getPlayerRelativeBlockHardness(mplayer, world, x, yPos, z) > 0) + mplayer.theItemInWorldManager.tryHarvestBlock(x, yPos, z); + else + break; } + tags.setBoolean("AOEBreaking", false); } - else - break; } - if (!world.isRemote) - world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(wood) + (meta << 12)); return super.onBlockStartBreak(stack, x, y, z, player); } } diff --git a/src/main/java/tconstruct/items/tools/Excavator.java b/src/main/java/tconstruct/items/tools/Excavator.java index 59fcbbbbb1b..419084ff26f 100644 --- a/src/main/java/tconstruct/items/tools/Excavator.java +++ b/src/main/java/tconstruct/items/tools/Excavator.java @@ -4,6 +4,7 @@ import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -141,107 +142,54 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl return false; World world = player.worldObj; - final int meta = world.getBlockMetadata(x, y, z); - Block block = world.getBlock(x, y, z); - if (!stack.hasTagCompound()) - return false; - - if (block == null) - return super.onBlockStartBreak(stack, x, y, z, player); - - float blockHardness = block.getBlockHardness(world, x, y, z); - - boolean validStart = false; - for (int iter = 0; iter < materials.length; iter++) + MovingObjectPosition mop = AbilityHelper.raytraceFromEntity(world, player, true, 5.0D); + if (mop != null && player instanceof EntityPlayerMP) { - if (materials[iter] == block.getMaterial()) + EntityPlayerMP mplayer = (EntityPlayerMP) player; + NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); + if (!tags.hasKey("AOEBreaking") || !tags.getBoolean("AOEBreaking")) { - validStart = true; - break; - } - } + tags.setBoolean("AOEBreaking", true); - MovingObjectPosition mop = AbilityHelper.raytraceFromEntity(world, player, true, 5.0D); - if (mop == null || !validStart) - return super.onBlockStartBreak(stack, x, y, z, player); + int xRange = 1; + int yRange = 1; + int zRange = 1; + switch (mop.sideHit) + { + case 0: + case 1: + yRange = 0; + break; + case 2: + case 3: + zRange = 0; + break; + case 4: + case 5: + xRange = 0; + break; + } - int xRange = 1; - int yRange = 1; - int zRange = 1; - switch (mop.sideHit) - { - case 0: - case 1: - yRange = 0; - break; - case 2: - case 3: - zRange = 0; - break; - case 4: - case 5: - xRange = 0; - break; - } - NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); - for (int xPos = x - xRange; xPos <= x + xRange; xPos++) - { - for (int yPos = y - yRange; yPos <= y + yRange; yPos++) - { - for (int zPos = z - zRange; zPos <= z + zRange; zPos++) + for (int xPos = x - xRange; xPos <= x + xRange; xPos++) { - if (!(tags.getBoolean("Broken"))) + for (int yPos = y - yRange; yPos <= y + yRange; yPos++) { - Block localblock = world.getBlock(xPos, yPos, zPos); - block = localblock; - int localMeta = world.getBlockMetadata(xPos, yPos, zPos); - int hlvl = block.getHarvestLevel(meta); - float localHardness = block == null ? Float.MAX_VALUE : block.getBlockHardness(world, xPos, yPos, zPos); - - if (hlvl <= tags.getInteger("HarvestLevel") && localHardness - 1.5 <= blockHardness) + for (int zPos = z - zRange; zPos <= z + zRange; zPos++) { - boolean cancelHarvest = false; - for (ActiveToolMod mod : TConstructRegistry.activeModifiers) - { - if (mod.beforeBlockBreak(this, stack, xPos, yPos, zPos, player)) - cancelHarvest = true; - } - - if (!cancelHarvest) + Block block = world.getBlock(xPos, yPos, zPos); + for (Material mat : this.materials) { - if (block != null && !(localHardness < 0)) - { - for (int iter = 0; iter < materials.length; iter++) - { - if (materials[iter] == block.getMaterial()) - { - if (!player.capabilities.isCreativeMode) - { - if (block.removedByPlayer(world, player, xPos, yPos, zPos)) - { - block.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, localMeta); - } - block.harvestBlock(world, player, xPos, yPos, zPos, localMeta); - block.onBlockHarvested(world, xPos, yPos, zPos, localMeta, player); - if (blockHardness > 0f) - onBlockDestroyed(stack, world, localblock, xPos, yPos, zPos, player); - } - else - { - WorldHelper.setBlockToAir(world, xPos, yPos, zPos); - } - } - } - } + if (block != null && mat == block.getMaterial() + && block.getPlayerRelativeBlockHardness(mplayer, world, x, yPos, z) > 0) + mplayer.theItemInWorldManager.tryHarvestBlock(xPos, yPos, zPos); } } } } + tags.setBoolean("AOEBreaking", false); } } - if (!world.isRemote) - world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12)); - return true; + return super.onBlockStartBreak(stack, x, y, z, player); } @Override diff --git a/src/main/java/tconstruct/items/tools/Hammer.java b/src/main/java/tconstruct/items/tools/Hammer.java index 0aa72590008..11d340a8aa5 100644 --- a/src/main/java/tconstruct/items/tools/Hammer.java +++ b/src/main/java/tconstruct/items/tools/Hammer.java @@ -7,6 +7,7 @@ import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -235,115 +236,54 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl return false; World world = player.worldObj; - final Block block = world.getBlock(x, y, z); - final int meta = world.getBlockMetadata(x, y, z); - if (!stack.hasTagCompound()) - return false; - - if (block == null) - return super.onBlockStartBreak(stack, x, y, z, player); - - float blockHardness = block.getBlockHardness(world, x, y, z); - - boolean validStart = false; - for (int iter = 0; iter < materials.length; iter++) + MovingObjectPosition mop = AbilityHelper.raytraceFromEntity(world, player, true, 4.5D); + if (mop != null && player instanceof EntityPlayerMP) { - if (materials[iter] == block.getMaterial()) + EntityPlayerMP mplayer = (EntityPlayerMP) player; + NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); + if (!tags.hasKey("AOEBreaking") || !tags.getBoolean("AOEBreaking")) { - validStart = true; - break; - } - } - - if (block == Blocks.monster_egg) - validStart = true; - - MovingObjectPosition mop = AbilityHelper.raytraceFromEntity(world, player, true, 4.5D); - if (mop == null || !validStart) - return super.onBlockStartBreak(stack, x, y, z, player); + tags.setBoolean("AOEBreaking", true); - int xRange = 1; - int yRange = 1; - int zRange = 1; - switch (mop.sideHit) - { - case 0: - case 1: - yRange = 0; - break; - case 2: - case 3: - zRange = 0; - break; - case 4: - case 5: - xRange = 0; - break; - } + int xRange = 1; + int yRange = 1; + int zRange = 1; + switch (mop.sideHit) + { + case 0: + case 1: + yRange = 0; + break; + case 2: + case 3: + zRange = 0; + break; + case 4: + case 5: + xRange = 0; + break; + } - NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); - int toolLevel = tags.getInteger("HarvestLevel"); - for (int xPos = x - xRange; xPos <= x + xRange; xPos++) - { - for (int yPos = y - yRange; yPos <= y + yRange; yPos++) - { - for (int zPos = z - zRange; zPos <= z + zRange; zPos++) + for (int xPos = x - xRange; xPos <= x + xRange; xPos++) { - if (!(tags.getBoolean("Broken"))) + for (int yPos = y - yRange; yPos <= y + yRange; yPos++) { - Block localBlock = world.getBlock(xPos, yPos, zPos); - int localMeta = world.getBlockMetadata(xPos, yPos, zPos); - int hlvl = -1; - if (localBlock.getHarvestTool(localMeta) != null && localBlock.getHarvestTool(localMeta).equals(this.getHarvestType())) - hlvl = localBlock.getHarvestLevel(localMeta); - float localHardness = localBlock == null ? Float.MAX_VALUE : localBlock.getBlockHardness(world, xPos, yPos, zPos); - - if (hlvl <= toolLevel && localHardness - 1.5 <= blockHardness) + for (int zPos = z - zRange; zPos <= z + zRange; zPos++) { - boolean cancelHarvest = false; - for (ActiveToolMod mod : TConstructRegistry.activeModifiers) - { - if (mod.beforeBlockBreak(this, stack, xPos, yPos, zPos, player)) - cancelHarvest = true; - } - - if (!cancelHarvest) + Block block = world.getBlock(xPos, yPos, zPos); + for (Material mat : this.materials) { - if (localBlock != null && !(localHardness < 0)) - { - for (int iter = 0; iter < materials.length; iter++) - { - if (materials[iter] == localBlock.getMaterial() || localBlock == Blocks.monster_egg) - { - if (!player.capabilities.isCreativeMode) - { - if (localBlock.removedByPlayer(world, player, xPos, yPos, zPos)) - { - localBlock.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, localMeta); - } - localBlock.harvestBlock(world, player, xPos, yPos, zPos, localMeta); - localBlock.onBlockHarvested(world, xPos, yPos, zPos, localMeta, player); - if (blockHardness > 0f) - onBlockDestroyed(stack, world, localBlock, xPos, yPos, zPos, player); - world.func_147479_m(x, y, z); - } - else - { - WorldHelper.setBlockToAir(world, xPos, yPos, zPos); - world.func_147479_m(x, y, z); - } - } - } - } + if (block != null && mat == block.getMaterial() + && block.getPlayerRelativeBlockHardness(mplayer, world, x, yPos, z) > 0) + mplayer.theItemInWorldManager.tryHarvestBlock(xPos, yPos, zPos); } } } } + tags.setBoolean("AOEBreaking", false); } } - if (!world.isRemote) - world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12)); - return true; + return super.onBlockStartBreak(stack, x, y, z, player); } @Override diff --git a/src/main/java/tconstruct/items/tools/LumberAxe.java b/src/main/java/tconstruct/items/tools/LumberAxe.java index 137bd177182..30293a7f5f7 100644 --- a/src/main/java/tconstruct/items/tools/LumberAxe.java +++ b/src/main/java/tconstruct/items/tools/LumberAxe.java @@ -5,6 +5,7 @@ import net.minecraft.block.material.Material; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -135,150 +136,81 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl if (!stack.hasTagCompound()) return false; - World world = player.worldObj; - final Block wood = world.getBlock(x, y, z); - ; - if (wood == null) + if (player instanceof EntityPlayerMP) { - return super.onBlockStartBreak(stack, x, y, z, player); - } - if (wood.isWood(world, x, y, z) || wood.getMaterial() == Material.sponge) - { - int height = y; - boolean foundTop = false; - do + EntityPlayerMP mplayer = (EntityPlayerMP) player; + NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); + if (!tags.hasKey("AOEBreaking") || !tags.getBoolean("AOEBreaking")) { - height++; - Block block = world.getBlock(x, height, z); - if (block != wood) + tags.setBoolean("AOEBreaking", true); + World world = player.worldObj; + Block block = world.getBlock(x, y, z); + if (block.isWood(world, x, y, z)) { - height--; - foundTop = true; - } - } while (!foundTop); + int height = y; + while (true) + { + height++; + if (block != world.getBlock(x, height, z)) + { + height--; + break; + } + } - int numLeaves = 0; - if (height - y < 50) - { - for (int xPos = x - 1; xPos <= x + 1; xPos++) - { - for (int yPos = height - 1; yPos <= height + 1; yPos++) + int numLeaves = 0; + if (height - y < 50) { - for (int zPos = z - 1; zPos <= z + 1; zPos++) + for (int xPos = x - 1; xPos <= x + 1; xPos++) { - Block leaves = world.getBlock(xPos, yPos, zPos); - if (leaves != null && leaves.isLeaves(world, xPos, yPos, zPos)) - numLeaves++; + for (int zPos = z - 1; zPos <= z + 1; zPos++) + { + for (int yPos = height - 1; yPos <= height + 1; yPos++) + { + Block leaf = world.getBlock(xPos, yPos, zPos); + if (leaf != null && leaf.isLeaves(world, xPos, yPos, zPos)) + numLeaves++; + } + } } } + + if (numLeaves > 3) + breakTree(world, x, y, z, stack, tags, block, world.getBlockMetadata(x, y, z), mplayer); + else + destroyWood(world, x, y, z, stack, tags, mplayer); } + else if (block.getMaterial() == Material.wood) + { + destroyWood(world, x, y, z, stack, tags, mplayer); + } + tags.setBoolean("AOEBreaking", false); } - - NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); - int meta = world.getBlockMetadata(x, y, z); - if (numLeaves > 3) - breakTree(world, x, y, z, stack, tags, wood, meta, player); - else - destroyWood(world, x, y, z, stack, tags, player); - - if (!world.isRemote) - world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(wood) + (meta << 12)); - } - else if (wood.getMaterial() == Material.wood) - { - NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); - int meta = world.getBlockMetadata(x, y, z); - destroyWood(world, x, y, z, stack, tags, player); - if (!world.isRemote) - world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(wood) + (meta << 12)); } return super.onBlockStartBreak(stack, x, y, z, player); } - void breakTree (World world, int x, int y, int z, ItemStack stack, NBTTagCompound tags, Block bID, int meta, EntityPlayer player) + void breakTree (World world, int x, int y, int z, ItemStack stack, NBTTagCompound tags, Block bID, int meta, EntityPlayerMP player) { - Block block; for (int xPos = x - 1; xPos <= x + 1; xPos++) { for (int yPos = y; yPos <= y + 1; yPos++) { for (int zPos = z - 1; zPos <= z + 1; zPos++) { - if (!(tags.getBoolean("Broken"))) + Block block = world.getBlock(xPos, yPos, zPos); + if (bID == block && world.getBlockMetadata(xPos, yPos, zPos) == meta) { - Block localblock = world.getBlock(xPos, yPos, zPos); - if (bID == localblock) - { - block = localblock; - meta = world.getBlockMetadata(xPos, yPos, zPos); - int hlvl = block.getHarvestLevel(meta); - - if (hlvl <= tags.getInteger("HarvestLevel")) - { - boolean cancelHarvest = false; - for (ActiveToolMod mod : TConstructRegistry.activeModifiers) - { - if (mod.beforeBlockBreak(this, stack, xPos, yPos, zPos, player)) - cancelHarvest = true; - } - - if (cancelHarvest) - { - breakTree(world, xPos, yPos, zPos, stack, tags, bID, meta, player); - } - else - { - if (localblock == bID && world.getBlockMetadata(xPos, yPos, zPos) % 4 == meta % 4) - { - /* - * world.setBlock(xPos, yPos, zPos, 0, - * 0, 3); if - * (!player.capabilities.isCreativeMode) - * { - * Block.blocksList[bID].harvestBlock(world - * , player, xPos, yPos, zPos, meta); - * onBlockDestroyed(stack, world, bID, - * xPos, yPos, zPos, player); } - */ - if (!player.capabilities.isCreativeMode) - { - if (block.removedByPlayer(world, player, xPos, yPos, zPos)) - { - block.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, meta); - } - block.harvestBlock(world, player, xPos, yPos, zPos, meta); - block.onBlockHarvested(world, xPos, yPos, zPos, meta, player); - onBlockDestroyed(stack, world, localblock, xPos, yPos, zPos, player); - } - else - { - WorldHelper.setBlockToAir(world, xPos, yPos, zPos); - } - breakTree(world, xPos, yPos, zPos, stack, tags, bID, meta, player); - } - /* - * else { Block leaves = - * Block.blocksList[localID]; if (leaves != - * null && leaves.isLeaves(world, xPos, - * yPos, zPos)) { - * WorldHelper.setBlockToAir(world, xPos, - * yPos, zPos); if - * (!player.capabilities.isCreativeMode) { - * Block.blocksList[bID].harvestBlock(world, - * player, xPos, yPos, zPos, meta); - * onBlockDestroyed(stack, world, bID, xPos, - * yPos, zPos, player); } } } - */ - } - } - } + if (block.getPlayerRelativeBlockHardness(player, world, x, yPos, z) > 0) + player.theItemInWorldManager.tryHarvestBlock(x, yPos, z); + breakTree(world, xPos, yPos, zPos, stack, tags, bID, meta, player); } } } } } - void destroyWood (World world, int x, int y, int z, ItemStack stack, NBTTagCompound tags, EntityPlayer player) + void destroyWood (World world, int x, int y, int z, ItemStack stack, NBTTagCompound tags, EntityPlayerMP player) { for (int xPos = x - 1; xPos <= x + 1; xPos++) { @@ -286,36 +218,10 @@ void destroyWood (World world, int x, int y, int z, ItemStack stack, NBTTagCompo { for (int zPos = z - 1; zPos <= z + 1; zPos++) { - if (!(tags.getBoolean("Broken"))) - { - Block block = world.getBlock(xPos, yPos, zPos); - int meta = world.getBlockMetadata(xPos, yPos, zPos); - int hlvl = block.getHarvestLevel(meta); - - if (block != null && block.getMaterial() == Material.wood) - { - if (hlvl <= tags.getInteger("HarvestLevel")) - { - boolean cancelHarvest = false; - for (ActiveToolMod mod : TConstructRegistry.activeModifiers) - { - if (mod.beforeBlockBreak(this, stack, xPos, yPos, zPos, player)) - cancelHarvest = true; - } - - if (!cancelHarvest) - { - WorldHelper.setBlockToAir(world, xPos, yPos, zPos); - if (!player.capabilities.isCreativeMode) - { - // TODO harvestBlock - block.harvestBlock(world, player, xPos, yPos, zPos, meta); - onBlockDestroyed(stack, world, block, xPos, yPos, zPos, player); - } - } - } - } - } + Block block = world.getBlock(xPos, yPos, zPos); + if (block != null && block.getMaterial() == Material.wood + && block.getPlayerRelativeBlockHardness(player, world, xPos, yPos, zPos) > 0) + player.theItemInWorldManager.tryHarvestBlock(xPos, yPos, zPos); } } } diff --git a/src/main/java/tconstruct/items/tools/Scythe.java b/src/main/java/tconstruct/items/tools/Scythe.java index b639c25a5f0..c808ed2ed20 100644 --- a/src/main/java/tconstruct/items/tools/Scythe.java +++ b/src/main/java/tconstruct/items/tools/Scythe.java @@ -12,6 +12,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -162,90 +163,33 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl if (!stack.hasTagCompound()) return false; - World world = player.worldObj; - final Block blockB = world.getBlock(x, y, z); - final int meta = world.getBlockMetadata(x, y, z); - if (!stack.hasTagCompound()) - return false; - NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); - boolean butter = EnchantmentHelper.getEnchantmentLevel(Enchantment.silkTouch.effectId, stack) > 0; - for (int xPos = x - 1; xPos <= x + 1; xPos++) + if (player instanceof EntityPlayerMP) { - for (int yPos = y - 1; yPos <= y + 1; yPos++) + EntityPlayerMP mplayer = (EntityPlayerMP) player; + World world = player.worldObj; + NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); + if (!tags.hasKey("AOEBreaking") || !tags.getBoolean("AOEBreaking")) { - for (int zPos = z - 1; zPos <= z + 1; zPos++) + tags.setBoolean("AOEBreaking", true); + for (int xPos = x - 1; xPos <= x + 1; xPos++) { - if (!(tags.getBoolean("Broken"))) + for (int yPos = y - 1; yPos <= y + 1; yPos++) { - boolean cancelHarvest = false; - for (ActiveToolMod mod : TConstructRegistry.activeModifiers) + for (int zPos = z - 1; zPos <= z + 1; zPos++) { - if (mod.beforeBlockBreak(this, stack, xPos, yPos, zPos, player)) - cancelHarvest = true; - } - - if (!cancelHarvest) - { - Block localBlock = world.getBlock(xPos, yPos, zPos); - int localMeta = world.getBlockMetadata(xPos, yPos, zPos); - float localHardness = localBlock == null ? Float.MAX_VALUE : localBlock.getBlockHardness(world, xPos, yPos, zPos); - if (localBlock != null)// && (block.blockMaterial == Material.leaves || block.isLeaves(world, xPos, yPos, zPos))) + Block block = world.getBlock(xPos, yPos, zPos); + for (Material mat : this.materials) { - for (int iter = 0; iter < materials.length; iter++) - { - if (materials[iter] == localBlock.getMaterial()) - { - if (!player.capabilities.isCreativeMode) - { - if (butter && localBlock instanceof IShearable && ((IShearable) localBlock).isShearable(stack, player.worldObj, x, y, z)) - { - ArrayList drops = ((IShearable) localBlock).onSheared(stack, player.worldObj, x, y, z, - EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack)); - Random rand = new Random(); - - if (!world.isRemote) - for (ItemStack dropStack : drops) - { - float f = 0.7F; - double d = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D; - double d1 = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D; - double d2 = (double) (rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D; - EntityItem entityitem = new EntityItem(player.worldObj, (double) xPos + d, (double) yPos + d1, (double) zPos + d2, dropStack); - entityitem.delayBeforeCanPickup = 10; - player.worldObj.spawnEntityInWorld(entityitem); - } - - if (localHardness > 0f) - onBlockDestroyed(stack, world, localBlock, xPos, yPos, zPos, player); - player.addStat(StatList.mineBlockStatArray[Block.getIdFromBlock(localBlock)], 1); - world.setBlockToAir(xPos, yPos, zPos); - } - else - { - if (localBlock.removedByPlayer(world, player, xPos, yPos, zPos)) - { - localBlock.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, localMeta); - } - localBlock.harvestBlock(world, player, xPos, yPos, zPos, localMeta); - localBlock.onBlockHarvested(world, xPos, yPos, zPos, localMeta, player); - if (localHardness > 0f) - onBlockDestroyed(stack, world, localBlock, xPos, yPos, zPos, player); - } - } - else - { - world.setBlockToAir(xPos, yPos, zPos); - } - } - } + if (block != null && mat == block.getMaterial() + && block.getPlayerRelativeBlockHardness(mplayer, world, x, yPos, z) > 0) + mplayer.theItemInWorldManager.tryHarvestBlock(xPos, yPos, zPos); } } } } + tags.setBoolean("AOEBreaking", false); } } - if (!world.isRemote) - world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(blockB) + (meta << 12)); return super.onBlockStartBreak(stack, x, y, z, player); } diff --git a/src/main/java/tconstruct/library/tools/DualHarvestTool.java b/src/main/java/tconstruct/library/tools/DualHarvestTool.java index f6c291ed6d7..ff15a8711ec 100644 --- a/src/main/java/tconstruct/library/tools/DualHarvestTool.java +++ b/src/main/java/tconstruct/library/tools/DualHarvestTool.java @@ -20,44 +20,6 @@ public DualHarvestTool(int baseDamage) super(baseDamage); } - @Override - public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPlayer player) - { - NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); - World world = player.worldObj; - int meta = world.getBlockMetadata(x, y, z); - Block block = player.worldObj.getBlock(x, y, z); - if (block == null || block == Blocks.air) - return false; - int hlvl = -1; - int shlvl = -1; - if (block.getHarvestTool(meta) == null || block.getHarvestTool(meta).equals(getHarvestType())) - hlvl = block.getHarvestLevel(meta); - if (block.getHarvestTool(meta) == null || block.getHarvestTool(meta).equals(getSecondHarvestType())) - shlvl = block.getHarvestLevel(meta); - - if (hlvl <= tags.getInteger("HarvestLevel") && shlvl <= tags.getInteger("HarvestLevel2")) - { - boolean cancelHarvest = false; - for (ActiveToolMod mod : TConstructRegistry.activeModifiers) - { - if (mod.beforeBlockBreak(this, stack, x, y, z, player)) - cancelHarvest = true; - } - - return cancelHarvest; - } - else - { - if (!player.capabilities.isCreativeMode) - onBlockDestroyed(stack, world, block, x, y, z, player); - WorldHelper.setBlockToAir(world, x, y, z); - if (!world.isRemote) - world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12)); - return true; - } - } - @Override public float getDigSpeed (ItemStack stack, Block block, int meta) { diff --git a/src/main/java/tconstruct/library/tools/HarvestTool.java b/src/main/java/tconstruct/library/tools/HarvestTool.java index 6b265ef3723..3efb07ee9d7 100644 --- a/src/main/java/tconstruct/library/tools/HarvestTool.java +++ b/src/main/java/tconstruct/library/tools/HarvestTool.java @@ -22,96 +22,6 @@ public HarvestTool(int baseDamage) super(baseDamage); } - @Override - public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPlayer player) - { - if (!stack.hasTagCompound()) - return false; - - NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); - World world = player.worldObj; - Block block = player.worldObj.getBlock(x, y, z); - int meta = world.getBlockMetadata(x, y, z); - // Block block = Block.blocksList[bID]; - if (block == null || block == Blocks.air) - return false; - int hlvl = -1; - if (!(tags.getBoolean("Broken"))) - { - Block localBlock = world.getBlock(x, y, z); - int localMeta = world.getBlockMetadata(x, y, z); - if (block.getHarvestTool(meta) != null && block.getHarvestTool(meta).equals(this.getHarvestType())) - hlvl = block.getHarvestLevel(meta); - int toolLevel = tags.getInteger("HarvestLevel"); - float blockHardness = block.getBlockHardness(world, x, y, z); - float localHardness = localBlock == null ? Float.MAX_VALUE : localBlock.getBlockHardness(world, x, y, z); - - if (hlvl <= toolLevel && localHardness - 1.5 <= blockHardness) - { - boolean cancelHarvest = false; - for (ActiveToolMod mod : TConstructRegistry.activeModifiers) - { - if (mod.beforeBlockBreak(this, stack, x, y, z, player)) - cancelHarvest = true; - } - - if (!cancelHarvest) - { - if (localBlock != null && !(localHardness < 0)) - { - - boolean isEffective = false; - - for (int iter = 0; iter < getEffectiveMaterials().length; iter++) - { - if (getEffectiveMaterials()[iter] == localBlock.getMaterial() || localBlock == Blocks.monster_egg) - { - isEffective = true; - break; - } - } - - if (localBlock.getMaterial().isToolNotRequired()) - { - isEffective = true; - } - - if (!player.capabilities.isCreativeMode) - { - if (isEffective) - { - if (localBlock.removedByPlayer(world, player, x, y, z)) - { - localBlock.onBlockDestroyedByPlayer(world, x, y, z, localMeta); - } - localBlock.harvestBlock(world, player, x, y, z, localMeta); - localBlock.onBlockHarvested(world, x, y, z, localMeta, player); - if (blockHardness > 0f) - onBlockDestroyed(stack, world, localBlock, x, y, z, player); - world.func_147479_m(x, y, z); - } - else - { - WorldHelper.setBlockToAir(world, x, y, z); - world.func_147479_m(x, y, z); - } - - } - else - { - WorldHelper.setBlockToAir(world, x, y, z); - world.func_147479_m(x, y, z); - } - } - } - } - } - if (!world.isRemote) - world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12)); - return true; - - } - @Override public float getDigSpeed (ItemStack stack, Block block, int meta) { diff --git a/src/main/java/tconstruct/library/tools/ToolCore.java b/src/main/java/tconstruct/library/tools/ToolCore.java index ab0fae9b265..a5baf602160 100644 --- a/src/main/java/tconstruct/library/tools/ToolCore.java +++ b/src/main/java/tconstruct/library/tools/ToolCore.java @@ -606,14 +606,28 @@ public void onUpdate (ItemStack stack, World world, Entity entity, int par4, boo @Override public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPlayer player) { - boolean cancelHarvest = false; - for (ActiveToolMod mod : TConstructRegistry.activeModifiers) - { - if (mod.beforeBlockBreak(this, stack, x, y, z, player)) - cancelHarvest = true; - } - - return cancelHarvest; + World world = player.worldObj; + if (stack.getTagCompound().getCompoundTag("InfiTool").getBoolean("Lava") && world.isRemote) + for (int i = 0; i < 5; i++) + { + float f = (float) x + random.nextFloat(); + float f1 = (float) y + random.nextFloat(); + float f2 = (float) z + random.nextFloat(); + float f3 = 0.52F; + float f4 = random.nextFloat() * 0.6F - 0.3F; + world.spawnParticle("smoke", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D); + world.spawnParticle("flame", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D); + + world.spawnParticle("smoke", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D); + world.spawnParticle("flame", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D); + + world.spawnParticle("smoke", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D); + world.spawnParticle("flame", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D); + + world.spawnParticle("smoke", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D); + world.spawnParticle("flame", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D); + } + return false; } @Override diff --git a/src/main/java/tconstruct/modifiers/tools/TActiveOmniMod.java b/src/main/java/tconstruct/modifiers/tools/TActiveOmniMod.java index 076474ec2df..f8f82834fdb 100644 --- a/src/main/java/tconstruct/modifiers/tools/TActiveOmniMod.java +++ b/src/main/java/tconstruct/modifiers/tools/TActiveOmniMod.java @@ -58,91 +58,6 @@ public boolean beforeBlockBreak (ToolCore tool, ItemStack stack, int x, int y, i return false; TRepo.modLapis.midStreamModify(stack, tool); - World world = entity.worldObj; - Block block = entity.worldObj.getBlock(x, y, z); - int meta = world.getBlockMetadata(x, y, z); - // TODO do we need the next to lines???????? - if (block == null) - return false; - - if (tags.getBoolean("Lava") && block.quantityDropped(meta, 0, random) != 0) - { - ItemStack smeltStack = new ItemStack(block.getItemDropped(meta, random, 0), block.quantityDropped(meta, 0, random), block.damageDropped(meta)); - if (smeltStack.getItem() == null) - return false; - ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(smeltStack); - if (result != null) - { - WorldHelper.setBlockToAir(world, x, y, z); - if (entity instanceof EntityPlayer && !((EntityPlayer) entity).capabilities.isCreativeMode) - tool.onBlockDestroyed(stack, world, block, x, y, z, entity); - if (!world.isRemote) - { - ItemStack spawnme = result.copy(); - if (!(result.getItem() instanceof ItemBlock) && PHConstruct.lavaFortuneInteraction) - { - int loot = EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack); - if (loot > 0) - { - spawnme.stackSize *= (random.nextInt(loot + 1) + 1); - } - } - EntityItem entityitem = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, spawnme); - - entityitem.delayBeforeCanPickup = 10; - world.spawnEntityInWorld(entityitem); - world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12)); - - int i = spawnme.stackSize; - float f = FurnaceRecipes.smelting().func_151398_b(spawnme); - int j; - - if (f == 0.0F) - { - i = 0; - } - else if (f < 1.0F) - { - j = MathHelper.floor_float((float) i * f); - - if (j < MathHelper.ceiling_float_int((float) i * f) && (float) Math.random() < (float) i * f - (float) j) - { - ++j; - } - - i = j; - } - - while (i > 0) - { - j = EntityXPOrb.getXPSplit(i); - i -= j; - entity.worldObj.spawnEntityInWorld(new EntityXPOrb(world, x, y + 0.5, z, j)); - } - } - for (int i = 0; i < 5; i++) - { - float f = (float) x + random.nextFloat(); - float f1 = (float) y + random.nextFloat(); - float f2 = (float) z + random.nextFloat(); - float f3 = 0.52F; - float f4 = random.nextFloat() * 0.6F - 0.3F; - world.spawnParticle("smoke", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D); - world.spawnParticle("flame", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D); - - world.spawnParticle("smoke", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D); - world.spawnParticle("flame", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D); - - world.spawnParticle("smoke", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D); - world.spawnParticle("flame", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D); - - world.spawnParticle("smoke", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D); - world.spawnParticle("flame", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D); - } - return true; - } - } - return false; } diff --git a/src/main/java/tconstruct/util/TEventHandler.java b/src/main/java/tconstruct/util/TEventHandler.java index 3dce49101c6..5521d2b8600 100644 --- a/src/main/java/tconstruct/util/TEventHandler.java +++ b/src/main/java/tconstruct/util/TEventHandler.java @@ -50,6 +50,8 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action; import net.minecraftforge.oredict.OreDictionary.OreRegisterEvent; +import net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent; +import net.minecraftforge.event.world.BlockEvent.BreakEvent; import tconstruct.TConstruct; import tconstruct.achievements.TAchievements; import tconstruct.blocks.LiquidMetalFinite; @@ -58,6 +60,7 @@ import tconstruct.entity.BlueSlime; import tconstruct.items.tools.FryingPan; import tconstruct.library.TConstructRegistry; +import tconstruct.library.ActiveToolMod; import tconstruct.library.event.PartBuilderEvent; import tconstruct.library.event.ToolCraftEvent; import tconstruct.library.tools.ArrowMaterial; @@ -747,4 +750,40 @@ public void playerInteract (PlayerInteractEvent event) } } + @SubscribeEvent + public void harvestBlock (HarvestDropsEvent event) + { + if (event.harvester == null) + return; + ItemStack stack = event.harvester.getCurrentEquippedItem(); + if (stack == null || stack.getItem() == null || !(stack.getItem() instanceof ToolCore)) + return; + if (stack.getTagCompound().getCompoundTag("InfiTool").getBoolean("Lava")) + { + for (int i = 0; i < event.drops.size(); i++) + { + ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(event.drops.get(i)); + if (result != null) + event.drops.set(i, result.copy()); + } + } + } + + @SubscribeEvent + public void breakBlock (BreakEvent event) + { + ItemStack stack = event.getPlayer().getCurrentEquippedItem(); + if (stack == null || stack.getItem() == null || !(stack.getItem() instanceof ToolCore)) + return; + if (stack.getTagCompound().getCompoundTag("InfiTool").getBoolean("Broken")) + { + event.setCanceled(true); + } + else + { + for (ActiveToolMod mod : TConstructRegistry.activeModifiers) + if (mod.beforeBlockBreak((ToolCore)stack.getItem(), stack, event.x, event.y, event.z, event.getPlayer())) + event.setCanceled(true); + } + } }