equivalent-exchange-3/src/main/java/com/pahimar/ee3/client/renderer/tileentity/TileEntityRendererGlassBell.java

292 lines
10 KiB
Java
Raw Normal View History

package com.pahimar.ee3.client.renderer.tileentity;
import com.pahimar.ee3.client.renderer.model.ModelGlassBell;
import com.pahimar.ee3.reference.Textures;
2014-04-30 03:46:59 +02:00
import com.pahimar.ee3.tileentity.TileEntityGlassBell;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
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.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
@SideOnly(Side.CLIENT)
2023-01-03 17:47:36 +01:00
public class TileEntityRendererGlassBell extends TileEntitySpecialRenderer {
private final ModelGlassBell modelGlassBell = new ModelGlassBell();
private final RenderItem customRenderItem;
2023-01-03 17:47:36 +01:00
public TileEntityRendererGlassBell() {
customRenderItem = new RenderItem() {
@Override
2023-01-03 17:47:36 +01:00
public boolean shouldBob() {
return false;
}
};
customRenderItem.setRenderManager(RenderManager.instance);
}
@Override
2023-01-03 17:47:36 +01:00
public void
renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float tick) {
if (tileEntity instanceof TileEntityGlassBell) {
2014-04-30 03:46:59 +02:00
TileEntityGlassBell tileEntityGlassBell = (TileEntityGlassBell) tileEntity;
GL11.glDisable(GL11.GL_CULL_FACE);
/**
* Render the Glass Bell
*/
GL11.glPushMatrix();
// Scale, Translate, Rotate
2014-04-30 03:46:59 +02:00
renderGlassBellByOrientation(x, y, z, tileEntityGlassBell.getOrientation());
// Bind texture
this.bindTexture(Textures.Model.GLASS_BELL);
modelGlassBell.render();
GL11.glPopMatrix();
/**
* Render the ghost item inside of the Glass Bell, slowly spinning
*/
GL11.glPushMatrix();
2023-01-03 17:47:36 +01:00
if (tileEntityGlassBell.outputItemStack != null) {
// TODO Stop the ghost item rendering in the event that the client's game
// is paused
float scaleFactor
= getGhostItemScaleFactor(tileEntityGlassBell.outputItemStack);
float rotationAngle
= (float) (720.0 * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL);
2023-01-03 17:47:36 +01:00
EntityItem ghostEntityItem
= new EntityItem(tileEntityGlassBell.getWorldObj());
ghostEntityItem.hoverStart = 0.0F;
2014-04-30 03:46:59 +02:00
ghostEntityItem.setEntityItemStack(tileEntityGlassBell.outputItemStack);
2023-01-03 17:47:36 +01:00
translateGhostItemByOrientation(
ghostEntityItem.getEntityItem(),
x,
y,
z,
tileEntityGlassBell.getOrientation()
);
GL11.glScalef(scaleFactor, scaleFactor, scaleFactor);
GL11.glRotatef(rotationAngle, 0.0F, 1.0F, 0.0F);
customRenderItem.doRender(ghostEntityItem, 0, 0, 0, 0, 0);
}
GL11.glPopMatrix();
GL11.glEnable(GL11.GL_CULL_FACE);
}
}
2023-01-03 17:47:36 +01:00
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);
return;
}
2023-01-03 17:47:36 +01:00
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);
return;
}
2023-01-03 17:47:36 +01:00
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);
return;
}
2023-01-03 17:47:36 +01:00
case SOUTH: {
GL11.glScalef(1.0F, 1.0F, 1.0F);
GL11.glTranslatef((float) x + 0.0F, (float) y + 0.0F, (float) z + -1.0F);
return;
}
2023-01-03 17:47:36 +01:00
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);
return;
}
2023-01-03 17:47:36 +01:00
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);
return;
}
2023-01-03 17:47:36 +01:00
case UNKNOWN: {
return;
}
2023-01-03 17:47:36 +01:00
default: {
}
}
}
2023-01-03 17:47:36 +01:00
private void translateGhostItemByOrientation(
ItemStack ghostItemStack,
double x,
double y,
double z,
ForgeDirection forgeDirection
) {
if (ghostItemStack != null) {
if (ghostItemStack.getItem() instanceof ItemBlock) {
switch (forgeDirection) {
case DOWN: {
GL11.glTranslatef(
(float) x + 0.5F, (float) y + 0.7F, (float) z + 0.5F
);
return;
}
2023-01-03 17:47:36 +01:00
case UP: {
GL11.glTranslatef(
(float) x + 0.5F, (float) y + 0.25F, (float) z + 0.5F
);
return;
}
2023-01-03 17:47:36 +01:00
case NORTH: {
GL11.glTranslatef(
(float) x + 0.5F, (float) y + 0.5F, (float) z + 0.7F
);
return;
}
2023-01-03 17:47:36 +01:00
case SOUTH: {
GL11.glTranslatef(
(float) x + 0.5F, (float) y + 0.5F, (float) z + 0.3F
);
return;
}
2023-01-03 17:47:36 +01:00
case EAST: {
GL11.glTranslatef(
(float) x + 0.3F, (float) y + 0.5F, (float) z + 0.5F
);
return;
}
2023-01-03 17:47:36 +01:00
case WEST: {
GL11.glTranslatef(
(float) x + 0.70F, (float) y + 0.5F, (float) z + 0.5F
);
return;
}
2023-01-03 17:47:36 +01:00
case UNKNOWN: {
return;
}
2023-01-03 17:47:36 +01:00
default: {
}
}
2023-01-03 17:47:36 +01:00
} else {
switch (forgeDirection) {
case DOWN: {
GL11.glTranslatef(
(float) x + 0.5F, (float) y + 0.6F, (float) z + 0.5F
);
return;
}
2023-01-03 17:47:36 +01:00
case UP: {
GL11.glTranslatef(
(float) x + 0.5F, (float) y + 0.20F, (float) z + 0.5F
);
return;
}
2023-01-03 17:47:36 +01:00
case NORTH: {
GL11.glTranslatef(
(float) x + 0.5F, (float) y + 0.4F, (float) z + 0.7F
);
return;
}
2023-01-03 17:47:36 +01:00
case SOUTH: {
GL11.glTranslatef(
(float) x + 0.5F, (float) y + 0.4F, (float) z + 0.3F
);
return;
}
2023-01-03 17:47:36 +01:00
case EAST: {
GL11.glTranslatef(
(float) x + 0.3F, (float) y + 0.4F, (float) z + 0.5F
);
return;
}
2023-01-03 17:47:36 +01:00
case WEST: {
GL11.glTranslatef(
(float) x + 0.70F, (float) y + 0.4F, (float) z + 0.5F
);
return;
}
2023-01-03 17:47:36 +01:00
case UNKNOWN: {
return;
}
2023-01-03 17:47:36 +01:00
default: {
}
}
}
}
}
2023-01-03 17:47:36 +01:00
private float getGhostItemScaleFactor(ItemStack itemStack) {
float scaleFactor = 1.0F;
2023-01-03 17:47:36 +01:00
if (itemStack != null) {
byte numBlocks = 1;
2023-01-03 17:47:36 +01:00
if (itemStack.stackSize > 1) {
numBlocks = 2;
2023-01-03 17:47:36 +01:00
} else if (itemStack.stackSize > 5) {
numBlocks = 3;
2023-01-03 17:47:36 +01:00
} else if (itemStack.stackSize > 20) {
numBlocks = 4;
2023-01-03 17:47:36 +01:00
} else if (itemStack.stackSize > 40) {
numBlocks = 5;
}
2023-01-03 17:47:36 +01:00
if (itemStack.getItem() instanceof ItemBlock) {
switch (numBlocks) {
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;
}
2023-01-03 17:47:36 +01:00
} else {
switch (numBlocks) {
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;
}
}