Apply QuantumChest fixes to DigitalChest
This commit is contained in:
parent
baebc948d9
commit
da41ae7731
1 changed files with 103 additions and 53 deletions
|
@ -6,72 +6,92 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.network.NetworkManager;
|
import net.minecraft.network.NetworkManager;
|
||||||
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
|
||||||
|
import powercrystals.minefactoryreloaded.api.IDeepStorageUnit;
|
||||||
|
|
||||||
import reborncore.api.IListInfoProvider;
|
import reborncore.api.IListInfoProvider;
|
||||||
import reborncore.api.tile.IInventoryProvider;
|
import reborncore.api.tile.IInventoryProvider;
|
||||||
import reborncore.common.IWrenchable;
|
import reborncore.common.IWrenchable;
|
||||||
import reborncore.common.tile.TileLegacyMachineBase;
|
import reborncore.common.tile.TileLegacyMachineBase;
|
||||||
import reborncore.common.util.Inventory;
|
import reborncore.common.util.Inventory;
|
||||||
import reborncore.common.util.ItemUtils;
|
import reborncore.common.util.ItemUtils;
|
||||||
|
|
||||||
import techreborn.init.ModBlocks;
|
import techreborn.init.ModBlocks;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TileDigitalChest extends TileLegacyMachineBase implements IInventoryProvider, IWrenchable, IListInfoProvider {
|
public class TileDigitalChest extends TileLegacyMachineBase
|
||||||
|
implements IInventoryProvider, IWrenchable, IListInfoProvider, IDeepStorageUnit {
|
||||||
|
|
||||||
// Slot 0 = Input
|
// Slot 0 = Input
|
||||||
// Slot 1 = Output
|
// Slot 1 = Output
|
||||||
// Slot 2 = Fake Item
|
// Slot 2 = Fake Item
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public ItemStack storedItem = ItemStack.EMPTY;
|
public ItemStack storedItem = ItemStack.EMPTY;
|
||||||
// TODO use long so we can have 9,223,372,036,854,775,807 items instead of
|
|
||||||
// 2,147,483,647
|
int storage = Short.MAX_VALUE;
|
||||||
int storage = 32767;
|
|
||||||
public Inventory inventory = new Inventory(3, "TileDigitalChest", storage, this);
|
public Inventory inventory = new Inventory(3, "TileDigitalChest", storage, this);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity() {
|
public void updateEntity() {
|
||||||
if (!world.isRemote) {
|
if (!world.isRemote) {
|
||||||
if (storedItem != ItemStack.EMPTY) {
|
if (this.getStackInSlot(0) != ItemStack.EMPTY) {
|
||||||
ItemStack fakeStack = storedItem.copy();
|
if (this.getStoredItemType().isEmpty() || (this.storedItem.isEmpty()
|
||||||
fakeStack.setCount(1);
|
&& ItemUtils.isItemEqual(this.getStackInSlot(0), this.getStackInSlot(1), true, true))) {
|
||||||
setInventorySlotContents(2, fakeStack);
|
|
||||||
} else if (storedItem == ItemStack.EMPTY && getStackInSlot(1) != ItemStack.EMPTY) {
|
|
||||||
ItemStack fakeStack = getStackInSlot(1).copy();
|
|
||||||
fakeStack.setCount(1);
|
|
||||||
setInventorySlotContents(2, fakeStack);
|
|
||||||
} else {
|
|
||||||
setInventorySlotContents(2, ItemStack.EMPTY);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getStackInSlot(0) != ItemStack.EMPTY) {
|
this.storedItem = this.getStackInSlot(0);
|
||||||
if (storedItem == ItemStack.EMPTY) {
|
this.setInventorySlotContents(0, ItemStack.EMPTY);
|
||||||
storedItem = getStackInSlot(0);
|
this.syncWithAll();
|
||||||
setInventorySlotContents(0, ItemStack.EMPTY);
|
} else if (ItemUtils.isItemEqual(this.getStoredItemType(), this.getStackInSlot(0), true, true)) {
|
||||||
} else if (ItemUtils.isItemEqual(storedItem, getStackInSlot(0), true, true)) {
|
|
||||||
if (storedItem.getCount() <= storage - getStackInSlot(0).getCount()) {
|
this.setStoredItemCount(this.getStackInSlot(0).getCount());
|
||||||
storedItem.grow(getStackInSlot(0).getCount());
|
this.setInventorySlotContents(0, ItemStack.EMPTY);
|
||||||
decrStackSize(0, getStackInSlot(0).getCount());
|
this.syncWithAll();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (storedItem != ItemStack.EMPTY && getStackInSlot(1) == ItemStack.EMPTY) {
|
if (this.storedItem != ItemStack.EMPTY) {
|
||||||
ItemStack itemStack = storedItem.copy();
|
if (this.getStackInSlot(1) == ItemStack.EMPTY) {
|
||||||
itemStack.setCount(itemStack.getMaxStackSize());
|
|
||||||
setInventorySlotContents(1, itemStack);
|
ItemStack delivered = this.storedItem.copy();
|
||||||
storedItem.shrink(itemStack.getMaxStackSize());
|
delivered.setCount(Math.min(this.storedItem.getCount(), delivered.getMaxStackSize()));
|
||||||
} else if (ItemUtils.isItemEqual(getStackInSlot(1), storedItem, true, true)) {
|
|
||||||
int wanted = getStackInSlot(1).getMaxStackSize() - getStackInSlot(1).getCount();
|
this.storedItem.shrink(delivered.getCount());
|
||||||
if (storedItem.getCount() >= wanted) {
|
|
||||||
decrStackSize(1, -wanted);
|
if (this.storedItem.isEmpty())
|
||||||
storedItem.shrink(wanted);
|
this.storedItem = ItemStack.EMPTY;
|
||||||
} else {
|
|
||||||
decrStackSize(1, -storedItem.getCount());
|
this.setInventorySlotContents(1, delivered);
|
||||||
storedItem = ItemStack.EMPTY;
|
this.syncWithAll();
|
||||||
|
} else if (ItemUtils.isItemEqual(this.storedItem, this.getStackInSlot(1), true, true)
|
||||||
|
&& this.getStackInSlot(1).getCount() < this.getStackInSlot(1).getMaxStackSize()) {
|
||||||
|
|
||||||
|
int wanted = Math.min(this.storedItem.getCount(),
|
||||||
|
this.getStackInSlot(1).getMaxStackSize() - this.getStackInSlot(1).getCount());
|
||||||
|
|
||||||
|
this.getStackInSlot(1).setCount(this.getStackInSlot(1).getCount() + wanted);
|
||||||
|
this.storedItem.shrink(wanted);
|
||||||
|
|
||||||
|
if (this.storedItem.isEmpty())
|
||||||
|
this.storedItem = ItemStack.EMPTY;
|
||||||
|
this.syncWithAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.getStackInSlot(2) == ItemStack.EMPTY
|
||||||
|
&& (!this.storedItem.isEmpty() || !this.getStackInSlot(1).isEmpty())) {
|
||||||
|
|
||||||
|
ItemStack fake = storedItem.isEmpty() ? this.getStackInSlot(1).copy() : storedItem.copy();
|
||||||
|
fake.setCount(1);
|
||||||
|
|
||||||
|
this.setInventorySlotContents(2, fake);
|
||||||
|
} else if (!ItemUtils.isItemEqual(this.getStackInSlot(2), this.storedItem, true, true)) {
|
||||||
|
|
||||||
|
ItemStack fake = storedItem.isEmpty() ? this.getStackInSlot(1).copy() : storedItem.copy();
|
||||||
|
fake.setCount(1);
|
||||||
|
|
||||||
|
this.setInventorySlotContents(2, fake);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,8 +132,10 @@ public class TileDigitalChest extends TileLegacyMachineBase implements IInventor
|
||||||
if (storedItem != ItemStack.EMPTY) {
|
if (storedItem != ItemStack.EMPTY) {
|
||||||
tagCompound.setTag("storedStack", storedItem.writeToNBT(new NBTTagCompound()));
|
tagCompound.setTag("storedStack", storedItem.writeToNBT(new NBTTagCompound()));
|
||||||
tagCompound.setInteger("storedQuantity", storedItem.getCount());
|
tagCompound.setInteger("storedQuantity", storedItem.getCount());
|
||||||
} else
|
} else {
|
||||||
tagCompound.setInteger("storedQuantity", 0);
|
tagCompound.setInteger("storedQuantity", 0);
|
||||||
|
}
|
||||||
|
|
||||||
return tagCompound;
|
return tagCompound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,8 +173,36 @@ public class TileDigitalChest extends TileLegacyMachineBase implements IInventor
|
||||||
return dropStack;
|
return dropStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getStoredItemType() {
|
||||||
|
return this.storedItem.isEmpty() ? this.getStackInSlot(1) : this.storedItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStoredItemCount(int amount) {
|
||||||
|
storedItem.grow(amount);
|
||||||
|
this.markDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStoredItemType(ItemStack type, int amount) {
|
||||||
|
this.storedItem = type;
|
||||||
|
storedItem.setCount(amount);
|
||||||
|
this.markDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxStoredCount() {
|
||||||
|
return this.storage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStoredCount() {
|
||||||
|
return this.storedItem.getCount();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addInfo(List<String> info, boolean isRealTile) {
|
public void addInfo(List<String> info, boolean isRealTile) {
|
||||||
|
if (isRealTile) {
|
||||||
int size = 0;
|
int size = 0;
|
||||||
String name = "of nothing";
|
String name = "of nothing";
|
||||||
if (storedItem != ItemStack.EMPTY) {
|
if (storedItem != ItemStack.EMPTY) {
|
||||||
|
@ -164,7 +214,7 @@ public class TileDigitalChest extends TileLegacyMachineBase implements IInventor
|
||||||
size += getStackInSlot(1).getCount();
|
size += getStackInSlot(1).getCount();
|
||||||
}
|
}
|
||||||
info.add(size + " " + name);
|
info.add(size + " " + name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue