Minor progress

This commit is contained in:
Justin Aquadro committed 2014-11-02 00:57:10 -04:00
1 parent c95ac3a0f4
commit d9d4459183
10 files changed
+688 -665

No files matched your search

@@ -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;
@@ -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
@@ -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<Slot> 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) {
@@ -35,7 +35,7 @@ public class ContainerDrawers extends Container
storageSlots = new ArrayList<Slot>();
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<Slot>();
for (int i = 0; i < 5; i++)
@@ -60,6 +60,10 @@ public class ContainerDrawers extends Container
return 0;
}
public List<Slot> getStorageSlots () {
return storageSlots;
}
@Override
public boolean canInteractWith (EntityPlayer player) {
return storageInventory.isUseableByPlayer(player) || upgradeInventory.isUseableByPlayer(player);
@@ -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();
}
@@ -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;
}
}