mirror of
https://github.com/GTNewHorizons/StorageDrawers.git
synced 2026-11-18 19:39:15 +00:00
Hoppers can insert items into drawers again.
This commit is contained in:
1 parent
4bf1d387d1
commit
b74c2d127b
5 files changed
+69
-19
No files matched your search
@@ -4,6 +4,7 @@ import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.inventory.IDrawerInventory;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup;
|
||||
import com.jaquadro.minecraft.storagedrawers.inventory.ISideManager;
|
||||
import com.jaquadro.minecraft.storagedrawers.inventory.StorageInventory;
|
||||
import com.jaquadro.minecraft.storagedrawers.network.CountUpdateMessage;
|
||||
import com.jaquadro.minecraft.storagedrawers.storage.DrawerData;
|
||||
@@ -30,6 +31,8 @@ public abstract class TileEntityDrawers extends TileEntity implements IDrawerGro
|
||||
private IDrawer[] drawers;
|
||||
private IDrawerInventory inventory;
|
||||
|
||||
private int[] autoSides = new int[] { 0, 1 };
|
||||
|
||||
private int direction;
|
||||
private int drawerCapacity = 1;
|
||||
private int storageLevel = 1;
|
||||
@@ -44,12 +47,16 @@ public abstract class TileEntityDrawers extends TileEntity implements IDrawerGro
|
||||
|
||||
protected abstract IStorageProvider getStorageProvider ();
|
||||
|
||||
protected ISideManager getSideManager () {
|
||||
return new DefaultSideManager();
|
||||
}
|
||||
|
||||
protected void initWithDrawerCount (int drawerCount) {
|
||||
drawers = new IDrawer[drawerCount];
|
||||
for (int i = 0; i < drawerCount; i++)
|
||||
drawers[i] = new DrawerData(getStorageProvider(), i);
|
||||
|
||||
inventory = new StorageInventory(this);
|
||||
inventory = new StorageInventory(this, getSideManager());
|
||||
}
|
||||
|
||||
public int getDirection () {
|
||||
@@ -58,13 +65,13 @@ public abstract class TileEntityDrawers extends TileEntity implements IDrawerGro
|
||||
|
||||
public void setDirection (int direction) {
|
||||
this.direction = direction % 6;
|
||||
// TODO: Deal with sides
|
||||
/*autoSides = new int[] { 0, 1, ForgeDirection.OPPOSITES[direction], 2, 3 };
|
||||
|
||||
autoSides = new int[] { 0, 1, ForgeDirection.OPPOSITES[direction], 2, 3 };
|
||||
|
||||
if (direction == 2 || direction == 3) {
|
||||
autoSides[3] = 4;
|
||||
autoSides[4] = 5;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
public int getStorageLevel () {
|
||||
@@ -191,7 +198,7 @@ public abstract class TileEntityDrawers extends TileEntity implements IDrawerGro
|
||||
drawers[i].readFromNBT(slot);
|
||||
}
|
||||
|
||||
inventory = new StorageInventory(this);
|
||||
inventory = new StorageInventory(this, getSideManager());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -222,7 +229,7 @@ public abstract class TileEntityDrawers extends TileEntity implements IDrawerGro
|
||||
|
||||
@Override
|
||||
public void markDirty () {
|
||||
|
||||
inventory.markDirty();
|
||||
super.markDirty();
|
||||
}
|
||||
|
||||
@@ -348,4 +355,12 @@ public abstract class TileEntityDrawers extends TileEntity implements IDrawerGro
|
||||
public boolean isItemValidForSlot (int slot, ItemStack stack) {
|
||||
return inventory.isItemValidForSlot(slot, stack);
|
||||
}
|
||||
|
||||
private class DefaultSideManager implements ISideManager
|
||||
{
|
||||
@Override
|
||||
public int[] getSlotsForSide (int side) {
|
||||
return autoSides;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.inventory;
|
||||
|
||||
/**
|
||||
* Created by Justin on 11/9/2014.
|
||||
*/
|
||||
public interface ISideManager
|
||||
{
|
||||
public int[] getSlotsForSide (int side);
|
||||
}
|
||||
@@ -51,6 +51,9 @@ public abstract class InventoryStack
|
||||
}
|
||||
|
||||
public int getDiff () {
|
||||
if (nativeStack == null)
|
||||
return 0;
|
||||
|
||||
int diffNative = nativeStack.stackSize - nativeCount;
|
||||
int diffIn = inStack.stackSize - inCount;
|
||||
int diffOut = outStack.stackSize - outCount;
|
||||
|
||||
@@ -11,10 +11,13 @@ import net.minecraft.item.ItemStack;
|
||||
public class StorageInventory implements IDrawerInventory
|
||||
{
|
||||
private final IDrawerGroup group;
|
||||
private final ISideManager sideMan;
|
||||
|
||||
private final int[] inventorySlots;
|
||||
|
||||
public StorageInventory (IDrawerGroup drawerGroup) {
|
||||
public StorageInventory (IDrawerGroup drawerGroup, ISideManager sideManager) {
|
||||
group = drawerGroup;
|
||||
sideMan = sideManager;
|
||||
|
||||
inventorySlots = new int[group.getDrawerCount() * SlotType.values.length];
|
||||
for (int i = 0, n = inventorySlots.length; i < n; i++)
|
||||
@@ -38,8 +41,7 @@ public class StorageInventory implements IDrawerInventory
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide (int side) {
|
||||
// TODO
|
||||
return new int[0];
|
||||
return sideMan.getSlotsForSide(side);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -143,6 +145,11 @@ public class StorageInventory implements IDrawerInventory
|
||||
int insertCount = (item != null) ? item.stackSize : 0;
|
||||
switch (getInventorySlotType(slot)) {
|
||||
case INPUT:
|
||||
if (drawer.isEmpty()) {
|
||||
setInventorySlotContents(drawer, item);
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack inStack = adapter.getInventoryStack(SlotType.INPUT);
|
||||
if (inStack != null)
|
||||
insertCount -= inStack.stackSize;
|
||||
@@ -153,16 +160,7 @@ public class StorageInventory implements IDrawerInventory
|
||||
insertCount -= outStack.stackSize;
|
||||
break;
|
||||
case STORAGE:
|
||||
if (item == null)
|
||||
drawer.setStoredItem(null, 0);
|
||||
else {
|
||||
insertCount = item.stackSize;
|
||||
if (insertCount > drawer.getMaxCapacity())
|
||||
insertCount = drawer.getMaxCapacity();
|
||||
|
||||
drawer.setStoredItem(item, insertCount);
|
||||
item.stackSize -= insertCount;
|
||||
}
|
||||
setInventorySlotContents(drawer, item);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -174,6 +172,21 @@ public class StorageInventory implements IDrawerInventory
|
||||
}
|
||||
}
|
||||
|
||||
private void setInventorySlotContents (IDrawer drawer, ItemStack item) {
|
||||
if (item == null)
|
||||
drawer.setStoredItem(null, 0);
|
||||
else {
|
||||
drawer.setStoredItem(item, 0);
|
||||
|
||||
int insertCount = item.stackSize;
|
||||
if (insertCount > drawer.getMaxCapacity())
|
||||
insertCount = drawer.getMaxCapacity();
|
||||
|
||||
drawer.setStoredItemCount(insertCount);
|
||||
item.stackSize -= insertCount;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName () {
|
||||
return null;
|
||||
@@ -191,7 +204,14 @@ public class StorageInventory implements IDrawerInventory
|
||||
|
||||
@Override
|
||||
public void markDirty () {
|
||||
for (int i = 0, n = group.getDrawerCount(); i < n; i++) {
|
||||
if (!group.isDrawerEnabled(i))
|
||||
continue;
|
||||
|
||||
IDrawer drawer = group.getDrawer(i);
|
||||
if (drawer instanceof IInventoryAdapter)
|
||||
((IInventoryAdapter) drawer).syncInventory();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -52,6 +52,9 @@ public class DefaultStorageProvider implements IStorageProvider
|
||||
|
||||
@Override
|
||||
public void markDirty (int slot) {
|
||||
if (tile.getWorldObj().isRemote)
|
||||
return;
|
||||
|
||||
tile.getWorldObj().markBlockForUpdate(tile.xCoord, tile.yCoord, tile.zCoord);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user