From 3d32a6347590e95338103144c9b176bb768b2b75 Mon Sep 17 00:00:00 2001 From: pahimar Date: Sat, 27 Apr 2013 00:31:27 -0400 Subject: [PATCH] More work on Glass Bell rendering (now will mount to walls and ceilings, and will emit light based on the item in it's inventory). Still buggy and incomplete. --- ee3_common/com/pahimar/ee3/block/BlockEE.java | 2 +- .../com/pahimar/ee3/block/BlockGlassBell.java | 83 ++++++++++++++++++- .../TileEntityGlassBellRenderer.java | 56 +++++++++++-- 3 files changed, 130 insertions(+), 11 deletions(-) diff --git a/ee3_common/com/pahimar/ee3/block/BlockEE.java b/ee3_common/com/pahimar/ee3/block/BlockEE.java index db52fc33..efdb2f60 100644 --- a/ee3_common/com/pahimar/ee3/block/BlockEE.java +++ b/ee3_common/com/pahimar/ee3/block/BlockEE.java @@ -43,7 +43,7 @@ public abstract class BlockEE extends BlockContainer { */ @Override public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving entityLiving, ItemStack itemStack) { - + int direction = 0; int facing = MathHelper.floor_double(entityLiving.rotationYaw * 4.0F / 360.0F + 0.5D) & 3; diff --git a/ee3_common/com/pahimar/ee3/block/BlockGlassBell.java b/ee3_common/com/pahimar/ee3/block/BlockGlassBell.java index ae44646d..2a2e00d3 100644 --- a/ee3_common/com/pahimar/ee3/block/BlockGlassBell.java +++ b/ee3_common/com/pahimar/ee3/block/BlockGlassBell.java @@ -2,19 +2,29 @@ package com.pahimar.ee3.block; import java.util.Random; +import org.lwjgl.opengl.GL11; + +import net.minecraft.block.Block; 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; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MathHelper; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import net.minecraft.world.IBlockAccess; 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.TileEE; import com.pahimar.ee3.tileentity.TileGlassBell; public class BlockGlassBell extends BlockEE { @@ -30,7 +40,6 @@ public class BlockGlassBell extends BlockEE { super(id, Material.glass); this.setUnlocalizedName(Strings.GLASS_BELL_NAME); this.setCreativeTab(EquivalentExchange3.tabsEE3); - this.setBlockBounds(0.125F, 0.0F, 0.125F, 0.875F, 0.66F, 0.875F); this.setHardness(1.0F); } @@ -82,6 +91,78 @@ public class BlockGlassBell extends BlockEE { return true; } } + + @Override + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving entityLiving, ItemStack itemStack) { + + if (itemStack.hasDisplayName()) { + ((TileEE) world.getBlockTileEntity(x, y, z)).setCustomName(itemStack.getDisplayName()); + } + + ((TileEE) world.getBlockTileEntity(x, y, z)).setOrientation(world.getBlockMetadata(x, y, z)); + } + + @Override + public int onBlockPlaced(World world, int x, int y, int z, int sideHit, float hitX, float hitY, float hitZ, int metaData) { + + return sideHit; + } + + /** + * Ray traces through the blocks collision from start vector to end vector returning a ray trace hit. Args: world, + * x, y, z, startVec, endVec + */ + @Override + public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 startVec, Vec3 endVec) + { + int metaData = world.getBlockMetadata(x, y, z) & 7; + float f = 0.15F; + + switch (ForgeDirection.getOrientation(metaData)) { + case DOWN: { + this.setBlockBounds(0.125F, 0.33F, 0.125F, 0.875F, 1.0F, 0.875F); + break; + } + case UP: { + this.setBlockBounds(0.125F, 0.0F, 0.125F, 0.875F, 0.66F, 0.875F); + break; + } + case NORTH: { + this.setBlockBounds(0.125F, 0.125F, 0.33F, 0.875F, 0.875F, 1.0F); + break; + } + case SOUTH: { + this.setBlockBounds(0.125F, 0.125F, 0.0F, 0.875F, 0.875F, 0.66F); + break; + } + case EAST: { + this.setBlockBounds(0.0F, 0.125F, 0.125F, 0.66F, 0.875F, 0.875F); + break; + } + case WEST: { + this.setBlockBounds(0.33F, 0.125F, 0.125F, 1.0F, 0.875F, 0.875F); + break; + } + } + + return super.collisionRayTrace(world, x, y, z, startVec, endVec); + } + + @Override + public int getLightValue(IBlockAccess world, int x, int y, int z) { + + TileGlassBell tileGlassBell = (TileGlassBell) world.getBlockTileEntity(x, y, z); + + if (tileGlassBell != null) { + if (tileGlassBell.getStackInSlot(0) != null) { + if (tileGlassBell.getStackInSlot(0).itemID < 4096) { + return Block.lightValue[tileGlassBell.getStackInSlot(0).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/TileEntityGlassBellRenderer.java b/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityGlassBellRenderer.java index 9bba7acc..22b39c40 100644 --- a/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityGlassBellRenderer.java +++ b/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityGlassBellRenderer.java @@ -6,6 +6,7 @@ import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.ForgeDirection; import org.lwjgl.opengl.GL11; @@ -51,7 +52,7 @@ public class TileEntityGlassBellRenderer extends TileEntitySpecialRenderer { if (tileEntity instanceof TileGlassBell) { TileGlassBell tileGlassBell = (TileGlassBell) tileEntity; - + GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_CULL_FACE); @@ -61,10 +62,7 @@ public class TileEntityGlassBellRenderer extends TileEntitySpecialRenderer { GL11.glPushMatrix(); // Scale, Translate, Rotate - GL11.glScalef(1.0F, 1.0F, 1.0F); - GL11.glTranslatef((float) x + 0.0F, (float) y + -1.0F, (float) z + 1.0F); - GL11.glRotatef(0F, 0F, 1F, 0F); - GL11.glRotatef(-90F, 1F, 0F, 0F); + renderGlassBellByOrientation(x, y, z, tileGlassBell.getOrientation()); // Bind texture FMLClientHandler.instance().getClient().renderEngine.bindTexture(Textures.MODEL_GLASS_BELL); @@ -84,10 +82,6 @@ public class TileEntityGlassBellRenderer extends TileEntitySpecialRenderer { float scaleFactor = getGhostItemScaleFactor(tileGlassBell.getStackInSlot(i)); float rotationAngle = (float) (720.0 * (double) (System.currentTimeMillis() & 0x3FFFL) / (double) 0x3FFFL); - if (tileGlassBell.getStackInSlot(i).itemID < 4096) { - - } - EntityItem ghostEntityItem = new EntityItem(tileGlassBell.worldObj); ghostEntityItem.hoverStart = 0.0F; ghostEntityItem.setEntityItemStack(tileGlassBell.getStackInSlot(i)); @@ -109,6 +103,50 @@ public class TileEntityGlassBellRenderer extends TileEntitySpecialRenderer { } } + private void renderGlassBellByOrientation(double x, double y, double z, ForgeDirection forgeDirection) { + + switch (forgeDirection) { + case DOWN: { + GL11.glScalef(1.0F, 1.0F, 1.0F); + GL11.glTranslatef((float) x + 0.0F, (float) y + 2.0F, (float) z + 0.0F); + GL11.glRotatef(90F, 1F, 0F, 0F); + break; + } + case UP: { + GL11.glScalef(1.0F, 1.0F, 1.0F); + GL11.glTranslatef((float) x + 0.0F, (float) y + -1.0F, (float) z + 1.0F); + GL11.glRotatef(-90F, 1F, 0F, 0F); + break; + } + case NORTH: { + GL11.glScalef(1.0F, 1.0F, 1.0F); + GL11.glTranslatef((float) x + 1.0F, (float) y + 0.0F, (float) z + 2.0F); + GL11.glRotatef(180F, 0F, 1F, 0F); + break; + } + case SOUTH: { + GL11.glScalef(1.0F, 1.0F, 1.0F); + GL11.glTranslatef((float) x + 0.0F, (float) y + 0.0F, (float) z + -1.0F); + GL11.glRotatef(0F, 0F, 1F, 0F); + break; + } + case EAST: { + GL11.glScalef(1.0F, 1.0F, 1.0F); + GL11.glTranslatef((float) x + -1.0F, (float) y + 1.0F, (float) z + 1.0F); + GL11.glRotatef(-90F, 0F, 0F, 1F); + GL11.glRotatef(-90F, 1F, 0F, 0F); + break; + } + case WEST: { + GL11.glScalef(1.0F, 1.0F, 1.0F); + GL11.glTranslatef((float) x + 2.0F, (float) y + 0.0F, (float) z + 1.0F); + GL11.glRotatef(90F, 0F, 0F, 1F); + GL11.glRotatef(-90F, 1F, 0F, 0F); + break; + } + } + } + private float getGhostItemYTranslateFactor(ItemStack itemStack) { float scaleFactor = 0.1F;