2x2 drawers implemented

This commit is contained in:
Justin Aquadro committed 2014-08-24 02:27:05 -04:00
1 parent 2acefc3e4d
commit 7841bdabaa
4 files changed
+79 -25

No files matched your search

@@ -146,8 +146,7 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
if (tileDrawers.getDirection() != side)
return false;
int slot = (hitY > .5) ? 0 : 1;
int slot = getDrawerSlot(side, hitX, hitY, hitZ);
int countAdded = tileDrawers.putItemsIntoSlot(slot, item, 1);
//if (countAdded > 0)
@@ -156,6 +155,35 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
return countAdded > 0;
}
private int getDrawerSlot (int side, float hitX, float hitY, float hitZ) {
if (drawerCount == 2)
return hitTop(hitY) ? 0 : 1;
if (hitLeft(side, hitX, hitZ))
return hitTop(hitY) ? 0 : 1;
else
return hitTop(hitY) ? 2 : 3;
}
private boolean hitTop (float hitY) {
return hitY > .5;
}
private boolean hitLeft (int side, float hitX, float hitZ) {
switch (side) {
case 2:
return hitX > .5;
case 3:
return hitX < .5;
case 4:
return hitZ > .5;
case 5:
return hitZ < .5;
default:
return true;
}
}
@Override
public void onBlockClicked (World world, int x, int y, int z, EntityPlayer player) {
if (world.isRemote) {
@@ -13,8 +13,6 @@ import net.minecraftforge.common.util.Constants;
public class TileEntityDrawers extends TileEntity
{
private class DrawerData {
public int stackSlots;
public Item item;
public int meta;
public int count;
@@ -25,8 +23,6 @@ public class TileEntityDrawers extends TileEntity
}
public void writeToNBT (NBTTagCompound tag) {
tag.setInteger("StackSlots", stackSlots);
if (item != null) {
tag.setShort("Item", (short) Item.getIdFromItem(item));
tag.setShort("Meta", (short) meta);
@@ -38,8 +34,6 @@ public class TileEntityDrawers extends TileEntity
}
public void readFromNBT (NBTTagCompound tag) {
stackSlots = tag.getInteger("StackSlots");
if (tag.hasKey("Item")) {
item = Item.getItemById(tag.getShort("Item"));
meta = tag.getShort("Meta");
@@ -61,7 +55,7 @@ public class TileEntityDrawers extends TileEntity
if (item == null)
return 0;
return item.getItemStackLimit(null) * stackSlots;
return item.getItemStackLimit(null) * stackCapacity();
}
public int remainingCapacity () {
@@ -70,17 +64,21 @@ public class TileEntityDrawers extends TileEntity
return maxCapacity() - count;
}
public int stackCapacity () {
return drawerCount * drawerCapacity;
}
}
private int direction;
private int drawerCount = 2;
private int drawerCapacity = 1;
private int level = 1;
private DrawerData[] data;
public TileEntityDrawers () {
data = new DrawerData[2];
for (int i = 0; i < data.length; i++) {
data[i] = new DrawerData();
data[i].stackSlots = 1;
}
setDrawerCount(2);
}
public int getDirection () {
@@ -91,6 +89,18 @@ public class TileEntityDrawers extends TileEntity
this.direction = direction % 6;
}
public void setDrawerCount (int count) {
drawerCount = count;
data = new DrawerData[drawerCount];
for (int i = 0; i < data.length; i++)
data[i] = new DrawerData();
}
public void setDrawerCapacity (int stackCount) {
drawerCapacity = stackCount;
}
public int getSlotCount () {
return data.length;
}
@@ -129,8 +139,6 @@ public class TileEntityDrawers extends TileEntity
if (data[slot].count == 0)
data[slot].reset();
//invalidate();
return stack;
}
@@ -155,8 +163,6 @@ public class TileEntityDrawers extends TileEntity
data[slot].count += countAdded;
stack.stackSize -= countAdded;
//invalidate();
return countAdded;
}
@@ -165,8 +171,11 @@ public class TileEntityDrawers extends TileEntity
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++) {
@@ -181,6 +190,8 @@ public class TileEntityDrawers extends TileEntity
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++) {
@@ -51,16 +51,19 @@ public class TileEntityDrawersRenderer extends TileEntitySpecialRenderer
GL11.glEnable(GL11.GL_LIGHTING);
int drawerCount = 2;
double depth = 1;
double unit = .0625;
Block block = tile.getWorldObj().getBlock(tile.xCoord, tile.yCoord, tile.zCoord);
if (block instanceof BlockDrawers)
if (block instanceof BlockDrawers) {
depth = ((BlockDrawers) block).halfDepth ? .5 : 1;
drawerCount = ((BlockDrawers) block).drawerCount;
}
itemRenderer.setRenderManager(RenderManager.instance);
for (int i = 0; i < 2; i++) {
for (int i = 0; i < drawerCount; i++) {
ItemStack itemStack = tileDrawers.getSingleItemStack(i);
if (itemStack != null) {
GL11.glPushMatrix();
@@ -70,7 +73,8 @@ public class TileEntityDrawersRenderer extends TileEntitySpecialRenderer
&& RenderBlocks.renderItemIn3d(Block.getBlockFromItem(itemStack.getItem()).getRenderType());
double xunit = itemOffset2X[i];
double xunit = (drawerCount == 2) ? itemOffset2X[i] : itemOffset4X[i];
double yunit = (drawerCount == 2) ? itemOffset2Y[i] : itemOffset4Y[i];
double zunit = blockType ? 2 * unit : unit;
double xc = 0, zc = 0;
@@ -98,11 +102,11 @@ public class TileEntityDrawersRenderer extends TileEntitySpecialRenderer
}
if (blockType) {
GL11.glTranslated(xc, unit * (itemOffset2Y[i] + 1.25), zc);
GL11.glTranslated(xc, unit * (yunit + 1.25), zc);
GL11.glScaled(1, 1, 1);
GL11.glRotatef(r - 90.0F, 0.0F, 1.0F, 0.0F);
} else {
GL11.glTranslated(xc, unit * itemOffset2Y[i], zc);
GL11.glTranslated(xc, unit * yunit, zc);
GL11.glScaled(.6, .6, .6);
GL11.glRotatef(r, 0.0F, 1.0F, 0.0F);
}
@@ -1,5 +1,6 @@
package com.jaquadro.minecraft.storagedrawers.item;
import com.jaquadro.minecraft.storagedrawers.block.BlockDrawers;
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
import net.minecraft.block.Block;
import net.minecraft.block.BlockWood;
@@ -21,8 +22,18 @@ public class ItemDrawers extends ItemMultiTexture
return false;
TileEntityDrawers tile = (TileEntityDrawers) world.getTileEntity(x, y, z);
if (tile != null && side > 1)
tile.setDirection(ForgeDirection.OPPOSITES[side]);
if (tile != null) {
if (side > 1)
tile.setDirection(ForgeDirection.OPPOSITES[side]);
BlockDrawers block = (BlockDrawers) field_150939_a;
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);
}
return true;
}