From 9e15f7aeb824167f3889f22dc059079e0eb53f0b Mon Sep 17 00:00:00 2001 From: pahimar Date: Tue, 14 May 2013 14:50:22 -0400 Subject: [PATCH] toString methods for the EE3 tile entities, and fixing lighting for the Aludel and the Glass Bell --- .../pahimar/ee3/block/BlockAludelBase.java | 33 +++++++++---- .../com/pahimar/ee3/block/BlockGlassBell.java | 33 +++++++++++-- .../tileentity/TileEntityAludelRenderer.java | 21 +++++---- .../TileEntityGlassBellRenderer.java | 1 + .../ee3/tileentity/TileAlchemicalChest.java | 25 ++++++++++ .../pahimar/ee3/tileentity/TileAludel.java | 47 +++++++++---------- .../ee3/tileentity/TileCalcinator.java | 25 ++++++++++ .../com/pahimar/ee3/tileentity/TileEE.java | 12 ++--- .../pahimar/ee3/tileentity/TileGlassBell.java | 41 +++++++++++----- 9 files changed, 168 insertions(+), 70 deletions(-) diff --git a/ee3_common/com/pahimar/ee3/block/BlockAludelBase.java b/ee3_common/com/pahimar/ee3/block/BlockAludelBase.java index 8a73db22..c33ec713 100644 --- a/ee3_common/com/pahimar/ee3/block/BlockAludelBase.java +++ b/ee3_common/com/pahimar/ee3/block/BlockAludelBase.java @@ -10,6 +10,7 @@ import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; @@ -74,6 +75,12 @@ public class BlockAludelBase extends BlockEE { public void breakBlock(World world, int x, int y, int z, int id, int meta) { dropInventory(world, x, y, z); + + if (world.getBlockTileEntity(x, y + 1, z) instanceof TileGlassBell) { + world.markBlockForUpdate(x, y + 1, z); + world.updateAllLightTypes(x, y + 1, z); + } + super.breakBlock(world, x, y, z, id, meta); } @@ -94,31 +101,37 @@ public class BlockAludelBase extends BlockEE { return true; } } - + @Override public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving entityLiving, ItemStack itemStack) { super.onBlockPlacedBy(world, x, y, z, entityLiving, itemStack); - - if ((world.getBlockTileEntity(x, y + 1, z) != null) && (world.getBlockTileEntity(x, y + 1, z) instanceof TileGlassBell)) { - + + if (world.getBlockTileEntity(x, y + 1, z) != null && world.getBlockTileEntity(x, y + 1, z) instanceof TileGlassBell) { + TileGlassBell tileGlassBell = (TileGlassBell) world.getBlockTileEntity(x, y + 1, z); - + tileGlassBell.setOrientation(ForgeDirection.UP); - if ((world.getBlockTileEntity(x, y, z) != null) && (world.getBlockTileEntity(x, y, z) instanceof TileAludel)) { - + if (world.getBlockTileEntity(x, y, z) != null && world.getBlockTileEntity(x, y, z) instanceof TileAludel) { + TileAludel tileAludel = (TileAludel) world.getBlockTileEntity(x, y, z); - + ItemStack itemStackGlassBell = tileGlassBell.getStackInSlot(TileGlassBell.DISPLAY_SLOT_INVENTORY_INDEX); - + tileGlassBell.setInventorySlotContents(TileGlassBell.DISPLAY_SLOT_INVENTORY_INDEX, null); - + tileAludel.setInventorySlotContents(TileAludel.INPUT_INVENTORY_INDEX, itemStackGlassBell); } } } + @Override + public int getLightValue(IBlockAccess world, int x, int y, int z) { + + return 0; + } + private void dropInventory(World world, int x, int y, int z) { TileEntity tileEntity = world.getBlockTileEntity(x, y, z); diff --git a/ee3_common/com/pahimar/ee3/block/BlockGlassBell.java b/ee3_common/com/pahimar/ee3/block/BlockGlassBell.java index 121dd1bf..f6e64a43 100644 --- a/ee3_common/com/pahimar/ee3/block/BlockGlassBell.java +++ b/ee3_common/com/pahimar/ee3/block/BlockGlassBell.java @@ -2,6 +2,7 @@ package com.pahimar.ee3.block; import java.util.Random; +import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.item.EntityItem; @@ -80,12 +81,12 @@ public class BlockGlassBell extends BlockEE { if (!world.isRemote) { TileGlassBell tileGlassBell = (TileGlassBell) world.getBlockTileEntity(x, y, z); TileAludel tileAludel = (TileAludel) world.getBlockTileEntity(x, y - 1, z); - - if ((tileAludel != null) && (tileGlassBell != null)) { + + if (tileAludel != null && tileGlassBell != null) { player.openGui(EquivalentExchange3.instance, GuiIds.ALUDEL, world, x, y - 1, z); return true; } - + if (tileGlassBell != null) { player.openGui(EquivalentExchange3.instance, GuiIds.GLASS_BELL, world, x, y, z); } @@ -102,7 +103,7 @@ public class BlockGlassBell extends BlockEE { ((TileEE) world.getBlockTileEntity(x, y, z)).setCustomName(itemStack.getDisplayName()); } - if ((world.getBlockTileEntity(x, y - 1, z) != null) && (world.getBlockTileEntity(x, y - 1, z) instanceof TileAludel)) { + if (world.getBlockTileEntity(x, y - 1, z) != null && world.getBlockTileEntity(x, y - 1, z) instanceof TileAludel) { ((TileEE) world.getBlockTileEntity(x, y, z)).setOrientation(ForgeDirection.UP); } else { @@ -124,6 +125,7 @@ public class BlockGlassBell extends BlockEE { */ @Override public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 startVec, Vec3 endVec) { + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); if (tileEntity != null) { @@ -169,7 +171,28 @@ public class BlockGlassBell extends BlockEE { @Override public int getLightValue(IBlockAccess world, int x, int y, int z) { - return world.getBlockMetadata(x, y, z); + ItemStack itemStack; + + if (world.getBlockTileEntity(x, y, z) instanceof TileGlassBell) { + + TileGlassBell tileGlassBell = (TileGlassBell) world.getBlockTileEntity(x, y, z); + + if (world.getBlockTileEntity(x, y - 1, z) instanceof TileAludel) { + TileAludel tileAludel = (TileAludel) world.getBlockTileEntity(x, y - 1, z); + + itemStack = tileAludel.getStackInSlot(TileAludel.INPUT_INVENTORY_INDEX); + + if (itemStack != null && itemStack.itemID < 4096) + return Block.lightValue[itemStack.itemID]; + } + + itemStack = tileGlassBell.getStackInSlot(TileGlassBell.DISPLAY_SLOT_INVENTORY_INDEX); + + if (itemStack != null && itemStack.itemID < 4096) + return Block.lightValue[itemStack.itemID]; + } + + return 0; } private void dropInventory(World world, int x, int y, int z) { diff --git a/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityAludelRenderer.java b/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityAludelRenderer.java index f1af9a22..b8f3a720 100644 --- a/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityAludelRenderer.java +++ b/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityAludelRenderer.java @@ -34,7 +34,7 @@ public class TileEntityAludelRenderer extends TileEntitySpecialRenderer { private ModelAludel modelAludel = new ModelAludel(); private final RenderItem customRenderItem; - + public TileEntityAludelRenderer() { customRenderItem = new RenderItem() { @@ -69,34 +69,34 @@ public class TileEntityAludelRenderer extends TileEntitySpecialRenderer { modelAludel.render(); GL11.glPopMatrix(); - + /** * Render the ghost item inside of the Aludel, slowly spinning */ GL11.glPushMatrix(); TileEntity tileGlassBell = tileAludel.worldObj.getBlockTileEntity(tileAludel.xCoord, tileAludel.yCoord + 1, tileAludel.zCoord); - - if ((tileGlassBell != null) && (tileGlassBell instanceof TileGlassBell)) { + + if (tileGlassBell != null && tileGlassBell instanceof TileGlassBell) { if (tileAludel.getStackInSlot(TileAludel.INPUT_INVENTORY_INDEX) != null) { - + float scaleFactor = getGhostItemScaleFactor(tileAludel.getStackInSlot(TileAludel.INPUT_INVENTORY_INDEX)); float rotationAngle = (float) (720.0 * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL); - + EntityItem ghostEntityItem = new EntityItem(tileAludel.worldObj); ghostEntityItem.hoverStart = 0.0F; ghostEntityItem.setEntityItemStack(tileAludel.getStackInSlot(TileAludel.INPUT_INVENTORY_INDEX)); - + GL11.glTranslatef((float) x + 0.5F, (float) y + 1.2F, (float) z + 0.5F); GL11.glScalef(scaleFactor, scaleFactor, scaleFactor); GL11.glRotatef(rotationAngle, 0.0F, 1.0F, 0.0F); - + customRenderItem.doRenderItem(ghostEntityItem, 0, 0, 0, 0, 0); } } GL11.glPopMatrix(); - + GL11.glEnable(GL11.GL_LIGHTING); } } @@ -124,8 +124,9 @@ public class TileEntityAludelRenderer extends TileEntitySpecialRenderer { GL11.glRotatef(-90F, 1F, 0F, 0F); } } - + private float getGhostItemScaleFactor(ItemStack itemStack) { + float scaleFactor = 1.0F; if (itemStack != null) { diff --git a/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityGlassBellRenderer.java b/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityGlassBellRenderer.java index e25fdb93..04c1ab2d 100644 --- a/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityGlassBellRenderer.java +++ b/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityGlassBellRenderer.java @@ -224,6 +224,7 @@ public class TileEntityGlassBellRenderer extends TileEntitySpecialRenderer { } private float getGhostItemScaleFactor(ItemStack itemStack) { + float scaleFactor = 1.0F; if (itemStack != null) { diff --git a/ee3_common/com/pahimar/ee3/tileentity/TileAlchemicalChest.java b/ee3_common/com/pahimar/ee3/tileentity/TileAlchemicalChest.java index d4b6f52a..a3dad9c4 100644 --- a/ee3_common/com/pahimar/ee3/tileentity/TileAlchemicalChest.java +++ b/ee3_common/com/pahimar/ee3/tileentity/TileAlchemicalChest.java @@ -240,4 +240,29 @@ public class TileAlchemicalChest extends TileEE implements IInventory { return true; } + + @Override + public String toString() { + + StringBuilder stringBuilder = new StringBuilder(); + + stringBuilder.append(super.toString()); + + stringBuilder.append("TileAlchemicalChest Data - "); + for (int i = 0; i < inventory.length; i++) { + if (i != 0) { + stringBuilder.append(", "); + } + + if (inventory[i] != null) { + stringBuilder.append(String.format("inventory[%d]: %s", i, inventory[i].toString())); + } + else { + stringBuilder.append(String.format("inventory[%d]: empty", i)); + } + } + stringBuilder.append("\n"); + + return stringBuilder.toString(); + } } diff --git a/ee3_common/com/pahimar/ee3/tileentity/TileAludel.java b/ee3_common/com/pahimar/ee3/tileentity/TileAludel.java index fc1da6c9..6f5bfdd9 100644 --- a/ee3_common/com/pahimar/ee3/tileentity/TileAludel.java +++ b/ee3_common/com/pahimar/ee3/tileentity/TileAludel.java @@ -1,8 +1,5 @@ package com.pahimar.ee3.tileentity; -import java.util.logging.Level; - -import net.minecraft.block.Block; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -10,7 +7,6 @@ import net.minecraft.nbt.NBTTagList; import net.minecraft.network.packet.Packet; import com.pahimar.ee3.core.helper.ItemHelper; -import com.pahimar.ee3.core.helper.LogHelper; import com.pahimar.ee3.lib.Strings; import com.pahimar.ee3.network.PacketTypeHandler; import com.pahimar.ee3.network.packet.PacketTileWithItemUpdate; @@ -161,49 +157,50 @@ public class TileAludel extends TileEE implements IInventory { return true; } - + @Override public Packet getDescriptionPacket() { ItemStack itemStack = getStackInSlot(INPUT_INVENTORY_INDEX); - - if (itemStack != null && itemStack.stackSize > 0) { + + if (itemStack != null && itemStack.stackSize > 0) return PacketTypeHandler.populatePacket(new PacketTileWithItemUpdate(xCoord, yCoord, zCoord, orientation, state, customName, itemStack.itemID, itemStack.getItemDamage(), itemStack.stackSize, ItemHelper.getColor(itemStack))); - } - else { + else return super.getDescriptionPacket(); - } } - + @Override public void onInventoryChanged() { - - ItemStack itemStack = getStackInSlot(INPUT_INVENTORY_INDEX); - if ((itemStack != null) && (itemStack.itemID < 4096)) { - worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, Block.lightValue[itemStack.itemID], 2); - } - else { - worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 2); + worldObj.updateAllLightTypes(xCoord, yCoord, zCoord); + + if (worldObj.getBlockTileEntity(xCoord, yCoord + 1, zCoord) instanceof TileGlassBell) { + worldObj.updateAllLightTypes(xCoord, yCoord + 1, zCoord); } } - + @Override public String toString() { + StringBuilder stringBuilder = new StringBuilder(); - - stringBuilder.append("TileEE Type: TileAludel\n"); + stringBuilder.append(super.toString()); - + + stringBuilder.append("TileAludel Data - "); for (int i = 0; i < inventory.length; i++) { + if (i != 0) { + stringBuilder.append(", "); + } + if (inventory[i] != null) { - stringBuilder.append("inventory[" + i + "]: " + inventory[i].toString() + "\n"); + stringBuilder.append(String.format("inventory[%d]: %s", i, inventory[i].toString())); } else { - stringBuilder.append("inventory[" + i + "]: empty\n"); + stringBuilder.append(String.format("inventory[%d]: empty", i)); } } - + stringBuilder.append("\n"); + return stringBuilder.toString(); } } diff --git a/ee3_common/com/pahimar/ee3/tileentity/TileCalcinator.java b/ee3_common/com/pahimar/ee3/tileentity/TileCalcinator.java index c0bd8266..0bd6ce9f 100644 --- a/ee3_common/com/pahimar/ee3/tileentity/TileCalcinator.java +++ b/ee3_common/com/pahimar/ee3/tileentity/TileCalcinator.java @@ -158,4 +158,29 @@ public class TileCalcinator extends TileEE implements IInventory { return true; } + + @Override + public String toString() { + + StringBuilder stringBuilder = new StringBuilder(); + + stringBuilder.append(super.toString()); + + stringBuilder.append("TileCalcinator Data - "); + for (int i = 0; i < inventory.length; i++) { + if (i != 0) { + stringBuilder.append(", "); + } + + if (inventory[i] != null) { + stringBuilder.append(String.format("inventory[%d]: %s", i, inventory[i].toString())); + } + else { + stringBuilder.append(String.format("inventory[%d]: empty", i)); + } + } + stringBuilder.append("\n"); + + return stringBuilder.toString(); + } } diff --git a/ee3_common/com/pahimar/ee3/tileentity/TileEE.java b/ee3_common/com/pahimar/ee3/tileentity/TileEE.java index 80e8a65c..e1153baa 100644 --- a/ee3_common/com/pahimar/ee3/tileentity/TileEE.java +++ b/ee3_common/com/pahimar/ee3/tileentity/TileEE.java @@ -113,16 +113,14 @@ public class TileEE extends TileEntity { return PacketTypeHandler.populatePacket(new PacketTileUpdate(xCoord, yCoord, zCoord, orientation, state, customName)); } - + @Override public String toString() { + StringBuilder stringBuilder = new StringBuilder(); - - stringBuilder.append("x: " + xCoord + ", y: " + yCoord + ", z: " + zCoord + "\n"); - stringBuilder.append("customName: " + customName + "\n"); - stringBuilder.append("orientation: " + orientation.toString() + "\n"); - stringBuilder.append("state: " + state + "\n"); - + + stringBuilder.append(String.format("TileEE Data - xCoord: %d, yCoord: %d, zCoord: %d, customName: '%s', orientation: %s, state: %d\n", xCoord, yCoord, zCoord, customName, orientation, state)); + return stringBuilder.toString(); } diff --git a/ee3_common/com/pahimar/ee3/tileentity/TileGlassBell.java b/ee3_common/com/pahimar/ee3/tileentity/TileGlassBell.java index 6bfee26b..2541d1e8 100644 --- a/ee3_common/com/pahimar/ee3/tileentity/TileGlassBell.java +++ b/ee3_common/com/pahimar/ee3/tileentity/TileGlassBell.java @@ -1,6 +1,5 @@ package com.pahimar.ee3.tileentity; -import net.minecraft.block.Block; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -151,25 +150,41 @@ public class TileGlassBell extends TileEE implements IInventory { public Packet getDescriptionPacket() { ItemStack itemStack = getStackInSlot(DISPLAY_SLOT_INVENTORY_INDEX); - - if (itemStack != null && itemStack.stackSize > 0) { + + if (itemStack != null && itemStack.stackSize > 0) return PacketTypeHandler.populatePacket(new PacketTileWithItemUpdate(xCoord, yCoord, zCoord, orientation, state, customName, itemStack.itemID, itemStack.getItemDamage(), itemStack.stackSize, ItemHelper.getColor(itemStack))); - } - else { + else return super.getDescriptionPacket(); - } } @Override public void onInventoryChanged() { - - ItemStack itemStack = getStackInSlot(DISPLAY_SLOT_INVENTORY_INDEX); - if ((itemStack != null) && (itemStack.itemID < 4096)) { - worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, Block.lightValue[itemStack.itemID], 2); - } - else { - worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 2); + worldObj.updateAllLightTypes(xCoord, yCoord, zCoord); + } + + @Override + public String toString() { + + StringBuilder stringBuilder = new StringBuilder(); + + stringBuilder.append(super.toString()); + + stringBuilder.append("TileGlassBell Data - "); + for (int i = 0; i < inventory.length; i++) { + if (i != 0) { + stringBuilder.append(", "); + } + + if (inventory[i] != null) { + stringBuilder.append(String.format("inventory[%d]: %s", i, inventory[i].toString())); + } + else { + stringBuilder.append(String.format("inventory[%d]: empty", i)); + } } + stringBuilder.append("\n"); + + return stringBuilder.toString(); } }