Multimeter now renders connected textures
This commit is contained in:
parent
411c3b8161
commit
356edf9b62
4 changed files with 55 additions and 143 deletions
|
@ -34,10 +34,10 @@ public class ItemMultimeter extends ItemMultipartBase
|
||||||
/**
|
/**
|
||||||
* If we're clicking on the multipart
|
* If we're clicking on the multipart
|
||||||
*/
|
*/
|
||||||
if (world.getBlockTileEntity(pos.x, pos.y, pos.z) instanceof TileMultipart && !ControlKeyModifer.isControlDown(player))
|
/*if (world.getBlockTileEntity(pos.x, pos.y, pos.z) instanceof TileMultipart && !ControlKeyModifer.isControlDown(player))
|
||||||
{
|
{
|
||||||
pos.offset(side ^ 1, -1);
|
pos.offset(side ^ 1, -1);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
PartMultimeter part = (PartMultimeter) MultiPartRegistry.createPart("resonant_induction_multimeter", false);
|
PartMultimeter part = (PartMultimeter) MultiPartRegistry.createPart("resonant_induction_multimeter", false);
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ public class ItemMultimeter extends ItemMultipartBase
|
||||||
{
|
{
|
||||||
part.preparePlacement(side, itemStack.getItemDamage());
|
part.preparePlacement(side, itemStack.getItemDamage());
|
||||||
}
|
}
|
||||||
System.out.println("OFFSET"+pos);
|
|
||||||
return part;
|
return part;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ import codechicken.multipart.JNormalOcclusion;
|
||||||
import codechicken.multipart.NormalOcclusionTest;
|
import codechicken.multipart.NormalOcclusionTest;
|
||||||
import codechicken.multipart.TFacePart;
|
import codechicken.multipart.TFacePart;
|
||||||
import codechicken.multipart.TMultiPart;
|
import codechicken.multipart.TMultiPart;
|
||||||
|
import codechicken.multipart.TileMultipart;
|
||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||||
* @author Calclavia
|
* @author Calclavia
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class PartMultimeter extends JCuboidPart implements TFacePart, JNormalOcclusion, IPacketReceiver
|
public class PartMultimeter extends JCuboidPart implements TFacePart, JNormalOcclusion, IRedstonePart, IPacketReceiver
|
||||||
{
|
{
|
||||||
public static Cuboid6[][] bounds = new Cuboid6[6][2];
|
public static Cuboid6[][] bounds = new Cuboid6[6][2];
|
||||||
|
|
||||||
|
@ -95,6 +96,23 @@ public class PartMultimeter extends JCuboidPart implements TFacePart, JNormalOcc
|
||||||
this.side = (byte) (side ^ 1);
|
this.side = (byte) (side ^ 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasMultimeter(int x, int y, int z)
|
||||||
|
{
|
||||||
|
TileEntity tileEntity = world().getBlockTileEntity(x, y, z);
|
||||||
|
|
||||||
|
if (tileEntity instanceof TileMultipart)
|
||||||
|
{
|
||||||
|
TMultiPart part = ((TileMultipart) tileEntity).partMap(side);
|
||||||
|
|
||||||
|
if (part instanceof PartMultimeter)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item)
|
public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item)
|
||||||
{
|
{
|
||||||
|
@ -379,19 +397,19 @@ public class PartMultimeter extends JCuboidPart implements TFacePart, JNormalOcc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
@Override
|
||||||
public boolean canConnectRedstone(int arg0)
|
public boolean canConnectRedstone(int arg0)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
@Override
|
||||||
public int strongPowerLevel(int arg0)
|
public int strongPowerLevel(int arg0)
|
||||||
{
|
{
|
||||||
return redstoneOn ? 14 : 0;
|
return redstoneOn ? 14 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
@Override
|
||||||
public int weakPowerLevel(int arg0)
|
public int weakPowerLevel(int arg0)
|
||||||
{
|
{
|
||||||
return redstoneOn ? 14 : 0;
|
return redstoneOn ? 14 : 0;
|
||||||
|
|
|
@ -2,13 +2,17 @@ package resonantinduction.electrical.multimeter;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.FontRenderer;
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
|
import net.minecraft.client.renderer.texture.TextureMap;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import calclavia.lib.render.RenderUtility;
|
import calclavia.lib.render.RenderUtility;
|
||||||
|
import resonantinduction.archaic.Archaic;
|
||||||
import resonantinduction.core.Reference;
|
import resonantinduction.core.Reference;
|
||||||
|
import resonantinduction.core.ResonantInduction;
|
||||||
|
import resonantinduction.mechanical.Mechanical;
|
||||||
import universalelectricity.api.energy.UnitDisplay;
|
import universalelectricity.api.energy.UnitDisplay;
|
||||||
import universalelectricity.api.energy.UnitDisplay.Unit;
|
import universalelectricity.api.energy.UnitDisplay.Unit;
|
||||||
import cpw.mods.fml.client.FMLClientHandler;
|
import cpw.mods.fml.client.FMLClientHandler;
|
||||||
|
@ -18,6 +22,8 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||||
/**
|
/**
|
||||||
* Class used to render text onto the multimeter block.
|
* Class used to render text onto the multimeter block.
|
||||||
*
|
*
|
||||||
|
* The more space we have, the more information and detail we render.
|
||||||
|
*
|
||||||
* @author Calclavia
|
* @author Calclavia
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -29,145 +35,33 @@ public class RenderMultimeter
|
||||||
|
|
||||||
public static void render(PartMultimeter part, double x, double y, double z)
|
public static void render(PartMultimeter part, double x, double y, double z)
|
||||||
{
|
{
|
||||||
GL11.glPushMatrix();
|
|
||||||
RenderUtility.rotateFaceBlockToSide(part.getDirection());
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The more space we have, the more information we render.
|
|
||||||
*
|
|
||||||
* 1x1: Show storage
|
|
||||||
* 1x2: Show storage + capacity
|
|
||||||
* 3x3: Show graph behind
|
|
||||||
*/
|
|
||||||
|
|
||||||
RenderUtility.renderText("test", 0, 1, x, y, z);
|
|
||||||
GL11.glPopMatrix();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void renderOld(PartMultimeter tileEntity, double x, double y, double z)
|
|
||||||
{
|
|
||||||
ForgeDirection direction = tileEntity.getDirection();
|
|
||||||
|
|
||||||
GL11.glPushMatrix();
|
GL11.glPushMatrix();
|
||||||
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5);
|
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5);
|
||||||
GL11.glRotatef(90, 0, 0, 1);
|
RenderUtility.rotateFaceBlockToSideOutwards(part.getDirection().getOpposite());
|
||||||
GL11.glTranslated(0, -1, 0);
|
|
||||||
|
|
||||||
switch (direction)
|
|
||||||
{
|
|
||||||
case UP:
|
|
||||||
GL11.glRotatef(90, 0, 1, 0);
|
|
||||||
break;
|
|
||||||
case DOWN:
|
|
||||||
GL11.glRotatef(-90, 0, 1, 0);
|
|
||||||
break;
|
|
||||||
case NORTH:
|
|
||||||
GL11.glRotatef(180, 0, 1, 0);
|
|
||||||
GL11.glRotatef(180, 0, 0, 1);
|
|
||||||
GL11.glTranslatef(0, -2, 0);
|
|
||||||
break;
|
|
||||||
case SOUTH:
|
|
||||||
break;
|
|
||||||
case WEST:
|
|
||||||
GL11.glTranslatef(0, 1, 1);
|
|
||||||
GL11.glRotatef(-90, 1, 0, 0);
|
|
||||||
break;
|
|
||||||
case EAST:
|
|
||||||
GL11.glTranslatef(0, 1, -1);
|
|
||||||
GL11.glRotatef(90, 1, 0, 0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
|
|
||||||
MODEL.render(0.0625f);
|
|
||||||
|
|
||||||
GL11.glPopMatrix();
|
|
||||||
|
|
||||||
GL11.glPushMatrix();
|
GL11.glPushMatrix();
|
||||||
GL11.glPolygonOffset(-10, -10);
|
RenderUtility.bind(TextureMap.locationBlocksTexture);
|
||||||
GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
|
// Render the main panel
|
||||||
|
RenderUtility.renderCube(-0.5, -0.05, -0.5, 0.5, 0.05, 0.5, Archaic.blockMachinePart, ResonantInduction.loadedIconMap.get(Reference.PREFIX + "multimeter_screen"));
|
||||||
float dx = 1F / 16;
|
ForgeDirection dir = part.getDirection();
|
||||||
float dz = 1F / 16;
|
final int metadata = 8;
|
||||||
float displayWidth = 1 - 2F / 16;
|
// Render edges
|
||||||
float displayHeight = 1 - 2F / 16;
|
// UP
|
||||||
GL11.glTranslatef((float) x, (float) y, (float) z);
|
if (!part.hasMultimeter(part.x(), part.y() + 1, part.z()))
|
||||||
|
RenderUtility.renderCube(-0.501, -0.0501, -0.501, 0.501, 0.0501, -0.44, Archaic.blockMachinePart, null, metadata);
|
||||||
switch (direction)
|
// DOWN
|
||||||
{
|
if (!part.hasMultimeter(part.x(), part.y() - 1, part.z()))
|
||||||
case UP:
|
RenderUtility.renderCube(-0.501, -0.0501, 0.44, 0.501, 0.0501, 0.501, Archaic.blockMachinePart, null, metadata);
|
||||||
GL11.glTranslatef(1, 1, 0);
|
// LEFT
|
||||||
GL11.glRotatef(180, 1, 0, 0);
|
if (((dir == ForgeDirection.WEST || dir == ForgeDirection.EAST) && !part.hasMultimeter(part.x(), part.y(), part.z() - 1)) || ((dir == ForgeDirection.SOUTH || dir == ForgeDirection.NORTH) && !part.hasMultimeter(part.x() + 1, part.y(), part.z())))
|
||||||
GL11.glRotatef(180, 0, 1, 0);
|
RenderUtility.renderCube(-0.501, -0.0501, -0.501, -0.44, 0.0501, 0.501, Archaic.blockMachinePart, null, metadata);
|
||||||
GL11.glTranslatef(0, -0.9f, -0.1f);
|
// RIGHT
|
||||||
break;
|
if (((dir == ForgeDirection.WEST || dir == ForgeDirection.EAST) && !part.hasMultimeter(part.x(), part.y(), part.z() + 1)) || ((dir == ForgeDirection.SOUTH || dir == ForgeDirection.NORTH) && !part.hasMultimeter(part.x() - 1, part.y(), part.z())))
|
||||||
case DOWN:
|
RenderUtility.renderCube(0.44, -0.0501, -0.501, 0.501, 0.0501, 0.501, Archaic.blockMachinePart, null, metadata);
|
||||||
GL11.glRotatef(180, 0, 1, 0);
|
GL11.glPopMatrix();
|
||||||
GL11.glTranslatef(-1, -0.9f, -1.1f);
|
GL11.glTranslated(0, 0.05, 0);
|
||||||
break;
|
// Render all the multimeter text
|
||||||
case SOUTH:
|
RenderUtility.renderText("" + part.getDetectedEnergy(), 0.8f);
|
||||||
GL11.glTranslatef(1, 1, 1);
|
|
||||||
GL11.glRotatef(180, 0, 1, 0);
|
|
||||||
GL11.glRotatef(90, 1, 0, 0);
|
|
||||||
GL11.glTranslatef(0, -0.9f, -0.1f);
|
|
||||||
break;
|
|
||||||
case NORTH:
|
|
||||||
GL11.glTranslatef(0, 1, 0);
|
|
||||||
GL11.glRotatef(0, 0, 1, 0);
|
|
||||||
GL11.glRotatef(90, 1, 0, 0);
|
|
||||||
GL11.glTranslatef(0, -0.9f, -0.1f);
|
|
||||||
break;
|
|
||||||
case EAST:
|
|
||||||
GL11.glTranslatef(1, 1, 0);
|
|
||||||
GL11.glRotatef(-90, 0, 1, 0);
|
|
||||||
GL11.glRotatef(90, 1, 0, 0);
|
|
||||||
GL11.glTranslatef(0, -0.9f, -0.1f);
|
|
||||||
break;
|
|
||||||
case WEST:
|
|
||||||
GL11.glTranslatef(0, 1, 1);
|
|
||||||
GL11.glRotatef(90, 0, 1, 0);
|
|
||||||
GL11.glRotatef(90, 1, 0, 0);
|
|
||||||
GL11.glTranslatef(0, -0.9f, -0.1f);
|
|
||||||
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 = Minecraft.getMinecraft().fontRenderer;
|
|
||||||
|
|
||||||
String joules = UnitDisplay.getDisplayShort(tileEntity.getDetectedEnergy(), Unit.JOULES);
|
|
||||||
|
|
||||||
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();
|
GL11.glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Binary file not shown.
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Loading…
Reference in a new issue