diff --git a/StorageDrawers.iml b/StorageDrawers.iml index dd0e211..aa404f8 100644 --- a/StorageDrawers.iml +++ b/StorageDrawers.iml @@ -1,676 +1,83 @@ - + + + + - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StorageDrawers.ipr b/StorageDrawers.ipr index 3eedc57..95250f9 100644 --- a/StorageDrawers.ipr +++ b/StorageDrawers.ipr @@ -30,6 +30,11 @@ @@ -192,5 +197,528 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/assets/storagedrawers/textures/gui/drawers_2.png b/resources/assets/storagedrawers/textures/gui/drawers_2.png index 6cefbe2..9857fac 100644 Binary files a/resources/assets/storagedrawers/textures/gui/drawers_2.png and b/resources/assets/storagedrawers/textures/gui/drawers_2.png differ diff --git a/resources/assets/storagedrawers/textures/gui/drawers_comp.png b/resources/assets/storagedrawers/textures/gui/drawers_comp.png index 125fc30..8f086a6 100644 Binary files a/resources/assets/storagedrawers/textures/gui/drawers_comp.png and b/resources/assets/storagedrawers/textures/gui/drawers_comp.png differ diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityCompDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityCompDrawers.java index fe0672a..c38c794 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityCompDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityCompDrawers.java @@ -502,7 +502,7 @@ public class TileEntityCompDrawers extends TileEntityDrawersBase implements ISto @Override public void setInventorySlotContents (int slot, ItemStack itemStack) { - if (slot < 0 || slot >= getSizeInventory()) + if (slot < 0 || slot >= getSizeInventory() || itemStack == null) return; int insertCount = itemStack.stackSize; diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java index 3786064..c6238b7 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java @@ -288,7 +288,7 @@ public class TileEntityDrawers extends TileEntityDrawersBase implements IStorage @Override public String getInventoryName () { - return null; + return "container.drawers"; } @Override @@ -303,7 +303,11 @@ public class TileEntityDrawers extends TileEntityDrawersBase implements IStorage @Override public boolean isUseableByPlayer (EntityPlayer player) { - return false; + if (worldObj.getTileEntity(xCoord, yCoord, zCoord) != this) + return false; + + return player.getDistanceSq(xCoord + .5, yCoord + .5, zCoord + .5) <= 64; + } @Override diff --git a/src/com/jaquadro/minecraft/storagedrawers/client/gui/GuiDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/client/gui/GuiDrawers.java index 89cb09c..9d3ac6b 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/client/gui/GuiDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/client/gui/GuiDrawers.java @@ -20,12 +20,17 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; +import java.util.List; + public class GuiDrawers extends GuiContainer { private static final ResourceLocation guiTextures2 = new ResourceLocation("storagedrawers", "textures/gui/drawers_2.png"); private static final ResourceLocation guiTextures4 = new ResourceLocation("storagedrawers", "textures/gui/drawers_4.png"); private static final ResourceLocation guiTexturesComp = new ResourceLocation("storagedrawers", "textures/gui/drawers_comp.png"); + private static final int smDisabledX = 176; + private static final int smDisabledY = 0; + private static final Object[] empty = new Object[0]; private static RenderItem storageItemRender = new StorageRenderItem(); @@ -75,6 +80,15 @@ public class GuiDrawers extends GuiContainer int guiX = (width - xSize) / 2; int guiY = (height - ySize) / 2; drawTexturedModalRect(guiX, guiY, 0, 0, xSize, ySize); + + if (inventorySlots instanceof ContainerDrawers) { + ContainerDrawers container = (ContainerDrawers) inventorySlots; + List storageSlots = container.getStorageSlots(); + for (int i = 0, n = storageSlots.size(); i < n; i++) { + Slot slot = container.getSlot(i); + drawTexturedModalRect(guiX + slot.xDisplayPosition, guiY + slot.yDisplayPosition, smDisabledX, smDisabledY, 16, 16); + } + } } private RenderItem setItemRender (RenderItem renderItem) { diff --git a/src/com/jaquadro/minecraft/storagedrawers/inventory/ContainerDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/inventory/ContainerDrawers.java index d1302b9..12d2775 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/inventory/ContainerDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/inventory/ContainerDrawers.java @@ -35,7 +35,7 @@ public class ContainerDrawers extends Container storageSlots = new ArrayList(); for (int i = 0; i < tileEntity.getDrawerCount(); i++) - storageSlots.add(addSlotToContainer(new Slot(storageInventory, i, getStorageSlotX(i), getStorageSlotY(i)))); + storageSlots.add(addSlotToContainer(new SlotStorage(storageInventory, i, getStorageSlotX(i), getStorageSlotY(i)))); upgradeSlots = new ArrayList(); for (int i = 0; i < 5; i++) @@ -60,6 +60,10 @@ public class ContainerDrawers extends Container return 0; } + public List getStorageSlots () { + return storageSlots; + } + @Override public boolean canInteractWith (EntityPlayer player) { return storageInventory.isUseableByPlayer(player) || upgradeInventory.isUseableByPlayer(player); diff --git a/src/com/jaquadro/minecraft/storagedrawers/inventory/InventoryStorage.java b/src/com/jaquadro/minecraft/storagedrawers/inventory/InventoryStorage.java index 799d69f..eff63b0 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/inventory/InventoryStorage.java +++ b/src/com/jaquadro/minecraft/storagedrawers/inventory/InventoryStorage.java @@ -1,16 +1,58 @@ package com.jaquadro.minecraft.storagedrawers.inventory; import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersBase; +import cpw.mods.fml.common.asm.transformers.ItemStackTransformer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; public class InventoryStorage implements IInventory { + private static class InventorySnapshot { + private ItemStack[] snapshotItems; + private int[] snapshotCounts; + + public InventorySnapshot (int size) { + snapshotItems = new ItemStack[size]; + snapshotCounts = new int[snapshotItems.length]; + } + + public ItemStack takeSnapshot (ItemStack stack, int slot) { + if (stack != null) { + snapshotItems[slot] = stack; + snapshotCounts[slot] = stack.stackSize; + } + else { + snapshotItems[slot] = null; + snapshotCounts[slot] = 0; + } + + return stack; + } + + public int getDiff (int slot) { + if (snapshotItems[slot] == null) + return 0; + + return snapshotItems[slot].stackSize - snapshotCounts[slot]; + } + + public int splitDiff (int slot) { + int diff = getDiff(slot); + if (diff != 0) { + snapshotCounts[slot] = snapshotItems[slot].stackSize; + } + + return diff; + } + } + private TileEntityDrawersBase tile; + private InventorySnapshot snapshot; public InventoryStorage (TileEntityDrawersBase tileEntity) { tile = tileEntity; + snapshot = new InventorySnapshot(tile.getSizeInventory()); } @Override @@ -27,12 +69,12 @@ public class InventoryStorage implements IInventory stack = stack.copy(); stack.stackSize = tile.getItemCount(slot); - return stack; + return snapshot.takeSnapshot(stack, slot); } @Override public ItemStack decrStackSize (int slot, int count) { - return tile.decrStackSize(slot, count); + return snapshot.takeSnapshot(tile.decrStackSize(slot, count), slot); } @Override @@ -57,11 +99,18 @@ public class InventoryStorage implements IInventory @Override public int getInventoryStackLimit () { - return Integer.MAX_VALUE; + int limit = tile.getInventoryStackLimit(); + return (limit > 64) ? 64 : limit; } @Override public void markDirty () { + for (int i = 0, n = getSizeInventory(); i < n; i++) { + int diff = snapshot.splitDiff(i); + if (diff != 0) + tile.getStackInSlot(i).stackSize += diff; + } + tile.markDirty(); } diff --git a/src/com/jaquadro/minecraft/storagedrawers/inventory/SlotStorage.java b/src/com/jaquadro/minecraft/storagedrawers/inventory/SlotStorage.java new file mode 100644 index 0000000..0b34aa7 --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/inventory/SlotStorage.java @@ -0,0 +1,17 @@ +package com.jaquadro.minecraft.storagedrawers.inventory; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; + +public class SlotStorage extends Slot +{ + public SlotStorage (IInventory inventory, int index, int x, int y) { + super(inventory, index, x, y); + } + + @Override + public boolean canTakeStack (EntityPlayer player) { + return false; + } +}