toString methods for the EE3 tile entities, and fixing lighting for the Aludel and the Glass Bell

This commit is contained in:
pahimar 2013-05-14 14:50:22 -04:00
parent fc58391854
commit 9e15f7aeb8
9 changed files with 168 additions and 70 deletions

View file

@ -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);

View file

@ -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) {

View file

@ -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) {

View file

@ -224,6 +224,7 @@ public class TileEntityGlassBellRenderer extends TileEntitySpecialRenderer {
}
private float getGhostItemScaleFactor(ItemStack itemStack) {
float scaleFactor = 1.0F;
if (itemStack != null) {

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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();
}

View file

@ -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();
}
}