mirror of
https://github.com/GTNewHorizons/StorageDrawers.git
synced 2026-11-13 00:47:31 +00:00
Dead file removal
This commit is contained in:
1 parent
bdcaa5faa1
commit
074064e97c
5 files changed
-1448
No files matched your search
@@ -1,215 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.block.tile;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
public class DrawerData
|
||||
{
|
||||
private static final ItemStack nullStack = new ItemStack((Item)null);
|
||||
|
||||
private int slot;
|
||||
//private Item item;
|
||||
//private int meta;
|
||||
public int count;
|
||||
//private NBTTagCompound attrs;
|
||||
|
||||
private IStorageProvider storageProvider;
|
||||
private ItemStack protoStack;
|
||||
|
||||
private List<ItemStack> oreDictMatches;
|
||||
|
||||
public DrawerData (IStorageProvider storageProvider, int slot) {
|
||||
this.storageProvider = storageProvider;
|
||||
this.slot = slot;
|
||||
this.protoStack = nullStack;
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
public Item getItem () {
|
||||
return protoStack.getItem();
|
||||
}
|
||||
|
||||
public int getMeta () {
|
||||
return protoStack.getItemDamage();
|
||||
}
|
||||
|
||||
public NBTTagCompound getAttrs () {
|
||||
return protoStack.getTagCompound();
|
||||
}
|
||||
|
||||
public void setAttrs (NBTTagCompound attrs) {
|
||||
if (protoStack != nullStack)
|
||||
protoStack.setTagCompound(attrs);
|
||||
}
|
||||
|
||||
public void setItem (Item item, int meta) {
|
||||
setItem(item, meta, null);
|
||||
}
|
||||
|
||||
public void setItem (Item item, int meta, NBTTagCompound attrs) {
|
||||
protoStack = new ItemStack(item, 1, meta);
|
||||
protoStack.setTagCompound(attrs);
|
||||
|
||||
int[] oreIDs = OreDictionary.getOreIDs(protoStack);
|
||||
if (oreIDs.length == 0)
|
||||
oreDictMatches = null;
|
||||
else {
|
||||
oreDictMatches = new ArrayList<ItemStack>();
|
||||
for (int id : oreIDs) {
|
||||
if (StorageDrawers.oreDictRegistry.isEntryBlacklisted(OreDictionary.getOreName(id)))
|
||||
continue;
|
||||
|
||||
List<ItemStack> list = OreDictionary.getOres(OreDictionary.getOreName(id));
|
||||
for (int i = 0, n = list.size(); i < n; i++)
|
||||
oreDictMatches.add(list.get(i));
|
||||
}
|
||||
|
||||
if (oreDictMatches.size() == 0)
|
||||
oreDictMatches = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setItem (ItemStack stack) {
|
||||
setItem(stack.getItem(), stack.getItemDamage(), stack.getTagCompound());
|
||||
}
|
||||
|
||||
// Can't actually enforce write access, so take this as a severe advisory.
|
||||
// Don't needlessly force me to feed the Garbage Collector, folks.
|
||||
public ItemStack getReadOnlyItemStack () {
|
||||
return protoStack;
|
||||
}
|
||||
|
||||
public ItemStack getNewItemStack () {
|
||||
if (protoStack == nullStack)
|
||||
return null;
|
||||
|
||||
return protoStack.copy();
|
||||
}
|
||||
|
||||
public void writeToNBT (NBTTagCompound tag) {
|
||||
if (protoStack.getItem() != null) {
|
||||
tag.setShort("Item", (short) Item.getIdFromItem(protoStack.getItem()));
|
||||
tag.setShort("Meta", (short) protoStack.getItemDamage());
|
||||
tag.setInteger("Count", count);
|
||||
|
||||
if (protoStack.getTagCompound() != null)
|
||||
tag.setTag("Tags", protoStack.getTagCompound());
|
||||
}
|
||||
}
|
||||
|
||||
public void readFromNBT (NBTTagCompound tag) {
|
||||
protoStack = nullStack;
|
||||
|
||||
if (tag.hasKey("Item")) {
|
||||
setItem(Item.getItemById(tag.getShort("Item")), tag.getShort("Meta"));
|
||||
count = tag.getInteger("Count");
|
||||
|
||||
if (tag.hasKey("Tags"))
|
||||
protoStack.setTagCompound(tag.getCompoundTag("Tags"));
|
||||
}
|
||||
}
|
||||
|
||||
public void reset () {
|
||||
count = 0;
|
||||
protoStack = nullStack;
|
||||
oreDictMatches = null;
|
||||
}
|
||||
|
||||
public int stackCapacity () {
|
||||
return storageProvider.getSlotCapacity(slot);
|
||||
}
|
||||
|
||||
public int itemStackMaxSize () {
|
||||
if (protoStack.getItem() == null)
|
||||
return 0;
|
||||
|
||||
return protoStack.getItem().getItemStackLimit(protoStack);
|
||||
}
|
||||
|
||||
public int maxCapacity () {
|
||||
if (protoStack.getItem() == null)
|
||||
return 0;
|
||||
|
||||
return protoStack.getItem().getItemStackLimit(protoStack) * stackCapacity();
|
||||
}
|
||||
|
||||
public int remainingCapacity () {
|
||||
if (protoStack.getItem() == null)
|
||||
return 0;
|
||||
|
||||
return maxCapacity() - count;
|
||||
}
|
||||
|
||||
public boolean areItemsEqual (ItemStack stack) {
|
||||
if (protoStack == null || stack == null)
|
||||
return false;
|
||||
if (protoStack.getItem() == null || stack.getItem() == null)
|
||||
return false;
|
||||
|
||||
if (!protoStack.isItemEqual(stack)) {
|
||||
if (oreDictMatches == null)
|
||||
return false;
|
||||
|
||||
boolean oreMatch = false;
|
||||
for (int i = 0; i < oreDictMatches.size(); i++) {
|
||||
ItemStack candidate = oreDictMatches.get(i);
|
||||
if (candidate == null || candidate.getItemDamage() == OreDictionary.WILDCARD_VALUE)
|
||||
continue;
|
||||
|
||||
oreMatch |= stack.isItemEqual(oreDictMatches.get(i));
|
||||
if (oreMatch)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!oreMatch)
|
||||
return false;
|
||||
}
|
||||
|
||||
return ItemStack.areItemStackTagsEqual(protoStack, stack);
|
||||
}
|
||||
|
||||
public static boolean areItemsEqual (ItemStack stack1, ItemStack stack2) {
|
||||
if (stack1 == null || stack2 == null)
|
||||
return false;
|
||||
if (stack1.getItem() == null || stack2.getItem() == null)
|
||||
return false;
|
||||
|
||||
if (!stack1.isItemEqual(stack2)) {
|
||||
int[] ids1 = OreDictionary.getOreIDs(stack1);
|
||||
int[] ids2 = OreDictionary.getOreIDs(stack2);
|
||||
if (ids1.length == 0 || ids2.length == 0)
|
||||
return false;
|
||||
|
||||
boolean oreMatch = false;
|
||||
|
||||
BRK_ORE_MATCH:
|
||||
for (int oreIndexLeft : ids1) {
|
||||
if (StorageDrawers.oreDictRegistry.isEntryBlacklisted(OreDictionary.getOreName(oreIndexLeft)))
|
||||
continue;
|
||||
|
||||
for (int oreIndexRight : ids2) {
|
||||
if (StorageDrawers.oreDictRegistry.isEntryBlacklisted(OreDictionary.getOreName(oreIndexRight)))
|
||||
continue;
|
||||
|
||||
if (oreIndexLeft == oreIndexRight) {
|
||||
oreMatch = true;
|
||||
break BRK_ORE_MATCH;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!oreMatch)
|
||||
return false;
|
||||
}
|
||||
|
||||
return ItemStack.areItemStackTagsEqual(stack1, stack2);
|
||||
}
|
||||
}*/
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.block.tile;
|
||||
|
||||
/*
|
||||
public interface IStorageProvider
|
||||
{
|
||||
public int getSlotCapacity (int slot);
|
||||
}*/
|
||||
@@ -1,648 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.block.tile;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.config.CompTierRegistry;
|
||||
import com.jaquadro.minecraft.storagedrawers.config.ConfigManager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.*;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
import net.minecraft.item.crafting.ShapelessRecipes;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
/*public class TileEntityCompDrawers extends TileEntityDrawersBase implements IStorageProvider, ISidedInventory
|
||||
{
|
||||
private static InventoryLookup lookup1 = new InventoryLookup(1, 1);
|
||||
private static InventoryLookup lookup2 = new InventoryLookup(2, 2);
|
||||
private static InventoryLookup lookup3 = new InventoryLookup(3, 3);
|
||||
|
||||
private DrawerData[] data = new DrawerData[3];
|
||||
private int[] convRate = new int[3];
|
||||
|
||||
int pooledCount;
|
||||
int lookupSizeResult;
|
||||
|
||||
private ItemStack[] snapshotItems;
|
||||
private int[] snapshotCounts;
|
||||
|
||||
private long lastClickTime;
|
||||
private UUID lastClickUUID;
|
||||
|
||||
public TileEntityCompDrawers () {
|
||||
data = new DrawerData[3];
|
||||
for (int i = 0, n = data.length; i < n; i++)
|
||||
data[i] = new DrawerData(this, i);
|
||||
|
||||
snapshotItems = new ItemStack[3];
|
||||
snapshotCounts = new int[3];
|
||||
}
|
||||
|
||||
public int getDrawerCount () {
|
||||
return 3;
|
||||
}
|
||||
|
||||
public int getItemCount (int slot) {
|
||||
if (convRate[slot] == 0)
|
||||
return 0;
|
||||
|
||||
return pooledCount / convRate[slot];
|
||||
}
|
||||
|
||||
public int getItemRemainderCount (int slot) {
|
||||
int count = getItemCount(slot);
|
||||
if (slot > 0)
|
||||
count -= getItemCount(slot - 1) * (convRate[slot - 1] / convRate[slot]);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public int getItemCapacity (int slot) {
|
||||
if (!isSlotValid(slot))
|
||||
return 0;
|
||||
|
||||
return data[slot].maxCapacity();
|
||||
}
|
||||
|
||||
public int getItemStackSize (int slot) {
|
||||
return data[slot].itemStackMaxSize();
|
||||
}
|
||||
|
||||
public ItemStack getSingleItemStack (int slot) {
|
||||
if (!isSlotValid(slot))
|
||||
return null;
|
||||
|
||||
return data[slot].getReadOnlyItemStack();
|
||||
}
|
||||
|
||||
private ItemStack getItemsFromSlot (int slot, int count) {
|
||||
if (!isSlotValid(slot))
|
||||
return null;
|
||||
|
||||
int adjCount = count * convRate[slot];
|
||||
if (adjCount > pooledCount)
|
||||
count = pooledCount / convRate[slot];
|
||||
|
||||
ItemStack stack = data[slot].getNewItemStack();
|
||||
stack.stackSize = Math.min(stack.getMaxStackSize(), count);
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public ItemStack takeItemsFromSlot (int slot, int count) {
|
||||
ItemStack stack = getItemsFromSlot(slot, count);
|
||||
if (stack == null)
|
||||
return null;
|
||||
|
||||
int adjCount = stack.stackSize * convRate[slot];
|
||||
pooledCount -= adjCount;
|
||||
if (pooledCount <= 0) {
|
||||
pooledCount = 0;
|
||||
for (DrawerData d : data)
|
||||
d.reset();
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public int putItemsIntoSlot (int slot, ItemStack stack, int count) {
|
||||
if (!isSlotValid(0)) {
|
||||
populateSlots(stack);
|
||||
if (isSlotValid(0) && data[0].areItemsEqual(stack))
|
||||
slot = 0;
|
||||
else if (isSlotValid(1) && data[1].areItemsEqual(stack))
|
||||
slot = 1;
|
||||
else if (isSlotValid(2) && data[2].areItemsEqual(stack))
|
||||
slot = 2;
|
||||
}
|
||||
|
||||
if (!data[slot].areItemsEqual(stack))
|
||||
return 0;
|
||||
|
||||
count = Math.min(count, stack.stackSize);
|
||||
int adjCount = count * convRate[slot];
|
||||
int adjCountAdded = Math.min(remainingCapacity(), adjCount);
|
||||
|
||||
int countAdded = adjCountAdded / convRate[slot];
|
||||
|
||||
pooledCount += countAdded * convRate[slot];
|
||||
stack.stackSize -= countAdded;
|
||||
|
||||
return countAdded;
|
||||
}
|
||||
|
||||
public int interactPutItemsIntoSlot (int slot, EntityPlayer player) {
|
||||
int count = 0;
|
||||
|
||||
ItemStack currentStack = player.inventory.getCurrentItem();
|
||||
if (currentStack != null)
|
||||
count += putItemsIntoSlot(slot, currentStack, currentStack.stackSize);
|
||||
|
||||
if (worldObj.getWorldTime() - lastClickTime < 10 && player.getPersistentID().equals(lastClickUUID)) {
|
||||
for (int i = 0, n = player.inventory.getSizeInventory(); i < n; i++) {
|
||||
ItemStack subStack = player.inventory.getStackInSlot(i);
|
||||
if (subStack != null) {
|
||||
int subCount = putItemsIntoSlot(slot, subStack, subStack.stackSize);
|
||||
if (subCount > 0 && subStack.stackSize == 0)
|
||||
player.inventory.setInventorySlotContents(i, null);
|
||||
|
||||
count += subCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastClickTime = worldObj.getWorldTime();
|
||||
lastClickUUID = player.getPersistentID();
|
||||
|
||||
markDirty();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUpdate () {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT (NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
|
||||
NBTTagList slots = tag.getTagList("Slots", Constants.NBT.TAG_COMPOUND);
|
||||
data = new DrawerData[slots.tagCount()];
|
||||
|
||||
for (int i = 0, n = data.length; i < n; i++) {
|
||||
NBTTagCompound slot = slots.getCompoundTagAt(i);
|
||||
data[i] = new DrawerData(this, i);
|
||||
data[i].readFromNBT(slot);
|
||||
}
|
||||
|
||||
pooledCount = tag.getInteger("Count");
|
||||
|
||||
for (int i = 0, n = convRate.length; i < n; i++)
|
||||
convRate[i] = 0;
|
||||
|
||||
if (tag.hasKey("Conv0"))
|
||||
convRate[0] = tag.getByte("Conv0");
|
||||
if (tag.hasKey("Conv1"))
|
||||
convRate[1] = tag.getByte("Conv1");
|
||||
if (tag.hasKey("Conv2"))
|
||||
convRate[2] = tag.getByte("Conv2");
|
||||
|
||||
snapshotItems = new ItemStack[3];
|
||||
snapshotCounts = new int[3];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT (NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
|
||||
NBTTagList slots = new NBTTagList();
|
||||
for (DrawerData drawer : data) {
|
||||
NBTTagCompound slot = new NBTTagCompound();
|
||||
drawer.writeToNBT(slot);
|
||||
slots.appendTag(slot);
|
||||
}
|
||||
|
||||
tag.setInteger("Count", pooledCount);
|
||||
|
||||
if (convRate[0] > 0)
|
||||
tag.setByte("Conv0", (byte)convRate[0]);
|
||||
if (convRate[1] > 0)
|
||||
tag.setByte("Conv1", (byte)convRate[1]);
|
||||
if (convRate[2] > 0)
|
||||
tag.setByte("Conv2", (byte)convRate[2]);
|
||||
|
||||
tag.setTag("Slots", slots);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clientUpdateCount (int slot, int count) {
|
||||
pooledCount = count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void markDirty () {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (snapshotItems[i] != null && snapshotItems[i].stackSize != snapshotCounts[i]) {
|
||||
int diff = snapshotItems[i].stackSize - snapshotCounts[i];
|
||||
if (diff > 0)
|
||||
putItemsIntoSlot(i, snapshotItems[i], diff);
|
||||
else
|
||||
takeItemsFromSlot(i, -diff);
|
||||
|
||||
int itemStackLimit = getItemStackSize(i);
|
||||
snapshotItems[i].stackSize = itemStackLimit - Math.min(itemStackLimit, data[i].remainingCapacity());
|
||||
snapshotCounts[i] = snapshotItems[i].stackSize;
|
||||
}
|
||||
}
|
||||
|
||||
super.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotCapacity (int slot) {
|
||||
ConfigManager config = StorageDrawers.config;
|
||||
return getDrawerCapacity() * config.getStorageUpgradeMultiplier(getLevel());
|
||||
}
|
||||
|
||||
private int remainingCapacity () {
|
||||
if (!isSlotValid(0))
|
||||
return 0;
|
||||
|
||||
return data[0].maxCapacity() * convRate[0] - pooledCount;
|
||||
}
|
||||
|
||||
private int remainingCapacity (int slot) {
|
||||
if (!isSlotValid(slot))
|
||||
return 0;
|
||||
|
||||
int adjCapacity = data[0].maxCapacity() * convRate[0] - pooledCount;
|
||||
return adjCapacity / convRate[slot];
|
||||
}
|
||||
|
||||
private boolean isSlotValid (int slot) {
|
||||
return data[slot] != null && data[slot].getItem() != null;
|
||||
}
|
||||
|
||||
private void populateSlots (ItemStack stack) {
|
||||
int index = 0;
|
||||
|
||||
ItemStack uTier1 = findHigherTier(stack);
|
||||
if (uTier1 != null) {
|
||||
int uCount1 = lookupSizeResult;
|
||||
ItemStack uTier2 = findHigherTier(uTier1);
|
||||
if (uTier2 != null)
|
||||
populateSlot(index++, uTier2, lookupSizeResult * uCount1);
|
||||
|
||||
populateSlot(index++, uTier1, uCount1);
|
||||
}
|
||||
|
||||
populateSlot(index++, stack, 1);
|
||||
|
||||
if (index == 3)
|
||||
return;
|
||||
|
||||
ItemStack lTier1 = findLowerTier(stack);
|
||||
if (lTier1 != null) {
|
||||
populateSlot(index++, lTier1, 1);
|
||||
for (int i = 0; i < index - 1; i++)
|
||||
convRate[i] *= lookupSizeResult;
|
||||
}
|
||||
|
||||
if (index == 3 || lTier1 == null)
|
||||
return;
|
||||
|
||||
ItemStack lTier2 = findLowerTier(lTier1);
|
||||
if (lTier2 != null) {
|
||||
populateSlot(index++, lTier2, 1);
|
||||
for (int i = 0; i < index - 1; i++)
|
||||
convRate[i] *= lookupSizeResult;
|
||||
}
|
||||
}
|
||||
|
||||
private void populateSlot (int slot, ItemStack stack, int conversion) {
|
||||
data[slot].setItem(stack);
|
||||
convRate[slot] = conversion;
|
||||
}
|
||||
|
||||
private ItemStack findHigherTier (ItemStack stack) {
|
||||
CompTierRegistry.Record record = StorageDrawers.compRegistry.findHigherTier(stack);
|
||||
if (record != null) {
|
||||
lookupSizeResult = record.convRate;
|
||||
return record.upper;
|
||||
}
|
||||
|
||||
CraftingManager cm = CraftingManager.getInstance();
|
||||
|
||||
setupLookup(lookup3, stack);
|
||||
ItemStack match = cm.findMatchingRecipe(lookup3, worldObj);
|
||||
|
||||
if (match == null || match.getItem() == null) {
|
||||
setupLookup(lookup2, stack);
|
||||
match = cm.findMatchingRecipe(lookup2, worldObj);
|
||||
}
|
||||
|
||||
if (match != null && match.getItem() != null) {
|
||||
int size = lookupSizeResult;
|
||||
|
||||
setupLookup(lookup1, match);
|
||||
ItemStack comp = cm.findMatchingRecipe(lookup1, worldObj);
|
||||
if (!DrawerData.areItemsEqual(comp, stack) || comp.stackSize != size)
|
||||
return null;
|
||||
|
||||
lookupSizeResult = size;
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
private ItemStack findLowerTier (ItemStack stack) {
|
||||
CompTierRegistry.Record record = StorageDrawers.compRegistry.findLowerTier(stack);
|
||||
if (record != null) {
|
||||
lookupSizeResult = record.convRate;
|
||||
return record.lower;
|
||||
}
|
||||
|
||||
CraftingManager cm = CraftingManager.getInstance();
|
||||
List recipeList = cm.getRecipeList();
|
||||
|
||||
for (int i = 0, n = recipeList.size(); i < n; i++) {
|
||||
IRecipe recipe = (IRecipe) recipeList.get(i);
|
||||
ItemStack match = null;
|
||||
|
||||
ItemStack output = recipe.getRecipeOutput();
|
||||
if (!DrawerData.areItemsEqual(stack, output))
|
||||
continue;
|
||||
|
||||
if (recipe instanceof ShapelessOreRecipe)
|
||||
match = tryMatch(stack, ((ShapelessOreRecipe) recipe).getInput());
|
||||
else if (recipe instanceof ShapelessRecipes)
|
||||
match = tryMatch(stack, ((ShapelessRecipes) recipe).recipeItems);
|
||||
else if (recipe instanceof ShapedOreRecipe)
|
||||
match = tryMatch(stack, ((ShapedOreRecipe) recipe).getInput());
|
||||
else if (recipe instanceof ShapedRecipes)
|
||||
match = tryMatch(stack, ((ShapedRecipes) recipe).recipeItems);
|
||||
|
||||
if (match != null) {
|
||||
setupLookup(lookup1, stack);
|
||||
ItemStack comp = cm.findMatchingRecipe(lookup1, worldObj);
|
||||
if (DrawerData.areItemsEqual(match, comp) && comp.stackSize == recipe.getRecipeSize()) {
|
||||
lookupSizeResult = recipe.getRecipeSize();
|
||||
return match;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private ItemStack tryMatch (ItemStack stack, List list) {
|
||||
if (list.size() != 9 && list.size() != 4)
|
||||
return null;
|
||||
|
||||
Object item = list.get(0);
|
||||
if (item instanceof ItemStack) {
|
||||
ItemStack item1 = (ItemStack)item;
|
||||
for (int i = 1, n = list.size(); i < n; i++) {
|
||||
Object item2 = list.get(i);
|
||||
if (item2.getClass() != ItemStack.class)
|
||||
return null;
|
||||
if (!item1.isItemEqual((ItemStack)item2))
|
||||
return null;
|
||||
}
|
||||
return item1;
|
||||
}
|
||||
else if (item instanceof ArrayList) {
|
||||
for (int i = 1, n = list.size(); i < n; i++) {
|
||||
if (item != list.get(i))
|
||||
return null;
|
||||
}
|
||||
|
||||
ArrayList itemList = (ArrayList)item;
|
||||
if (itemList.size() > 0) {
|
||||
Object item1 = itemList.get(0);
|
||||
if (item1 instanceof ItemStack)
|
||||
return (ItemStack)item1;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private ItemStack tryMatch (ItemStack stack, Object[] list) {
|
||||
if (list.length != 9 && list.length != 4)
|
||||
return null;
|
||||
|
||||
Object item = list[0];
|
||||
if (item instanceof ItemStack) {
|
||||
ItemStack item1 = (ItemStack)item;
|
||||
for (int i = 1, n = list.length; i < n; i++) {
|
||||
Object item2 = list[i];
|
||||
if (item2 == null || item2.getClass() != ItemStack.class)
|
||||
return null;
|
||||
if (!item1.isItemEqual((ItemStack)item2))
|
||||
return null;
|
||||
}
|
||||
return item1;
|
||||
}
|
||||
else if (item instanceof ArrayList) {
|
||||
for (int i = 1, n = list.length; i < n; i++) {
|
||||
if (item != list[i])
|
||||
return null;
|
||||
}
|
||||
|
||||
ArrayList itemList = (ArrayList)item;
|
||||
if (itemList.size() > 0) {
|
||||
Object item1 = itemList.get(0);
|
||||
if (item1 instanceof ItemStack)
|
||||
return (ItemStack)item1;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void setupLookup (InventoryLookup inv, ItemStack stack) {
|
||||
for (int i = 0, n = inv.getSizeInventory(); i < n; i++)
|
||||
inv.setInventorySlotContents(i, stack);
|
||||
|
||||
lookupSizeResult = inv.getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory () {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot (int slot) {
|
||||
if (slot < 0 || slot >= getSizeInventory())
|
||||
return null;
|
||||
|
||||
int itemStackLimit = getItemStackSize(slot);
|
||||
ItemStack stack = getItemsFromSlot(slot, itemStackLimit);
|
||||
if (stack != null) {
|
||||
stack.stackSize = itemStackLimit - Math.min(itemStackLimit, remainingCapacity(slot));
|
||||
snapshotItems[slot] = stack;
|
||||
snapshotCounts[slot] = stack.stackSize;
|
||||
}
|
||||
else {
|
||||
snapshotItems[slot] = null;
|
||||
snapshotCounts[slot] = 0;
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize (int slot, int count) {
|
||||
if (slot < 0 || slot >= getSizeInventory())
|
||||
return null;
|
||||
|
||||
ItemStack stack = takeItemsFromSlot(slot, count);
|
||||
if (stack != null && !worldObj.isRemote)
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing (int slot) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents (int slot, ItemStack itemStack) {
|
||||
if (slot < 0 || slot >= getSizeInventory())
|
||||
return;
|
||||
|
||||
int insertCount = itemStack.stackSize;
|
||||
if (snapshotItems[slot] != null)
|
||||
insertCount = itemStack.stackSize - snapshotCounts[slot];
|
||||
|
||||
if (insertCount > 0) {
|
||||
int count = putItemsIntoSlot(slot, itemStack, insertCount);
|
||||
if (count > 0 && !worldObj.isRemote)
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
else if (insertCount < 0) {
|
||||
ItemStack rmStack = takeItemsFromSlot(slot, -insertCount);
|
||||
if (rmStack != null && rmStack.stackSize > 0 && !worldObj.isRemote)
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
if (snapshotItems[slot] != null) {
|
||||
int itemStackLimit = getItemStackSize(slot);
|
||||
snapshotItems[slot].stackSize = itemStackLimit - Math.min(itemStackLimit, remainingCapacity(slot));
|
||||
snapshotCounts[slot] = snapshotItems[slot].stackSize;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName () {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName () {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit () {
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer (EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory () {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory () {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot (int slot, ItemStack itemStack) {
|
||||
if (slot < 0 || slot >= getSizeInventory())
|
||||
return false;
|
||||
|
||||
if (!isSlotValid(0))
|
||||
return true;
|
||||
|
||||
if (!data[slot].areItemsEqual(itemStack))
|
||||
return false;
|
||||
|
||||
if (remainingCapacity(slot) < itemStack.stackSize)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static final int[] drawerSlots0 = new int[0];
|
||||
private static final int[] drawerSlots3 = new int[] { 0, 1, 2 };
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide (int side) {
|
||||
for (int aside : autoSides) {
|
||||
if (side == aside)
|
||||
return drawerSlots3;
|
||||
}
|
||||
|
||||
return drawerSlots0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem (int slot, ItemStack stack, int side) {
|
||||
if (slot < 0 || slot >= getSizeInventory())
|
||||
return false;
|
||||
|
||||
for (int aside : autoSides) {
|
||||
if (side == aside) {
|
||||
return isItemValidForSlot(slot, stack);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem (int slot, ItemStack stack, int side) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class InventoryLookup extends InventoryCrafting
|
||||
{
|
||||
private ItemStack[] stackList;
|
||||
|
||||
public InventoryLookup (int width, int height) {
|
||||
super(null, width, height);
|
||||
stackList = new ItemStack[width * height];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory ()
|
||||
{
|
||||
return this.stackList.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot (int slot)
|
||||
{
|
||||
return slot >= this.getSizeInventory() ? null : this.stackList[slot];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing (int slot) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize (int slot, int count) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents (int slot, ItemStack stack) {
|
||||
stackList[slot] = stack;
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -1,125 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.block.tile;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.inventory.InventoryStack;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
/*
|
||||
public abstract class TileEntityDrawersBase extends TileEntity
|
||||
{
|
||||
private int direction;
|
||||
private int drawerCapacity = 1;
|
||||
private int level = 1;
|
||||
private int statusLevel = 0;
|
||||
|
||||
protected int[] autoSides = new int[] { 0, 1 };
|
||||
|
||||
protected InventoryStack[] inventoryStacks;
|
||||
|
||||
public int getDirection () {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void setDirection (int direction) {
|
||||
this.direction = direction % 6;
|
||||
autoSides = new int[] { 0, 1, ForgeDirection.OPPOSITES[direction], 2, 3 };
|
||||
|
||||
if (direction == 2 || direction == 3) {
|
||||
autoSides[3] = 4;
|
||||
autoSides[4] = 5;
|
||||
}
|
||||
}
|
||||
|
||||
public int getLevel () {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel (int level) {
|
||||
this.level = MathHelper.clamp_int(level, 1, 6);
|
||||
}
|
||||
|
||||
public int getStatusLevel () {
|
||||
return statusLevel;
|
||||
}
|
||||
|
||||
public void setStatusLevel (int level) {
|
||||
this.statusLevel = MathHelper.clamp_int(level, 1, 3);
|
||||
}
|
||||
|
||||
public int getDrawerCapacity () {
|
||||
return drawerCapacity;
|
||||
}
|
||||
|
||||
public void setDrawerCapacity (int stackCount) {
|
||||
drawerCapacity = stackCount;
|
||||
}
|
||||
|
||||
public abstract int getDrawerCount ();
|
||||
|
||||
public abstract ItemStack takeItemsFromSlot (int slot, int count);
|
||||
|
||||
public abstract int interactPutItemsIntoSlot (int slot, EntityPlayer player);
|
||||
|
||||
public abstract int getItemCount (int slot);
|
||||
|
||||
public abstract int getItemStackSize (int slot);
|
||||
|
||||
public abstract int getItemCapacity (int slot);
|
||||
|
||||
public abstract ItemStack getSingleItemStack (int slot);
|
||||
|
||||
public abstract void setStoredItemCount (int slot, int count);
|
||||
|
||||
public abstract boolean isItemValidForDrawer (int slot, ItemStack item);
|
||||
|
||||
public abstract void setStoredItemPrototype (int slot, ItemStack protoItem);
|
||||
|
||||
@Override
|
||||
public void readFromNBT (NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
|
||||
setDirection(tag.getByte("Dir"));
|
||||
|
||||
drawerCapacity = tag.getByte("Cap");
|
||||
level = tag.getByte("Lev");
|
||||
|
||||
statusLevel = 0;
|
||||
if (tag.hasKey("Stat"))
|
||||
statusLevel = tag.getByte("Stat");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT (NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
|
||||
tag.setByte("Dir", (byte)direction);
|
||||
tag.setByte("Cap", (byte)drawerCapacity);
|
||||
tag.setByte("Lev", (byte)level);
|
||||
|
||||
if (statusLevel > 0)
|
||||
tag.setByte("Stat", (byte)statusLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket () {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeToNBT(tag);
|
||||
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 5, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity pkt) {
|
||||
readFromNBT(pkt.func_148857_g());
|
||||
getWorldObj().func_147479_m(xCoord, yCoord, zCoord); // markBlockForRenderUpdate
|
||||
}
|
||||
|
||||
public abstract void clientUpdateCount (int slot, int count);
|
||||
}*/
|
||||
@@ -1,453 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.block.tile;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.config.ConfigManager;
|
||||
import com.jaquadro.minecraft.storagedrawers.inventory.InventoryStack;
|
||||
import com.jaquadro.minecraft.storagedrawers.network.CountUpdateMessage;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import java.util.UUID;
|
||||
/*
|
||||
public class TileEntityDrawers extends TileEntityDrawersBase implements IStorageProvider, ISidedInventory
|
||||
{
|
||||
private class DrawerInventoryStack extends InventoryStack
|
||||
{
|
||||
private int slot;
|
||||
|
||||
public DrawerInventoryStack (int slot) {
|
||||
this.slot = slot;
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack getNewItemStack () {
|
||||
return data[slot].getNewItemStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getItemStackSize () {
|
||||
return data[slot].itemStackMaxSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getItemCount () {
|
||||
return data[slot].count;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getItemCapacity () {
|
||||
return data[slot].maxCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyDiff (int diff) {
|
||||
if (diff != 0) {
|
||||
if (diff > 0)
|
||||
putItemsIntoSlot(slot, getNativeStack(), diff);
|
||||
else
|
||||
takeItemsFromSlot(slot, -diff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int drawerCount = 2;
|
||||
|
||||
private DrawerData[] data;
|
||||
//private ItemStack[] snapshotItems;
|
||||
//private int[] snapshotCounts;
|
||||
|
||||
private long lastClickTime;
|
||||
private UUID lastClickUUID;
|
||||
|
||||
public TileEntityDrawers () {
|
||||
setDrawerCount(2);
|
||||
}
|
||||
|
||||
public int getDrawerCount () {
|
||||
return drawerCount;
|
||||
}
|
||||
|
||||
public void setDrawerCount (int count) {
|
||||
drawerCount = count;
|
||||
|
||||
data = new DrawerData[drawerCount];
|
||||
for (int i = 0, n = data.length; i < n; i++)
|
||||
data[i] = new DrawerData(this, i);
|
||||
|
||||
inventoryStacks = new InventoryStack[count];
|
||||
//snapshotItems = new ItemStack[count];
|
||||
//snapshotCounts = new int[count];
|
||||
}
|
||||
|
||||
public int getItemCount (int slot) {
|
||||
return data[slot].count;
|
||||
}
|
||||
|
||||
public int getItemCapacity (int slot) {
|
||||
return data[slot].maxCapacity();
|
||||
}
|
||||
|
||||
public int getItemStackSize (int slot) {
|
||||
return data[slot].itemStackMaxSize();
|
||||
}
|
||||
|
||||
public ItemStack getSingleItemStack (int slot) {
|
||||
if (data[slot].getItem() == null)
|
||||
return null;
|
||||
|
||||
return data[slot].getReadOnlyItemStack();
|
||||
}
|
||||
|
||||
public NBTTagCompound getItemAttrs (int slot) {
|
||||
return data[slot].getAttrs();
|
||||
}
|
||||
|
||||
public ItemStack takeItemsFromSlot (int slot, int count) {
|
||||
ItemStack stack = getItemsFromSlot(slot, count);
|
||||
if (stack == null)
|
||||
return null;
|
||||
|
||||
data[slot].count -= stack.stackSize;
|
||||
if (data[slot].count <= 0) {
|
||||
data[slot].reset();
|
||||
inventoryStacks[slot] = null;
|
||||
}
|
||||
|
||||
if (!worldObj.isRemote)
|
||||
syncClientCount(slot);
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public int interactPutItemsIntoSlot (int slot, EntityPlayer player) {
|
||||
int count = 0;
|
||||
|
||||
ItemStack currentStack = player.inventory.getCurrentItem();
|
||||
if (currentStack != null)
|
||||
count += putItemsIntoSlot(slot, currentStack, currentStack.stackSize);
|
||||
|
||||
if (worldObj.getWorldTime() - lastClickTime < 10 && player.getPersistentID().equals(lastClickUUID)) {
|
||||
for (int i = 0, n = player.inventory.getSizeInventory(); i < n; i++) {
|
||||
ItemStack subStack = player.inventory.getStackInSlot(i);
|
||||
if (subStack != null) {
|
||||
int subCount = putItemsIntoSlot(slot, subStack, subStack.stackSize);
|
||||
if (subCount > 0 && subStack.stackSize == 0)
|
||||
player.inventory.setInventorySlotContents(i, null);
|
||||
|
||||
count += subCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastClickTime = worldObj.getWorldTime();
|
||||
lastClickUUID = player.getPersistentID();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public int putItemsIntoSlot (int slot, ItemStack stack, int count) {
|
||||
if (data[slot].getItem() == null) {
|
||||
data[slot].setItem(stack);
|
||||
inventoryStacks[slot] = new DrawerInventoryStack(slot);
|
||||
inventoryStacks[slot].markDirty();
|
||||
}
|
||||
|
||||
if (!data[slot].areItemsEqual(stack))
|
||||
return 0;
|
||||
|
||||
int countAdded = Math.min(data[slot].remainingCapacity(), stack.stackSize);
|
||||
countAdded = Math.min(countAdded, count);
|
||||
|
||||
data[slot].count += countAdded;
|
||||
stack.stackSize -= countAdded;
|
||||
|
||||
if (!worldObj.isRemote)
|
||||
syncClientCount(slot);
|
||||
|
||||
return countAdded;
|
||||
}
|
||||
|
||||
private ItemStack getItemsFromSlot (int slot, int count) {
|
||||
if (data[slot].getItem() == null)
|
||||
return null;
|
||||
|
||||
ItemStack stack = data[slot].getNewItemStack();
|
||||
stack.stackSize = Math.min(stack.getMaxStackSize(), count);
|
||||
stack.stackSize = Math.min(stack.stackSize, data[slot].count);
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotCapacity (int slot) {
|
||||
ConfigManager config = StorageDrawers.config;
|
||||
return config.getStorageUpgradeMultiplier(getLevel()) * getDrawerCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUpdate () {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT (NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
|
||||
NBTTagList slots = tag.getTagList("Slots", Constants.NBT.TAG_COMPOUND);
|
||||
drawerCount = slots.tagCount();
|
||||
data = new DrawerData[slots.tagCount()];
|
||||
|
||||
inventoryStacks = new InventoryStack[drawerCount];
|
||||
|
||||
for (int i = 0, n = data.length; i < n; i++) {
|
||||
NBTTagCompound slot = slots.getCompoundTagAt(i);
|
||||
data[i] = new DrawerData(this, i);
|
||||
data[i].readFromNBT(slot);
|
||||
if (data[i].getItem() != null)
|
||||
inventoryStacks[i] = new DrawerInventoryStack(i);
|
||||
}
|
||||
|
||||
|
||||
//snapshotItems = new ItemStack[drawerCount];
|
||||
//snapshotCounts = new int[drawerCount];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT (NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
|
||||
NBTTagList slots = new NBTTagList();
|
||||
for (DrawerData drawer : data) {
|
||||
NBTTagCompound slot = new NBTTagCompound();
|
||||
drawer.writeToNBT(slot);
|
||||
slots.appendTag(slot);
|
||||
}
|
||||
|
||||
tag.setTag("Slots", slots);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clientUpdateCount (int slot, int count) {
|
||||
if (data[slot].count != count) {
|
||||
data[slot].count = count;
|
||||
getWorldObj().func_147479_m(xCoord, yCoord, zCoord); // markBlockForRenderUpdate
|
||||
}
|
||||
}
|
||||
|
||||
protected void syncClientCount (int slot) {
|
||||
IMessage message = new CountUpdateMessage(xCoord, yCoord, zCoord, slot, data[slot].count);
|
||||
NetworkRegistry.TargetPoint targetPoint = new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 500);
|
||||
|
||||
StorageDrawers.network.sendToAllAround(message, targetPoint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket () {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeToNBT(tag);
|
||||
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 5, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity pkt) {
|
||||
readFromNBT(pkt.func_148857_g());
|
||||
getWorldObj().func_147479_m(xCoord, yCoord, zCoord); // markBlockForRenderUpdate
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty () {
|
||||
for (int i = 0; i < drawerCount; i++) {
|
||||
if (inventoryStacks[i] != null)
|
||||
inventoryStacks[i].markDirty();
|
||||
}
|
||||
|
||||
super.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory () {
|
||||
return drawerCount * 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot (int slot) {
|
||||
if (slot < 0 || slot >= getSizeInventory())
|
||||
return null;
|
||||
|
||||
int baseSlot = slot % drawerCount;
|
||||
InventoryStack invStack = inventoryStacks[baseSlot];
|
||||
if (invStack == null)
|
||||
return null;
|
||||
|
||||
invStack.markDirty();
|
||||
|
||||
int groupSlot = slot / drawerCount;
|
||||
switch (groupSlot) {
|
||||
case 0: return invStack.getInStack();
|
||||
case 1: return invStack.getOutStack();
|
||||
case 2: return invStack.getNativeStack();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize (int slot, int count) {
|
||||
if (slot < 0 || slot >= getSizeInventory())
|
||||
return null;
|
||||
|
||||
int baseSlot = slot % drawerCount;
|
||||
ItemStack stack = takeItemsFromSlot(baseSlot, count);
|
||||
if (stack != null && !worldObj.isRemote)
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
|
||||
if (inventoryStacks[baseSlot] != null)
|
||||
inventoryStacks[baseSlot].markDirty();
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing (int slot) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents (int slot, ItemStack itemStack) {
|
||||
if (slot < 0 || slot >= getSizeInventory())
|
||||
return;
|
||||
|
||||
int baseSlot = slot % drawerCount;
|
||||
int slotGroup = slot / drawerCount;
|
||||
int insertCount = 0;
|
||||
|
||||
if (slotGroup == 0) {
|
||||
insertCount = (itemStack != null) ? itemStack.stackSize : 0;
|
||||
if (inventoryStacks[baseSlot] != null)
|
||||
insertCount -= inventoryStacks[baseSlot].getInStack().stackSize;
|
||||
}
|
||||
else if (slotGroup == 1) {
|
||||
insertCount = (itemStack != null) ? itemStack.stackSize : 0;
|
||||
if (inventoryStacks[baseSlot] != null)
|
||||
insertCount -= inventoryStacks[baseSlot].getOutStack().stackSize;
|
||||
}
|
||||
|
||||
//if (snapshotItems[slot] != null)
|
||||
// insertCount = itemStack.stackSize - snapshotCounts[slot];
|
||||
|
||||
if (insertCount > 0) {
|
||||
int count = putItemsIntoSlot(baseSlot, itemStack, insertCount);
|
||||
if (count > 0 && !worldObj.isRemote)
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
else if (insertCount < 0) {
|
||||
ItemStack rmStack = takeItemsFromSlot(baseSlot, -insertCount);
|
||||
if (rmStack != null && rmStack.stackSize > 0 && !worldObj.isRemote)
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
if (inventoryStacks[baseSlot] != null)
|
||||
inventoryStacks[baseSlot].markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName () {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName () {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit () {
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer (EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory () {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory () {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot (int slot, ItemStack itemStack) {
|
||||
if (slot < 0 || slot >= getSizeInventory())
|
||||
return false;
|
||||
|
||||
int baseSlot = slot % drawerCount;
|
||||
if (data[baseSlot].getItem() == null)
|
||||
return true;
|
||||
|
||||
if (!data[baseSlot].areItemsEqual(itemStack))
|
||||
return false;
|
||||
|
||||
if (data[baseSlot].remainingCapacity() < itemStack.stackSize)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static final int[] drawerSlots0 = new int[0];
|
||||
private static final int[] drawerSlots2 = new int[] { 0, 1, 2, 3 };
|
||||
private static final int[] drawerSlots4 = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 };
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide (int side) {
|
||||
for (int aside : autoSides) {
|
||||
if (side == aside)
|
||||
return (drawerCount == 2) ? drawerSlots2 : drawerSlots4;
|
||||
}
|
||||
|
||||
return drawerSlots0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem (int slot, ItemStack stack, int side) {
|
||||
if (slot < 0 || slot >= getSizeInventory() / 3)
|
||||
return false;
|
||||
|
||||
for (int aside : autoSides) {
|
||||
if (side == aside) {
|
||||
return isItemValidForSlot(slot, stack);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem (int slot, ItemStack stack, int side) {
|
||||
int baseUnit = getSizeInventory() / 3;
|
||||
if (slot < baseUnit || slot >= 2 * baseUnit)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
*/
|
||||
Reference in new issue
Block a user