Fix QuantumChest duplication bug and content sync
This commit is contained in:
parent
f65999f960
commit
3bf346f39a
2 changed files with 68 additions and 41 deletions
|
@ -6,6 +6,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.text.translation.I18n;
|
import net.minecraft.util.text.translation.I18n;
|
||||||
|
import reborncore.common.util.ItemUtils;
|
||||||
import techreborn.client.container.ContainerQuantumChest;
|
import techreborn.client.container.ContainerQuantumChest;
|
||||||
import techreborn.tiles.TileQuantumChest;
|
import techreborn.tiles.TileQuantumChest;
|
||||||
|
|
||||||
|
@ -39,10 +40,15 @@ public class GuiQuantumChest extends GuiContainer {
|
||||||
this.fontRendererObj.drawString(I18n.translateToLocalFormatted("container.inventory", new Object[0]), 8,
|
this.fontRendererObj.drawString(I18n.translateToLocalFormatted("container.inventory", new Object[0]), 8,
|
||||||
this.ySize - 96 + 2, 4210752);
|
this.ySize - 96 + 2, 4210752);
|
||||||
this.fontRendererObj.drawString("Amount", 10, 20, 16448255);
|
this.fontRendererObj.drawString("Amount", 10, 20, 16448255);
|
||||||
if (tile.storedItem != ItemStack.EMPTY && tile.getStackInSlot(1) != null)
|
|
||||||
this.fontRendererObj.drawString(tile.storedItem.getCount() + tile.getStackInSlot(1).getCount() + "", 10, 30,
|
int count = 0;
|
||||||
16448255);
|
if (tile.storedItem != ItemStack.EMPTY || !tile.getStackInSlot(1).isEmpty()) {
|
||||||
if (tile.storedItem == ItemStack.EMPTY && tile.getStackInSlot(1) != null)
|
|
||||||
this.fontRendererObj.drawString(tile.getStackInSlot(1).getCount() + "", 10, 30, 16448255);
|
count = tile.storedItem.getCount();
|
||||||
|
if (tile.getStackInSlot(1) != ItemStack.EMPTY && (tile.storedItem.isEmpty()
|
||||||
|
|| ItemUtils.isItemEqual(tile.getStackInSlot(1), tile.getStackInSlot(2), true, true)))
|
||||||
|
count += tile.getStackInSlot(1).getCount();
|
||||||
|
}
|
||||||
|
this.fontRendererObj.drawString(count + "", 10, 30, 16448255);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,55 +25,72 @@ public class TileQuantumChest extends TileLegacyMachineBase
|
||||||
// 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
|
// TODO use long so we can have 9,223,372,036,854,775,807 items instead of
|
||||||
// 2,147,483,647
|
// 2,147,483,647
|
||||||
int storage = (int) Double.MAX_VALUE;
|
int storage = Integer.MAX_VALUE;
|
||||||
public Inventory inventory = new Inventory(3, "TileQuantumChest", storage, this);
|
public Inventory inventory = new Inventory(3, "TileQuantumChest", 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +174,7 @@ public class TileQuantumChest extends TileLegacyMachineBase
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getStoredItemType() {
|
public ItemStack getStoredItemType() {
|
||||||
return this.storedItem;
|
return this.storedItem.isEmpty() ? this.getStackInSlot(1) : this.storedItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -178,6 +195,10 @@ public class TileQuantumChest extends TileLegacyMachineBase
|
||||||
return this.storage;
|
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) {
|
if (isRealTile) {
|
||||||
|
|
Loading…
Reference in a new issue