Fix #964 tools not working in Adventure Mode

This commit is contained in:
mezz committed 2015-11-15 02:19:29 -08:00
1 parent 8d7dc86e9f
commit 71b5f2f181
8 files changed
+50 -141

No files matched your search

@@ -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);
@@ -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;
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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<Block> 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;
}
}
@@ -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;
}
}
@@ -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) {
@@ -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");