From 71b5f2f181dcf5916d47ce9a32eff513aa0f39ac Mon Sep 17 00:00:00 2001 From: mezz Date: Sun, 15 Nov 2015 02:19:29 -0800 Subject: [PATCH] Fix #964 tools not working in Adventure Mode --- .../arboriculture/blocks/BlockSlab.java | 6 --- .../arboriculture/items/ItemGrafter.java | 36 +++++-------- .../core/items/ItemForestryPickaxe.java | 34 ------------ .../core/items/ItemForestryShovel.java | 32 ------------ .../forestry/core/items/ItemForestryTool.java | 52 ++++++++++--------- .../java/forestry/core/items/ItemScoop.java | 15 +----- .../forestry/core/utils/ItemStackUtil.java | 3 +- .../java/forestry/plugins/PluginCore.java | 13 +++-- 8 files changed, 50 insertions(+), 141 deletions(-) delete mode 100755 src/main/java/forestry/core/items/ItemForestryPickaxe.java delete mode 100755 src/main/java/forestry/core/items/ItemForestryShovel.java diff --git a/src/main/java/forestry/arboriculture/blocks/BlockSlab.java b/src/main/java/forestry/arboriculture/blocks/BlockSlab.java index f93e86c57..0bb34a181 100644 --- a/src/main/java/forestry/arboriculture/blocks/BlockSlab.java +++ b/src/main/java/forestry/arboriculture/blocks/BlockSlab.java @@ -12,7 +12,6 @@ package forestry.arboriculture.blocks; import java.util.ArrayList; import java.util.List; -import java.util.Random; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; @@ -88,11 +87,6 @@ public class BlockSlab extends net.minecraft.block.BlockSlab implements IWoodTyp return IconProviderWood.getPlankIcon(woodType); } - @Override - public Item getItemDropped(int meta, Random random, int par3) { - return Item.getItemFromBlock(this); - } - @Override protected ItemStack createStackedBlock(int meta) { return new ItemStack(Blocks.wooden_slab, 2, meta & 7); diff --git a/src/main/java/forestry/arboriculture/items/ItemGrafter.java b/src/main/java/forestry/arboriculture/items/ItemGrafter.java index 4f972d07d..da5113a10 100755 --- a/src/main/java/forestry/arboriculture/items/ItemGrafter.java +++ b/src/main/java/forestry/arboriculture/items/ItemGrafter.java @@ -11,48 +11,38 @@ package forestry.arboriculture.items; import net.minecraft.block.Block; +import net.minecraft.block.BlockLeaves; +import net.minecraft.block.material.Material; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; -import net.minecraftforge.common.ForgeHooks; - import forestry.api.arboriculture.IToolGrafter; import forestry.api.core.Tabs; -import forestry.core.items.ItemForestry; - -public class ItemGrafter extends ItemForestry implements IToolGrafter { - private final float efficiencyOnProperMaterial; +import forestry.core.items.ItemForestryTool; +public class ItemGrafter extends ItemForestryTool implements IToolGrafter { public ItemGrafter(int maxDamage) { - setMaxStackSize(1); - efficiencyOnProperMaterial = 4.0F; + super(null); setMaxDamage(maxDamage); + setMaxStackSize(1); setCreativeTab(Tabs.tabArboriculture); + setHarvestLevel("grafter", 3); + setEfficiencyOnProperMaterial(4.0f); } @Override - public float func_150893_a(ItemStack itemstack, Block block) { - return 1.0F; - } - - @Override - public float getDigSpeed(ItemStack itemstack, Block block, int md) { - if (ForgeHooks.isToolEffective(itemstack, block, md)) { - return efficiencyOnProperMaterial; + public boolean canHarvestBlock(Block block, ItemStack itemStack) { + if (block instanceof BlockLeaves || block.getMaterial() == Material.leaves) { + return true; } - - return func_150893_a(itemstack, block); + return super.canHarvestBlock(block, itemStack); } @Override public boolean onBlockDestroyed(ItemStack itemstack, World world, Block block, int j, int k, int l, EntityLivingBase entityliving) { - return true; - } - - @Override - public boolean isFull3D() { + // damage is done by the harvested leaves return true; } diff --git a/src/main/java/forestry/core/items/ItemForestryPickaxe.java b/src/main/java/forestry/core/items/ItemForestryPickaxe.java deleted file mode 100755 index 9c71cdadd..000000000 --- a/src/main/java/forestry/core/items/ItemForestryPickaxe.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.core.items; - -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; - -import forestry.core.config.ForestryBlock; - -public class ItemForestryPickaxe extends ItemForestryTool { - - private static final Block blocksEffectiveAgainst[]; - - static { - blocksEffectiveAgainst = (new Block[]{Blocks.cobblestone, Blocks.stone, Blocks.sandstone, Blocks.mossy_cobblestone, Blocks.iron_ore, Blocks.iron_block, - Blocks.coal_ore, Blocks.gold_block, Blocks.brick_block, Blocks.nether_brick, Blocks.netherrack, Blocks.gold_ore, Blocks.diamond_ore, Blocks.diamond_block, - Blocks.ice, Blocks.netherrack, Blocks.lapis_ore, Blocks.lapis_block, ForestryBlock.resources.block(), ForestryBlock.beehives.block(), ForestryBlock.engine.block(), - ForestryBlock.factoryTESR.block(), ForestryBlock.factoryPlain.block()}); - } - - public ItemForestryPickaxe(ItemStack remnants) { - super(blocksEffectiveAgainst, remnants); - } - -} diff --git a/src/main/java/forestry/core/items/ItemForestryShovel.java b/src/main/java/forestry/core/items/ItemForestryShovel.java deleted file mode 100755 index 77ae9ab4f..000000000 --- a/src/main/java/forestry/core/items/ItemForestryShovel.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.core.items; - -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; - -import forestry.core.config.ForestryBlock; - -public class ItemForestryShovel extends ItemForestryTool { - - private static final Block blocksEffectiveAgainst[]; - - static { - blocksEffectiveAgainst = (new Block[]{Blocks.grass, Blocks.dirt, Blocks.sand, Blocks.gravel, Blocks.snow_layer, Blocks.snow, Blocks.clay, - Blocks.farmland, ForestryBlock.soil.block()}); - } - - public ItemForestryShovel(ItemStack remnants) { - super(blocksEffectiveAgainst, remnants); - } - -} diff --git a/src/main/java/forestry/core/items/ItemForestryTool.java b/src/main/java/forestry/core/items/ItemForestryTool.java index e3fe12545..27b8bdec4 100755 --- a/src/main/java/forestry/core/items/ItemForestryTool.java +++ b/src/main/java/forestry/core/items/ItemForestryTool.java @@ -10,48 +10,50 @@ ******************************************************************************/ package forestry.core.items; -import java.util.Arrays; -import java.util.List; - import net.minecraft.block.Block; import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; -public abstract class ItemForestryTool extends ItemForestry { +import forestry.core.utils.ItemStackUtil; +public class ItemForestryTool extends ItemForestry { private final ItemStack remnants; - protected float efficiencyOnProperMaterial; - private final List blocksEffectiveAgainst; + private float efficiencyOnProperMaterial; - protected ItemForestryTool(Block[] blocksEffectiveAgainst, ItemStack remnants) { - this.blocksEffectiveAgainst = Arrays.asList(blocksEffectiveAgainst); + public ItemForestryTool(ItemStack remnants) { this.maxStackSize = 1; efficiencyOnProperMaterial = 6F; setMaxDamage(200); this.remnants = remnants; + if (remnants != null) { + MinecraftForge.EVENT_BUS.register(this); + } + } + + public void setEfficiencyOnProperMaterial(float efficiencyOnProperMaterial) { + this.efficiencyOnProperMaterial = efficiencyOnProperMaterial; } @Override - public float func_150893_a(ItemStack itemstack, Block block) { - if (blocksEffectiveAgainst.contains(block)) { + public float getDigSpeed(ItemStack itemstack, Block block, int metadata) { + if (ForgeHooks.isToolEffective(itemstack, block, metadata)) { return efficiencyOnProperMaterial; } - return 1.0F; + + return super.getDigSpeed(itemstack, block, metadata); } @Override - public float getDigSpeed(ItemStack itemstack, Block block, int md) { - if (ForgeHooks.isToolEffective(itemstack, block, md)) { - return efficiencyOnProperMaterial; - } - return func_150893_a(itemstack, block); + public boolean canHarvestBlock(Block block, ItemStack stack) { + return ForgeHooks.canToolHarvestBlock(block, 0, stack); } @SubscribeEvent @@ -60,16 +62,19 @@ public abstract class ItemForestryTool extends ItemForestry { return; } - if (!event.entityPlayer.worldObj.isRemote && remnants != null) { - EntityItem entity = new EntityItem(event.entityPlayer.worldObj, event.entityPlayer.posX, event.entityPlayer.posY, event.entityPlayer.posZ, - remnants.copy()); - event.entityPlayer.worldObj.spawnEntityInWorld(entity); + EntityPlayer player = event.entityPlayer; + World world = player.worldObj; + + if (!world.isRemote && remnants != null) { + ItemStackUtil.dropItemStackAsEntity(remnants.copy(), world, player.posX, player.posY, player.posZ); } } @Override - public boolean onBlockDestroyed(ItemStack itemstack, World world, Block block, int j, int k, int l, EntityLivingBase entityliving) { - itemstack.damageItem(1, entityliving); + public boolean onBlockDestroyed(ItemStack itemstack, World world, Block block, int x, int y, int z, EntityLivingBase entityliving) { + if (block.getBlockHardness(world, x, y, z) != 0) { + itemstack.damageItem(1, entityliving); + } return true; } @@ -77,5 +82,4 @@ public abstract class ItemForestryTool extends ItemForestry { public boolean isFull3D() { return true; } - } diff --git a/src/main/java/forestry/core/items/ItemScoop.java b/src/main/java/forestry/core/items/ItemScoop.java index 8ca0820df..a958d2e21 100755 --- a/src/main/java/forestry/core/items/ItemScoop.java +++ b/src/main/java/forestry/core/items/ItemScoop.java @@ -10,26 +10,15 @@ ******************************************************************************/ package forestry.core.items; -import net.minecraft.block.Block; - import forestry.api.core.IToolScoop; import forestry.api.core.Tabs; -import forestry.core.config.ForestryBlock; public class ItemScoop extends ItemForestryTool implements IToolScoop { - public ItemScoop() { - super(new Block[]{ForestryBlock.beehives.block()}, null); - this.maxStackSize = 1; - efficiencyOnProperMaterial = 4.0F; + super(null); + setEfficiencyOnProperMaterial(4.0f); setMaxDamage(10); setCreativeTab(Tabs.tabApiculture); setMaxStackSize(1); } - - @Override - public boolean isFull3D() { - return true; - } - } diff --git a/src/main/java/forestry/core/utils/ItemStackUtil.java b/src/main/java/forestry/core/utils/ItemStackUtil.java index 1f5830eb2..ec3525f00 100644 --- a/src/main/java/forestry/core/utils/ItemStackUtil.java +++ b/src/main/java/forestry/core/utils/ItemStackUtil.java @@ -288,7 +288,7 @@ public abstract class ItemStackUtil { } public static void dropItemStackAsEntity(ItemStack items, World world, double x, double y, double z) { - if (items.stackSize <= 0) { + if (items.stackSize <= 0 || world.isRemote) { return; } @@ -300,7 +300,6 @@ public abstract class ItemStackUtil { entityitem.delayBeforeCanPickup = 10; world.spawnEntityInWorld(entityitem); - } public static ItemStack copyWithRandomSize(ItemStack template, int max, Random rand) { diff --git a/src/main/java/forestry/plugins/PluginCore.java b/src/main/java/forestry/plugins/PluginCore.java index dae80d48e..4d23f990c 100644 --- a/src/main/java/forestry/plugins/PluginCore.java +++ b/src/main/java/forestry/plugins/PluginCore.java @@ -20,7 +20,6 @@ import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.RecipeSorter; @@ -64,8 +63,7 @@ import forestry.core.items.ItemBlockTyped; import forestry.core.items.ItemElectronTube; import forestry.core.items.ItemForestry; import forestry.core.items.ItemForestryBonemeal; -import forestry.core.items.ItemForestryPickaxe; -import forestry.core.items.ItemForestryShovel; +import forestry.core.items.ItemForestryTool; import forestry.core.items.ItemFruit; import forestry.core.items.ItemMisc; import forestry.core.items.ItemOverlay.OverlayInfo; @@ -200,12 +198,13 @@ public class PluginCore extends ForestryPlugin { ForestryItem.brokenBronzeShovel.registerItem((new ItemForestry()), "brokenBronzeShovel"); // / TOOLS - ForestryItem.bronzePickaxe.registerItem(new ItemForestryPickaxe(ForestryItem.brokenBronzePickaxe.getItemStack()), "bronzePickaxe"); + final ItemStack remnants = ForestryItem.brokenBronzePickaxe.getItemStack(); + ForestryItem.bronzePickaxe.registerItem(new ItemForestryTool(remnants), "bronzePickaxe"); ForestryItem.bronzePickaxe.item().setHarvestLevel("pickaxe", 3); - MinecraftForge.EVENT_BUS.register(ForestryItem.bronzePickaxe.item()); - ForestryItem.bronzeShovel.registerItem(new ItemForestryShovel(ForestryItem.brokenBronzeShovel.getItemStack()), "bronzeShovel"); + + final ItemStack remnants1 = ForestryItem.brokenBronzeShovel.getItemStack(); + ForestryItem.bronzeShovel.registerItem(new ItemForestryTool(remnants1), "bronzeShovel"); ForestryItem.bronzeShovel.item().setHarvestLevel("shovel", 3); - MinecraftForge.EVENT_BUS.register(ForestryItem.bronzeShovel.item()); // / ASSEMBLY KITS ForestryItem.kitShovel.registerItem(new ItemAssemblyKit(ForestryItem.bronzeShovel.getItemStack()), "kitShovel");