From d9d4459183ae8cf9b348ed5eb752ead9e87f242c Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Sun, 2 Nov 2014 00:57:10 -0400 Subject: [PATCH] Minor progress --- StorageDrawers.iml | 723 ++---------------- StorageDrawers.ipr | 528 +++++++++++++ .../storagedrawers/textures/gui/drawers_2.png | Bin 1359 -> 1381 bytes .../textures/gui/drawers_comp.png | Bin 1533 -> 1544 bytes .../block/tile/TileEntityCompDrawers.java | 2 +- .../block/tile/TileEntityDrawers.java | 8 +- .../storagedrawers/client/gui/GuiDrawers.java | 14 + .../inventory/ContainerDrawers.java | 6 +- .../inventory/InventoryStorage.java | 55 +- .../storagedrawers/inventory/SlotStorage.java | 17 + 10 files changed, 688 insertions(+), 665 deletions(-) create mode 100644 src/com/jaquadro/minecraft/storagedrawers/inventory/SlotStorage.java 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 6cefbe252fa4ea25b395c503326bba504402d1f2..9857facc7cf6be3d33952269bd7c442822a336be 100644 GIT binary patch delta 983 zcmX@l^^|LZ4u>3z1=qW)LZ>I1Xw-l4ba4!+xb^m~W8Rf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=xY6HOOxIDFD}X7Qxi&L<;T9y~o+`(fVXJ2F{q{0APY)YTf*zdnDq z^1jTu%LV@hUu->mKj(j$(*A$Z=jVJs|ImiFo|R$Gdp=FWW0cZ=fj|ovqJU2%DA_=e1CGk|9JiI;^q7tmV+GdWVSK-cZC}$?3oB5_xWsJ ztn!Mt861CoYWnB-{ml6{i42$=-*BXyd-i;Tj5X8D%|9*6Sfcu58_(SQ z1LW%-w`JfECK_#4o?tn9{^6p&cN{FyDeem{Z)9mOU<9EJi_IC|a^;*8d$#AE=#0x7 zwKo72K7RJ42oli1uqFnbS$E)BP95LrjoJo>H)?-)8NuW*g8_&PrW}51zufRH%N^UQ z9sBoxKioRwu;_tzzkXG{O>Q(VX8vFj_n$%jnw>(0a(o@I*dhx^T#fI0a9={W=tv<* Nzo)C8%Q~loCIGW{^O*nu diff --git a/resources/assets/storagedrawers/textures/gui/drawers_comp.png b/resources/assets/storagedrawers/textures/gui/drawers_comp.png index 125fc30384076cb6768caba6f20f83fcf99b2573..8f086a6df1b6eb5aed64fd9a5d78112ec85462f5 100644 GIT binary patch delta 1153 zcmV-{1b+Md3y2JmEC?P1Hy(4B+If*QD1VnpL_t(|+U?y@PU31D#$h1t#3h(`q1(_s zcuV3wxOES>4ooyI!L8`=^GIM&P%NeW`aVxG;f!bIKg6^@+9F@aqm{Q2)M32*kDHsD zM%(S(-QBp!->==t=i}SEuAdA1%6L338*B8Adnl8UouA4q7K`#=qdkC=%`ZGWJRWrY zoM5NfY&N>Sz8=lza}j80vi=)8KV+FS9|6=#liLIyf3TD0BkD4pPP={zt+~3o8eLvq zcKtMt>iPNk`#9$UE~qK>+9^re(_4Ka@I3*bdcS?2 zUj)7q0IIg{5BZ3|zXX6m*ynwIKNGOx2Z5;Cf78>``17&rr&1+H01!+7AeaC^FadyI z0sz4T0D^fNuz|7`K=Mkw)K35!C@c9`%!8Ua1%P1DM*w9>?Xs#aq>2teVM%S0dHI82 z(MJGn-Wh29jy=cvcVJ)90VvwKiob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)puP7v5xu-t_prNt@H{r@XU2+PO5Ca~Qy#xu99s>tw>j5-S)&eN^^Fyr! zpnO!jM02G$gCYg^v2o`+=(B_kYR-f2&s(%L#6&--0 zt*iL!PwY9>zXOMG3IM_4j{ufV^^_k^6QWN9V8yAP^5bbj^o3KC@B|{0uL2B0Sr6dT zsh;xVX+rdg0DL;tQ+_;6h(2)&0KuY<08aH}AWtBouc8A`oN7sJOLx;pK9(R@+!27Q z@bD!r0ItHr7pIdC1QnCO1O}5H0}6jt-3&CDOd8K9cLP2?KAN**PPt)<3{?f7C>v-K zQ4by_3dlrL!HBL3?=}_I-fO%Bu)V!m;gYqs!jop^=NN%;D6(f zAMYO)zpxMlHJDDPi`Us~R$j(kzmxm}DI9q>pvQ5W(}y`8SKgiuRs=Gq_j9ZW)E+AWnbZ3@Rs?E~Ym*NI6_daO29q8G z5I6|{1hXQLIlZ4ldv>k}1bt*hpyP200Ko(Rf(ZZw+j$Yts=(&-Vb1!hz#NZNfz9dt z92ckC;}nyi0w|NO0tQ7^1vaPmb7+rMfvJvFfse;200a{N2qpkjWqJ6|ag>XI;}7ri z`P_dlgjpT|j4v-QyM8aQHx~epWBotyz3Vpwd$RKblfeZrlh6eR7(lK5193@F{hyE* QIsgCw07*qoM6N<$f;~|hM*si- 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; + } +}