Fix #914 Multifarms delete harvested wood from forestry saplings

This commit is contained in:
mezz committed 2015-10-24 23:20:03 -07:00
1 parent d25f869129
commit dffa89709b
7 files changed
+102 -78

No files matched your search

@@ -106,7 +106,7 @@ public class BlockArbFence extends BlockFence implements IWoodTyped, ITileEntity
@Override
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
TileWood wood = BlockWood.getWoodTile(world, x, y, z);
TileWood wood = TileWood.getWoodTile(world, x, y, z);
EnumWoodType woodType = wood.getWoodType();
return IconProviderWood.getPlankIcon(woodType);
}
@@ -125,30 +125,37 @@ public class BlockArbFence extends BlockFence implements IWoodTyped, ITileEntity
@Override
public final ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
ItemStack itemStack = new ItemStack(this);
NBTTagCompound nbt = BlockWood.getTagCompound(world, x, y, z);
NBTTagCompound nbt = TileWood.getTagCompound(world, x, y, z);
itemStack.setTagCompound(nbt);
return itemStack;
}
@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z) {
return TileWood.blockRemovedByPlayer(this, world, player, x, y, z);
}
/* DROP HANDLING */
// Hack: When harvesting we need to get the drops in onBlockHarvested,
// because Mojang destroys the block and tile before calling getDrops.
private final ThreadLocal<ArrayList<ItemStack>> drops = new ThreadLocal<>();
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
world.removeTileEntity(x, y, z);
super.breakBlock(world, x, y, z, block, meta);
public void onBlockHarvested(World world, int x, int y, int z, int meta, EntityPlayer playerProfile) {
drops.set(TileWood.getDrops(this, world, x, y, z));
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
return new ArrayList<>();
ArrayList<ItemStack> ret = drops.get();
drops.remove();
// not harvested, get drops normally
if (ret == null) {
ret = TileWood.getDrops(this, world, x, y, z);
}
return ret;
}
@Override
public final float getBlockHardness(World world, int x, int y, int z) {
TileWood wood = BlockWood.getWoodTile(world, x, y, z);
TileWood wood = TileWood.getWoodTile(world, x, y, z);
if (wood == null) {
return EnumWoodType.DEFAULT_HARDNESS;
}
@@ -67,26 +67,33 @@ public class BlockArbStairs extends BlockStairs implements IWoodTyped, ITileEnti
}
}
@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z) {
return TileWood.blockRemovedByPlayer(this, world, player, x, y, z);
}
/* DROP HANDLING */
// Hack: When harvesting we need to get the drops in onBlockHarvested,
// because Mojang destroys the block and tile before calling getDrops.
private final ThreadLocal<ArrayList<ItemStack>> drops = new ThreadLocal<>();
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
world.removeTileEntity(x, y, z);
super.breakBlock(world, x, y, z, block, meta);
public void onBlockHarvested(World world, int x, int y, int z, int meta, EntityPlayer playerProfile) {
drops.set(TileWood.getDrops(this, world, x, y, z));
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
return new ArrayList<>();
ArrayList<ItemStack> ret = drops.get();
drops.remove();
// not harvested, get drops normally
if (ret == null) {
ret = TileWood.getDrops(this, world, x, y, z);
}
return ret;
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
ItemStack itemStack = super.getPickBlock(target, world, x, y, z);
NBTTagCompound stairsNBT = BlockWood.getTagCompound(world, x, y, z);
NBTTagCompound stairsNBT = TileWood.getTagCompound(world, x, y, z);
itemStack.setTagCompound(stairsNBT);
return itemStack;
}
@@ -107,7 +114,7 @@ public class BlockArbStairs extends BlockStairs implements IWoodTyped, ITileEnti
@Override
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
TileWood wood = BlockWood.getWoodTile(world, x, y, z);
TileWood wood = TileWood.getWoodTile(world, x, y, z);
EnumWoodType woodType = wood.getWoodType();
return IconProviderWood.getPlankIcon(woodType);
}
@@ -45,6 +45,7 @@ public class BlockLog extends BlockWood {
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
super.breakBlock(world, x, y, z, block, meta);
byte radius = 4;
int boundary = radius + 1;
@@ -101,7 +102,7 @@ public class BlockLog extends BlockWood {
@Override
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
int meta = world.getBlockMetadata(x, y, z);
TileWood wood = getWoodTile(world, x, y, z);
TileWood wood = TileWood.getWoodTile(world, x, y, z);
EnumWoodType type = wood.getWoodType();
if (type == null) {
return getIcon(side, meta);
@@ -50,7 +50,7 @@ public class BlockPlanks extends BlockWood {
@Override
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
TileWood wood = getWoodTile(world, x, y, z);
TileWood wood = TileWood.getWoodTile(world, x, y, z);
EnumWoodType woodType = wood.getWoodType();
return IconProviderWood.getPlankIcon(woodType);
}
@@ -85,7 +85,7 @@ public class BlockSlab extends net.minecraft.block.BlockSlab implements IWoodTyp
@Override
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
TileWood wood = BlockWood.getWoodTile(world, x, y, z);
TileWood wood = TileWood.getWoodTile(world, x, y, z);
EnumWoodType woodType = wood.getWoodType();
return IconProviderWood.getPlankIcon(woodType);
}
@@ -122,30 +122,37 @@ public class BlockSlab extends net.minecraft.block.BlockSlab implements IWoodTyp
@Override
public final ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
ItemStack itemStack = new ItemStack(this);
NBTTagCompound nbt = BlockWood.getTagCompound(world, x, y, z);
NBTTagCompound nbt = TileWood.getTagCompound(world, x, y, z);
itemStack.setTagCompound(nbt);
return itemStack;
}
@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z) {
return TileWood.blockRemovedByPlayer(this, world, player, x, y, z);
}
/* DROP HANDLING */
// Hack: When harvesting we need to get the drops in onBlockHarvested,
// because Mojang destroys the block and tile before calling getDrops.
private final ThreadLocal<ArrayList<ItemStack>> drops = new ThreadLocal<>();
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
world.removeTileEntity(x, y, z);
super.breakBlock(world, x, y, z, block, meta);
public void onBlockHarvested(World world, int x, int y, int z, int meta, EntityPlayer playerProfile) {
drops.set(TileWood.getDrops(this, world, x, y, z));
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
return new ArrayList<>();
ArrayList<ItemStack> ret = drops.get();
drops.remove();
// not harvested, get drops normally
if (ret == null) {
ret = TileWood.getDrops(this, world, x, y, z);
}
return ret;
}
@Override
public final float getBlockHardness(World world, int x, int y, int z) {
TileWood wood = BlockWood.getWoodTile(world, x, y, z);
TileWood wood = TileWood.getWoodTile(world, x, y, z);
if (wood == null) {
return EnumWoodType.DEFAULT_HARDNESS;
}
@@ -37,7 +37,6 @@ import forestry.arboriculture.IWoodTyped;
import forestry.arboriculture.render.IconProviderWood;
import forestry.arboriculture.tiles.TileWood;
import forestry.core.render.ParticleHelper;
import forestry.core.tiles.TileUtil;
public abstract class BlockWood extends Block implements ITileEntityProvider, IWoodTyped {
@@ -66,21 +65,6 @@ public abstract class BlockWood extends Block implements ITileEntityProvider, IW
return fireproof;
}
public static TileWood getWoodTile(IBlockAccess world, int x, int y, int z) {
return TileUtil.getTile(world, x, y, z, TileWood.class);
}
protected static NBTTagCompound getTagCompound(IBlockAccess world, int x, int y, int z) {
TileWood wood = getWoodTile(world, x, y, z);
NBTTagCompound nbttagcompound = new NBTTagCompound();
if (wood == null) {
return nbttagcompound;
}
EnumWoodType woodType = wood.getWoodType();
woodType.saveToCompound(nbttagcompound);
return nbttagcompound;
}
@SideOnly(Side.CLIENT)
@Override
public final void registerBlockIcons(IIconRegister register) {
@@ -95,30 +79,37 @@ public abstract class BlockWood extends Block implements ITileEntityProvider, IW
@Override
public final ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
ItemStack itemStack = new ItemStack(this);
NBTTagCompound nbt = getTagCompound(world, x, y, z);
NBTTagCompound nbt = TileWood.getTagCompound(world, x, y, z);
itemStack.setTagCompound(nbt);
return itemStack;
}
@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z) {
return TileWood.blockRemovedByPlayer(this, world, player, x, y, z);
}
/* DROP HANDLING */
// Hack: When harvesting we need to get the drops in onBlockHarvested,
// because Mojang destroys the block and tile before calling getDrops.
private final ThreadLocal<ArrayList<ItemStack>> drops = new ThreadLocal<>();
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
world.removeTileEntity(x, y, z);
super.breakBlock(world, x, y, z, block, meta);
public void onBlockHarvested(World world, int x, int y, int z, int meta, EntityPlayer playerProfile) {
drops.set(TileWood.getDrops(this, world, x, y, z));
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
return new ArrayList<>();
ArrayList<ItemStack> ret = drops.get();
drops.remove();
// not harvested, get drops normally
if (ret == null) {
ret = TileWood.getDrops(this, world, x, y, z);
}
return ret;
}
@Override
public final float getBlockHardness(World world, int x, int y, int z) {
TileWood wood = getWoodTile(world, x, y, z);
TileWood wood = TileWood.getWoodTile(world, x, y, z);
if (wood == null) {
return EnumWoodType.DEFAULT_HARDNESS;
}
@@ -11,13 +11,14 @@
package forestry.arboriculture.tiles;
import java.io.IOException;
import java.util.ArrayList;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import forestry.api.arboriculture.EnumWoodType;
@@ -26,7 +27,7 @@ import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.IStreamable;
import forestry.core.network.PacketTileStream;
import forestry.core.utils.ItemStackUtil;
import forestry.core.tiles.TileUtil;
public class TileWood extends TileEntity implements IStreamable {
private EnumWoodType woodType;
@@ -84,23 +85,33 @@ public class TileWood extends TileEntity implements IStreamable {
}
}
public static <T extends Block & IWoodTyped> boolean blockRemovedByPlayer(T block, World world, EntityPlayer player, int x, int y, int z) {
int meta = world.getBlockMetadata(x, y, z);
if (!world.isRemote && block.canHarvestBlock(player, meta) && !player.capabilities.isCreativeMode) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileWood) {
TileWood wood = (TileWood) tile;
ItemStack stack = new ItemStack(block);
NBTTagCompound compound = new NBTTagCompound();
wood.getWoodType().saveToCompound(compound);
stack.setTagCompound(compound);
ItemStackUtil.dropItemStackAsEntity(stack, world, x, y, z);
}
public static NBTTagCompound getTagCompound(IBlockAccess world, int x, int y, int z) {
TileWood wood = getWoodTile(world, x, y, z);
NBTTagCompound nbttagcompound = new NBTTagCompound();
if (wood == null) {
return nbttagcompound;
}
return world.setBlockToAir(x, y, z);
EnumWoodType woodType = wood.getWoodType();
woodType.saveToCompound(nbttagcompound);
return nbttagcompound;
}
public static TileWood getWoodTile(IBlockAccess world, int x, int y, int z) {
return TileUtil.getTile(world, x, y, z, TileWood.class);
}
public static <T extends Block & IWoodTyped> ArrayList<ItemStack> getDrops(T block, World world, int x, int y, int z) {
ArrayList<ItemStack> drops = new ArrayList<>();
TileWood wood = getWoodTile(world, x, y, z);
if (wood != null) {
ItemStack stack = new ItemStack(block);
NBTTagCompound compound = new NBTTagCompound();
wood.getWoodType().saveToCompound(compound);
stack.setTagCompound(compound);
drops.add(stack);
}
return drops;
}
}