Work on Glass Bell & Aludel interaction :)

This commit is contained in:
pahimar 2013-05-12 22:08:11 -04:00
parent 5ac9f427eb
commit d841fbef4f
7 changed files with 181 additions and 34 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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