mirror of
https://github.com/GTNewHorizons/StorageDrawers.git
synced 2026-11-23 13:39:39 +00:00
Holy refactor, Batman!
This commit is contained in:
1 parent
f336180037
commit
73b8e5fd91
30 files changed
+1446
-439
No files matched your search
@@ -55,6 +55,7 @@ dependencies {
|
||||
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
|
||||
// http://www.gradle.org/docs/current/userguide/dependency_management.html
|
||||
|
||||
// compile "appeng:appliedenergistics2:rv1-stable-1:api"
|
||||
}
|
||||
|
||||
processResources
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.inventory;
|
||||
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
|
||||
public interface IDrawerInventory extends ISidedInventory
|
||||
{
|
||||
/**
|
||||
* Gets a drawer's group slot index from an IInventory slot index.
|
||||
*
|
||||
* @param inventorySlot An IInventory slot index returned from getInventorySlot.
|
||||
*/
|
||||
public int getDrawerSlot (int inventorySlot);
|
||||
|
||||
/**
|
||||
* Gets an IInventory slot index suitable for operations for the given type.
|
||||
*
|
||||
* @param drawerSlot The index of the drawer within its group.
|
||||
* @param type The type of IInventory slot to return an index for.
|
||||
*/
|
||||
public int getInventorySlot (int drawerSlot, SlotType type);
|
||||
|
||||
/**
|
||||
* Gets the type associated with a given IInventory slot index.
|
||||
*
|
||||
* @param inventorySlot An IInventory slot index returned from getInventorySlot.
|
||||
*/
|
||||
public SlotType getInventorySlotType (int inventorySlot);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.inventory;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IInventoryAdapter
|
||||
{
|
||||
public ItemStack getInventoryStack (SlotType slotType);
|
||||
|
||||
public void syncInventory ();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.inventory;
|
||||
|
||||
/**
|
||||
* Classifies different IInventory slots according to how they should be used.
|
||||
*/
|
||||
public enum SlotType
|
||||
{
|
||||
/** An inventory slot for native StorageDrawers operations; stack sizes exceed 64. */
|
||||
STORAGE,
|
||||
|
||||
/** An inventory slot for input-only operations; stack sizes artificially held low. */
|
||||
INPUT,
|
||||
|
||||
/** An inventory slot for output-only operations; stack sizes artificially held high. */
|
||||
OUTPUT;
|
||||
|
||||
public static final SlotType[] values = values();
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.storage;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public interface IDrawer
|
||||
{
|
||||
@@ -79,4 +80,8 @@ public interface IDrawer
|
||||
* A drawer set with an item type and 0 count is not considered empty.
|
||||
*/
|
||||
boolean isEmpty ();
|
||||
|
||||
public void writeToNBT (NBTTagCompound tag);
|
||||
|
||||
public void readFromNBT (NBTTagCompound tag);
|
||||
}
|
||||
@@ -1,16 +1,12 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.block;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityCompDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersBase;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.ModItems;
|
||||
import cpw.mods.fml.common.registry.GameData;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersComp;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockWood;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
@@ -56,8 +52,8 @@ public class BlockCompDrawers extends BlockDrawers
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntityDrawersBase createNewTileEntity (World world, int meta) {
|
||||
return new TileEntityCompDrawers();
|
||||
public TileEntityDrawers createNewTileEntity (World world, int meta) {
|
||||
return new TileEntityDrawersComp();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,29 +83,30 @@ public class BlockCompDrawers extends BlockDrawers
|
||||
|
||||
@Override
|
||||
public IIcon getIcon (IBlockAccess blockAccess, int x, int y, int z, int side) {
|
||||
TileEntityDrawersBase tile = getTileEntity(blockAccess, x, y, z);
|
||||
TileEntityDrawers tile = getTileEntity(blockAccess, x, y, z);
|
||||
if (tile == null)
|
||||
return iconFront[0];
|
||||
|
||||
if (side == tile.getDirection()) {
|
||||
if (tile.getStatusLevel() != 3) {
|
||||
if (tile.getItemStackSize(2) > 0)
|
||||
if (tile.getDrawer(2).getStoredItemStackSize() > 0)
|
||||
return iconFront[2];
|
||||
else if (tile.getItemStackSize(1) > 0)
|
||||
else if (tile.getDrawer(1).getStoredItemStackSize() > 0)
|
||||
return iconFront[1];
|
||||
else
|
||||
return iconFront[0];
|
||||
}
|
||||
else {
|
||||
IDrawer main = tile.getDrawer(0);
|
||||
int plev = 0;
|
||||
if (tile.getItemCapacity(0) != 0) {
|
||||
float pfull = (float) tile.getItemCount(0) / tile.getItemCapacity(0);
|
||||
if (main.getMaxCapacity() != 0) {
|
||||
float pfull = (float) main.getStoredItemCount() / main.getMaxCapacity();
|
||||
plev = MathHelper.clamp_int((int) (pfull * 6.99), 0, 6);
|
||||
}
|
||||
|
||||
if (tile.getItemStackSize(2) > 0)
|
||||
if (tile.getDrawer(2).getStoredItemStackSize() > 0)
|
||||
return iconFrontInd[2][plev];
|
||||
else if (tile.getItemStackSize(1) > 0)
|
||||
else if (tile.getDrawer(1).getStoredItemStackSize() > 0)
|
||||
return iconFrontInd[1][plev];
|
||||
else
|
||||
return iconFrontInd[0][plev];
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.block;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersBase;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersStandard;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.ModCreativeTabs;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.ModItems;
|
||||
import com.jaquadro.minecraft.storagedrawers.network.BlockClickMessage;
|
||||
@@ -101,7 +102,7 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
|
||||
@Override
|
||||
public void setBlockBoundsBasedOnState (IBlockAccess blockAccess, int x, int y, int z) {
|
||||
TileEntityDrawersBase tile = getTileEntity(blockAccess, x, y, z);
|
||||
TileEntityDrawers tile = getTileEntity(blockAccess, x, y, z);
|
||||
if (tile == null) {
|
||||
setBlockBounds(0, 0, 0, 1, 1, 1);
|
||||
return;
|
||||
@@ -140,7 +141,7 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy (World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemStack) {
|
||||
TileEntityDrawersBase tile = getTileEntitySafe(world, x, y, z);
|
||||
TileEntityDrawers tile = getTileEntitySafe(world, x, y, z);
|
||||
if (tile.getDirection() > 1)
|
||||
return;
|
||||
|
||||
@@ -168,12 +169,12 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated (World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
||||
TileEntityDrawersBase tileDrawers = getTileEntitySafe(world, x, y, z);
|
||||
TileEntityDrawers tileDrawers = getTileEntitySafe(world, x, y, z);
|
||||
ItemStack item = player.inventory.getCurrentItem();
|
||||
|
||||
if (item != null && item.getItem() != null) {
|
||||
if (item.getItem() == ModItems.upgrade && item.getItemDamage() != tileDrawers.getLevel()) {
|
||||
tileDrawers.setLevel(item.getItemDamage());
|
||||
if (item.getItem() == ModItems.upgrade && item.getItemDamage() != tileDrawers.getStorageLevel()) {
|
||||
tileDrawers.setStorageLevel(item.getItemDamage());
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
|
||||
if (player != null && !player.capabilities.isCreativeMode) {
|
||||
@@ -251,15 +252,16 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
|
||||
@Override
|
||||
public void onBlockClicked (World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
||||
TileEntityDrawersBase tileDrawers = getTileEntitySafe(world, x, y, z);
|
||||
TileEntityDrawers tileDrawers = getTileEntitySafe(world, x, y, z);
|
||||
if (tileDrawers.getDirection() != side)
|
||||
return;
|
||||
|
||||
int slot = getDrawerSlot(side, hitX, hitY, hitZ);
|
||||
IDrawer drawer = tileDrawers.getDrawer(slot);
|
||||
|
||||
ItemStack item = null;
|
||||
if (player.isSneaking())
|
||||
item = tileDrawers.takeItemsFromSlot(slot, tileDrawers.getItemStackSize(slot));
|
||||
item = tileDrawers.takeItemsFromSlot(slot, drawer.getStoredItemStackSize());
|
||||
else
|
||||
item = tileDrawers.takeItemsFromSlot(slot, 1);
|
||||
|
||||
@@ -277,7 +279,7 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
@Override
|
||||
public boolean removedByPlayer (World world, EntityPlayer player, int x, int y, int z) {
|
||||
if (world.isRemote && player.capabilities.isCreativeMode) {
|
||||
TileEntityDrawersBase tile = getTileEntity(world, x, y, z);
|
||||
TileEntityDrawers tile = getTileEntity(world, x, y, z);
|
||||
MovingObjectPosition posn = Minecraft.getMinecraft().objectMouseOver;
|
||||
|
||||
if (tile.getDirection() == posn.sideHit) {
|
||||
@@ -291,17 +293,18 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
|
||||
@Override
|
||||
public void breakBlock (World world, int x, int y, int z, Block block, int meta) {
|
||||
TileEntityDrawersBase tile = getTileEntity(world, x, y, z);
|
||||
TileEntityDrawers tile = getTileEntity(world, x, y, z);
|
||||
|
||||
if (tile != null) {
|
||||
if (tile.getLevel() > 1)
|
||||
dropBlockAsItem(world, x, y, z, new ItemStack(ModItems.upgrade, 1, tile.getLevel()));
|
||||
if (tile.getStorageLevel() > 1)
|
||||
dropBlockAsItem(world, x, y, z, new ItemStack(ModItems.upgrade, 1, tile.getStorageLevel()));
|
||||
if (tile.getStatusLevel() > 0)
|
||||
dropBlockAsItem(world, x, y, z, new ItemStack(ModItems.upgradeStatus, 1, tile.getStatusLevel()));
|
||||
|
||||
for (int i = 0; i < tile.getDrawerCount(); i++) {
|
||||
while (tile.getItemCount(i) > 0) {
|
||||
ItemStack stack = tile.takeItemsFromSlot(i, tile.getItemStackSize(i));
|
||||
IDrawer drawer = tile.getDrawer(i);
|
||||
while (drawer.getStoredItemCount() > 0) {
|
||||
ItemStack stack = tile.takeItemsFromSlot(i, drawer.getStoredItemStackSize());
|
||||
if (stack == null || stack.stackSize == 0)
|
||||
break;
|
||||
|
||||
@@ -347,19 +350,19 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntityDrawersBase createNewTileEntity (World world, int meta) {
|
||||
return new TileEntityDrawers();
|
||||
public TileEntityDrawers createNewTileEntity (World world, int meta) {
|
||||
return new TileEntityDrawersStandard();
|
||||
}
|
||||
|
||||
public TileEntityDrawersBase getTileEntity (IBlockAccess blockAccess, int x, int y, int z) {
|
||||
public TileEntityDrawers getTileEntity (IBlockAccess blockAccess, int x, int y, int z) {
|
||||
TileEntity tile = blockAccess.getTileEntity(x, y, z);
|
||||
return (tile instanceof TileEntityDrawersBase) ? (TileEntityDrawersBase) tile : null;
|
||||
return (tile instanceof TileEntityDrawers) ? (TileEntityDrawers) tile : null;
|
||||
}
|
||||
|
||||
public TileEntityDrawersBase getTileEntitySafe (World world, int x, int y, int z) {
|
||||
TileEntityDrawersBase tile = getTileEntity(world, x, y, z);
|
||||
public TileEntityDrawers getTileEntitySafe (World world, int x, int y, int z) {
|
||||
TileEntityDrawers tile = getTileEntity(world, x, y, z);
|
||||
if (tile == null) {
|
||||
tile = (TileEntityDrawersBase)createNewTileEntity(world, world.getBlockMetadata(x, y, z));
|
||||
tile = (TileEntityDrawers)createNewTileEntity(world, world.getBlockMetadata(x, y, z));
|
||||
world.setTileEntity(x, y, z, tile);
|
||||
}
|
||||
|
||||
@@ -370,8 +373,8 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean addHitEffects (World worldObj, MovingObjectPosition target, EffectRenderer effectRenderer) {
|
||||
TileEntity tile = worldObj.getTileEntity(target.blockX, target.blockY, target.blockZ);
|
||||
if (tile instanceof TileEntityDrawersBase) {
|
||||
if (((TileEntityDrawersBase) tile).getDirection() == target.sideHit)
|
||||
if (tile instanceof TileEntityDrawers) {
|
||||
if (((TileEntityDrawers) tile).getDirection() == target.sideHit)
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -468,7 +471,7 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
private IIcon getIcon (IBlockAccess blockAccess, int x, int y, int z, int side, int level) {
|
||||
int meta = blockAccess.getBlockMetadata(x, y, z) % BlockWood.field_150096_a.length;
|
||||
|
||||
TileEntityDrawersBase tile = getTileEntity(blockAccess, x, y, z);
|
||||
TileEntityDrawers tile = getTileEntity(blockAccess, x, y, z);
|
||||
if (tile == null || side == tile.getDirection()) {
|
||||
if (drawerCount == 2)
|
||||
return iconFront2[meta];
|
||||
|
||||
@@ -9,6 +9,7 @@ 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);
|
||||
@@ -211,4 +212,4 @@ public class DrawerData
|
||||
|
||||
return ItemStack.areItemStackTagsEqual(stack1, stack2);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.block.tile;
|
||||
|
||||
/*
|
||||
public interface IStorageProvider
|
||||
{
|
||||
public int getSlotCapacity (int slot);
|
||||
}
|
||||
}*/
|
||||
@@ -19,7 +19,7 @@ import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
public class TileEntityCompDrawers extends TileEntityDrawersBase implements IStorageProvider, ISidedInventory
|
||||
/*public class TileEntityCompDrawers extends TileEntityDrawersBase implements IStorageProvider, ISidedInventory
|
||||
{
|
||||
private static InventoryLookup lookup1 = new InventoryLookup(1, 1);
|
||||
private static InventoryLookup lookup2 = new InventoryLookup(2, 2);
|
||||
@@ -645,4 +645,4 @@ class InventoryLookup extends InventoryCrafting
|
||||
stackList[slot] = stack;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
@@ -1,14 +1,17 @@
|
||||
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.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.StorageInventory;
|
||||
import com.jaquadro.minecraft.storagedrawers.network.CountUpdateMessage;
|
||||
import com.jaquadro.minecraft.storagedrawers.storage.DrawerData;
|
||||
import com.jaquadro.minecraft.storagedrawers.storage.IStorageProvider;
|
||||
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;
|
||||
@@ -22,117 +25,121 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class TileEntityDrawers extends TileEntityDrawersBase implements IStorageProvider, ISidedInventory
|
||||
public abstract class TileEntityDrawers extends TileEntity implements IDrawerGroup, ISidedInventory
|
||||
{
|
||||
private class DrawerInventoryStack extends InventoryStack
|
||||
{
|
||||
private int slot;
|
||||
private IDrawer[] drawers;
|
||||
private IDrawerInventory inventory;
|
||||
|
||||
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 int direction;
|
||||
private int drawerCapacity = 1;
|
||||
private int storageLevel = 1;
|
||||
private int statusLevel = 0;
|
||||
|
||||
private long lastClickTime;
|
||||
private UUID lastClickUUID;
|
||||
|
||||
public TileEntityDrawers () {
|
||||
setDrawerCount(2);
|
||||
protected TileEntityDrawers (int drawerCount) {
|
||||
initWithDrawerCount(drawerCount);
|
||||
}
|
||||
|
||||
public int getDrawerCount () {
|
||||
return drawerCount;
|
||||
protected abstract IStorageProvider getStorageProvider ();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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 getDirection () {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public int getItemCount (int slot) {
|
||||
return data[slot].count;
|
||||
public void setDirection (int direction) {
|
||||
this.direction = direction % 6;
|
||||
// TODO: Deal with sides
|
||||
/*autoSides = new int[] { 0, 1, ForgeDirection.OPPOSITES[direction], 2, 3 };
|
||||
|
||||
if (direction == 2 || direction == 3) {
|
||||
autoSides[3] = 4;
|
||||
autoSides[4] = 5;
|
||||
}*/
|
||||
}
|
||||
|
||||
public int getItemCapacity (int slot) {
|
||||
return data[slot].maxCapacity();
|
||||
public int getStorageLevel () {
|
||||
return storageLevel;
|
||||
}
|
||||
|
||||
public int getItemStackSize (int slot) {
|
||||
return data[slot].itemStackMaxSize();
|
||||
public void setStorageLevel (int level) {
|
||||
this.storageLevel = MathHelper.clamp_int(level, 1, 6);
|
||||
}
|
||||
|
||||
public ItemStack getSingleItemStack (int slot) {
|
||||
if (data[slot].getItem() == null)
|
||||
return null;
|
||||
|
||||
return data[slot].getReadOnlyItemStack();
|
||||
public int getStatusLevel () {
|
||||
return statusLevel;
|
||||
}
|
||||
|
||||
public NBTTagCompound getItemAttrs (int slot) {
|
||||
return data[slot].getAttrs();
|
||||
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 ItemStack takeItemsFromSlot (int slot, int count) {
|
||||
if (slot < 0 || slot >= getDrawerCount())
|
||||
return null;
|
||||
|
||||
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;
|
||||
}
|
||||
IDrawer drawer = drawers[slot];
|
||||
drawer.setStoredItemCount(drawer.getStoredItemCount() - stack.stackSize);
|
||||
|
||||
if (!worldObj.isRemote)
|
||||
syncClientCount(slot);
|
||||
// TODO: Reset empty drawer in subclasses
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
protected ItemStack getItemsFromSlot (int slot, int count) {
|
||||
if (drawers[slot].isEmpty())
|
||||
return null;
|
||||
|
||||
ItemStack stack = drawers[slot].getStoredItemCopy();
|
||||
stack.stackSize = Math.min(stack.getMaxStackSize(), count);
|
||||
stack.stackSize = Math.min(stack.stackSize, drawers[slot].getStoredItemCount());
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public int putItemsIntoSlot (int slot, ItemStack stack, int count) {
|
||||
if (slot < 0 || slot >= getDrawerCount())
|
||||
return 0;
|
||||
|
||||
// TODO: Override comp to pick the right slot
|
||||
|
||||
IDrawer drawer = drawers[slot];
|
||||
if (drawer.isEmpty())
|
||||
drawer.setStoredItem(stack, 0);
|
||||
|
||||
if (!drawer.canItemBeStored(stack))
|
||||
return 0;
|
||||
|
||||
int countAdded = Math.min(drawer.getRemainingCapacity(), stack.stackSize);
|
||||
countAdded = Math.min(countAdded, count);
|
||||
|
||||
drawer.setStoredItemCount(drawer.getStoredItemCount() + countAdded);
|
||||
stack.stackSize -= countAdded;
|
||||
|
||||
return countAdded;
|
||||
}
|
||||
|
||||
public int interactPutItemsIntoSlot (int slot, EntityPlayer player) {
|
||||
int count = 0;
|
||||
|
||||
@@ -156,82 +163,50 @@ public class TileEntityDrawers extends TileEntityDrawersBase implements IStorage
|
||||
lastClickTime = worldObj.getWorldTime();
|
||||
lastClickUUID = player.getPersistentID();
|
||||
|
||||
markDirty();
|
||||
|
||||
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);
|
||||
|
||||
setDirection(tag.getByte("Dir"));
|
||||
|
||||
drawerCapacity = tag.getByte("Cap");
|
||||
storageLevel = tag.getByte("Lev");
|
||||
|
||||
statusLevel = 0;
|
||||
if (tag.hasKey("Stat"))
|
||||
statusLevel = tag.getByte("Stat");
|
||||
|
||||
NBTTagList slots = tag.getTagList("Slots", Constants.NBT.TAG_COMPOUND);
|
||||
drawerCount = slots.tagCount();
|
||||
data = new DrawerData[slots.tagCount()];
|
||||
int drawerCount = slots.tagCount();
|
||||
drawers = new DrawerData[slots.tagCount()];
|
||||
|
||||
inventoryStacks = new InventoryStack[drawerCount];
|
||||
|
||||
for (int i = 0, n = data.length; i < n; i++) {
|
||||
for (int i = 0, n = drawers.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);
|
||||
drawers[i] = new DrawerData(getStorageProvider(), i);
|
||||
drawers[i].readFromNBT(slot);
|
||||
}
|
||||
|
||||
|
||||
//snapshotItems = new ItemStack[drawerCount];
|
||||
//snapshotCounts = new int[drawerCount];
|
||||
inventory = new StorageInventory(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT (NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
|
||||
tag.setByte("Dir", (byte)direction);
|
||||
tag.setByte("Cap", (byte)drawerCapacity);
|
||||
tag.setByte("Lev", (byte) storageLevel);
|
||||
|
||||
if (statusLevel > 0)
|
||||
tag.setByte("Stat", (byte)statusLevel);
|
||||
|
||||
NBTTagList slots = new NBTTagList();
|
||||
for (DrawerData drawer : data) {
|
||||
for (IDrawer drawer : drawers) {
|
||||
NBTTagCompound slot = new NBTTagCompound();
|
||||
drawer.writeToNBT(slot);
|
||||
slots.appendTag(slot);
|
||||
@@ -241,20 +216,32 @@ public class TileEntityDrawers extends TileEntityDrawersBase implements IStorage
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUpdate () {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty () {
|
||||
|
||||
super.markDirty();
|
||||
}
|
||||
|
||||
public void clientUpdateCount (int slot, int count) {
|
||||
if (data[slot].count != count) {
|
||||
data[slot].count = count;
|
||||
IDrawer drawer = getDrawer(slot);
|
||||
if (drawer.getStoredItemCount() != count) {
|
||||
drawer.setStoredItemCount(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);
|
||||
private void syncClientCount (int slot) {
|
||||
IMessage message = new CountUpdateMessage(xCoord, yCoord, zCoord, slot, drawers[slot].getStoredItemCount());
|
||||
NetworkRegistry.TargetPoint targetPoint = new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 500);
|
||||
|
||||
StorageDrawers.network.sendToAllAround(message, targetPoint);
|
||||
}
|
||||
|
||||
// TODO: Eventually eliminate these expensive network updates
|
||||
@Override
|
||||
public Packet getDescriptionPacket () {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
@@ -270,215 +257,95 @@ public class TileEntityDrawers extends TileEntityDrawersBase implements IStorage
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty () {
|
||||
for (int i = 0; i < drawerCount; i++) {
|
||||
if (inventoryStacks[i] != null)
|
||||
inventoryStacks[i].markDirty();
|
||||
|
||||
/*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();
|
||||
public int getDrawerCount () {
|
||||
return drawers.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory () {
|
||||
return drawerCount * 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot (int slot) {
|
||||
if (slot < 0 || slot >= getSizeInventory())
|
||||
public IDrawer getDrawer (int slot) {
|
||||
if (slot < 0 || slot >= drawers.length)
|
||||
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;
|
||||
|
||||
/*int itemStackLimit = getItemStackSize(baseSlot);
|
||||
ItemStack stack = getItemsFromSlot(slot, itemStackLimit);
|
||||
if (stack != null) {
|
||||
stack.stackSize = itemStackLimit - Math.min(itemStackLimit, data[slot].remainingCapacity());
|
||||
snapshotItems[slot] = stack;
|
||||
snapshotCounts[slot] = stack.stackSize;
|
||||
}
|
||||
else {
|
||||
snapshotItems[slot] = null;
|
||||
snapshotCounts[slot] = 0;
|
||||
}
|
||||
|
||||
return stack;*/
|
||||
return drawers[slot];
|
||||
}
|
||||
|
||||
@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;
|
||||
public boolean isDrawerEnabled (int slot) {
|
||||
return getDrawer(slot) != null;
|
||||
}
|
||||
|
||||
@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();
|
||||
|
||||
/*if (snapshotItems[slot] != null) {
|
||||
int itemStackLimit = getItemStackSize(slot);
|
||||
snapshotItems[slot].stackSize = itemStackLimit - Math.min(itemStackLimit, data[slot].remainingCapacity());
|
||||
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;
|
||||
|
||||
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;
|
||||
return inventory.getAccessibleSlotsFromSide(side);
|
||||
}
|
||||
|
||||
@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;
|
||||
return inventory.canInsertItem(slot, stack, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem (int slot, ItemStack stack, int side) {
|
||||
int baseUnit = getSizeInventory() / 3;
|
||||
if (slot < baseUnit || slot >= 2 * baseUnit)
|
||||
return false;
|
||||
return inventory.canExtractItem(slot, stack, side);
|
||||
}
|
||||
|
||||
return true;
|
||||
@Override
|
||||
public int getSizeInventory () {
|
||||
return inventory.getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot (int slot) {
|
||||
return inventory.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize (int slot, int count) {
|
||||
return inventory.decrStackSize(slot, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing (int slot) {
|
||||
return inventory.getStackInSlotOnClosing(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents (int slot, ItemStack stack) {
|
||||
inventory.setInventorySlotContents(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName () {
|
||||
return inventory.getInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName () {
|
||||
return inventory.hasCustomInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit () {
|
||||
return inventory.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer (EntityPlayer player) {
|
||||
return inventory.isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory () {
|
||||
inventory.openInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory () {
|
||||
inventory.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot (int slot, ItemStack stack) {
|
||||
return inventory.isItemValidForSlot(slot, stack);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ 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;
|
||||
@@ -122,4 +122,4 @@ public abstract class TileEntityDrawersBase extends TileEntity
|
||||
}
|
||||
|
||||
public abstract void clientUpdateCount (int slot, int count);
|
||||
}
|
||||
}*/
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.block.tile;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.storage.*;
|
||||
import com.jaquadro.minecraft.storagedrawers.storage.IStorageProvider;
|
||||
|
||||
public class TileEntityDrawersComp extends TileEntityDrawers
|
||||
{
|
||||
public TileEntityDrawersComp () {
|
||||
super(3);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IStorageProvider getStorageProvider () {
|
||||
return new CompStorageProvider();
|
||||
}
|
||||
|
||||
private class CompStorageProvider extends DefaultStorageProvider
|
||||
{
|
||||
public CompStorageProvider () {
|
||||
super(TileEntityDrawersComp.this, TileEntityDrawersComp.this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,453 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.block.tile;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.storage.*;
|
||||
import com.jaquadro.minecraft.storagedrawers.storage.IStorageProvider;
|
||||
|
||||
public class TileEntityDrawersStandard extends TileEntityDrawers
|
||||
{
|
||||
public TileEntityDrawersStandard () {
|
||||
super(1);
|
||||
}
|
||||
|
||||
public void setDrawerCount (int count) {
|
||||
initWithDrawerCount(count);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IStorageProvider getStorageProvider () {
|
||||
return new DefaultStorageProvider(this, this);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,13 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.client.renderer;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.BlockCompDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.BlockDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersBase;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.ClientProxy;
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.ItemRenderer;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -65,7 +56,7 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler
|
||||
}
|
||||
|
||||
private boolean renderWorldBlock (IBlockAccess world, int x, int y, int z, BlockDrawers block, int modelId, RenderBlocks renderer) {
|
||||
TileEntityDrawersBase tile = block.getTileEntity(world, x, y, z);
|
||||
TileEntityDrawers tile = block.getTileEntity(world, x, y, z);
|
||||
if (tile == null)
|
||||
return false;
|
||||
|
||||
@@ -83,12 +74,12 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler
|
||||
|
||||
renderExterior(block, x, y, z, side, renderer);
|
||||
|
||||
if (tile.getLevel() > 1 && StorageDrawers.config.cache.renderStorageUpgrades) {
|
||||
if (tile.getStorageLevel() > 1 && StorageDrawers.config.cache.renderStorageUpgrades) {
|
||||
for (int i = 0; i < 6; i++)
|
||||
boxRenderer.setExteriorIcon(block.getOverlayIcon(world, x, y, z, i, tile.getLevel()), i);
|
||||
boxRenderer.setExteriorIcon(block.getOverlayIcon(world, x, y, z, i, tile.getStorageLevel()), i);
|
||||
|
||||
boxRenderer.setCutIcon(block.getOverlayIconTrim(tile.getLevel()));
|
||||
boxRenderer.setInteriorIcon(block.getOverlayIconTrim(tile.getLevel()));
|
||||
boxRenderer.setCutIcon(block.getOverlayIconTrim(tile.getStorageLevel()));
|
||||
boxRenderer.setInteriorIcon(block.getOverlayIconTrim(tile.getStorageLevel()));
|
||||
|
||||
renderExterior(block, x, y, z, side, renderer);
|
||||
}
|
||||
@@ -140,7 +131,7 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler
|
||||
if (level <= 0 || side < 2 || side > 5)
|
||||
return;
|
||||
|
||||
TileEntityDrawersBase tile = block.getTileEntity(renderer.blockAccess, x, y, z);
|
||||
TileEntityDrawers tile = block.getTileEntity(renderer.blockAccess, x, y, z);
|
||||
|
||||
int d = block.halfDepth ? 1 : 0;
|
||||
int xi = side - 2;
|
||||
@@ -167,11 +158,12 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler
|
||||
return;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
IDrawer drawer = tile.getDrawer(i);
|
||||
int iconIndex = 0;
|
||||
if (level == 2)
|
||||
iconIndex = (tile.getItemCapacity(i) > 0 && (float)tile.getItemCount(i) / tile.getItemCapacity(i) > .75) ? 1 : iconIndex;
|
||||
iconIndex = (drawer.getMaxCapacity() > 0 && (float)drawer.getStoredItemCount() / drawer.getMaxCapacity() > .75) ? 1 : iconIndex;
|
||||
if (level >= 1)
|
||||
iconIndex = (tile.getItemCapacity(i) > 0 && tile.getItemCount(i) == tile.getItemCapacity(i)) ? 2 : iconIndex;
|
||||
iconIndex = (drawer.getMaxCapacity() > 0 && drawer.getStoredItemCount() == drawer.getMaxCapacity()) ? 2 : iconIndex;
|
||||
|
||||
boxRenderer.setExteriorIcon(block.getIndicatorIcon(iconIndex));
|
||||
boxRenderer.renderExterior(renderer, block, x, y, z, indX[xi][d][i] * unit, indY[i] * unit, indX[zi][d][i] * unit,
|
||||
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.client.renderer;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.BlockDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersBase;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -27,7 +27,6 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -212,7 +211,7 @@ public class TileEntityDrawersRenderer extends TileEntitySpecialRenderer
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt (TileEntity tile, double x, double y, double z, float partialTickTime) {
|
||||
TileEntityDrawersBase tileDrawers = (TileEntityDrawersBase) tile;
|
||||
TileEntityDrawers tileDrawers = (TileEntityDrawers) tile;
|
||||
if (tileDrawers == null)
|
||||
return;
|
||||
|
||||
@@ -247,7 +246,8 @@ public class TileEntityDrawersRenderer extends TileEntitySpecialRenderer
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
|
||||
ItemStack itemStack = tileDrawers.getSingleItemStack(i);
|
||||
IDrawer drawer = tileDrawers.getDrawer(i);
|
||||
ItemStack itemStack = drawer.getStoredItemPrototype();
|
||||
if (itemStack != null) {
|
||||
GL11.glPushMatrix();
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.compat;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.block.BlockCompDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.BlockDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityCompDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersBase;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersComp;
|
||||
import mcp.mobius.waila.api.IWailaConfigHandler;
|
||||
import mcp.mobius.waila.api.IWailaDataAccessor;
|
||||
import mcp.mobius.waila.api.IWailaDataProvider;
|
||||
@@ -37,16 +36,19 @@ public class WailaProvider
|
||||
|
||||
@Override
|
||||
public List<String> getWailaBody (ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
|
||||
TileEntityDrawersBase tile = (TileEntityDrawersBase) accessor.getTileEntity();
|
||||
TileEntityDrawers tile = (TileEntityDrawers) accessor.getTileEntity();
|
||||
|
||||
for (int i = 0; i < tile.getDrawerCount(); i++) {
|
||||
String name = StatCollector.translateToLocal("storageDrawers.waila.empty");
|
||||
ItemStack stack = tile.getSingleItemStack(i);
|
||||
|
||||
IDrawer drawer = tile.getDrawer(i);
|
||||
ItemStack stack = drawer.getStoredItemPrototype();
|
||||
if (stack != null && stack.getItem() != null) {
|
||||
if (tile instanceof TileEntityCompDrawers)
|
||||
name = stack.getDisplayName() + ((i == 0) ? " [" : " [+") + ((TileEntityCompDrawers) tile).getItemRemainderCount(i) + "]";
|
||||
if (tile instanceof TileEntityDrawersComp)
|
||||
// TODO: WAILA remainder counts for comp drawers
|
||||
name = stack.getDisplayName(); // + ((i == 0) ? " [" : " [+") + ((TileEntityDrawersComp) tile).getItemRemainderCount(i) + "]";
|
||||
else
|
||||
name = stack.getDisplayName() + " [" + tile.getItemCount(i) + "]";
|
||||
name = stack.getDisplayName() + " [" + drawer.getStoredItemCount() + "]";
|
||||
}
|
||||
currenttip.add(StatCollector.translateToLocalFormatted("storageDrawers.waila.drawer", i + 1, name));
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.core;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityCompDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersComp;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersStandard;
|
||||
import com.jaquadro.minecraft.storagedrawers.client.renderer.DrawersRenderer;
|
||||
import com.jaquadro.minecraft.storagedrawers.client.renderer.TileEntityDrawersRenderer;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
@@ -15,7 +15,7 @@ public class ClientProxy extends CommonProxy
|
||||
|
||||
RenderingRegistry.registerBlockHandler(drawersRenderID, new DrawersRenderer());
|
||||
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDrawers.class, new TileEntityDrawersRenderer());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCompDrawers.class, new TileEntityDrawersRenderer());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDrawersStandard.class, new TileEntityDrawersRenderer());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDrawersComp.class, new TileEntityDrawersRenderer());
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.core;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersBase;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
@@ -12,8 +11,8 @@ public class ForgeEventHandler
|
||||
public void playerInteracts (PlayerInteractEvent event) {
|
||||
if (event.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK && event.entityPlayer.capabilities.isCreativeMode) {
|
||||
TileEntity tile = event.world.getTileEntity(event.x, event.y, event.z);
|
||||
if (tile instanceof TileEntityDrawersBase) {
|
||||
int dir = ((TileEntityDrawersBase) tile).getDirection();
|
||||
if (tile instanceof TileEntityDrawers) {
|
||||
int dir = ((TileEntityDrawers) tile).getDirection();
|
||||
if (dir == event.face) {
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
|
||||
@@ -3,8 +3,8 @@ package com.jaquadro.minecraft.storagedrawers.core;
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.BlockCompDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.BlockDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityCompDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersComp;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersStandard;
|
||||
import com.jaquadro.minecraft.storagedrawers.config.ConfigManager;
|
||||
import com.jaquadro.minecraft.storagedrawers.item.ItemCompDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.item.ItemDrawers;
|
||||
@@ -31,24 +31,24 @@ public class ModBlocks
|
||||
|
||||
if (config.isBlockEnabled("fulldrawers2")) {
|
||||
GameRegistry.registerBlock(fullDrawers2, ItemDrawers.class, "fullDrawers2");
|
||||
GameRegistry.registerTileEntity(TileEntityDrawers.class, ModBlocks.getQualifiedName(fullDrawers2));
|
||||
GameRegistry.registerTileEntity(TileEntityDrawersStandard.class, ModBlocks.getQualifiedName(fullDrawers2));
|
||||
}
|
||||
if (config.isBlockEnabled("fulldrawers4")) {
|
||||
GameRegistry.registerBlock(fullDrawers4, ItemDrawers.class, "fullDrawers4");
|
||||
GameRegistry.registerTileEntity(TileEntityDrawers.class, ModBlocks.getQualifiedName(fullDrawers4));
|
||||
GameRegistry.registerTileEntity(TileEntityDrawersStandard.class, ModBlocks.getQualifiedName(fullDrawers4));
|
||||
}
|
||||
if (config.isBlockEnabled("halfdrawers2")) {
|
||||
GameRegistry.registerBlock(halfDrawers2, ItemDrawers.class, "halfDrawers2");
|
||||
GameRegistry.registerTileEntity(TileEntityDrawers.class, ModBlocks.getQualifiedName(halfDrawers2));
|
||||
GameRegistry.registerTileEntity(TileEntityDrawersStandard.class, ModBlocks.getQualifiedName(halfDrawers2));
|
||||
}
|
||||
if (config.isBlockEnabled("halfdrawers4")) {
|
||||
GameRegistry.registerBlock(halfDrawers4, ItemDrawers.class, "halfDrawers4");
|
||||
GameRegistry.registerTileEntity(TileEntityDrawers.class, ModBlocks.getQualifiedName(halfDrawers4));
|
||||
GameRegistry.registerTileEntity(TileEntityDrawersStandard.class, ModBlocks.getQualifiedName(halfDrawers4));
|
||||
}
|
||||
|
||||
if (config.isBlockEnabled("compdrawers")) {
|
||||
GameRegistry.registerBlock(compDrawers, ItemCompDrawers.class, "compDrawers");
|
||||
GameRegistry.registerTileEntity(TileEntityCompDrawers.class, ModBlocks.getQualifiedName(compDrawers));
|
||||
GameRegistry.registerTileEntity(TileEntityDrawersComp.class, ModBlocks.getQualifiedName(compDrawers));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-1
@@ -6,7 +6,6 @@ import appeng.api.storage.IExternalStorageHandler;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersBase;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
|
||||
@@ -13,10 +13,18 @@ public abstract class InventoryStack
|
||||
private int outCount;
|
||||
|
||||
public void init () {
|
||||
reset();
|
||||
}
|
||||
|
||||
public void reset () {
|
||||
nativeStack = getNewItemStack();
|
||||
inStack = getNewItemStack();
|
||||
outStack = getNewItemStack();
|
||||
|
||||
nativeCount = 0;
|
||||
inCount = 0;
|
||||
outCount = 0;
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
@@ -57,13 +65,19 @@ public abstract class InventoryStack
|
||||
int itemCount = getItemCount();
|
||||
int remainingLimit = getItemCapacity() - itemCount;
|
||||
|
||||
nativeCount = itemCount;
|
||||
nativeStack.stackSize = nativeCount;
|
||||
if (nativeStack != null) {
|
||||
nativeCount = itemCount;
|
||||
nativeStack.stackSize = nativeCount;
|
||||
}
|
||||
|
||||
inCount = itemStackLimit - Math.min(itemStackLimit, remainingLimit);
|
||||
inStack.stackSize = inCount;
|
||||
if (inStack != null) {
|
||||
inCount = itemStackLimit - Math.min(itemStackLimit, remainingLimit);
|
||||
inStack.stackSize = inCount;
|
||||
}
|
||||
|
||||
outCount = Math.min(itemStackLimit, itemCount);
|
||||
outStack.stackSize = outCount;
|
||||
if (outStack != null) {
|
||||
outCount = Math.min(itemStackLimit, itemCount);
|
||||
outStack.stackSize = outCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.inventory;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.inventory.IInventoryAdapter;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.inventory.SlotType;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.inventory.IDrawerInventory;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class StorageInventory implements IDrawerInventory
|
||||
{
|
||||
private final IDrawerGroup group;
|
||||
private final int[] inventorySlots;
|
||||
|
||||
public StorageInventory (IDrawerGroup drawerGroup) {
|
||||
group = drawerGroup;
|
||||
|
||||
inventorySlots = new int[group.getDrawerCount() * SlotType.values.length];
|
||||
for (int i = 0, n = inventorySlots.length; i < n; i++)
|
||||
inventorySlots[i] = i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDrawerSlot (int inventorySlot) {
|
||||
return inventorySlot % SlotType.values.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlotType getInventorySlotType (int inventorySlot) {
|
||||
return SlotType.values[inventorySlot / SlotType.values.length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventorySlot (int drawerSlot, SlotType type) {
|
||||
return group.getDrawerCount() * type.ordinal() + drawerSlot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide (int side) {
|
||||
// TODO
|
||||
return new int[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem (int slot, ItemStack item, int side) {
|
||||
int lowerThresh = SlotType.INPUT.ordinal() * group.getDrawerCount();
|
||||
int upperThresh = lowerThresh + group.getDrawerCount();
|
||||
if (slot < lowerThresh || slot >= upperThresh)
|
||||
return false;
|
||||
|
||||
IDrawer drawer = group.getDrawer(getDrawerSlot(slot));
|
||||
if (drawer == null)
|
||||
return false;
|
||||
|
||||
return drawer.canItemBeStored(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem (int slot, ItemStack item, int side) {
|
||||
int lowerThresh = SlotType.OUTPUT.ordinal() * group.getDrawerCount();
|
||||
int upperThresh = lowerThresh + group.getDrawerCount();
|
||||
if (slot < lowerThresh || slot >= upperThresh)
|
||||
return false;
|
||||
|
||||
IDrawer drawer = group.getDrawer(getDrawerSlot(slot));
|
||||
if (drawer == null)
|
||||
return false;
|
||||
|
||||
return drawer.canItemBeExtracted(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory () {
|
||||
return inventorySlots.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot (int slot) {
|
||||
if (slot < 0 || slot >= getSizeInventory())
|
||||
return null;
|
||||
|
||||
IDrawer drawer = group.getDrawer(getDrawerSlot(slot));
|
||||
if (drawer == null)
|
||||
return null;
|
||||
|
||||
if (!(drawer instanceof IInventoryAdapter))
|
||||
return null;
|
||||
|
||||
IInventoryAdapter adapter = (IInventoryAdapter)drawer;
|
||||
adapter.syncInventory();
|
||||
|
||||
return adapter.getInventoryStack(getInventorySlotType(slot));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize (int slot, int count) {
|
||||
if (slot < 0 || slot >= getSizeInventory())
|
||||
return null;
|
||||
|
||||
IDrawer drawer = group.getDrawer(getDrawerSlot(slot));
|
||||
if (drawer == null)
|
||||
return null;
|
||||
|
||||
if (!(drawer instanceof IInventoryAdapter))
|
||||
return null;
|
||||
|
||||
IInventoryAdapter adapter = (IInventoryAdapter)drawer;
|
||||
adapter.syncInventory();
|
||||
|
||||
ItemStack stack = drawer.getStoredItemCopy();
|
||||
if (stack.stackSize <= count) {
|
||||
drawer.setStoredItem(null, 0);
|
||||
}
|
||||
else {
|
||||
stack.stackSize = count;
|
||||
drawer.setStoredItemCount(drawer.getStoredItemCount() - count);
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing (int slot) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents (int slot, ItemStack item) {
|
||||
if (slot < 0 || slot >= getSizeInventory())
|
||||
return;
|
||||
|
||||
IDrawer drawer = group.getDrawer(getDrawerSlot(slot));
|
||||
if (drawer == null)
|
||||
return;
|
||||
|
||||
if (!(drawer instanceof IInventoryAdapter))
|
||||
return;
|
||||
|
||||
IInventoryAdapter adapter = (IInventoryAdapter)drawer;
|
||||
adapter.syncInventory();
|
||||
|
||||
int insertCount = (item != null) ? item.stackSize : 0;
|
||||
switch (getInventorySlotType(slot)) {
|
||||
case INPUT:
|
||||
ItemStack inStack = adapter.getInventoryStack(SlotType.INPUT);
|
||||
if (inStack != null)
|
||||
insertCount -= inStack.stackSize;
|
||||
break;
|
||||
case OUTPUT:
|
||||
ItemStack outStack = adapter.getInventoryStack(SlotType.OUTPUT);
|
||||
if (outStack != null)
|
||||
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;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (insertCount != 0) {
|
||||
int newStoredCount = drawer.getStoredItemCount() + insertCount;
|
||||
newStoredCount = Math.max(0, Math.min(newStoredCount, drawer.getMaxCapacity()));
|
||||
|
||||
drawer.setStoredItemCount(newStoredCount);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName () {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName () {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit () {
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty () {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer (EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory () { }
|
||||
|
||||
@Override
|
||||
public void closeInventory () { }
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot (int slot, ItemStack item) {
|
||||
if (slot < 0 || slot >= getSizeInventory())
|
||||
return false;
|
||||
|
||||
IDrawer drawer = group.getDrawer(getDrawerSlot(slot));
|
||||
if (drawer == null)
|
||||
return false;
|
||||
|
||||
// TODO: Is it valid to accept an item if its stack size is larger than available storage?
|
||||
switch (getInventorySlotType(slot)) {
|
||||
case INPUT:
|
||||
return drawer.canItemBeStored(item);
|
||||
case OUTPUT:
|
||||
return drawer.canItemBeExtracted(item);
|
||||
default:
|
||||
return drawer.canItemBeStored(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.item;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersBase;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.config.ConfigManager;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
@@ -25,7 +25,7 @@ public class ItemCompDrawers extends ItemBlock
|
||||
if (!super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata))
|
||||
return false;
|
||||
|
||||
TileEntityDrawersBase tile = (TileEntityDrawersBase) world.getTileEntity(x, y, z);
|
||||
TileEntityDrawers tile = (TileEntityDrawers) world.getTileEntity(x, y, z);
|
||||
if (tile != null) {
|
||||
if (side > 1)
|
||||
tile.setDirection(side);
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.jaquadro.minecraft.storagedrawers.item;
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.BlockDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersBase;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersStandard;
|
||||
import com.jaquadro.minecraft.storagedrawers.config.ConfigManager;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.ModBlocks;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@@ -11,12 +11,10 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockWood;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemMultiTexture;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -31,14 +29,14 @@ public class ItemDrawers extends ItemMultiTexture
|
||||
if (!super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata))
|
||||
return false;
|
||||
|
||||
TileEntityDrawersBase tile = (TileEntityDrawersBase) world.getTileEntity(x, y, z);
|
||||
TileEntityDrawers tile = (TileEntityDrawers) world.getTileEntity(x, y, z);
|
||||
if (tile != null) {
|
||||
if (side > 1)
|
||||
tile.setDirection(side);
|
||||
|
||||
BlockDrawers block = (BlockDrawers) field_150939_a;
|
||||
if (tile instanceof TileEntityDrawers)
|
||||
((TileEntityDrawers)tile).setDrawerCount(block.drawerCount);
|
||||
if (tile instanceof TileEntityDrawersStandard)
|
||||
((TileEntityDrawersStandard)tile).setDrawerCount(block.drawerCount);
|
||||
|
||||
tile.setDrawerCapacity(getCapacityForBlock(block));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.network;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersBase;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
@@ -53,8 +53,8 @@ public class CountUpdateMessage implements IMessage
|
||||
if (ctx.side == Side.CLIENT) {
|
||||
World world = Minecraft.getMinecraft().theWorld;
|
||||
TileEntity tileEntity = world.getTileEntity(message.x, message.y, message.z);
|
||||
if (tileEntity instanceof TileEntityDrawersBase) {
|
||||
((TileEntityDrawersBase) tileEntity).clientUpdateCount(message.slot, message.count);
|
||||
if (tileEntity instanceof TileEntityDrawers) {
|
||||
((TileEntityDrawers) tileEntity).clientUpdateCount(message.slot, message.count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.storage;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup;
|
||||
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.tileentity.TileEntity;
|
||||
|
||||
public class DefaultStorageProvider implements IStorageProvider
|
||||
{
|
||||
TileEntity tile;
|
||||
IDrawerGroup group;
|
||||
|
||||
public DefaultStorageProvider (TileEntity tileEntity, IDrawerGroup drawerGroup) {
|
||||
tile = tileEntity;
|
||||
group = drawerGroup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCountCentrallyManaged () {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotCount (int slot) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int setSlotCount (int slot) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotStackCapacity (int slot) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markAmountDirty (int slot) {
|
||||
int count = group.getDrawer(slot).getStoredItemCount();
|
||||
|
||||
IMessage message = new CountUpdateMessage(tile.xCoord, tile.yCoord, tile.zCoord, slot, count);
|
||||
NetworkRegistry.TargetPoint targetPoint = new NetworkRegistry.TargetPoint(tile.getWorldObj().provider.dimensionId, tile.xCoord, tile.yCoord, tile.zCoord, 500);
|
||||
|
||||
StorageDrawers.network.sendToAllAround(message, targetPoint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty (int slot) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.storage;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.inventory.IInventoryAdapter;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.inventory.SlotType;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
import com.jaquadro.minecraft.storagedrawers.inventory.InventoryStack;
|
||||
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 implements IDrawer, IInventoryAdapter
|
||||
{
|
||||
private static final ItemStack nullStack = new ItemStack((Item)null);
|
||||
|
||||
private IStorageProvider storageProvider;
|
||||
private int slot;
|
||||
|
||||
private ItemStack protoStack;
|
||||
private InventoryStack inventoryStack;
|
||||
|
||||
private int count;
|
||||
private List<ItemStack> oreDictMatches;
|
||||
|
||||
public DrawerData (IStorageProvider provider, int slot) {
|
||||
storageProvider = provider;
|
||||
this.slot = slot;
|
||||
|
||||
inventoryStack = new DrawerInventoryStack();
|
||||
reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStoredItemPrototype () {
|
||||
if (protoStack == nullStack)
|
||||
return null;
|
||||
|
||||
return protoStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStoredItemCopy () {
|
||||
if (protoStack == nullStack)
|
||||
return null;
|
||||
|
||||
ItemStack stack = protoStack.copy();
|
||||
stack.stackSize = count;
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStoredItem (ItemStack itemPrototype, int amount) {
|
||||
if (itemPrototype == null) {
|
||||
reset();
|
||||
storageProvider.markDirty(slot);
|
||||
return;
|
||||
}
|
||||
|
||||
protoStack = itemPrototype.copy();
|
||||
protoStack.stackSize = 1;
|
||||
|
||||
refreshOreDictMatches();
|
||||
setStoredItemCount(amount);
|
||||
inventoryStack.reset();
|
||||
|
||||
storageProvider.markDirty(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStoredItemCount () {
|
||||
if (storageProvider.isCountCentrallyManaged())
|
||||
return storageProvider.getSlotCount(slot);
|
||||
else
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStoredItemCount (int amount) {
|
||||
if (storageProvider.isCountCentrallyManaged())
|
||||
storageProvider.setSlotCount(amount);
|
||||
else
|
||||
count = amount;
|
||||
|
||||
storageProvider.markAmountDirty(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxCapacity () {
|
||||
if (protoStack.getItem() == null)
|
||||
return 0;
|
||||
|
||||
return protoStack.getItem().getItemStackLimit(protoStack) * storageProvider.getSlotStackCapacity(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRemainingCapacity () {
|
||||
if (protoStack.getItem() == null)
|
||||
return 0;
|
||||
|
||||
return getMaxCapacity() - getStoredItemCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStoredItemStackSize () {
|
||||
if (protoStack.getItem() == null)
|
||||
return 0;
|
||||
|
||||
return protoStack.getItem().getItemStackLimit(protoStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canItemBeStored (ItemStack itemPrototype) {
|
||||
if (protoStack == nullStack)
|
||||
return true;
|
||||
|
||||
return areItemsEqual(itemPrototype);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canItemBeExtracted (ItemStack itemPrototype) {
|
||||
if (protoStack == nullStack)
|
||||
return false;
|
||||
|
||||
return areItemsEqual(itemPrototype);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty () {
|
||||
return protoStack == nullStack;
|
||||
}
|
||||
|
||||
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) {
|
||||
reset();
|
||||
|
||||
if (tag.hasKey("Item") && tag.hasKey("Count")) {
|
||||
ItemStack stack = new ItemStack(Item.getItemById(tag.getShort("Item")));
|
||||
stack.setItemDamage(tag.getShort("Meta"));
|
||||
if (tag.hasKey("Tags"))
|
||||
stack.setTagCompound(tag.getCompoundTag("Tags"));
|
||||
|
||||
setStoredItem(stack, tag.getInteger("Count"));
|
||||
}
|
||||
}
|
||||
|
||||
private void reset () {
|
||||
setStoredItemCount(0);
|
||||
protoStack = nullStack;
|
||||
oreDictMatches = null;
|
||||
inventoryStack.reset();
|
||||
}
|
||||
|
||||
public boolean areItemsEqual (ItemStack item) {
|
||||
return areItemsEqual(protoStack, item);
|
||||
}
|
||||
|
||||
private void refreshOreDictMatches () {
|
||||
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 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getInventoryStack (SlotType slotType) {
|
||||
switch (slotType) {
|
||||
case INPUT:
|
||||
return inventoryStack.getInStack();
|
||||
case OUTPUT:
|
||||
return inventoryStack.getOutStack();
|
||||
default:
|
||||
return inventoryStack.getNativeStack();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncInventory () {
|
||||
inventoryStack.markDirty();
|
||||
}
|
||||
|
||||
class DrawerInventoryStack extends InventoryStack
|
||||
{
|
||||
public DrawerInventoryStack () {
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack getNewItemStack () {
|
||||
return getStoredItemCopy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getItemStackSize () {
|
||||
return getStoredItemStackSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getItemCount () {
|
||||
return getStoredItemCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getItemCapacity () {
|
||||
return getMaxCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyDiff (int diff) {
|
||||
if (diff != 0)
|
||||
setStoredItemCount(getStoredItemCount() + diff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.storage;
|
||||
|
||||
public interface IStorageProvider
|
||||
{
|
||||
public boolean isCountCentrallyManaged ();
|
||||
|
||||
public int getSlotCount (int slot);
|
||||
|
||||
public int setSlotCount (int slot);
|
||||
|
||||
public int getSlotStackCapacity (int slot);
|
||||
|
||||
public void markAmountDirty (int slot);
|
||||
|
||||
public void markDirty (int slot);
|
||||
}
|
||||
Reference in new issue
Block a user