From c4be02f9c012fe3794abc04fc62aad166053482c Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Mon, 17 Nov 2014 23:37:47 -0500 Subject: [PATCH] Comp Drawer extraction working now --- .../block/tile/TileEntityDrawersComp.java | 37 +++++++++++++++++-- .../inventory/StorageInventory.java | 19 ++++++++++ 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawersComp.java b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawersComp.java index cdac336..df93f51 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawersComp.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawersComp.java @@ -61,13 +61,29 @@ public class TileEntityDrawersComp extends TileEntityDrawers return new CompDrawerData(getCentralInventory(), slot); } + @Override + public boolean isDrawerEnabled (int slot) { + if (slot > 0 && convRate[slot] == 0) + return false; + + return super.isDrawerEnabled(slot); + } + @Override public int putItemsIntoSlot (int slot, ItemStack stack, int count) { if (stack != null && convRate != null && convRate[0] == 0) { populateSlots(stack); + int added = 0; + for (int i = 0; i < getDrawerCount(); i++) { if (BaseDrawerData.areItemsEqual(protoStack[i], stack)) - return super.putItemsIntoSlot(i, stack, count); + added = super.putItemsIntoSlot(i, stack, count); + } + + for (int i = 0; i < getDrawerCount(); i++) { + IDrawer drawer = getDrawer(i); + if (drawer instanceof CompDrawerData) + ((CompDrawerData) drawer).refresh(); } } @@ -318,7 +334,7 @@ public class TileEntityDrawersComp extends TileEntityDrawers populateSlots(itemPrototype); for (int i = 0; i < getDrawerCount(); i++) { if (BaseDrawerData.areItemsEqual(protoStack[i], itemPrototype)) - setStoredItemCount(i, amount); + pooledCount = (pooledCount % convRate[slot]) + convRate[slot] * amount; } for (int i = 0; i < getDrawerCount(); i++) { @@ -329,6 +345,14 @@ public class TileEntityDrawersComp extends TileEntityDrawers if (drawer instanceof CompDrawerData) ((CompDrawerData) drawer).refresh(); } + + if (worldObj != null && !worldObj.isRemote) { + //TileEntityDrawersComp.this.markDirty(); + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + } + else if (itemPrototype == null) { + setStoredItemCount(slot, 0); } } @@ -351,8 +375,13 @@ public class TileEntityDrawersComp extends TileEntityDrawers if (pooledCount != oldCount) { if (pooledCount != 0) markAmountDirty(); - else + else { clear(); + if (worldObj != null && !worldObj.isRemote) { + //TileEntityDrawersComp.this.markDirty(); + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + } } } @@ -387,7 +416,7 @@ public class TileEntityDrawersComp extends TileEntityDrawers TileEntityDrawersComp.this.markDirty(); } - private void refresh () { + public void refresh () { for (int i = 0; i < getDrawerCount(); i++) { IDrawer drawer = getDrawer(i); if (drawer instanceof CompDrawerData) diff --git a/src/com/jaquadro/minecraft/storagedrawers/inventory/StorageInventory.java b/src/com/jaquadro/minecraft/storagedrawers/inventory/StorageInventory.java index 22e3cb0..4905f86 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/inventory/StorageInventory.java +++ b/src/com/jaquadro/minecraft/storagedrawers/inventory/StorageInventory.java @@ -77,6 +77,9 @@ public class StorageInventory implements IDrawerInventory if (drawer == null) return false; + if (drawer.getStoredItemCount() == 0) + return false; + return drawer.canItemBeExtracted(item); } @@ -185,6 +188,9 @@ public class StorageInventory implements IDrawerInventory drawer.setStoredItem(null, 0); else { drawer.setStoredItem(item, 0); + drawer = findDrawer(item); + if (drawer == null) + return; int insertCount = item.stackSize; if (insertCount > drawer.getMaxCapacity()) @@ -195,6 +201,19 @@ public class StorageInventory implements IDrawerInventory } } + private IDrawer findDrawer (ItemStack item) { + for (int i = 0; i < group.getDrawerCount(); i++) { + if (!group.isDrawerEnabled(i)) + continue; + + IDrawer drawer = group.getDrawer(i); + if (drawer.canItemBeStored(item)) + return drawer; + } + + return null; + } + @Override public String getInventoryName () { return null;