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.
This commit is contained in:
parent
76dde33ae1
commit
3d32a63475
3 changed files with 130 additions and 11 deletions
|
@ -2,19 +2,29 @@ package com.pahimar.ee3.block;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
|
import net.minecraft.entity.EntityLiving;
|
||||||
import net.minecraft.entity.item.EntityItem;
|
import net.minecraft.entity.item.EntityItem;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
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.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
|
||||||
import com.pahimar.ee3.EquivalentExchange3;
|
import com.pahimar.ee3.EquivalentExchange3;
|
||||||
import com.pahimar.ee3.lib.GuiIds;
|
import com.pahimar.ee3.lib.GuiIds;
|
||||||
import com.pahimar.ee3.lib.RenderIds;
|
import com.pahimar.ee3.lib.RenderIds;
|
||||||
import com.pahimar.ee3.lib.Strings;
|
import com.pahimar.ee3.lib.Strings;
|
||||||
|
import com.pahimar.ee3.tileentity.TileEE;
|
||||||
import com.pahimar.ee3.tileentity.TileGlassBell;
|
import com.pahimar.ee3.tileentity.TileGlassBell;
|
||||||
|
|
||||||
public class BlockGlassBell extends BlockEE {
|
public class BlockGlassBell extends BlockEE {
|
||||||
|
@ -30,7 +40,6 @@ public class BlockGlassBell extends BlockEE {
|
||||||
super(id, Material.glass);
|
super(id, Material.glass);
|
||||||
this.setUnlocalizedName(Strings.GLASS_BELL_NAME);
|
this.setUnlocalizedName(Strings.GLASS_BELL_NAME);
|
||||||
this.setCreativeTab(EquivalentExchange3.tabsEE3);
|
this.setCreativeTab(EquivalentExchange3.tabsEE3);
|
||||||
this.setBlockBounds(0.125F, 0.0F, 0.125F, 0.875F, 0.66F, 0.875F);
|
|
||||||
this.setHardness(1.0F);
|
this.setHardness(1.0F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,6 +92,78 @@ public class BlockGlassBell extends BlockEE {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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) {
|
private void dropInventory(World world, int x, int y, int z) {
|
||||||
|
|
||||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||||
|
|
|
@ -6,6 +6,7 @@ import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||||
import net.minecraft.entity.item.EntityItem;
|
import net.minecraft.entity.item.EntityItem;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
@ -61,10 +62,7 @@ public class TileEntityGlassBellRenderer extends TileEntitySpecialRenderer {
|
||||||
GL11.glPushMatrix();
|
GL11.glPushMatrix();
|
||||||
|
|
||||||
// Scale, Translate, Rotate
|
// Scale, Translate, Rotate
|
||||||
GL11.glScalef(1.0F, 1.0F, 1.0F);
|
renderGlassBellByOrientation(x, y, z, tileGlassBell.getOrientation());
|
||||||
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);
|
|
||||||
|
|
||||||
// Bind texture
|
// Bind texture
|
||||||
FMLClientHandler.instance().getClient().renderEngine.bindTexture(Textures.MODEL_GLASS_BELL);
|
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 scaleFactor = getGhostItemScaleFactor(tileGlassBell.getStackInSlot(i));
|
||||||
float rotationAngle = (float) (720.0 * (double) (System.currentTimeMillis() & 0x3FFFL) / (double) 0x3FFFL);
|
float rotationAngle = (float) (720.0 * (double) (System.currentTimeMillis() & 0x3FFFL) / (double) 0x3FFFL);
|
||||||
|
|
||||||
if (tileGlassBell.getStackInSlot(i).itemID < 4096) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityItem ghostEntityItem = new EntityItem(tileGlassBell.worldObj);
|
EntityItem ghostEntityItem = new EntityItem(tileGlassBell.worldObj);
|
||||||
ghostEntityItem.hoverStart = 0.0F;
|
ghostEntityItem.hoverStart = 0.0F;
|
||||||
ghostEntityItem.setEntityItemStack(tileGlassBell.getStackInSlot(i));
|
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) {
|
private float getGhostItemYTranslateFactor(ItemStack itemStack) {
|
||||||
float scaleFactor = 0.1F;
|
float scaleFactor = 0.1F;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue