#2053 #1960 Refactor how block drops work. Now relies on getDrops.

This commit is contained in:
tterrag1098 committed 2015-03-05 15:13:03 -05:00
1 parent 583121f2be
commit b1efc0d8fe
5 files changed
+19 -82

No files matched your search

+19 -24
View File
@@ -4,6 +4,8 @@ import java.util.ArrayList;
import javax.annotation.Nullable;
import com.google.common.collect.Lists;
import net.minecraft.block.Block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
@@ -70,11 +72,6 @@ public abstract class BlockEio extends Block {
blockIcon = iIconRegister.registerIcon("enderio:" + name);
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
return doNormalDrops(world, x, y, z) ? super.getDrops(world, x, y, z, metadata, fortune) : new ArrayList<ItemStack>();
}
/* Subclass Helpers */
@Override
@@ -114,34 +111,32 @@ public abstract class BlockEio extends Block {
}
@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean doHarvest) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileEntityEio && ((TileEntityEio) te).shouldDrop()) {
if(!world.isRemote && !player.capabilities.isCreativeMode && !doNormalDrops(world, x, y, z)) {
dropAsItem(world, x, y, z, (TileEntityEio) te);
((TileEntityEio) te).preventDrops();
} else if(player.capabilities.isCreativeMode) {
((TileEntityEio) te).preventDrops();
}
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) {
if(willHarvest) {
return true;
}
return super.removedByPlayer(world, player, x, y, z, false);
return super.removedByPlayer(world, player, x, y, z, willHarvest);
}
@Override
public void harvestBlock(World world, EntityPlayer player, int x, int y, int z, int meta) {
super.harvestBlock(world, player, x, y, z, meta);
world.setBlockToAir(x, y, z);
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileEntityEio && ((TileEntityEio) te).shouldDrop() && !doNormalDrops(world, x, y, z)) {
dropAsItem(world, x, y, z, (TileEntityEio) te);
((TileEntityEio)te).preventDrops();
public final ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
if(doNormalDrops(world, x, y, z)) {
return super.getDrops(world, x, y, z, metadata, fortune);
}
super.breakBlock(world, x, y, z, block, meta);
return Lists.newArrayList(getNBTDrop(world, x, y, z, (TileEntityEio) world.getTileEntity(x, y, z)));
}
public void dropAsItem(World world, int x, int y, int z, TileEntityEio te) {
public ItemStack getNBTDrop(World world, int x, int y, int z, TileEntityEio te) {
int meta = damageDropped(te.getBlockMetadata());
ItemStack itemStack = new ItemStack(this, 1, meta);
processDrop(world, x, y, z, te, itemStack);
dropBlockAsItem(world, x, y, z, itemStack);
return itemStack;
}
protected void processDrop(World world, int x, int y, int z, @Nullable TileEntityEio te, ItemStack drop) {
@@ -10,8 +10,6 @@ import net.minecraft.tileentity.TileEntity;
* Created by CrazyPants on 27/02/14.
*/
public abstract class TileEntityEio extends TileEntity {
private boolean shouldDrop = true;
@Override
public final void readFromNBT(NBTTagCompound root) {
@@ -50,12 +48,4 @@ public abstract class TileEntityEio extends TileEntity {
protected boolean isPoweredRedstone() {
return worldObj.getStrongestIndirectPower(xCoord, yCoord, zCoord) > 0;
}
public void preventDrops() {
shouldDrop = false;
}
public boolean shouldDrop() {
return shouldDrop;
}
}
@@ -123,32 +123,6 @@ public class BlockHyperCube extends BlockEio implements IGuiHandler, IResourceTo
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
if(!world.isRemote) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileHyperCube) {
TileHyperCube hc = (TileHyperCube) te;
hc.onBreakBlock();
ItemStack itemStack = new ItemStack(this);
PowerHandlerUtil.setStoredEnergyForItem(itemStack, hc.getEnergyStored());
setChannelOnItem(hc, itemStack);
setIoOnItem(hc, itemStack);
ret.add(itemStack);
ItemRecieveBuffer rb = hc.getRecieveBuffer();
for (int i = 0; i < rb.getSizeInventory(); i++) {
ItemStack stack = rb.getStackInSlot(i);
if(stack != null) {
ret.add(stack);
}
}
}
}
return ret;
}
private void setChannelOnItem(TileHyperCube hc, ItemStack itemStack) {
Channel chan = hc.getChannel();
if(chan != null) {
@@ -255,23 +255,6 @@ public class BlockCapacitorBank extends BlockEio implements IGuiHandler, IAdvanc
}
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
if(!world.isRemote) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileCapacitorBank) {
TileCapacitorBank cb = (TileCapacitorBank) te;
cb.onBreakBlock();
ItemStack itemStack =
BlockItemCapacitorBank.createItemStackWithPower(cb.doGetEnergyStored());
ret.add(itemStack);
}
}
return ret;
}
@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z) {
if(!world.isRemote) {
@@ -37,11 +37,6 @@ public class ToolUtil {
public static boolean breakBlockWithTool(Block block, World world, int x, int y, int z, EntityPlayer entityPlayer) {
ITool tool = ToolUtil.getEquippedTool(entityPlayer);
if(tool != null && entityPlayer.isSneaking() && tool.canUse(entityPlayer.getCurrentEquippedItem(), entityPlayer, x, y, z)) {
if(entityPlayer.capabilities.isCreativeMode && block instanceof BlockEio) {
((BlockEio) block).dropAsItem(world, x, y, z, (TileEntityEio) world.getTileEntity(x, y, z));
} else if(!(block instanceof BlockEio) || ((BlockEio) block).doNormalDrops(world, x, y, z)) {
block.dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
}
block.removedByPlayer(world, entityPlayer, x, y, z, true);
tool.used(entityPlayer.getCurrentEquippedItem(), entityPlayer, x, y, z);
return true;