From d841fbef4f724ac0489d309a6ae0e7d76099dcda Mon Sep 17 00:00:00 2001 From: pahimar Date: Sun, 12 May 2013 22:08:11 -0400 Subject: [PATCH] Work on Glass Bell & Aludel interaction :) --- .../pahimar/ee3/block/BlockAludelBase.java | 27 ++++++ .../com/pahimar/ee3/block/BlockGlassBell.java | 7 ++ .../tileentity/TileEntityAludelRenderer.java | 85 ++++++++++++++++++- .../TileEntityGlassBellRenderer.java | 23 +++-- .../pahimar/ee3/core/proxy/ClientProxy.java | 12 ++- .../pahimar/ee3/tileentity/TileAludel.java | 31 +++++++ .../pahimar/ee3/tileentity/TileGlassBell.java | 30 +++---- 7 files changed, 181 insertions(+), 34 deletions(-) diff --git a/ee3_common/com/pahimar/ee3/block/BlockAludelBase.java b/ee3_common/com/pahimar/ee3/block/BlockAludelBase.java index aedca633..8a73db22 100644 --- a/ee3_common/com/pahimar/ee3/block/BlockAludelBase.java +++ b/ee3_common/com/pahimar/ee3/block/BlockAludelBase.java @@ -3,6 +3,7 @@ package com.pahimar.ee3.block; import java.util.Random; import net.minecraft.block.material.Material; +import net.minecraft.entity.EntityLiving; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; @@ -10,12 +11,14 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; +import net.minecraftforge.common.ForgeDirection; import com.pahimar.ee3.EquivalentExchange3; import com.pahimar.ee3.lib.GuiIds; import com.pahimar.ee3.lib.RenderIds; import com.pahimar.ee3.lib.Strings; import com.pahimar.ee3.tileentity.TileAludel; +import com.pahimar.ee3.tileentity.TileGlassBell; /** * Equivalent-Exchange-3 @@ -91,6 +94,30 @@ 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)) { + + 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)) { + + 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); + } + } + } private void dropInventory(World world, int x, int y, int z) { diff --git a/ee3_common/com/pahimar/ee3/block/BlockGlassBell.java b/ee3_common/com/pahimar/ee3/block/BlockGlassBell.java index e905ebe0..c1ff7d1d 100644 --- a/ee3_common/com/pahimar/ee3/block/BlockGlassBell.java +++ b/ee3_common/com/pahimar/ee3/block/BlockGlassBell.java @@ -19,6 +19,7 @@ import com.pahimar.ee3.EquivalentExchange3; import com.pahimar.ee3.lib.GuiIds; import com.pahimar.ee3.lib.RenderIds; import com.pahimar.ee3.lib.Strings; +import com.pahimar.ee3.tileentity.TileAludel; import com.pahimar.ee3.tileentity.TileEE; import com.pahimar.ee3.tileentity.TileGlassBell; @@ -77,7 +78,13 @@ public class BlockGlassBell extends BlockEE { else { 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)) { + 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); } 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 5459f843..903dd00c 100644 --- a/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityAludelRenderer.java +++ b/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityAludelRenderer.java @@ -1,6 +1,11 @@ package com.pahimar.ee3.client.renderer.tileentity; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +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.ForgeDirection; @@ -27,6 +32,21 @@ import cpw.mods.fml.relauncher.SideOnly; public class TileEntityAludelRenderer extends TileEntitySpecialRenderer { private ModelAludel modelAludel = new ModelAludel(); + private final RenderItem customRenderItem; + + public TileEntityAludelRenderer() { + + customRenderItem = new RenderItem() { + + @Override + public boolean shouldBob() { + + return false; + }; + }; + + customRenderItem.setRenderManager(RenderManager.instance); + } @Override public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float tick) { @@ -47,8 +67,32 @@ public class TileEntityAludelRenderer extends TileEntitySpecialRenderer { // Render modelAludel.render(); - GL11.glEnable(GL11.GL_LIGHTING); GL11.glPopMatrix(); + + /** + * Render the ghost item inside of the Aludel, slowly spinning + */ + GL11.glPushMatrix(); + + 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); } } @@ -75,4 +119,43 @@ public class TileEntityAludelRenderer extends TileEntitySpecialRenderer { GL11.glRotatef(-90F, 1F, 0F, 0F); } } + + private float getGhostItemScaleFactor(ItemStack itemStack) { + float scaleFactor = 1.0F; + + if (itemStack != null) { + if (itemStack.getItem() instanceof ItemBlock) { + switch (customRenderItem.getMiniBlockCount(itemStack)) { + case 1: + return 0.90F; + case 2: + return 0.90F; + case 3: + return 0.90F; + case 4: + return 0.90F; + case 5: + return 0.80F; + default: + return 0.90F; + } + } + else { + switch (customRenderItem.getMiniItemCount(itemStack)) { + case 1: + return 0.65F; + case 2: + return 0.65F; + case 3: + return 0.65F; + case 4: + return 0.65F; + default: + return 0.65F; + } + } + } + + return scaleFactor; + } } 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 dbbefdac..e25fdb93 100644 --- a/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityGlassBellRenderer.java +++ b/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityGlassBellRenderer.java @@ -77,23 +77,20 @@ public class TileEntityGlassBellRenderer extends TileEntitySpecialRenderer { */ GL11.glPushMatrix(); - for (int i = 0; i < tileGlassBell.getSizeInventory(); i++) { + if (tileGlassBell.getStackInSlot(TileGlassBell.DISPLAY_SLOT_INVENTORY_INDEX) != null) { - if (tileGlassBell.getStackInSlot(i) != null) { + float scaleFactor = getGhostItemScaleFactor(tileGlassBell.getStackInSlot(TileGlassBell.DISPLAY_SLOT_INVENTORY_INDEX)); + float rotationAngle = (float) (720.0 * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL); - float scaleFactor = getGhostItemScaleFactor(tileGlassBell.getStackInSlot(i)); - float rotationAngle = (float) (720.0 * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL); + EntityItem ghostEntityItem = new EntityItem(tileGlassBell.worldObj); + ghostEntityItem.hoverStart = 0.0F; + ghostEntityItem.setEntityItemStack(tileGlassBell.getStackInSlot(TileGlassBell.DISPLAY_SLOT_INVENTORY_INDEX)); - EntityItem ghostEntityItem = new EntityItem(tileGlassBell.worldObj); - ghostEntityItem.hoverStart = 0.0F; - ghostEntityItem.setEntityItemStack(tileGlassBell.getStackInSlot(i)); + translateGhostItemByOrientation(ghostEntityItem.getEntityItem(), x, y, z, tileGlassBell.getOrientation()); + GL11.glScalef(scaleFactor, scaleFactor, scaleFactor); + GL11.glRotatef(rotationAngle, 0.0F, 1.0F, 0.0F); - translateGhostItemByOrientation(ghostEntityItem.getEntityItem(), x, y, z, tileGlassBell.getOrientation()); - GL11.glScalef(scaleFactor, scaleFactor, scaleFactor); - GL11.glRotatef(rotationAngle, 0.0F, 1.0F, 0.0F); - - customRenderItem.doRenderItem(ghostEntityItem, 0, 0, 0, 0, 0); - } + customRenderItem.doRenderItem(ghostEntityItem, 0, 0, 0, 0, 0); } GL11.glPopMatrix(); diff --git a/ee3_common/com/pahimar/ee3/core/proxy/ClientProxy.java b/ee3_common/com/pahimar/ee3/core/proxy/ClientProxy.java index a79626a3..3324149e 100644 --- a/ee3_common/com/pahimar/ee3/core/proxy/ClientProxy.java +++ b/ee3_common/com/pahimar/ee3/core/proxy/ClientProxy.java @@ -148,7 +148,17 @@ public class ClientProxy extends CommonProxy { ItemHelper.setColor(itemStack, color); } - ((TileGlassBell) tileEntity).setInventorySlotContents(0, itemStack); + ((TileGlassBell) tileEntity).setInventorySlotContents(TileGlassBell.DISPLAY_SLOT_INVENTORY_INDEX, itemStack); + world.updateAllLightTypes(x, y, z); + } + else if (tileEntity instanceof TileAludel) { + + ItemStack itemStack = new ItemStack(itemID, stackSize, metaData); + if (color != Integer.parseInt(Colours.PURE_WHITE, 16)) { + ItemHelper.setColor(itemStack, color); + } + + ((TileAludel) tileEntity).setInventorySlotContents(TileAludel.INPUT_INVENTORY_INDEX, itemStack); world.updateAllLightTypes(x, y, z); } } diff --git a/ee3_common/com/pahimar/ee3/tileentity/TileAludel.java b/ee3_common/com/pahimar/ee3/tileentity/TileAludel.java index b6d7a405..3616388a 100644 --- a/ee3_common/com/pahimar/ee3/tileentity/TileAludel.java +++ b/ee3_common/com/pahimar/ee3/tileentity/TileAludel.java @@ -1,11 +1,16 @@ 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; import net.minecraft.nbt.NBTTagList; +import net.minecraft.network.packet.Packet; +import com.pahimar.ee3.core.helper.ItemHelper; import com.pahimar.ee3.lib.Strings; +import com.pahimar.ee3.network.PacketTypeHandler; +import com.pahimar.ee3.network.packet.PacketTileWithItemUpdate; /** * Equivalent-Exchange-3 @@ -153,4 +158,30 @@ 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) { + return PacketTypeHandler.populatePacket(new PacketTileWithItemUpdate(xCoord, yCoord, zCoord, orientation, state, customName, itemStack.itemID, itemStack.getItemDamage(), itemStack.stackSize, ItemHelper.getColor(itemStack))); + } + 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); + } + } } diff --git a/ee3_common/com/pahimar/ee3/tileentity/TileGlassBell.java b/ee3_common/com/pahimar/ee3/tileentity/TileGlassBell.java index 750e01ef..6bfee26b 100644 --- a/ee3_common/com/pahimar/ee3/tileentity/TileGlassBell.java +++ b/ee3_common/com/pahimar/ee3/tileentity/TileGlassBell.java @@ -18,7 +18,6 @@ public class TileGlassBell extends TileEE implements IInventory { * The ItemStacks that hold the items currently being used in the Glass Bell */ private ItemStack[] inventory; - private ItemStack ghostItemStack; private final int INVENTORY_SIZE = 1; @@ -27,7 +26,6 @@ public class TileGlassBell extends TileEE implements IInventory { public TileGlassBell() { inventory = new ItemStack[INVENTORY_SIZE]; - ghostItemStack = null; } @Override @@ -102,16 +100,6 @@ public class TileGlassBell extends TileEE implements IInventory { } - public ItemStack getGhostItemStack() { - - return ghostItemStack; - } - - public void setGhostItemStack(ItemStack ghostItemStack) { - - this.ghostItemStack = ghostItemStack; - } - @Override public void readFromNBT(NBTTagCompound nbtTagCompound) { @@ -162,19 +150,23 @@ public class TileGlassBell extends TileEE implements IInventory { @Override public Packet getDescriptionPacket() { - if (inventory[0] != null && inventory[0].stackSize > 0) - return PacketTypeHandler.populatePacket(new PacketTileWithItemUpdate(xCoord, yCoord, zCoord, orientation, state, customName, inventory[0].itemID, inventory[0].getItemDamage(), inventory[0].stackSize, ItemHelper.getColor(inventory[0]))); - else + ItemStack itemStack = getStackInSlot(DISPLAY_SLOT_INVENTORY_INDEX); + + 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 { return super.getDescriptionPacket(); + } } @Override public void onInventoryChanged() { + + ItemStack itemStack = getStackInSlot(DISPLAY_SLOT_INVENTORY_INDEX); - if (inventory[0] != null) { - if (inventory[0].itemID < 4096) { - worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, Block.lightValue[inventory[0].itemID], 2); - } + if ((itemStack != null) && (itemStack.itemID < 4096)) { + worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, Block.lightValue[itemStack.itemID], 2); } else { worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 2);