2013-08-27 00:57:08 +02:00
|
|
|
package mekanism.client.render.tileentity;
|
2013-05-23 19:30:12 +02:00
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import mekanism.api.EnumColor;
|
|
|
|
import mekanism.api.IConfigurable;
|
|
|
|
import mekanism.api.Object3D;
|
2013-08-27 00:57:08 +02:00
|
|
|
import mekanism.client.render.MekanismRenderer;
|
|
|
|
import mekanism.client.render.MekanismRenderer.DisplayInteger;
|
|
|
|
import mekanism.client.render.MekanismRenderer.Model3D;
|
2013-08-27 00:49:32 +02:00
|
|
|
import mekanism.common.item.ItemConfigurator;
|
2013-08-27 00:57:08 +02:00
|
|
|
import mekanism.common.util.MekanismUtils;
|
|
|
|
import mekanism.common.util.MekanismUtils.ResourceType;
|
2013-05-23 19:30:12 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.renderer.GLAllocation;
|
|
|
|
import net.minecraft.client.renderer.texture.TextureMap;
|
|
|
|
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-05-28 06:29:29 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2013-05-23 19:30:12 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.Icon;
|
|
|
|
import net.minecraft.util.MathHelper;
|
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.ForgeDirection;
|
|
|
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
import cpw.mods.fml.client.FMLClientHandler;
|
2013-05-29 17:35:30 +02:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2013-05-23 19:30:12 +02:00
|
|
|
|
2013-05-29 17:35:30 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-05-23 19:30:12 +02:00
|
|
|
public class RenderConfigurableMachine extends TileEntitySpecialRenderer
|
|
|
|
{
|
|
|
|
private Minecraft mc = FMLClientHandler.instance().getClient();
|
|
|
|
|
|
|
|
private HashMap<ForgeDirection, HashMap<EnumColor, DisplayInteger>> cachedOverlays = new HashMap<ForgeDirection, HashMap<EnumColor, DisplayInteger>>();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick)
|
|
|
|
{
|
|
|
|
renderAModelAt((IConfigurable)tileEntity, x, y, z, partialTick);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void renderAModelAt(IConfigurable configurable, double x, double y, double z, float partialTick)
|
|
|
|
{
|
|
|
|
TileEntity tileEntity = (TileEntity)configurable;
|
|
|
|
EntityPlayer player = mc.thePlayer;
|
|
|
|
World world = mc.thePlayer.worldObj;
|
2013-05-28 06:29:29 +02:00
|
|
|
ItemStack itemStack = player.getCurrentEquippedItem();
|
2013-05-23 19:30:12 +02:00
|
|
|
MovingObjectPosition pos = player.rayTrace(8.0D, 1.0F);
|
|
|
|
|
2013-05-28 06:29:29 +02:00
|
|
|
if(pos != null && itemStack != null && itemStack.getItem() instanceof ItemConfigurator && ((ItemConfigurator)itemStack.getItem()).getState(itemStack) == 0)
|
2013-05-23 19:30:12 +02:00
|
|
|
{
|
|
|
|
int xPos = MathHelper.floor_double(pos.blockX);
|
|
|
|
int yPos = MathHelper.floor_double(pos.blockY);
|
|
|
|
int zPos = MathHelper.floor_double(pos.blockZ);
|
|
|
|
|
|
|
|
Object3D obj = new Object3D(xPos, yPos, zPos);
|
|
|
|
|
|
|
|
if(xPos == tileEntity.xCoord && yPos == tileEntity.yCoord && zPos == tileEntity.zCoord)
|
|
|
|
{
|
|
|
|
EnumColor color = configurable.getSideData().get(configurable.getConfiguration()[MekanismUtils.getBaseOrientation(pos.sideHit, configurable.getOrientation())]).color;
|
|
|
|
|
|
|
|
push();
|
|
|
|
|
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.4F);
|
|
|
|
|
2013-09-28 03:59:47 +02:00
|
|
|
bindTexture(MekanismUtils.getResource(ResourceType.TEXTURE_BLOCKS, "Overlay" + color.friendlyName.replace(" ", "") + ".png"));
|
2013-05-23 19:30:12 +02:00
|
|
|
GL11.glTranslatef((float)x, (float)y, (float)z);
|
|
|
|
|
|
|
|
int display = getOverlayDisplay(world, ForgeDirection.getOrientation(pos.sideHit), color).display;
|
|
|
|
GL11.glCallList(display);
|
|
|
|
|
|
|
|
pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void pop()
|
|
|
|
{
|
|
|
|
GL11.glPopAttrib();
|
|
|
|
GL11.glPopMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void push()
|
|
|
|
{
|
|
|
|
GL11.glPushMatrix();
|
|
|
|
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
|
|
|
GL11.glEnable(GL11.GL_CULL_FACE);
|
|
|
|
GL11.glEnable(GL11.GL_BLEND);
|
|
|
|
GL11.glDisable(GL11.GL_LIGHTING);
|
|
|
|
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
}
|
|
|
|
|
|
|
|
private DisplayInteger getOverlayDisplay(World world, ForgeDirection side, EnumColor color)
|
|
|
|
{
|
|
|
|
if(cachedOverlays.containsKey(side) && cachedOverlays.get(side).containsKey(color))
|
|
|
|
{
|
|
|
|
return cachedOverlays.get(side).get(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
Model3D toReturn = new Model3D();
|
|
|
|
toReturn.baseBlock = Block.stone;
|
2013-10-26 19:25:51 +02:00
|
|
|
toReturn.setTexture(MekanismRenderer.getColorIcon(color));
|
2013-05-23 19:30:12 +02:00
|
|
|
|
|
|
|
DisplayInteger display = new DisplayInteger();
|
|
|
|
|
|
|
|
if(cachedOverlays.containsKey(side))
|
|
|
|
{
|
|
|
|
cachedOverlays.get(side).put(color, display);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
HashMap<EnumColor, DisplayInteger> map = new HashMap<EnumColor, DisplayInteger>();
|
|
|
|
map.put(color, display);
|
|
|
|
cachedOverlays.put(side, map);
|
|
|
|
}
|
|
|
|
|
|
|
|
display.display = GLAllocation.generateDisplayLists(1);
|
|
|
|
GL11.glNewList(display.display, 4864);
|
|
|
|
|
|
|
|
switch(side)
|
|
|
|
{
|
|
|
|
case DOWN:
|
|
|
|
{
|
|
|
|
toReturn.minY = -.01;
|
|
|
|
toReturn.maxY = 0;
|
|
|
|
|
|
|
|
toReturn.minX = 0;
|
|
|
|
toReturn.minZ = 0;
|
|
|
|
toReturn.maxX = 1;
|
|
|
|
toReturn.maxZ = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case UP:
|
|
|
|
{
|
|
|
|
toReturn.minY = 1;
|
|
|
|
toReturn.maxY = 1.01;
|
|
|
|
|
|
|
|
toReturn.minX = 0;
|
|
|
|
toReturn.minZ = 0;
|
|
|
|
toReturn.maxX = 1;
|
|
|
|
toReturn.maxZ = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NORTH:
|
|
|
|
{
|
|
|
|
toReturn.minZ = -.01;
|
|
|
|
toReturn.maxZ = 0;
|
|
|
|
|
|
|
|
toReturn.minX = 0;
|
|
|
|
toReturn.minY = 0;
|
|
|
|
toReturn.maxX = 1;
|
|
|
|
toReturn.maxY = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SOUTH:
|
|
|
|
{
|
|
|
|
toReturn.minZ = 1;
|
|
|
|
toReturn.maxZ = 1.01;
|
|
|
|
|
|
|
|
toReturn.minX = 0;
|
|
|
|
toReturn.minY = 0;
|
|
|
|
toReturn.maxX = 1;
|
|
|
|
toReturn.maxY = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WEST:
|
|
|
|
{
|
|
|
|
toReturn.minX = -.01;
|
|
|
|
toReturn.maxX = 0;
|
|
|
|
|
|
|
|
toReturn.minY = 0;
|
|
|
|
toReturn.minZ = 0;
|
|
|
|
toReturn.maxY = 1;
|
|
|
|
toReturn.maxZ = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EAST:
|
|
|
|
{
|
|
|
|
toReturn.minX = 1;
|
|
|
|
toReturn.maxX = 1.01;
|
|
|
|
|
|
|
|
toReturn.minY = 0;
|
|
|
|
toReturn.minZ = 0;
|
|
|
|
toReturn.maxY = 1;
|
|
|
|
toReturn.maxZ = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-02 23:44:59 +02:00
|
|
|
MekanismRenderer.renderObject(toReturn);
|
2013-05-23 19:30:12 +02:00
|
|
|
GL11.glEndList();
|
|
|
|
|
|
|
|
return display;
|
|
|
|
}
|
|
|
|
}
|