Added block rendering for multimeter

This commit is contained in:
Calclavia 2013-08-03 21:38:12 -04:00
parent 50fe6c44d0
commit f77f7387b7
7 changed files with 143 additions and 21 deletions

View file

@ -1,6 +1,3 @@
/**
*
*/
package resonantinduction; package resonantinduction;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -14,6 +11,7 @@ import resonantinduction.multimeter.GuiMultimeter;
import resonantinduction.multimeter.TileEntityMultimeter; import resonantinduction.multimeter.TileEntityMultimeter;
import resonantinduction.render.BlockRenderingHandler; import resonantinduction.render.BlockRenderingHandler;
import resonantinduction.render.RenderEMContractor; import resonantinduction.render.RenderEMContractor;
import resonantinduction.render.RenderMultimeter;
import resonantinduction.render.RenderTesla; import resonantinduction.render.RenderTesla;
import resonantinduction.tesla.TileEntityTesla; import resonantinduction.tesla.TileEntityTesla;
import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.client.FMLClientHandler;
@ -37,6 +35,7 @@ public class ClientProxy extends CommonProxy
RenderingRegistry.registerBlockHandler(BlockRenderingHandler.INSTANCE); RenderingRegistry.registerBlockHandler(BlockRenderingHandler.INSTANCE);
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTesla.class, new RenderTesla()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTesla.class, new RenderTesla());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityMultimeter.class, new RenderMultimeter());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityEMContractor.class, new RenderEMContractor()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityEMContractor.class, new RenderEMContractor());
} }

View file

