parent
b9448d5d90
commit
33985f1a31
444 changed files with 26235 additions and 32364 deletions
|
@ -1,7 +1,6 @@
|
|||
package techreborn.tiles;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ic2.api.tile.IWrenchable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -17,53 +16,55 @@ import reborncore.common.tile.TileMachineBase;
|
|||
import reborncore.common.util.Inventory;
|
||||
import reborncore.common.util.ItemUtils;
|
||||
import techreborn.init.ModBlocks;
|
||||
import ic2.api.tile.IWrenchable;
|
||||
|
||||
public class TileQuantumChest extends TileMachineBase
|
||||
implements IInventory, IWrenchable, IDeepStorageUnit, IListInfoProvider
|
||||
{
|
||||
import java.util.List;
|
||||
|
||||
// Slot 0 = Input
|
||||
// Slot 1 = Output
|
||||
// Slot 2 = Fake Item
|
||||
public class TileQuantumChest extends TileMachineBase implements IInventory,
|
||||
IWrenchable, IDeepStorageUnit, IListInfoProvider {
|
||||
|
||||
// TODO use long so we can have 9,223,372,036,854,775,807 items instead of
|
||||
// 2,147,483,647
|
||||
int storage = (int) Double.MAX_VALUE;
|
||||
// Slot 0 = Input
|
||||
// Slot 1 = Output
|
||||
// Slot 2 = Fake Item
|
||||
|
||||
public Inventory inventory = new Inventory(3, "TileQuantumChest", storage, this);
|
||||
//TODO use long so we can have 9,223,372,036,854,775,807 items instead of 2,147,483,647
|
||||
int storage = (int) Double.MAX_VALUE;
|
||||
|
||||
public ItemStack storedItem;
|
||||
public Inventory inventory = new Inventory(3, "TileQuantumChest", storage, this);
|
||||
|
||||
public ItemStack storedItem;
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
public void updateEntity()
|
||||
{
|
||||
if (!worldObj.isRemote)
|
||||
if (!worldObj.isRemote)
|
||||
{
|
||||
if (storedItem != null)
|
||||
if (storedItem != null)
|
||||
{
|
||||
ItemStack fakeStack = storedItem.copy();
|
||||
fakeStack.stackSize = 1;
|
||||
setInventorySlotContents(2, fakeStack);
|
||||
} else if (storedItem == null && getStackInSlot(1) != null)
|
||||
}
|
||||
else if (storedItem == null && getStackInSlot(1) != null)
|
||||
{
|
||||
ItemStack fakeStack = getStackInSlot(1).copy();
|
||||
fakeStack.stackSize = 1;
|
||||
setInventorySlotContents(2, fakeStack);
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
setInventorySlotContents(2, null);
|
||||
}
|
||||
|
||||
if (getStackInSlot(0) != null)
|
||||
if (getStackInSlot(0) != null)
|
||||
{
|
||||
if (storedItem == null)
|
||||
if (storedItem == null)
|
||||
{
|
||||
storedItem = getStackInSlot(0);
|
||||
setInventorySlotContents(0, null);
|
||||
} else if (ItemUtils.isItemEqual(storedItem, getStackInSlot(0), true, true))
|
||||
}
|
||||
else if (ItemUtils.isItemEqual(storedItem, getStackInSlot(0), true, true))
|
||||
{
|
||||
if (storedItem.stackSize <= storage - getStackInSlot(0).stackSize)
|
||||
if (storedItem.stackSize <= storage - getStackInSlot(0).stackSize)
|
||||
{
|
||||
storedItem.stackSize += getStackInSlot(0).stackSize;
|
||||
decrStackSize(0, getStackInSlot(0).stackSize);
|
||||
|
@ -71,20 +72,21 @@ public class TileQuantumChest extends TileMachineBase
|
|||
}
|
||||
}
|
||||
|
||||
if (storedItem != null && getStackInSlot(1) == null)
|
||||
if (storedItem != null && getStackInSlot(1) == null)
|
||||
{
|
||||
ItemStack itemStack = storedItem.copy();
|
||||
itemStack.stackSize = itemStack.getMaxStackSize();
|
||||
setInventorySlotContents(1, itemStack);
|
||||
storedItem.stackSize -= itemStack.getMaxStackSize();
|
||||
} else if (ItemUtils.isItemEqual(getStackInSlot(1), storedItem, true, true))
|
||||
}
|
||||
else if (ItemUtils.isItemEqual(getStackInSlot(1), storedItem, true, true))
|
||||
{
|
||||
int wanted = getStackInSlot(1).getMaxStackSize() - getStackInSlot(1).stackSize;
|
||||
if (storedItem.stackSize >= wanted)
|
||||
if (storedItem.stackSize >= wanted)
|
||||
{
|
||||
decrStackSize(1, -wanted);
|
||||
storedItem.stackSize -= wanted;
|
||||
} else
|
||||
} else
|
||||
{
|
||||
decrStackSize(1, -storedItem.stackSize);
|
||||
storedItem = null;
|
||||
|
@ -93,255 +95,217 @@ public class TileQuantumChest extends TileMachineBase
|
|||
}
|
||||
}
|
||||
|
||||
public Packet getDescriptionPacket()
|
||||
{
|
||||
NBTTagCompound nbtTag = new NBTTagCompound();
|
||||
writeToNBT(nbtTag);
|
||||
return new SPacketUpdateTileEntity(this.getPos(), 1, nbtTag);
|
||||
}
|
||||
public Packet getDescriptionPacket() {
|
||||
NBTTagCompound nbtTag = new NBTTagCompound();
|
||||
writeToNBT(nbtTag);
|
||||
return new SPacketUpdateTileEntity(this.getPos(), 1, nbtTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet)
|
||||
{
|
||||
worldObj.markBlockRangeForRenderUpdate(getPos().getX(), getPos().getY(), getPos().getZ(), getPos().getX(),
|
||||
getPos().getY(), getPos().getZ());
|
||||
readFromNBT(packet.getNbtCompound());
|
||||
}
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
|
||||
worldObj.markBlockRangeForRenderUpdate(getPos().getX(), getPos().getY(), getPos().getZ(), getPos().getX(), getPos().getY(), getPos().getZ());
|
||||
readFromNBT(packet.getNbtCompound());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tagCompound)
|
||||
{
|
||||
super.readFromNBT(tagCompound);
|
||||
readFromNBTWithoutCoords(tagCompound);
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tagCompound) {
|
||||
super.readFromNBT(tagCompound);
|
||||
readFromNBTWithoutCoords(tagCompound);
|
||||
}
|
||||
|
||||
public void readFromNBTWithoutCoords(NBTTagCompound tagCompound)
|
||||
{
|
||||
inventory.readFromNBT(tagCompound);
|
||||
public void readFromNBTWithoutCoords(NBTTagCompound tagCompound) {
|
||||
inventory.readFromNBT(tagCompound);
|
||||
|
||||
storedItem = null;
|
||||
storedItem = null;
|
||||
|
||||
if (tagCompound.hasKey("storedStack"))
|
||||
{
|
||||
storedItem = ItemStack.loadItemStackFromNBT((NBTTagCompound) tagCompound.getTag("storedStack"));
|
||||
}
|
||||
if (tagCompound.hasKey("storedStack")) {
|
||||
storedItem = ItemStack
|
||||
.loadItemStackFromNBT((NBTTagCompound) tagCompound
|
||||
.getTag("storedStack"));
|
||||
}
|
||||
|
||||
if (storedItem != null)
|
||||
{
|
||||
storedItem.stackSize = tagCompound.getInteger("storedQuantity");
|
||||
}
|
||||
}
|
||||
if (storedItem != null) {
|
||||
storedItem.stackSize = tagCompound.getInteger("storedQuantity");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tagCompound)
|
||||
{
|
||||
super.writeToNBT(tagCompound);
|
||||
writeToNBTWithoutCoords(tagCompound);
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tagCompound) {
|
||||
super.writeToNBT(tagCompound);
|
||||
writeToNBTWithoutCoords(tagCompound);
|
||||
}
|
||||
|
||||
public void writeToNBTWithoutCoords(NBTTagCompound tagCompound)
|
||||
{
|
||||
inventory.writeToNBT(tagCompound);
|
||||
if (storedItem != null)
|
||||
{
|
||||
tagCompound.setTag("storedStack", storedItem.writeToNBT(new NBTTagCompound()));
|
||||
tagCompound.setInteger("storedQuantity", storedItem.stackSize);
|
||||
} else
|
||||
tagCompound.setInteger("storedQuantity", 0);
|
||||
}
|
||||
public void writeToNBTWithoutCoords(NBTTagCompound tagCompound) {
|
||||
inventory.writeToNBT(tagCompound);
|
||||
if (storedItem != null) {
|
||||
tagCompound.setTag("storedStack",
|
||||
storedItem.writeToNBT(new NBTTagCompound()));
|
||||
tagCompound.setInteger("storedQuantity", storedItem.stackSize);
|
||||
} else
|
||||
tagCompound.setInteger("storedQuantity", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return inventory.getSizeInventory();
|
||||
}
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return inventory.getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot)
|
||||
{
|
||||
return inventory.getStackInSlot(slot);
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return inventory.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slotId, int count)
|
||||
{
|
||||
return inventory.decrStackSize(slotId, count);
|
||||
}
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slotId, int count) {
|
||||
return inventory.decrStackSize(slotId, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int slot)
|
||||
{
|
||||
return inventory.removeStackFromSlot(slot);
|
||||
}
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int slot) {
|
||||
return inventory.removeStackFromSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack)
|
||||
{
|
||||
inventory.setInventorySlotContents(slot, stack);
|
||||
}
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
||||
inventory.setInventorySlotContents(slot, stack);
|
||||
}
|
||||
@Override
|
||||
public void openInventory(EntityPlayer player) {
|
||||
inventory.openInventory(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory(EntityPlayer player)
|
||||
{
|
||||
inventory.openInventory(player);
|
||||
}
|
||||
@Override
|
||||
public void closeInventory(EntityPlayer player) {
|
||||
inventory.closeInventory(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory(EntityPlayer player)
|
||||
{
|
||||
inventory.closeInventory(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField(int id)
|
||||
{
|
||||
return inventory.getField(id);
|
||||
}
|
||||
@Override
|
||||
public int getField(int id) {
|
||||
return inventory.getField(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField(int id, int value)
|
||||
{
|
||||
inventory.setField(id, value);
|
||||
}
|
||||
@Override
|
||||
public void setField(int id, int value) {
|
||||
inventory.setField(id, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount()
|
||||
{
|
||||
return inventory.getFieldCount();
|
||||
}
|
||||
@Override
|
||||
public int getFieldCount() {
|
||||
return inventory.getFieldCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
inventory.clear();
|
||||
}
|
||||
@Override
|
||||
public void clear() {
|
||||
inventory.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return inventory.getName();
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return inventory.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
{
|
||||
return inventory.hasCustomName();
|
||||
}
|
||||
@Override
|
||||
public boolean hasCustomName() {
|
||||
return inventory.hasCustomName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
return inventory.getDisplayName();
|
||||
}
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return inventory.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return inventory.getInventoryStackLimit();
|
||||
}
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return inventory.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player)
|
||||
{
|
||||
return inventory.isUseableByPlayer(player);
|
||||
}
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return inventory.isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack)
|
||||
{
|
||||
return inventory.isItemValidForSlot(slot, stack);
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
return inventory.isItemValidForSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumFacing getFacing()
|
||||
{
|
||||
return getFacingEnum();
|
||||
}
|
||||
@Override
|
||||
public EnumFacing getFacing() {
|
||||
return getFacingEnum();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wrenchCanRemove(EntityPlayer entityPlayer)
|
||||
{
|
||||
if (entityPlayer.isSneaking())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
|
||||
if (entityPlayer.isSneaking()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getWrenchDropRate()
|
||||
{
|
||||
return 1F;
|
||||
}
|
||||
@Override
|
||||
public float getWrenchDropRate() {
|
||||
return 1F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getWrenchDrop(EntityPlayer entityPlayer)
|
||||
{
|
||||
return getDropWithNBT();
|
||||
}
|
||||
@Override
|
||||
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
|
||||
return getDropWithNBT();
|
||||
}
|
||||
|
||||
public ItemStack getDropWithNBT()
|
||||
{
|
||||
NBTTagCompound tileEntity = new NBTTagCompound();
|
||||
ItemStack dropStack = new ItemStack(ModBlocks.quantumChest, 1);
|
||||
writeToNBTWithoutCoords(tileEntity);
|
||||
dropStack.setTagCompound(new NBTTagCompound());
|
||||
dropStack.getTagCompound().setTag("tileEntity", tileEntity);
|
||||
return dropStack;
|
||||
}
|
||||
public ItemStack getDropWithNBT() {
|
||||
NBTTagCompound tileEntity = new NBTTagCompound();
|
||||
ItemStack dropStack = new ItemStack(ModBlocks.quantumChest, 1);
|
||||
writeToNBTWithoutCoords(tileEntity);
|
||||
dropStack.setTagCompound(new NBTTagCompound());
|
||||
dropStack.getTagCompound().setTag("tileEntity", tileEntity);
|
||||
return dropStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStoredItemType()
|
||||
{
|
||||
return this.storedItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStoredItemCount(int amount)
|
||||
{
|
||||
this.storedItem.stackSize = 0;
|
||||
this.storedItem.stackSize += (amount);
|
||||
this.markDirty();
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStoredItemType() {
|
||||
return this.storedItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStoredItemType(ItemStack type, int amount)
|
||||
{
|
||||
this.storedItem = type;
|
||||
this.storedItem.stackSize = amount;
|
||||
this.markDirty();
|
||||
}
|
||||
@Override
|
||||
public void setStoredItemCount(int amount) {
|
||||
this.storedItem.stackSize = 0;
|
||||
this.storedItem.stackSize += (amount);
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStoredCount()
|
||||
{
|
||||
return this.storage;
|
||||
}
|
||||
@Override
|
||||
public void setStoredItemType(ItemStack type, int amount) {
|
||||
this.storedItem = type;
|
||||
this.storedItem.stackSize = amount;
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInfo(List<String> info, boolean isRealTile)
|
||||
{
|
||||
if (isRealTile)
|
||||
{
|
||||
int size = 0;
|
||||
String name = "of nothing";
|
||||
if (storedItem != null)
|
||||
{
|
||||
name = storedItem.getDisplayName();
|
||||
size += storedItem.stackSize;
|
||||
}
|
||||
if (getStackInSlot(1) != null)
|
||||
{
|
||||
name = getStackInSlot(1).getDisplayName();
|
||||
size += getStackInSlot(1).stackSize;
|
||||
}
|
||||
info.add(size + " " + name);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getMaxStoredCount() {
|
||||
return this.storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInfo(List<String> info, boolean isRealTile) {
|
||||
if (isRealTile) {
|
||||
int size = 0;
|
||||
String name = "of nothing";
|
||||
if (storedItem != null) {
|
||||
name = storedItem.getDisplayName();
|
||||
size += storedItem.stackSize;
|
||||
}
|
||||
if (getStackInSlot(1) != null) {
|
||||
name = getStackInSlot(1).getDisplayName();
|
||||
size += getStackInSlot(1).stackSize;
|
||||
}
|
||||
info.add(size + " " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue