mirror of
https://github.com/GTNewHorizons/StorageDrawers.git
synced 2026-11-21 20:52:27 +00:00
Full and half-depth drawers rendering correctly
This commit is contained in:
1 parent
b164248b68
commit
2acefc3e4d
10 files changed
+311
-61
No files matched your search
Binary file not shown.
|
Before Width: | Height: | Size: 473 B After Width: | Height: | Size: 472 B |
@@ -1,6 +1,7 @@
|
||||
package com.jaquadro.minecraft.storagedrawers;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.core.CommonProxy;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.ForgeEventHandler;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.ModBlocks;
|
||||
import com.jaquadro.minecraft.storagedrawers.network.BlockClickMessage;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
@@ -11,6 +12,7 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
@Mod(modid = StorageDrawers.MOD_ID, name = StorageDrawers.MOD_NAME, version = StorageDrawers.MOD_VERSION)
|
||||
public class StorageDrawers
|
||||
@@ -41,6 +43,8 @@ public class StorageDrawers
|
||||
@Mod.EventHandler
|
||||
public void init (FMLInitializationEvent event) {
|
||||
proxy.registerRenderers();
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new ForgeEventHandler());
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
|
||||
@@ -12,16 +12,27 @@ import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BlockDrawers extends BlockContainer implements IExtendedBlockClickHandler
|
||||
{
|
||||
public final boolean halfDepth;
|
||||
public final int drawerCount;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon iconSide;
|
||||
|
||||
@@ -31,21 +42,18 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon iconFront4;
|
||||
|
||||
public BlockDrawers (String blockName) {
|
||||
public BlockDrawers (String blockName, int drawerCount, boolean halfDepth) {
|
||||
super(Material.wood);
|
||||
|
||||
this.drawerCount = drawerCount;
|
||||
this.halfDepth = halfDepth;
|
||||
|
||||
setCreativeTab(CreativeTabs.tabDecorations);
|
||||
setHardness(2.5f);
|
||||
setStepSound(Block.soundTypeWood);
|
||||
setBlockName(blockName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockAdded (World world, int x, int y, int z) {
|
||||
super.onBlockAdded(world, x, y, z);
|
||||
setBlockDirection(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderAsNormalBlock () {
|
||||
return false;
|
||||
@@ -61,24 +69,70 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
return ClientProxy.drawersRenderID;
|
||||
}
|
||||
|
||||
private void setBlockDirection (World world, int x, int y, int z) {
|
||||
if (!world.isRemote) {
|
||||
Block blockZNeg = world.getBlock(x, y, z - 1);
|
||||
Block blockZPos = world.getBlock(x, y, z + 1);
|
||||
Block blockXNeg = world.getBlock(x - 1, y, z);
|
||||
Block blockXPos = world.getBlock(x + 1, y, z);
|
||||
@Override
|
||||
public void setBlockBoundsBasedOnState (IBlockAccess blockAccess, int x, int y, int z) {
|
||||
TileEntityDrawers tile = getTileEntity(blockAccess, x, y, z);
|
||||
if (tile == null) {
|
||||
setBlockBounds(0, 0, 0, 1, 1, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
byte dir = 3;
|
||||
if (blockZNeg.func_149730_j() && !blockZPos.func_149730_j())
|
||||
dir = 3;
|
||||
if (blockZPos.func_149730_j() && !blockZNeg.func_149730_j())
|
||||
dir = 2;
|
||||
if (blockXNeg.func_149730_j() && !blockXPos.func_149730_j())
|
||||
dir = 5;
|
||||
if (blockXPos.func_149730_j() && !blockXNeg.func_149730_j())
|
||||
dir = 4;
|
||||
float depth = halfDepth ? .5f : 1;
|
||||
switch (tile.getDirection()) {
|
||||
case 2:
|
||||
setBlockBounds(0, 0, 1 - depth, 1, 1, 1);
|
||||
break;
|
||||
case 3:
|
||||
setBlockBounds(0, 0, 0, 1, 1, depth);
|
||||
break;
|
||||
case 4:
|
||||
setBlockBounds(1 - depth, 0, 0, 1, 1, 1);
|
||||
break;
|
||||
case 5:
|
||||
setBlockBounds(0, 0, 0, depth, 1, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
world.setBlockMetadataWithNotify(x, y, z, dir, 2);
|
||||
@Override
|
||||
public void setBlockBoundsForItemRender () {
|
||||
if (halfDepth)
|
||||
setBlockBounds(0, 0, 0, 1, 1, .5f);
|
||||
else
|
||||
setBlockBounds(0, 0, 0, 1, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCollisionBoxesToList (World world, int x, int y, int z, AxisAlignedBB aabb, List list, Entity entity) {
|
||||
setBlockBoundsBasedOnState(world, x, y, z);
|
||||
super.addCollisionBoxesToList(world, x, y, z, aabb, list, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy (World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemStack) {
|
||||
TileEntityDrawers tile = getTileEntitySafe(world, x, y, z);
|
||||
if (tile.getDirection() > 1)
|
||||
return;
|
||||
|
||||
int quadrant = MathHelper.floor_double((entity.rotationYaw * 4f / 360f) + .5) & 3;
|
||||
switch (quadrant) {
|
||||
case 0:
|
||||
tile.setDirection(2);
|
||||
break;
|
||||
case 1:
|
||||
tile.setDirection(5);
|
||||
break;
|
||||
case 2:
|
||||
tile.setDirection(3);
|
||||
break;
|
||||
case 3:
|
||||
tile.setDirection(4);
|
||||
break;
|
||||
}
|
||||
|
||||
if (world.isRemote) {
|
||||
tile.invalidate();
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,9 +143,15 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
return false;
|
||||
|
||||
TileEntityDrawers tileDrawers = getTileEntitySafe(world, x, y, z);
|
||||
if (tileDrawers.getDirection() != side)
|
||||
return false;
|
||||
|
||||
int slot = (hitY > .5) ? 0 : 1;
|
||||
|
||||
int countAdded = tileDrawers.putItemsIntoSlot(slot, item);
|
||||
int countAdded = tileDrawers.putItemsIntoSlot(slot, item, 1);
|
||||
|
||||
//if (countAdded > 0)
|
||||
// world.markBlockForUpdate(x, y, z);
|
||||
|
||||
return countAdded > 0;
|
||||
}
|
||||
@@ -110,14 +170,34 @@ 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) {
|
||||
x += y;
|
||||
TileEntityDrawers tileDrawers = getTileEntitySafe(world, x, y, z);
|
||||
if (tileDrawers.getDirection() != side)
|
||||
return;
|
||||
|
||||
int slot = (hitY > .5) ? 0 : 1;
|
||||
|
||||
ItemStack item = tileDrawers.takeItemsFromSlot(slot, 1);
|
||||
if (item != null && item.stackSize > 0) {
|
||||
dropItemStack(world, x, y, z, player, item);
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
private void dropItemStack (World world, int x, int y, int z, EntityPlayer player, ItemStack stack) {
|
||||
EntityItem entity = new EntityItem(world, player.posX, player.posY, player.posZ, stack);
|
||||
world.spawnEntityInWorld(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removedByPlayer (World world, EntityPlayer player, int x, int y, int z) {
|
||||
if (player.capabilities.isCreativeMode && !player.isSneaking()) {
|
||||
onBlockClicked(world, x, y, z, player);
|
||||
return false;
|
||||
if (world.isRemote && player.capabilities.isCreativeMode && !player.isSneaking()) {
|
||||
TileEntityDrawers tile = getTileEntity(world, x, y, z);
|
||||
MovingObjectPosition posn = Minecraft.getMinecraft().objectMouseOver;
|
||||
|
||||
if (tile.getDirection() == posn.sideHit) {
|
||||
onBlockClicked(world, x, y, z, player);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return super.removedByPlayer(world, player, x, y, z);
|
||||
@@ -145,10 +225,16 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
|
||||
@Override
|
||||
public IIcon getIcon (int side, int meta) {
|
||||
if (side == meta)
|
||||
return iconFront2;
|
||||
else
|
||||
return iconSide;
|
||||
return drawerCount == 2 ? iconFront2 : iconFront4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon (IBlockAccess blockAccess, int x, int y, int z, int side) {
|
||||
TileEntityDrawers tile = getTileEntity(blockAccess, x, y, z);
|
||||
if (tile == null || side == tile.getDirection())
|
||||
return drawerCount == 2 ? iconFront2 : iconFront4;
|
||||
|
||||
return iconSide;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -72,6 +72,7 @@ public class TileEntityDrawers extends TileEntity
|
||||
}
|
||||
}
|
||||
|
||||
private int direction;
|
||||
private DrawerData[] data;
|
||||
|
||||
public TileEntityDrawers () {
|
||||
@@ -82,6 +83,14 @@ public class TileEntityDrawers extends TileEntity
|
||||
}
|
||||
}
|
||||
|
||||
public int getDirection () {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void setDirection (int direction) {
|
||||
this.direction = direction % 6;
|
||||
}
|
||||
|
||||
public int getSlotCount () {
|
||||
return data.length;
|
||||
}
|
||||
@@ -120,10 +129,12 @@ public class TileEntityDrawers extends TileEntity
|
||||
if (data[slot].count == 0)
|
||||
data[slot].reset();
|
||||
|
||||
//invalidate();
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public int putItemsIntoSlot (int slot, ItemStack stack) {
|
||||
public int putItemsIntoSlot (int slot, ItemStack stack, int count) {
|
||||
if (data[slot].item == null) {
|
||||
data[slot].item = stack.getItem();
|
||||
data[slot].meta = stack.getItemDamage();
|
||||
@@ -138,17 +149,23 @@ public class TileEntityDrawers extends TileEntity
|
||||
else if (data[slot].attrs != null && !data[slot].attrs.equals(stack.getTagCompound()))
|
||||
return 0;
|
||||
|
||||
int count = Math.min(data[slot].remainingCapacity(), stack.stackSize);
|
||||
data[slot].count += count;
|
||||
stack.stackSize -= count;
|
||||
int countAdded = Math.min(data[slot].remainingCapacity(), stack.stackSize);
|
||||
countAdded = Math.min(countAdded, count);
|
||||
|
||||
return count;
|
||||
data[slot].count += countAdded;
|
||||
stack.stackSize -= countAdded;
|
||||
|
||||
//invalidate();
|
||||
|
||||
return countAdded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT (NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
|
||||
direction = tag.getByte("Dir");
|
||||
|
||||
NBTTagList slots = tag.getTagList("Slots", Constants.NBT.TAG_COMPOUND);
|
||||
data = new DrawerData[slots.tagCount()];
|
||||
|
||||
@@ -163,6 +180,8 @@ public class TileEntityDrawers extends TileEntity
|
||||
public void writeToNBT (NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
|
||||
tag.setByte("Dir", (byte)direction);
|
||||
|
||||
NBTTagList slots = new NBTTagList();
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
NBTTagCompound slot = new NBTTagCompound();
|
||||
|
||||
@@ -34,7 +34,11 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler
|
||||
}
|
||||
|
||||
private boolean renderWorldBlock (IBlockAccess world, int x, int y, int z, BlockDrawers block, int modelId, RenderBlocks renderer) {
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
TileEntityDrawers tile = block.getTileEntity(world, x, y, z);
|
||||
if (tile == null)
|
||||
return false;
|
||||
|
||||
int side = tile.getDirection();
|
||||
|
||||
double unit = .0625;
|
||||
boxRenderer.setUnit(unit);
|
||||
@@ -42,25 +46,54 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler
|
||||
for (int i = 0; i < 6; i++)
|
||||
boxRenderer.setIcon(block.getIcon(world, x, y, z, i), i);
|
||||
|
||||
boxRenderer.renderExterior(renderer, block, x, y, z, 0, 0, 0, 1, .5, 1, 0, ModularBoxRenderer.sideCut[meta % 6]);
|
||||
boxRenderer.renderExterior(renderer, block, x, y, z, 0, .5, 0, 1, 1, 1, 0, ModularBoxRenderer.sideCut[meta % 6]);
|
||||
double depth = block.halfDepth ? .5 : 1;
|
||||
double xMin = 0, xMax = 0, zMin = 0, zMax = 0;
|
||||
|
||||
double xMin = unit;
|
||||
double xMax = 1 - unit;
|
||||
double zMin = unit;
|
||||
double zMax = 1 - unit;
|
||||
switch (side) {
|
||||
case 2:
|
||||
xMin = 0; xMax = 1;
|
||||
zMin = 1 - depth; zMax = 1;
|
||||
break;
|
||||
case 3:
|
||||
xMin = 0; xMax = 1;
|
||||
zMin = 0; zMax = depth;
|
||||
break;
|
||||
case 4:
|
||||
xMin = 1 - depth; xMax = 1;
|
||||
zMin = 0; zMax = 1;
|
||||
break;
|
||||
case 5:
|
||||
xMin = 0; xMax = depth;
|
||||
zMin = 0; zMax = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (meta) {
|
||||
case 2: zMin = 0; zMax = unit; break;
|
||||
case 3: zMin = 1 - unit; zMax = 1; break;
|
||||
case 4: xMin = 0; xMax = unit; break;
|
||||
case 5: xMin = 1 - unit; xMax = 1; break;
|
||||
boxRenderer.renderExterior(renderer, block, x, y, z, xMin, 0, zMin, xMax, .5, zMax, 0, ModularBoxRenderer.sideCut[side]);
|
||||
boxRenderer.renderExterior(renderer, block, x, y, z, xMin, .5, zMin, xMax, 1, zMax, 0, ModularBoxRenderer.sideCut[side]);
|
||||
|
||||
switch (side) {
|
||||
case 2:
|
||||
xMin = unit; xMax = 1 - unit;
|
||||
zMin = 1 - depth; zMax = 1 - depth + unit;
|
||||
break;
|
||||
case 3:
|
||||
xMin = unit; xMax = 1 - unit;
|
||||
zMin = depth - unit; zMax = depth;
|
||||
break;
|
||||
case 4:
|
||||
xMin = 1 - depth; xMax = 1 - depth + unit;
|
||||
zMin = unit; zMax = 1 - unit;
|
||||
break;
|
||||
case 5:
|
||||
xMin = depth - unit; xMax = depth;
|
||||
zMin = unit; zMax = 1 - unit;
|
||||
break;
|
||||
}
|
||||
|
||||
boxRenderer.setUnit(0);
|
||||
boxRenderer.setInteriorIcon(block.getIcon(world, x, y, z, meta), ForgeDirection.OPPOSITES[meta % 6]);
|
||||
boxRenderer.renderInterior(renderer, block, x, y, z, xMin, unit, zMin, xMax, unit * 7, zMax, 0, ModularBoxRenderer.sideCut[meta % 6]);
|
||||
boxRenderer.renderInterior(renderer, block, x, y, z, xMin, unit * 9, zMin, xMax, 1 - unit, zMax, 0, ModularBoxRenderer.sideCut[meta % 6]);
|
||||
boxRenderer.setInteriorIcon(block.getIcon(world, x, y, z, side), ForgeDirection.OPPOSITES[side]);
|
||||
boxRenderer.renderInterior(renderer, block, x, y, z, xMin, unit, zMin, xMax, unit * 7, zMax, 0, ModularBoxRenderer.sideCut[side]);
|
||||
boxRenderer.renderInterior(renderer, block, x, y, z, xMin, unit * 9, zMin, xMax, 1 - unit, zMax, 0, ModularBoxRenderer.sideCut[side]);
|
||||
|
||||
/*TileEntityDrawers tile = block.getTileEntity(world, x, y, z);
|
||||
if (tile != null) {
|
||||
|
||||
@@ -310,7 +310,7 @@ public class ModularBoxRenderer
|
||||
if ((cutFlags & TEST_ZNEG_XNEG) != 0) {
|
||||
renderer.setRenderBounds(xNeg, yNeg + unit, zNeg, xNeg + unit, yPos - unit, zNeg + unit);
|
||||
if ((cutFlags & CUT_ZNEG) != 0 && (connectedFlags & CONNECT_XNEG) == 0)
|
||||
renderCutFace(FACE_XNEG, renderer, block, x, y, z);
|
||||
renderCutFace(FACE_ZNEG, renderer, block, x, y, z);
|
||||
if ((cutFlags & CUT_XNEG) != 0 && (connectedFlags & CONNECT_ZNEG) == 0)
|
||||
renderCutFace(FACE_XNEG, renderer, block, x, y, z);
|
||||
}
|
||||
|
||||
+47
-4
@@ -1,5 +1,6 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.client.renderer;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.block.BlockDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
@@ -10,6 +11,8 @@ import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.common.util.RotationHelper;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class TileEntityDrawersRenderer extends TileEntitySpecialRenderer
|
||||
@@ -40,14 +43,21 @@ public class TileEntityDrawersRenderer extends TileEntitySpecialRenderer
|
||||
@Override
|
||||
public void renderTileEntityAt (TileEntity tile, double x, double y, double z, float partialTickTime) {
|
||||
TileEntityDrawers tileDrawers = (TileEntityDrawers) tile;
|
||||
if (tileDrawers == null)
|
||||
return;
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(x, y, z);
|
||||
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
|
||||
double depth = 1;
|
||||
double unit = .0625;
|
||||
|
||||
Block block = tile.getWorldObj().getBlock(tile.xCoord, tile.yCoord, tile.zCoord);
|
||||
if (block instanceof BlockDrawers)
|
||||
depth = ((BlockDrawers) block).halfDepth ? .5 : 1;
|
||||
|
||||
itemRenderer.setRenderManager(RenderManager.instance);
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
@@ -55,13 +65,46 @@ public class TileEntityDrawersRenderer extends TileEntitySpecialRenderer
|
||||
if (itemStack != null) {
|
||||
GL11.glPushMatrix();
|
||||
|
||||
if (itemStack.getItemSpriteNumber() == 0 && itemStack.getItem() instanceof ItemBlock && RenderBlocks.renderItemIn3d(Block.getBlockFromItem(itemStack.getItem()).getRenderType())) {
|
||||
GL11.glTranslated(itemOffset2X[i], unit * (itemOffset2Y[i] + 1.25), 1 - unit * 2);
|
||||
boolean blockType = itemStack.getItemSpriteNumber() == 0
|
||||
&& itemStack.getItem() instanceof ItemBlock
|
||||
&& RenderBlocks.renderItemIn3d(Block.getBlockFromItem(itemStack.getItem()).getRenderType());
|
||||
|
||||
|
||||
double xunit = itemOffset2X[i];
|
||||
double zunit = blockType ? 2 * unit : unit;
|
||||
|
||||
double xc = 0, zc = 0;
|
||||
float r = 0;
|
||||
switch (tileDrawers.getDirection()) {
|
||||
case 3:
|
||||
xc = xunit;
|
||||
zc = depth - zunit;
|
||||
r = 180;
|
||||
break;
|
||||
case 2:
|
||||
xc = 1 - xunit;
|
||||
zc = 1 - depth + zunit;
|
||||
break;
|
||||
case 5:
|
||||
xc = depth - zunit;
|
||||
zc = xunit;
|
||||
r = -90;
|
||||
break;
|
||||
case 4:
|
||||
xc = 1 - depth + zunit;
|
||||
zc = 1 - xunit;
|
||||
r = 90;
|
||||
break;
|
||||
}
|
||||
|
||||
if (blockType) {
|
||||
GL11.glTranslated(xc, unit * (itemOffset2Y[i] + 1.25), zc);
|
||||
GL11.glScaled(1, 1, 1);
|
||||
GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F);
|
||||
GL11.glRotatef(r - 90.0F, 0.0F, 1.0F, 0.0F);
|
||||
} else {
|
||||
GL11.glTranslated(itemOffset2X[i], unit * itemOffset2Y[i], 1 - unit);
|
||||
GL11.glTranslated(xc, unit * itemOffset2Y[i], zc);
|
||||
GL11.glScaled(.6, .6, .6);
|
||||
GL11.glRotatef(r, 0.0F, 1.0F, 0.0F);
|
||||
}
|
||||
|
||||
EntityItem itemEnt = new EntityItem(null, 0, 0, 0, itemStack);
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.core;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
|
||||
public class ForgeEventHandler
|
||||
{
|
||||
@SubscribeEvent
|
||||
public void playerInteracts (PlayerInteractEvent event) {
|
||||
if (event.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) {
|
||||
TileEntity tile = event.world.getTileEntity(event.x, event.y, event.z);
|
||||
if (tile instanceof TileEntityDrawers) {
|
||||
int dir = ((TileEntityDrawers) tile).getDirection();
|
||||
if (dir == event.face) {
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,20 +2,33 @@ package com.jaquadro.minecraft.storagedrawers.core;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.block.BlockDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.item.ItemDrawers;
|
||||
import cpw.mods.fml.common.registry.GameData;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
public class ModBlocks
|
||||
{
|
||||
public static BlockDrawers drawers;
|
||||
public static BlockDrawers fullDrawers2;
|
||||
public static BlockDrawers fullDrawers4;
|
||||
public static BlockDrawers halfDrawers2;
|
||||
public static BlockDrawers halfDrawers4;
|
||||
|
||||
public void init () {
|
||||
drawers = new BlockDrawers("drawers");
|
||||
fullDrawers2 = new BlockDrawers("fullDrawers2", 2, false);
|
||||
fullDrawers4 = new BlockDrawers("fullDrawers4", 4, false);
|
||||
halfDrawers2 = new BlockDrawers("halfDrawers2", 2, true);
|
||||
halfDrawers4 = new BlockDrawers("halfDrawers4", 4, true);
|
||||
|
||||
GameRegistry.registerBlock(drawers, "drawers");
|
||||
GameRegistry.registerBlock(fullDrawers2, ItemDrawers.class, "fullDrawers2");
|
||||
GameRegistry.registerBlock(fullDrawers4, ItemDrawers.class, "fullDrawers4");
|
||||
GameRegistry.registerBlock(halfDrawers2, ItemDrawers.class, "halfDrawers2");
|
||||
GameRegistry.registerBlock(halfDrawers4, ItemDrawers.class, "halfDrawers4");
|
||||
|
||||
GameRegistry.registerTileEntity(TileEntityDrawers.class, ModBlocks.getQualifiedName(drawers));
|
||||
GameRegistry.registerTileEntity(TileEntityDrawers.class, ModBlocks.getQualifiedName(fullDrawers2));
|
||||
GameRegistry.registerTileEntity(TileEntityDrawers.class, ModBlocks.getQualifiedName(fullDrawers4));
|
||||
GameRegistry.registerTileEntity(TileEntityDrawers.class, ModBlocks.getQualifiedName(halfDrawers2));
|
||||
GameRegistry.registerTileEntity(TileEntityDrawers.class, ModBlocks.getQualifiedName(halfDrawers4));
|
||||
}
|
||||
|
||||
public static String getQualifiedName (Block block) {
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.item;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockWood;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemMultiTexture;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class ItemDrawers extends ItemMultiTexture
|
||||
{
|
||||
public ItemDrawers (Block block) {
|
||||
super(block, block, BlockWood.field_150096_a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlockAt (ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) {
|
||||
if (!super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata))
|
||||
return false;
|
||||
|
||||
TileEntityDrawers tile = (TileEntityDrawers) world.getTileEntity(x, y, z);
|
||||
if (tile != null && side > 1)
|
||||
tile.setDirection(ForgeDirection.OPPOSITES[side]);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user