mirror of
https://github.com/GTNewHorizons/StorageDrawers.git
synced 2026-11-21 12:42:24 +00:00
Mostly working compression drawers implementation
This commit is contained in:
1 parent
78f71cc79c
commit
8b9c01536c
17 files changed
+811
-64
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 596 B |
Binary file not shown.
|
After Width: | Height: | Size: 593 B |
Binary file not shown.
|
After Width: | Height: | Size: 561 B |
Binary file not shown.
|
Before Width: | Height: | Size: 354 B After Width: | Height: | Size: 354 B |
@@ -0,0 +1,90 @@
|
||||
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.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 cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.BlockWood;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BlockCompDrawers extends BlockDrawers
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon[][] iconFront;
|
||||
|
||||
public BlockCompDrawers (String blockName) {
|
||||
super(blockName, 3, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDrawerSlot (int side, float hitX, float hitY, float hitZ) {
|
||||
if (hitTop(hitY))
|
||||
return 0;
|
||||
|
||||
if (hitLeft(side, hitX, hitZ))
|
||||
return 1;
|
||||
else
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntityDrawersBase createNewTileEntity (World world, int meta) {
|
||||
return new TileEntityCompDrawers();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIcon (int side, int meta) {
|
||||
if (side == 4) {
|
||||
meta %= BlockWood.field_150096_a.length;
|
||||
return iconFront[0][meta];
|
||||
}
|
||||
|
||||
return super.getIcon(side, meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon (IBlockAccess blockAccess, int x, int y, int z, int side) {
|
||||
TileEntityDrawersBase tile = getTileEntity(blockAccess, x, y, z);
|
||||
if (tile == null || side == tile.getDirection()) {
|
||||
int meta = blockAccess.getBlockMetadata(x, y, z) % BlockWood.field_150096_a.length;
|
||||
|
||||
if (tile == null)
|
||||
return iconFront[0][meta];
|
||||
else if (tile.getItemStackSize(2) > 0)
|
||||
return iconFront[2][meta];
|
||||
else if (tile.getItemStackSize(1) > 0)
|
||||
return iconFront[1][meta];
|
||||
else
|
||||
return iconFront[0][meta];
|
||||
}
|
||||
|
||||
return super.getIcon(blockAccess, x, y, z, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBlockIcons (IIconRegister register) {
|
||||
super.registerBlockIcons(register);
|
||||
String[] subtex = BlockWood.field_150096_a;
|
||||
|
||||
iconFront = new IIcon[3][subtex.length];
|
||||
|
||||
for (int i = 0; i < subtex.length; i++) {
|
||||
iconFront[0][i] = register.registerIcon(StorageDrawers.MOD_ID + ":drawers_" + subtex[i] + "_comp_0");
|
||||
iconFront[1][i] = register.registerIcon(StorageDrawers.MOD_ID + ":drawers_" + subtex[i] + "_comp_1");
|
||||
iconFront[2][i] = register.registerIcon(StorageDrawers.MOD_ID + ":drawers_" + subtex[i] + "_comp_2");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.jaquadro.minecraft.storagedrawers.block;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersBase;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.ModCreativeTabs;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.ModItems;
|
||||
import com.jaquadro.minecraft.storagedrawers.network.BlockClickMessage;
|
||||
@@ -87,7 +88,7 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
|
||||
@Override
|
||||
public void setBlockBoundsBasedOnState (IBlockAccess blockAccess, int x, int y, int z) {
|
||||
TileEntityDrawers tile = getTileEntity(blockAccess, x, y, z);
|
||||
TileEntityDrawersBase tile = getTileEntity(blockAccess, x, y, z);
|
||||
if (tile == null) {
|
||||
setBlockBounds(0, 0, 0, 1, 1, 1);
|
||||
return;
|
||||
@@ -126,7 +127,7 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy (World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemStack) {
|
||||
TileEntityDrawers tile = getTileEntitySafe(world, x, y, z);
|
||||
TileEntityDrawersBase tile = getTileEntitySafe(world, x, y, z);
|
||||
if (tile.getDirection() > 1)
|
||||
return;
|
||||
|
||||
@@ -154,7 +155,7 @@ 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) {
|
||||
TileEntityDrawers tileDrawers = getTileEntitySafe(world, x, y, z);
|
||||
TileEntityDrawersBase tileDrawers = getTileEntitySafe(world, x, y, z);
|
||||
ItemStack item = player.inventory.getCurrentItem();
|
||||
|
||||
if (item != null && item.getItem() != null) {
|
||||
@@ -183,7 +184,7 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
return true;
|
||||
}
|
||||
|
||||
private int getDrawerSlot (int side, float hitX, float hitY, float hitZ) {
|
||||
protected int getDrawerSlot (int side, float hitX, float hitY, float hitZ) {
|
||||
if (drawerCount == 2)
|
||||
return hitTop(hitY) ? 0 : 1;
|
||||
|
||||
@@ -193,11 +194,11 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
return hitTop(hitY) ? 2 : 3;
|
||||
}
|
||||
|
||||
private boolean hitTop (float hitY) {
|
||||
protected boolean hitTop (float hitY) {
|
||||
return hitY > .5;
|
||||
}
|
||||
|
||||
private boolean hitLeft (int side, float hitX, float hitZ) {
|
||||
protected boolean hitLeft (int side, float hitX, float hitZ) {
|
||||
switch (side) {
|
||||
case 2:
|
||||
return hitX > .5;
|
||||
@@ -226,7 +227,7 @@ 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) {
|
||||
TileEntityDrawers tileDrawers = getTileEntitySafe(world, x, y, z);
|
||||
TileEntityDrawersBase tileDrawers = getTileEntitySafe(world, x, y, z);
|
||||
if (tileDrawers.getDirection() != side)
|
||||
return;
|
||||
|
||||
@@ -234,7 +235,7 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
|
||||
ItemStack item = null;
|
||||
if (player.isSneaking())
|
||||
item = tileDrawers.takeItemsFromSlot(slot, tileDrawers.getStackSize(slot));
|
||||
item = tileDrawers.takeItemsFromSlot(slot, tileDrawers.getItemStackSize(slot));
|
||||
else
|
||||
item = tileDrawers.takeItemsFromSlot(slot, 1);
|
||||
|
||||
@@ -252,7 +253,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) {
|
||||
TileEntityDrawers tile = getTileEntity(world, x, y, z);
|
||||
TileEntityDrawersBase tile = getTileEntity(world, x, y, z);
|
||||
MovingObjectPosition posn = Minecraft.getMinecraft().objectMouseOver;
|
||||
|
||||
if (tile.getDirection() == posn.sideHit) {
|
||||
@@ -266,14 +267,14 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
|
||||
@Override
|
||||
public void breakBlock (World world, int x, int y, int z, Block block, int meta) {
|
||||
TileEntityDrawers tile = getTileEntity(world, x, y, z);
|
||||
TileEntityDrawersBase tile = getTileEntity(world, x, y, z);
|
||||
if (tile.getLevel() > 1)
|
||||
dropBlockAsItem(world, x, y, z, new ItemStack(ModItems.upgrade, 1, tile.getLevel()));
|
||||
|
||||
if (tile != null) {
|
||||
for (int i = 0; i < tile.getDrawerCount(); i++) {
|
||||
while (tile.getItemCount(i) > 0) {
|
||||
ItemStack stack = tile.takeItemsFromSlot(i, tile.getStackSize(i));
|
||||
ItemStack stack = tile.takeItemsFromSlot(i, tile.getItemStackSize(i));
|
||||
if (stack == null || stack.stackSize == 0)
|
||||
break;
|
||||
|
||||
@@ -319,19 +320,19 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntityDrawers createNewTileEntity (World world, int meta) {
|
||||
public TileEntityDrawersBase createNewTileEntity (World world, int meta) {
|
||||
return new TileEntityDrawers();
|
||||
}
|
||||
|
||||
public TileEntityDrawers getTileEntity (IBlockAccess blockAccess, int x, int y, int z) {
|
||||
public TileEntityDrawersBase getTileEntity (IBlockAccess blockAccess, int x, int y, int z) {
|
||||
TileEntity tile = blockAccess.getTileEntity(x, y, z);
|
||||
return (tile instanceof TileEntityDrawers) ? (TileEntityDrawers) tile : null;
|
||||
return (tile instanceof TileEntityDrawersBase) ? (TileEntityDrawersBase) tile : null;
|
||||
}
|
||||
|
||||
public TileEntityDrawers getTileEntitySafe (World world, int x, int y, int z) {
|
||||
TileEntityDrawers tile = getTileEntity(world, x, y, z);
|
||||
public TileEntityDrawersBase getTileEntitySafe (World world, int x, int y, int z) {
|
||||
TileEntityDrawersBase tile = getTileEntity(world, x, y, z);
|
||||
if (tile == null) {
|
||||
tile = createNewTileEntity(world, world.getBlockMetadata(x, y, z));
|
||||
tile = (TileEntityDrawersBase)createNewTileEntity(world, world.getBlockMetadata(x, y, z));
|
||||
world.setTileEntity(x, y, z, tile);
|
||||
}
|
||||
|
||||
@@ -342,8 +343,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 TileEntityDrawers) {
|
||||
if (((TileEntityDrawers) tile).getDirection() == target.sideHit)
|
||||
if (tile instanceof TileEntityDrawersBase) {
|
||||
if (((TileEntityDrawersBase) tile).getDirection() == target.sideHit)
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -403,7 +404,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;
|
||||
|
||||
TileEntityDrawers tile = getTileEntity(blockAccess, x, y, z);
|
||||
TileEntityDrawersBase tile = getTileEntity(blockAccess, x, y, z);
|
||||
if (tile == null || side == tile.getDirection()) {
|
||||
if (drawerCount == 2)
|
||||
return (level > 0) ? iconOverlayH[level] : iconFront2[meta];
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.block.tile;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class DrawerData
|
||||
{
|
||||
private int slot;
|
||||
private Item item;
|
||||
public int meta;
|
||||
public int count;
|
||||
public NBTTagCompound attrs;
|
||||
|
||||
private IStorageProvider storageProvider;
|
||||
private ItemStack protoStack;
|
||||
|
||||
public DrawerData (IStorageProvider storageProvider, int slot) {
|
||||
this.storageProvider = storageProvider;
|
||||
this.slot = slot;
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
public Item getItem () {
|
||||
return item;
|
||||
}
|
||||
|
||||
public void setItem (Item item) {
|
||||
this.item = item;
|
||||
protoStack = new ItemStack(item);
|
||||
}
|
||||
|
||||
public void writeToNBT (NBTTagCompound tag) {
|
||||
if (item != null) {
|
||||
tag.setShort("Item", (short) Item.getIdFromItem(item));
|
||||
tag.setShort("Meta", (short) meta);
|
||||
tag.setInteger("Count", count);
|
||||
|
||||
if (attrs != null)
|
||||
tag.setTag("Tags", attrs);
|
||||
}
|
||||
}
|
||||
|
||||
public void readFromNBT (NBTTagCompound tag) {
|
||||
if (tag.hasKey("Item")) {
|
||||
item = Item.getItemById(tag.getShort("Item"));
|
||||
meta = tag.getShort("Meta");
|
||||
count = tag.getInteger("Count");
|
||||
|
||||
if (tag.hasKey("Tags"))
|
||||
attrs = tag.getCompoundTag("Tags");
|
||||
|
||||
protoStack = new ItemStack(item);
|
||||
}
|
||||
}
|
||||
|
||||
public void reset () {
|
||||
item = null;
|
||||
meta = 0;
|
||||
count = 0;
|
||||
attrs = null;
|
||||
}
|
||||
|
||||
public int stackCapacity () {
|
||||
return storageProvider.getSlotCapacity(slot);
|
||||
}
|
||||
|
||||
public int itemStackMaxSize () {
|
||||
if (item == null)
|
||||
return 0;
|
||||
|
||||
return item.getItemStackLimit(protoStack);
|
||||
}
|
||||
|
||||
public int maxCapacity () {
|
||||
if (item == null)
|
||||
return 0;
|
||||
|
||||
protoStack.setItemDamage(meta);
|
||||
protoStack.setTagCompound(attrs);
|
||||
|
||||
return item.getItemStackLimit(protoStack) * stackCapacity();
|
||||
}
|
||||
|
||||
public int remainingCapacity () {
|
||||
if (item == null)
|
||||
return 0;
|
||||
|
||||
return maxCapacity() - count;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.block.tile;
|
||||
|
||||
public interface IStorageProvider
|
||||
{
|
||||
public int getSlotCapacity (int slot);
|
||||
}
|
||||
@@ -0,0 +1,450 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.block.tile;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
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.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
public class TileEntityCompDrawers extends TileEntityDrawersBase implements IStorageProvider
|
||||
{
|
||||
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; i < data.length; 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 getItemStackSize (int slot) {
|
||||
return data[slot].itemStackMaxSize();
|
||||
}
|
||||
|
||||
public ItemStack getSingleItemStack (int slot) {
|
||||
if (!isSlotValid(slot))
|
||||
return null;
|
||||
|
||||
ItemStack stack = new ItemStack(data[slot].getItem(), 1, data[slot].meta);
|
||||
stack.setTagCompound(data[slot].attrs);
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
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 = new ItemStack(data[slot].getItem(), 1, data[slot].meta);
|
||||
stack.stackSize = Math.min(stack.getMaxStackSize(), count);
|
||||
stack.setTagCompound(data[slot].attrs);
|
||||
|
||||
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 (!itemMatchesForSlot(slot, 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; i < player.inventory.getSizeInventory(); 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;
|
||||
}
|
||||
|
||||
@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; i < data.length; i++) {
|
||||
NBTTagCompound slot = slots.getCompoundTagAt(i);
|
||||
data[i] = new DrawerData(this, i);
|
||||
data[i].readFromNBT(slot);
|
||||
}
|
||||
|
||||
for (int i = 0; i < convRate.length; 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 (int i = 0; i < data.length; i++) {
|
||||
NBTTagCompound slot = new NBTTagCompound();
|
||||
data[i].writeToNBT(slot);
|
||||
slots.appendTag(slot);
|
||||
}
|
||||
|
||||
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 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);
|
||||
|
||||
snapshotItems[i].stackSize = 64 - Math.min(64, 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 () {
|
||||
ConfigManager config = StorageDrawers.config;
|
||||
return getDrawerCapacity() * config.getStorageUpgradeMultiplier(getLevel()) * convRate[0] - pooledCount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private boolean isSlotValid (int slot) {
|
||||
return data[slot] != null && data[slot].getItem() != null;
|
||||
}
|
||||
|
||||
private boolean itemMatchesForSlot (int slot, ItemStack stack) {
|
||||
if (!isSlotValid(slot))
|
||||
return false;
|
||||
if (data[slot].getItem() != stack.getItem() || data[slot].meta != stack.getItemDamage())
|
||||
return false;
|
||||
|
||||
if ((data[slot].attrs == null || stack.getTagCompound() == null) && data[slot].attrs != stack.getTagCompound())
|
||||
return false;
|
||||
else if (data[slot].attrs != null && !data[slot].attrs.equals(stack.getTagCompound()))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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.getItem());
|
||||
data[slot].meta = stack.getItemDamage();
|
||||
data[slot].attrs = stack.getTagCompound();
|
||||
|
||||
convRate[slot] = conversion;
|
||||
}
|
||||
|
||||
private ItemStack findHigherTier (ItemStack stack) {
|
||||
CraftingManager cm = CraftingManager.getInstance();
|
||||
|
||||
setupLookup(lookup3, stack);
|
||||
ItemStack match = cm.findMatchingRecipe(lookup3, worldObj);
|
||||
if (match != null)
|
||||
return match;
|
||||
|
||||
setupLookup(lookup2, stack);
|
||||
return cm.findMatchingRecipe(lookup2, worldObj);
|
||||
}
|
||||
|
||||
private ItemStack findLowerTier (ItemStack stack) {
|
||||
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 (output == null || !stack.isItemEqual(recipe.getRecipeOutput()))
|
||||
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) {
|
||||
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.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; i < inv.getSizeInventory(); i++)
|
||||
inv.setInventorySlotContents(i, stack);
|
||||
|
||||
lookupSizeResult = inv.getSizeInventory();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class TileEntityDrawers extends TileEntity implements ISidedInventory
|
||||
public class TileEntityDrawers extends TileEntityDrawersBase implements IStorageProvider, ISidedInventory
|
||||
{
|
||||
private class DrawerData {
|
||||
/*private class DrawerData {
|
||||
private Item item;
|
||||
public int meta;
|
||||
public int count;
|
||||
@@ -100,12 +100,12 @@ public class TileEntityDrawers extends TileEntity implements ISidedInventory
|
||||
ConfigManager config = StorageDrawers.config;
|
||||
return config.getStorageUpgradeMultiplier(level) * drawerCapacity;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
private int direction;
|
||||
//private int direction;
|
||||
private int drawerCount = 2;
|
||||
private int drawerCapacity = 1;
|
||||
private int level = 1;
|
||||
//private int drawerCapacity = 1;
|
||||
//private int level = 1;
|
||||
|
||||
private DrawerData[] data;
|
||||
private ItemStack[] snapshotItems;
|
||||
@@ -120,14 +120,14 @@ public class TileEntityDrawers extends TileEntity implements ISidedInventory
|
||||
setDrawerCount(2);
|
||||
}
|
||||
|
||||
public int getDirection () {
|
||||
/*public int getDirection () {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void setDirection (int direction) {
|
||||
this.direction = direction % 6;
|
||||
autoSides = new int[] { 0, 1, ForgeDirection.OPPOSITES[direction] };
|
||||
}
|
||||
}*/
|
||||
|
||||
public int getDrawerCount () {
|
||||
return drawerCount;
|
||||
@@ -138,13 +138,13 @@ public class TileEntityDrawers extends TileEntity implements ISidedInventory
|
||||
|
||||
data = new DrawerData[drawerCount];
|
||||
for (int i = 0; i < data.length; i++)
|
||||
data[i] = new DrawerData();
|
||||
data[i] = new DrawerData(this, i);
|
||||
|
||||
snapshotItems = new ItemStack[count];
|
||||
snapshotCounts = new int[count];
|
||||
}
|
||||
|
||||
public int getLevel () {
|
||||
/*public int getLevel () {
|
||||
return level;
|
||||
}
|
||||
|
||||
@@ -154,26 +154,14 @@ public class TileEntityDrawers extends TileEntity implements ISidedInventory
|
||||
|
||||
public void setDrawerCapacity (int stackCount) {
|
||||
drawerCapacity = stackCount;
|
||||
}
|
||||
|
||||
public int getSlotCount () {
|
||||
return data.length;
|
||||
}
|
||||
|
||||
public Item getItem (int slot) {
|
||||
return data[slot].item;
|
||||
}
|
||||
|
||||
public int getItemMeta (int slot) {
|
||||
return data[slot].meta;
|
||||
}
|
||||
}*/
|
||||
|
||||
public int getItemCount (int slot) {
|
||||
return data[slot].count;
|
||||
}
|
||||
|
||||
public int getStackSize (int slot) {
|
||||
return data[slot].stackSize();
|
||||
public int getItemStackSize (int slot) {
|
||||
return data[slot].itemStackMaxSize();
|
||||
}
|
||||
|
||||
public ItemStack getSingleItemStack (int slot) {
|
||||
@@ -271,6 +259,12 @@ public class TileEntityDrawers extends TileEntity implements ISidedInventory
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotCapacity (int slot) {
|
||||
ConfigManager config = StorageDrawers.config;
|
||||
return config.getStorageUpgradeMultiplier(getLevel()) * getDrawerCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUpdate () {
|
||||
return false;
|
||||
@@ -280,21 +274,16 @@ public class TileEntityDrawers extends TileEntity implements ISidedInventory
|
||||
public void readFromNBT (NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
|
||||
direction = tag.getByte("Dir");
|
||||
drawerCapacity = tag.getByte("Cap");
|
||||
level = tag.getByte("Lev");
|
||||
|
||||
NBTTagList slots = tag.getTagList("Slots", Constants.NBT.TAG_COMPOUND);
|
||||
drawerCount = slots.tagCount();
|
||||
data = new DrawerData[slots.tagCount()];
|
||||
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
NBTTagCompound slot = slots.getCompoundTagAt(i);
|
||||
data[i] = new DrawerData();
|
||||
data[i] = new DrawerData(this, i);
|
||||
data[i].readFromNBT(slot);
|
||||
}
|
||||
|
||||
autoSides = new int[] { 0, 1, ForgeDirection.OPPOSITES[direction] };
|
||||
snapshotItems = new ItemStack[drawerCount];
|
||||
snapshotCounts = new int[drawerCount];
|
||||
}
|
||||
@@ -303,10 +292,6 @@ public class TileEntityDrawers extends TileEntity implements ISidedInventory
|
||||
public void writeToNBT (NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
|
||||
tag.setByte("Dir", (byte)direction);
|
||||
tag.setByte("Cap", (byte)drawerCapacity);
|
||||
tag.setByte("Lev", (byte)level);
|
||||
|
||||
NBTTagList slots = new NBTTagList();
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
NBTTagCompound slot = new NBTTagCompound();
|
||||
@@ -359,7 +344,7 @@ public class TileEntityDrawers extends TileEntity implements ISidedInventory
|
||||
if (slot >= getSizeInventory())
|
||||
return null;
|
||||
|
||||
ItemStack stack = getItemsFromSlot(slot, getStackSize(slot));
|
||||
ItemStack stack = getItemsFromSlot(slot, getItemStackSize(slot));
|
||||
if (stack != null) {
|
||||
stack.stackSize = 64 - Math.min(64, data[slot].remainingCapacity());
|
||||
snapshotItems[slot] = stack;
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.block.tile;
|
||||
|
||||
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[] autoSides = new int[] { 0, 1 };
|
||||
|
||||
public int getDirection () {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void setDirection (int direction) {
|
||||
this.direction = direction % 6;
|
||||
autoSides = new int[] { 0, 1, ForgeDirection.OPPOSITES[direction] };
|
||||
}
|
||||
|
||||
public int getLevel () {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel (int level) {
|
||||
this.level = MathHelper.clamp_int(level, 1, 6);
|
||||
}
|
||||
|
||||
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 ItemStack getSingleItemStack (int slot);
|
||||
|
||||
@Override
|
||||
public void readFromNBT (NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
|
||||
direction = tag.getByte("Dir");
|
||||
drawerCapacity = tag.getByte("Cap");
|
||||
level = tag.getByte("Lev");
|
||||
|
||||
autoSides = new int[] { 0, 1, ForgeDirection.OPPOSITES[direction] };
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT (NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
|
||||
tag.setByte("Dir", (byte)direction);
|
||||
tag.setByte("Cap", (byte)drawerCapacity);
|
||||
tag.setByte("Lev", (byte)level);
|
||||
}
|
||||
|
||||
@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
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.jaquadro.minecraft.storagedrawers.client.renderer;
|
||||
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.core.ClientProxy;
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -62,7 +63,7 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler
|
||||
}
|
||||
|
||||
private boolean renderWorldBlock (IBlockAccess world, int x, int y, int z, BlockDrawers block, int modelId, RenderBlocks renderer) {
|
||||
TileEntityDrawers tile = block.getTileEntity(world, x, y, z);
|
||||
TileEntityDrawersBase tile = block.getTileEntity(world, x, y, z);
|
||||
if (tile == null)
|
||||
return false;
|
||||
|
||||
|
||||
+20
-3
@@ -3,6 +3,7 @@ package com.jaquadro.minecraft.storagedrawers.client.renderer;
|
||||
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 cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -150,13 +151,16 @@ public class TileEntityDrawersRenderer extends TileEntitySpecialRenderer
|
||||
private float itemOffset4X[] = new float[] { .25f, .25f, .75f, .75f };
|
||||
private float itemOffset4Y[] = new float[] { 10.25f, 2.25f, 10.25f, 2.25f };
|
||||
|
||||
private float itemOffset3X[] = new float[] { .5f, .25f, .75f };
|
||||
private float itemOffset3Y[] = new float[] { 10.25f, 2.25f, 2.25f };
|
||||
|
||||
private RenderBlocks renderBlocks = new RenderBlocks();
|
||||
|
||||
private float brightness;
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt (TileEntity tile, double x, double y, double z, float partialTickTime) {
|
||||
TileEntityDrawers tileDrawers = (TileEntityDrawers) tile;
|
||||
TileEntityDrawersBase tileDrawers = (TileEntityDrawersBase) tile;
|
||||
if (tileDrawers == null)
|
||||
return;
|
||||
|
||||
@@ -197,9 +201,22 @@ public class TileEntityDrawersRenderer extends TileEntitySpecialRenderer
|
||||
&& itemStack.getItem() instanceof ItemBlock
|
||||
&& RenderBlocks.renderItemIn3d(Block.getBlockFromItem(itemStack.getItem()).getRenderType());
|
||||
|
||||
float xunit, yunit;
|
||||
if (drawerCount == 2) {
|
||||
xunit = itemOffset2X[i];
|
||||
yunit = itemOffset2Y[i];
|
||||
}
|
||||
else if (drawerCount == 3) {
|
||||
xunit = itemOffset3X[i];
|
||||
yunit = itemOffset3Y[i];
|
||||
}
|
||||
else {
|
||||
xunit = itemOffset4X[i];
|
||||
yunit = itemOffset4Y[i];
|
||||
}
|
||||
|
||||
float xunit = (drawerCount == 2) ? itemOffset2X[i] : itemOffset4X[i];
|
||||
float yunit = (drawerCount == 2) ? itemOffset2Y[i] : itemOffset4Y[i];
|
||||
//float xunit = (drawerCount == 2) ? itemOffset2X[i] : itemOffset4X[i];
|
||||
//float yunit = (drawerCount == 2) ? itemOffset2Y[i] : itemOffset4Y[i];
|
||||
float zunit = blockType ? 1.95f * unit : unit;
|
||||
|
||||
float xc = 0, zc = 0;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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.client.renderer.DrawersRenderer;
|
||||
import com.jaquadro.minecraft.storagedrawers.client.renderer.TileEntityDrawersRenderer;
|
||||
@@ -15,5 +16,6 @@ public class ClientProxy extends CommonProxy
|
||||
RenderingRegistry.registerBlockHandler(drawersRenderID, new DrawersRenderer());
|
||||
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDrawers.class, new TileEntityDrawersRenderer());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCompDrawers.class, new TileEntityDrawersRenderer());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
@@ -11,8 +12,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 TileEntityDrawers) {
|
||||
int dir = ((TileEntityDrawers) tile).getDirection();
|
||||
if (tile instanceof TileEntityDrawersBase) {
|
||||
int dir = ((TileEntityDrawersBase) tile).getDirection();
|
||||
if (dir == event.face) {
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
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.config.ConfigManager;
|
||||
import com.jaquadro.minecraft.storagedrawers.item.ItemDrawers;
|
||||
@@ -15,12 +17,14 @@ public class ModBlocks
|
||||
public static BlockDrawers fullDrawers4;
|
||||
public static BlockDrawers halfDrawers2;
|
||||
public static BlockDrawers halfDrawers4;
|
||||
public static BlockCompDrawers compDrawers;
|
||||
|
||||
public void init () {
|
||||
fullDrawers2 = new BlockDrawers("fullDrawers2", 2, false);
|
||||
fullDrawers4 = new BlockDrawers("fullDrawers4", 4, false);
|
||||
halfDrawers2 = new BlockDrawers("halfDrawers2", 2, true);
|
||||
halfDrawers4 = new BlockDrawers("halfDrawers4", 4, true);
|
||||
compDrawers = new BlockCompDrawers("compDrawers");
|
||||
|
||||
ConfigManager config = StorageDrawers.config;
|
||||
|
||||
@@ -40,6 +44,9 @@ public class ModBlocks
|
||||
GameRegistry.registerBlock(halfDrawers4, ItemDrawers.class, "halfDrawers4");
|
||||
GameRegistry.registerTileEntity(TileEntityDrawers.class, ModBlocks.getQualifiedName(halfDrawers4));
|
||||
}
|
||||
|
||||
GameRegistry.registerBlock(compDrawers, ItemDrawers.class, "compDrawers");
|
||||
GameRegistry.registerTileEntity(TileEntityCompDrawers.class, ModBlocks.getQualifiedName(compDrawers));
|
||||
}
|
||||
|
||||
public static String getQualifiedName (Block block) {
|
||||
|
||||
@@ -3,6 +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.config.ConfigManager;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.ModBlocks;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@@ -30,18 +31,21 @@ public class ItemDrawers extends ItemMultiTexture
|
||||
if (!super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata))
|
||||
return false;
|
||||
|
||||
TileEntityDrawers tile = (TileEntityDrawers) world.getTileEntity(x, y, z);
|
||||
TileEntityDrawersBase tile = (TileEntityDrawersBase) world.getTileEntity(x, y, z);
|
||||
if (tile != null) {
|
||||
if (side > 1)
|
||||
tile.setDirection(side);
|
||||
|
||||
BlockDrawers block = (BlockDrawers) field_150939_a;
|
||||
tile.setDrawerCount(block.drawerCount);
|
||||
if (tile instanceof TileEntityDrawers)
|
||||
((TileEntityDrawers)tile).setDrawerCount(block.drawerCount);
|
||||
|
||||
if (block.drawerCount == 2)
|
||||
tile.setDrawerCapacity(block.halfDepth ? 4 : 8);
|
||||
else if (block.drawerCount == 4)
|
||||
tile.setDrawerCapacity(block.halfDepth ? 2 : 4);
|
||||
else if (block.drawerCount == 3)
|
||||
tile.setDrawerCapacity(8);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user