aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/api/objects/minecraft/BTF_Inventory.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/Java/gtPlusPlus/api/objects/minecraft/BTF_Inventory.java')
-rw-r--r--src/Java/gtPlusPlus/api/objects/minecraft/BTF_Inventory.java64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/BTF_Inventory.java b/src/Java/gtPlusPlus/api/objects/minecraft/BTF_Inventory.java
index 25968f1908..04ce0dff19 100644
--- a/src/Java/gtPlusPlus/api/objects/minecraft/BTF_Inventory.java
+++ b/src/Java/gtPlusPlus/api/objects/minecraft/BTF_Inventory.java
@@ -4,6 +4,7 @@ import java.util.ArrayList;
import gregtech.api.util.GT_Utility;
import gtPlusPlus.core.tileentities.base.TileEntityBase;
+import gtPlusPlus.core.util.data.ArrayUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
@@ -19,6 +20,7 @@ public class BTF_Inventory implements ISidedInventory{
}
public ItemStack[] getRealInventory() {
+ purgeNulls();
return this.mInventory;
}
@@ -139,6 +141,7 @@ public class BTF_Inventory implements ISidedInventory{
public void markDirty() {
if (mTile != null) {
+ purgeNulls();
mTile.markDirty();
}
}
@@ -160,5 +163,66 @@ public class BTF_Inventory implements ISidedInventory{
return this.mTile != null ? mTile.getInventoryName() : "";
}
+ public boolean isFull() {
+ for (int s=0;s<this.getSizeInventory();s++) {
+ ItemStack slot = mInventory[s];
+ if (slot == null || slot.stackSize != slot.getMaxStackSize()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public boolean isEmpty() {
+ for (int s=0;s<this.getSizeInventory();s++) {
+ ItemStack slot = mInventory[s];
+ if (slot == null) {
+ continue;
+ }
+ else {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public boolean addItemStack(ItemStack aInput) {
+ if (aInput != null & (isEmpty() || !isFull())) {
+ for (int s = 0; s < this.getSizeInventory(); s++) {
+ if (mInventory != null && mInventory[s] != null) {
+ ItemStack slot = mInventory[s];
+ if (slot == null || (slot != null && GT_Utility.areStacksEqual(aInput, slot) && slot.stackSize != slot.getItem().getItemStackLimit(slot))) {
+ if (slot == null) {
+ slot = aInput.copy();
+ } else {
+ slot.stackSize++;
+ }
+ this.setInventorySlotContents(s, slot);
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ public final void purgeNulls() {
+ ItemStack[] aTemp = ArrayUtils.removeNulls(this.mInventory);
+ for (int g=0;g<this.getSizeInventory();g++) {
+ if (aTemp.length < this.getSizeInventory()) {
+ if (g <= aTemp.length-1) {
+ this.mInventory[g] = aTemp[g];
+ }
+ else {
+ this.mInventory[g] = null;
+ }
+ }
+ else {
+ this.mInventory[g] = aTemp[g];
+ }
+ }
+
+ }
+
}