Fix a load of null issues, and get it to sort of work.

This commit is contained in:
modmuss50 2016-11-19 16:36:13 +00:00
parent 65e651f402
commit 528fecc2b5
No known key found for this signature in database
GPG key ID: 773D17BE8BF49C82
35 changed files with 101 additions and 87 deletions

View file

@ -16,6 +16,7 @@ import reborncore.common.util.Inventory;
import reborncore.common.util.ItemUtils;
import techreborn.init.ModBlocks;
import javax.annotation.Nonnull;
import java.util.List;
public class TileQuantumChest extends TileLegacyMachineBase
@ -25,7 +26,8 @@ public class TileQuantumChest extends TileLegacyMachineBase
// Slot 1 = Output
// Slot 2 = Fake Item
public ItemStack storedItem;
@Nonnull
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 = (int) Double.MAX_VALUE;
@ -34,7 +36,7 @@ public class TileQuantumChest extends TileLegacyMachineBase
@Override
public void updateEntity() {
if (!world.isRemote) {
if (storedItem != null) {
if (storedItem != ItemStack.EMPTY) {
ItemStack fakeStack = storedItem.copy();
fakeStack.setCount(1);
setInventorySlotContents(2, fakeStack);
@ -43,11 +45,11 @@ public class TileQuantumChest extends TileLegacyMachineBase
fakeStack.setCount(1);
setInventorySlotContents(2, fakeStack);
} else {
setInventorySlotContents(2, null);
setInventorySlotContents(2, ItemStack.EMPTY);
}
if (getStackInSlot(0) != null) {
if (storedItem == null) {
if (getStackInSlot(0) != ItemStack.EMPTY) {
if (storedItem == ItemStack.EMPTY) {
storedItem = getStackInSlot(0);
setInventorySlotContents(0, ItemStack.EMPTY);
} else if (ItemUtils.isItemEqual(storedItem, getStackInSlot(0), true, true)) {
@ -58,7 +60,7 @@ public class TileQuantumChest extends TileLegacyMachineBase
}
}
if (storedItem != null && getStackInSlot(1) == null) {
if (storedItem != ItemStack.EMPTY && getStackInSlot(1) == ItemStack.EMPTY) {
ItemStack itemStack = storedItem.copy();
itemStack.setCount(itemStack.getMaxStackSize());
setInventorySlotContents(1, itemStack);
@ -70,7 +72,7 @@ public class TileQuantumChest extends TileLegacyMachineBase
storedItem.shrink(wanted);
} else {
decrStackSize(1, -storedItem.getCount());
storedItem = null;
storedItem = ItemStack.EMPTY;
}
}
}
@ -91,13 +93,13 @@ public class TileQuantumChest extends TileLegacyMachineBase
public void readFromNBTWithoutCoords(NBTTagCompound tagCompound) {
storedItem = null;
storedItem = ItemStack.EMPTY;
if (tagCompound.hasKey("storedStack")) {
storedItem = new ItemStack((NBTTagCompound) tagCompound.getTag("storedStack"));
}
if (storedItem != null) {
if (storedItem != ItemStack.EMPTY) {
storedItem.setCount(tagCompound.getInteger("storedQuantity"));
}
}
@ -110,7 +112,7 @@ public class TileQuantumChest extends TileLegacyMachineBase
}
public NBTTagCompound writeToNBTWithoutCoords(NBTTagCompound tagCompound) {
if (storedItem != null) {
if (storedItem != ItemStack.EMPTY) {
tagCompound.setTag("storedStack", storedItem.writeToNBT(new NBTTagCompound()));
tagCompound.setInteger("storedQuantity", storedItem.getCount());
} else {
@ -182,11 +184,11 @@ public class TileQuantumChest extends TileLegacyMachineBase
if (isRealTile) {
int size = 0;
String name = "of nothing";
if (storedItem != null) {
if (storedItem != ItemStack.EMPTY) {
name = storedItem.getDisplayName();
size += storedItem.getCount();
}
if (getStackInSlot(1) != null) {
if (getStackInSlot(1) != ItemStack.EMPTY) {
name = getStackInSlot(1).getDisplayName();
size += getStackInSlot(1).getCount();
}