diff --git a/src/resonantinduction/ClientProxy.java b/src/resonantinduction/ClientProxy.java index 89f25e70..fd342465 100644 --- a/src/resonantinduction/ClientProxy.java +++ b/src/resonantinduction/ClientProxy.java @@ -1,6 +1,3 @@ -/** - * - */ package resonantinduction; import net.minecraft.entity.player.EntityPlayer; @@ -14,6 +11,7 @@ import resonantinduction.multimeter.GuiMultimeter; import resonantinduction.multimeter.TileEntityMultimeter; import resonantinduction.render.BlockRenderingHandler; import resonantinduction.render.RenderEMContractor; +import resonantinduction.render.RenderMultimeter; import resonantinduction.render.RenderTesla; import resonantinduction.tesla.TileEntityTesla; import cpw.mods.fml.client.FMLClientHandler; @@ -37,6 +35,7 @@ public class ClientProxy extends CommonProxy RenderingRegistry.registerBlockHandler(BlockRenderingHandler.INSTANCE); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTesla.class, new RenderTesla()); + ClientRegistry.bindTileEntitySpecialRenderer(TileEntityMultimeter.class, new RenderMultimeter()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityEMContractor.class, new RenderEMContractor()); } diff --git a/src/resonantinduction/ResonantInduction.java b/src/resonantinduction/ResonantInduction.java index b6dacc3e..5a0df48e 100644 --- a/src/resonantinduction/ResonantInduction.java +++ b/src/resonantinduction/ResonantInduction.java @@ -116,14 +116,14 @@ public class ResonantInduction public void preInit(FMLPreInitializationEvent evt) { LOGGER.setParent(FMLLog.getLogger()); - NetworkRegistry.instance().registerGuiHandler(this, this.proxy); + NetworkRegistry.instance().registerGuiHandler(this, ResonantInduction.proxy); CONFIGURATION.load(); // Config POWER_PER_COAL = (float) CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Coal Wattage", POWER_PER_COAL).getDouble(POWER_PER_COAL); SOUND_FXS = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Tesla Sound FXs", SOUND_FXS).getBoolean(SOUND_FXS); - + TileEntityEMContractor.ACCELERATION = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Contractor Item Acceleration", TileEntityEMContractor.ACCELERATION).getDouble(TileEntityEMContractor.ACCELERATION); TileEntityEMContractor.MAX_REACH = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Contractor Max Item Reach", TileEntityEMContractor.MAX_REACH).getInt(TileEntityEMContractor.MAX_REACH); TileEntityEMContractor.MAX_SPEED = CONFIGURATION.get(Configuration.CATEGORY_GENERAL, "Contractor Max Item Speed", TileEntityEMContractor.MAX_SPEED).getDouble(TileEntityEMContractor.MAX_SPEED); diff --git a/src/resonantinduction/model/ModelEMContractor.java b/src/resonantinduction/model/ModelEMContractor.java index 41fe2727..a52f9058 100644 --- a/src/resonantinduction/model/ModelEMContractor.java +++ b/src/resonantinduction/model/ModelEMContractor.java @@ -225,11 +225,11 @@ public class ModelEMContractor extends ModelBase 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); frame2.render(f5); frame3.render(f5); diff --git a/src/resonantinduction/multimeter/BlockMultimeter.java b/src/resonantinduction/multimeter/BlockMultimeter.java index 4434b3fd..0f8e3fa6 100644 --- a/src/resonantinduction/multimeter/BlockMultimeter.java +++ b/src/resonantinduction/multimeter/BlockMultimeter.java @@ -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) { - 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; } - if ((double) par2 - d0 > 0.0D) + if (par2 - d0 > 0.0D) { 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))); } @@ -61,6 +61,7 @@ public class BlockMultimeter extends BlockBase implements ITileEntityProvider world.setBlockMetadataWithNotify(x, y, z, l, 2); } + @Override public Icon getIcon(int side, int metadata) { if (side == metadata) diff --git a/src/resonantinduction/multimeter/GuiMultimeter.java b/src/resonantinduction/multimeter/GuiMultimeter.java index ec07f9a7..1904d9fb 100644 --- a/src/resonantinduction/multimeter/GuiMultimeter.java +++ b/src/resonantinduction/multimeter/GuiMultimeter.java @@ -13,7 +13,6 @@ import org.lwjgl.opengl.GL11; import resonantinduction.PacketHandler; import resonantinduction.ResonantInduction; -import resonantinduction.multimeter.TileEntityMultimeter.DetectMode; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -58,7 +57,7 @@ public class GuiMultimeter extends GuiContainer 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) { @@ -96,11 +95,12 @@ public class GuiMultimeter extends GuiContainer GL11.glColor4f(1, 1, 1, 1); this.drawTexturedModalRect(this.containerWidth, this.containerHeight, 0, 0, this.xSize, this.ySize); - /*if (this.tileEntity.getMode() != DetectMode.NONE) - { - int length = (int) (Math.abs(this.tileEntity.getDetectedEnergy() - this.tileEntity.getLimit()) / this.tileEntity.getLimit()) * 110; - this.drawTexturedModalRect(this.containerWidth + 13, this.containerHeight + 128 - length, 176, 0, 30, length); - }*/ + /* + * if (this.tileEntity.getMode() != DetectMode.NONE) { int length = (int) + * (Math.abs(this.tileEntity.getDetectedEnergy() - this.tileEntity.getLimit()) / + * this.tileEntity.getLimit()) * 110; this.drawTexturedModalRect(this.containerWidth + 13, + * this.containerHeight + 128 - length, 176, 0, 30, length); } + */ } @Override diff --git a/src/resonantinduction/render/RenderEMContractor.java b/src/resonantinduction/render/RenderEMContractor.java index 5b538d23..77817494 100644 --- a/src/resonantinduction/render/RenderEMContractor.java +++ b/src/resonantinduction/render/RenderEMContractor.java @@ -58,7 +58,7 @@ public class RenderEMContractor extends TileEntitySpecialRenderer { this.func_110628_a(TEXTURE_PUSH); } - + MODEL.render(0.0625f, true); GL11.glPopMatrix(); diff --git a/src/resonantinduction/render/RenderMultimeter.java b/src/resonantinduction/render/RenderMultimeter.java new file mode 100644 index 00000000..03361a22 --- /dev/null +++ b/src/resonantinduction/render/RenderMultimeter.java @@ -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(); + } + } + } +} \ No newline at end of file