mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-19 19:59:58 +00:00
#789 Vacuum chest now keeps its inventory when broken and can be wrenched properly.
This commit is contained in:
1 parent
296bd08514
commit
6043e1b52b
2 files changed
+59
-1
No files matched your search
@@ -1,12 +1,17 @@
|
||||
package crazypants.enderio.machine.vacuum;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import buildcraft.api.tools.IToolWrench;
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
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.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
@@ -17,6 +22,7 @@ import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.conduit.ConduitUtil;
|
||||
import crazypants.enderio.gui.IResourceTooltipProvider;
|
||||
import crazypants.enderio.machine.AbstractMachineEntity;
|
||||
import crazypants.enderio.machine.power.BlockItemCapacitorBank;
|
||||
import crazypants.enderio.machine.power.ContainerCapacitorBank;
|
||||
import crazypants.enderio.machine.power.GuiCapacitorBank;
|
||||
import crazypants.enderio.machine.power.TileCapacitorBank;
|
||||
@@ -63,6 +69,50 @@ public class BlockVacuumChest extends BlockEio implements IGuiHandler, IResource
|
||||
entityPlayer.openGui(EnderIO.instance, GuiHandler.GUI_ID_VACUUM_CHEST, world, x, y, z);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean harvested) {
|
||||
if(!world.isRemote) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof TileVacuumChest) {
|
||||
TileVacuumChest cb = (TileVacuumChest) te;
|
||||
if(!player.capabilities.isCreativeMode || "true".equalsIgnoreCase(System.getProperty("blockCapBankAllwaysDrop"))) {
|
||||
ItemStack itemStack = createItemStackWithInventory(cb);
|
||||
float f = 0.7F;
|
||||
double d0 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
double d1 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
double d2 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
EntityItem entityitem = new EntityItem(world, x + d0, y + d1, z + d2, itemStack);
|
||||
entityitem.delayBeforeCanPickup = 10;
|
||||
world.spawnEntityInWorld(entityitem);
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.removedByPlayer(world, player, x, y, z, harvested);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int quantityDropped(Random p_149745_1_) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private ItemStack createItemStackWithInventory(TileVacuumChest cb) {
|
||||
ItemStack stack = new ItemStack(this);
|
||||
stack.stackTagCompound = new NBTTagCompound();
|
||||
cb.writeContentsToNBT(stack.stackTagCompound);
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase placedBy, ItemStack stack) {
|
||||
if(!world.isRemote) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(stack != null && stack.stackTagCompound != null && te instanceof TileVacuumChest) {
|
||||
((TileVacuumChest)te).readContentsFromNBT(stack.stackTagCompound);
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
|
||||
@@ -196,6 +196,10 @@ public class TileVacuumChest extends TileEntity implements IEntitySelector, IIn
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbtRoot) {
|
||||
super.readFromNBT(nbtRoot);
|
||||
readContentsFromNBT(nbtRoot);
|
||||
}
|
||||
|
||||
public void readContentsFromNBT(NBTTagCompound nbtRoot) {
|
||||
NBTTagList itemList = (NBTTagList) nbtRoot.getTag("Items");
|
||||
if(itemList != null) {
|
||||
for (int i = 0; i < itemList.tagCount(); i++) {
|
||||
@@ -211,6 +215,10 @@ public class TileVacuumChest extends TileEntity implements IEntitySelector, IIn
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbtRoot) {
|
||||
super.writeToNBT(nbtRoot);
|
||||
writeContentsToNBT(nbtRoot);
|
||||
}
|
||||
|
||||
public void writeContentsToNBT(NBTTagCompound nbtRoot) {
|
||||
NBTTagList itemList = new NBTTagList();
|
||||
for (int i = 0; i < inv.length; i++) {
|
||||
if(inv[i] != null) {
|
||||
@@ -221,6 +229,6 @@ public class TileVacuumChest extends TileEntity implements IEntitySelector, IIn
|
||||
}
|
||||
}
|
||||
nbtRoot.setTag("Items", itemList);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user