@ -116,7 +116,7 @@ public class ResonantInduction
public void preInit(FMLPreInitializationEvent evt) public void preInit(FMLPreInitializationEvent evt)
{ {
LOGGER.setParent(FMLLog.getLogger()); LOGGER.setParent(FMLLog.getLogger());
NetworkRegistry.instance().registerGuiHandler(this, this.proxy); NetworkRegistry.instance().registerGuiHandler(this, ResonantInduction.proxy);
CONFIGURATION.load(); CONFIGURATION.load();

View file

@ -225,9 +225,9 @@ public class ModelEMContractor extends ModelBase
public void render(float f5, boolean rotate) public void render(float f5, boolean rotate)
{ {
if(rotate) if (rotate)
{ {
teslapole.rotateAngleY = (float)Math.toRadians(Math.toDegrees(teslapole.rotateAngleY)+4 < 360 ? Math.toDegrees(teslapole.rotateAngleY)+4 : 0); teslapole.rotateAngleY = (float) Math.toRadians(Math.toDegrees(teslapole.rotateAngleY) + 4 < 360 ? Math.toDegrees(teslapole.rotateAngleY) + 4 : 0);
} }
frame1.render(f5); frame1.render(f5);

View file

@ -35,22 +35,22 @@ public class BlockMultimeter extends BlockBase implements ITileEntityProvider
public static int determineOrientation(World par0World, int par1, int par2, int par3, EntityLivingBase par4EntityLivingBase) public static int determineOrientation(World par0World, int par1, int par2, int par3, EntityLivingBase par4EntityLivingBase)
{ {
if (MathHelper.abs((float) par4EntityLivingBase.posX - (float) par1) < 2.0F && MathHelper.abs((float) par4EntityLivingBase.posZ - (float) par3) < 2.0F) if (MathHelper.abs((float) par4EntityLivingBase.posX - par1) < 2.0F && MathHelper.abs((float) par4EntityLivingBase.posZ - par3) < 2.0F)
{ {
double d0 = par4EntityLivingBase.posY + 1.82D - (double) par4EntityLivingBase.yOffset; double d0 = par4EntityLivingBase.posY + 1.82D - par4EntityLivingBase.yOffset;
if (d0 - (double) par2 > 2.0D) if (d0 - par2 > 2.0D)
{ {
return 1; return 1;
} }
if ((double) par2 - d0 > 0.0D) if (par2 - d0 > 0.0D)
{ {
return 0; return 0;
} }
} }
int l = MathHelper.floor_double((double) (par4EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; int l = MathHelper.floor_double(par4EntityLivingBase.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
return l == 0 ? 2 : (l == 1 ? 5 : (l == 2 ? 3 : (l == 3 ? 4 : 0))); return l == 0 ? 2 : (l == 1 ? 5 : (l == 2 ? 3 : (l == 3 ? 4 : 0)));
} }
@ -61,6 +61,7 @@ public class BlockMultimeter extends BlockBase implements ITileEntityProvider
world.setBlockMetadataWithNotify(x, y, z, l, 2); world.setBlockMetadataWithNotify(x, y, z, l, 2);
} }
@Override
public Icon getIcon(int side, int metadata) public Icon getIcon(int side, int metadata)
{ {
if (side == metadata) if (side == metadata)

View file

@ -13,7 +13,6 @@ import org.lwjgl.opengl.GL11;
import resonantinduction.PacketHandler; import resonantinduction.PacketHandler;
import resonantinduction.ResonantInduction; import resonantinduction.ResonantInduction;
import resonantinduction.multimeter.TileEntityMultimeter.DetectMode;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@ -58,7 +57,7 @@ public class GuiMultimeter extends GuiContainer
try try
{ {
PacketHandler.sendTileEntityPacketToServer(this.tileEntity, (byte) 3, (float) Float.parseFloat(this.textFieldLimit.getText())); PacketHandler.sendTileEntityPacketToServer(this.tileEntity, (byte) 3, Float.parseFloat(this.textFieldLimit.getText()));
} }
catch (Exception e) catch (Exception e)
{ {
@ -96,11 +95,12 @@ public class GuiMultimeter extends GuiContainer
GL11.glColor4f(1, 1, 1, 1); GL11.glColor4f(1, 1, 1, 1);
this.drawTexturedModalRect(this.containerWidth, this.containerHeight, 0, 0, this.xSize, this.ySize); this.drawTexturedModalRect(this.containerWidth, this.containerHeight, 0, 0, this.xSize, this.ySize);
/*if (this.tileEntity.getMode() != DetectMode.NONE) /*
{ * if (this.tileEntity.getMode() != DetectMode.NONE) { int length = (int)
int length = (int) (Math.abs(this.tileEntity.getDetectedEnergy() - this.tileEntity.getLimit()) / this.tileEntity.getLimit()) * 110; * (Math.abs(this.tileEntity.getDetectedEnergy() - this.tileEntity.getLimit()) /
this.drawTexturedModalRect(this.containerWidth + 13, this.containerHeight + 128 - length, 176, 0, 30, length); * this.tileEntity.getLimit()) * 110; this.drawTexturedModalRect(this.containerWidth + 13,
}*/ * this.containerHeight + 128 - length, 176, 0, 30, length); }
*/
} }
@Override @Override

View file

@ -0,0 +1,122 @@
package resonantinduction.render;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import org.lwjgl.opengl.GL11;
import resonantinduction.multimeter.TileEntityMultimeter;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Class used to render text onto the multimeter block.
*
* @author Calclavia
*
*/
@SideOnly(Side.CLIENT)
public class RenderMultimeter extends TileEntitySpecialRenderer
{
@Override
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float var8)
{
TileEntityMultimeter tileEntity = (TileEntityMultimeter) t;
ForgeDirection direction = ForgeDirection.getOrientation(tileEntity.worldObj.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord));
/**
* Render from side 2 to 6. This means render all sides excluding top and bottom.
*/
for (int side = 0; side < 6; side++)
{
if (direction.ordinal() != side)
{
GL11.glPushMatrix();
GL11.glPolygonOffset(-10, -10);
GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
float dx = 1F / 16;
float dz = 1F / 16;
float displayWidth = 1 - 2F / 16;
float displayHeight = 1 - 2F / 16;
GL11.glTranslatef((float) x, (float) y, (float) z);
switch (side)
{
case 1:
break;
case 0:
GL11.glTranslatef(1, 1, 0);
GL11.glRotatef(180, 1, 0, 0);
GL11.glRotatef(180, 0, 1, 0);
break;
case 3:
GL11.glTranslatef(0, 1, 0);
GL11.glRotatef(0, 0, 1, 0);
GL11.glRotatef(90, 1, 0, 0);
break;
case 2:
GL11.glTranslatef(1, 1, 1);
GL11.glRotatef(180, 0, 1, 0);
GL11.glRotatef(90, 1, 0, 0);
break;
case 5:
GL11.glTranslatef(0, 1, 1);
GL11.glRotatef(90, 0, 1, 0);
GL11.glRotatef(90, 1, 0, 0);
break;
case 4:
GL11.glTranslatef(1, 1, 0);
GL11.glRotatef(-90, 0, 1, 0);
GL11.glRotatef(90, 1, 0, 0);
break;
}
GL11.glTranslatef(dx + displayWidth / 2, 1F, dz + displayHeight / 2);
GL11.glRotatef(-90, 1, 0, 0);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
FontRenderer fontRenderer = this.getFontRenderer();
String joules = Math.round(tileEntity.getDetectedEnergy()) + " J";
int stringWidth = Math.max(fontRenderer.getStringWidth(joules), 0);
// maxWidth += 8;
int lineHeight = fontRenderer.FONT_HEIGHT + 2;
int requiredHeight = lineHeight * 1;
/**
* Create an average scale.
*/
float scaleX = displayWidth / stringWidth;
float scaleY = displayHeight / requiredHeight;
float scale = (float) (Math.min(scaleX, scaleY) * 0.8);
GL11.glScalef(scale, -scale, scale);
GL11.glDepthMask(false);
int realHeight = (int) Math.floor(displayHeight / scale);
int realWidth = (int) Math.floor(displayWidth / scale);
int offsetY = (realHeight - requiredHeight) / 2;
int offsetX = (realWidth - stringWidth) / 2;
GL11.glDisable(GL11.GL_LIGHTING);
fontRenderer.drawString(joules, offsetX - realWidth / 2, 1 + offsetY - realHeight / 2 + 0 * lineHeight, 1);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glDepthMask(true);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glDisable(GL11.GL_POLYGON_OFFSET_FILL);
GL11.glPopMatrix();
}
}
}
}