Added I/O display for cap banks.

This commit is contained in:
CrazyPants committed 2014-12-05 23:35:36 +08:00
1 parent c55a5b8209
commit 3cd0b7f736
10 files changed
+222 -89

No files matched your search

@@ -1,6 +1,7 @@
package crazypants.enderio.machine.capbank;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;
@@ -34,6 +35,7 @@ import crazypants.enderio.gui.TooltipAddera;
import crazypants.enderio.machine.IoMode;
import crazypants.enderio.machine.capbank.network.CapBankClientNetwork;
import crazypants.enderio.machine.capbank.network.ICapBankNetwork;
import crazypants.enderio.machine.capbank.network.NetworkUtil;
import crazypants.enderio.machine.capbank.packet.PacketGuiChange;
import crazypants.enderio.machine.capbank.packet.PacketNetworkEnergyRequest;
import crazypants.enderio.machine.capbank.packet.PacketNetworkEnergyResponse;
@@ -84,6 +86,8 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
private IIcon[] outputIcons;
@SideOnly(Side.CLIENT)
private IIcon[] lockedIcons;
@SideOnly(Side.CLIENT)
private IIcon infoPanelIcon;
protected BlockCapBank() {
super(ModObject.blockCapBank.unlocalisedName, TileCapBank.class);
@@ -226,6 +230,7 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
blockIcon = IIconRegister.registerIcon("enderio:capacitorBank");
gaugeIcon = IIconRegister.registerIcon("enderio:capacitorBankOverlays");
fillBarIcon = IIconRegister.registerIcon("enderio:capacitorBankFillBar");
infoPanelIcon = IIconRegister.registerIcon("enderio:capBankInfoPanel");
blockIcons = new IIcon[CapBankType.types().size()];
borderIcons = new IIcon[CapBankType.types().size()];
@@ -290,6 +295,11 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
if(!(te instanceof TileCapBank)) {
return blockIcons[0];
}
// if(true) {
// return IconUtil.blankTexture;
// }
TileCapBank cb = (TileCapBank) te;
ForgeDirection face = ForgeDirection.values()[side];
@@ -309,14 +319,21 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
return lockedIcons[meta];
}
@SideOnly(Side.CLIENT)
public IIcon getGaugeIcon() {
return gaugeIcon;
}
@SideOnly(Side.CLIENT)
public IIcon getFillBarIcon() {
return fillBarIcon;
}
@SideOnly(Side.CLIENT)
public IIcon getInfoPanelIcon() {
return infoPanelIcon;
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block blockId) {
if(world.isRemote) {
@@ -347,12 +364,34 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
if(stack.stackTagCompound != null) {
cb.readCommonNBT(stack.stackTagCompound);
}
Collection<TileCapBank> neigbours = NetworkUtil.getNeigbours(cb);
if(neigbours.isEmpty()) {
int heading = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
ForgeDirection dir = getDirForHeading(heading);
cb.setDisplayType(dir, InfoDisplayType.LEVEL_BAR);
}
if(world.isRemote) {
return;
}
world.markBlockForUpdate(x, y, z);
}
protected ForgeDirection getDirForHeading(int heading) {
switch (heading) {
case 0:
return ForgeDirection.values()[2];
case 1:
return ForgeDirection.values()[5];
case 2:
return ForgeDirection.values()[3];
case 3:
default:
return ForgeDirection.values()[4];
}
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
@@ -4,7 +4,8 @@ package crazypants.enderio.machine.capbank;
public enum InfoDisplayType {
NONE,
LEVEL_BAR;
LEVEL_BAR,
IO;
public InfoDisplayType next() {
int ord = ordinal();
@@ -344,7 +344,7 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
for (Entry<ForgeDirection, InfoDisplayType> entry : faceDisplayTypes.entrySet()) {
BlockCoord bc = getLocation().getLocation(entry.getKey());
Block block = worldObj.getBlock(bc.x, bc.y, bc.z);
if(block != null && block.isOpaqueCube()) {
if(block != null && (block.isOpaqueCube() || block == EnderIO.blockCapBank)) {
reset.add(entry.getKey());
}
}
@@ -1,7 +1,9 @@
package crazypants.enderio.machine.capbank.render;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
@@ -21,24 +23,24 @@ import crazypants.enderio.machine.capbank.BlockCapBank;
import crazypants.enderio.machine.capbank.CapBankType;
import crazypants.enderio.machine.capbank.InfoDisplayType;
import crazypants.enderio.machine.capbank.TileCapBank;
import crazypants.enderio.machine.capbank.network.CapBankClientNetwork;
import crazypants.render.BoundingBox;
import crazypants.render.ConnectedTextureRenderer;
import crazypants.render.CubeRenderer;
import crazypants.render.CustomCubeRenderer;
import crazypants.render.RenderUtil;
import crazypants.util.ForgeDirectionOffsets;
import crazypants.vecmath.Vector3d;
public class CapBankRenderer extends TileEntitySpecialRenderer implements ISimpleBlockRenderingHandler, IItemRenderer {
private ConnectedTextureRenderer connectedTexRenderer;
private FillGauge fillGauge;
private Map<InfoDisplayType, IInfoRenderer> infoRenderers;
public CapBankRenderer() {
connectedTexRenderer = new ConnectedTextureRenderer();
connectedTexRenderer.setMatchMeta(true);
fillGauge = new FillGauge();
infoRenderers = new HashMap<InfoDisplayType, IInfoRenderer>();
infoRenderers.put(InfoDisplayType.LEVEL_BAR, new FillGauge());
infoRenderers.put(InfoDisplayType.IO, new IoDisplay());
}
//------- Block
@@ -121,20 +123,10 @@ public class CapBankRenderer extends TileEntitySpecialRenderer implements ISimpl
TileCapBank cb = (TileCapBank) te;
float f = cb.getWorldObj().getBlockLightValue(te.xCoord, te.yCoord, te.zCoord);
int l = cb.getWorldObj().getLightBrightnessForSkyBlocks(te.xCoord, te.yCoord, te.zCoord, 0);
int l1 = l % 65536;
int l2 = l / 65536;
Tessellator.instance.setColorOpaque_F(f, f, f);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, l1, l2);
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
GL11.glPolygonOffset(-1.0f, -1.0f);
GL11.glDisable(GL11.GL_LIGHTING);
// GL11.glEnable(GL11.GL_BLEND);
// GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glPushMatrix();
GL11.glTranslatef((float) x, (float) y, (float) z);
@@ -142,64 +134,16 @@ public class CapBankRenderer extends TileEntitySpecialRenderer implements ISimpl
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
InfoDisplayType type = cb.getDisplayType(dir);
if(type != InfoDisplayType.NONE) {
renderInfoDisplay(cb, dir, type, x, y, z, partialTick);
IInfoRenderer rend = infoRenderers.get(type);
if(rend != null) {
rend.render(cb, dir, x, y, z, partialTick);
}
}
}
GL11.glPopMatrix();
GL11.glPopAttrib();
//GL11.glDisable(GL11.GL_POLYGON_OFFSET_FILL);
}
private void renderInfoDisplay(TileCapBank cb, ForgeDirection dir, InfoDisplayType type, double x, double y, double z, float partialTick) {
CapBankClientNetwork nw = (CapBankClientNetwork) cb.getNetwork();
if(type == InfoDisplayType.LEVEL_BAR && nw != null) {
nw.requestPowerUpdate(cb, 20);
}
RenderUtil.bindBlockTexture();
int brightness = cb.getWorldObj().getLightBrightnessForSkyBlocks(cb.xCoord + dir.offsetX, cb.yCoord + dir.offsetY, cb.zCoord + dir.offsetZ, 0);
Tessellator tes = Tessellator.instance;
tes.startDrawingQuads();
tes.setBrightness(brightness);
tes.setColorOpaque_F(1, 1, 1);
if(type == InfoDisplayType.LEVEL_BAR) {
fillGauge.render(cb, nw, dir);
}
tes.draw();
}
protected BoundingBox getBoundForFace(ForgeDirection dir) {
double widthScale = 0.25;
double heightScale = 0.8;
;
boolean isUp = dir.offsetY != 0;
double xScale = dir.offsetX == 0 ? widthScale : 1;
double yScale = isUp ? widthScale : heightScale;
double zScale = isUp ? heightScale : (dir.offsetZ == 0 ? widthScale : 1);
BoundingBox bb = BoundingBox.UNIT_CUBE;
Vector3d off = ForgeDirectionOffsets.forDirCopy(dir);
off.scale(-1);
bb = bb.translate(off);
bb = bb.scale(xScale, yScale, zScale);
off.scale(-1);
bb = bb.translate(off);
return bb;
}
// private int getEnergyStoredScaled(CapBankClientNetwork network, int scale) {
// return (int) VecmathUtil.clamp(Math.round(scale * network.getEnergyStoredRatio()), 0, scale);
// }
}
@@ -22,7 +22,7 @@ import crazypants.vecmath.Vector3d;
import crazypants.vecmath.Vector4f;
import crazypants.vecmath.Vertex;
public class FillGauge {
public class FillGauge implements IInfoRenderer {
private static final double HEIGHT = 0.75;
private static final double VERT_BORDER = (1 - HEIGHT) / 2;
@@ -47,17 +47,35 @@ public class FillGauge {
FillGauge() {
}
public void render(TileCapBank cb, CapBankClientNetwork nw, ForgeDirection dir) {
@Override
public void render(TileCapBank cb, ForgeDirection dir, double x, double y, double z, float partialTick) {
if(gaugeVertexCache == null) {
createVertexCache();
}
CapBankClientNetwork nw = null;
if(cb.getNetwork() != null) {
nw = (CapBankClientNetwork) cb.getNetwork();
nw.requestPowerUpdate(cb, 20);
}
RenderUtil.bindBlockTexture();
int brightness = cb.getWorldObj().getLightBrightnessForSkyBlocks(cb.xCoord + dir.offsetX, cb.yCoord + dir.offsetY, cb.zCoord + dir.offsetZ, 0);
Tessellator tes = Tessellator.instance;
tes.startDrawingQuads();
tes.setBrightness(brightness);
tes.setColorOpaque_F(1, 1, 1);
GaugeInfo info = getGaugeInfo(cb, dir);
GaugeKey key = new GaugeKey(dir, info.type);
List<Vertex> verts = gaugeVertexCache.get(key);
RenderUtil.addVerticesToTessellator(verts, Tessellator.instance);
renderFillBar(key, nw, info);
tes.draw();
}
private void renderFillBar(GaugeKey key, CapBankClientNetwork nw, GaugeInfo info) {
@@ -0,0 +1,10 @@
package crazypants.enderio.machine.capbank.render;
import net.minecraftforge.common.util.ForgeDirection;
import crazypants.enderio.machine.capbank.TileCapBank;
public interface IInfoRenderer {
void render(TileCapBank cb, ForgeDirection dir, double x, double y, double z, float partialTick);
}
@@ -0,0 +1,128 @@
package crazypants.enderio.machine.capbank.render;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
import crazypants.enderio.EnderIO;
import crazypants.enderio.machine.capbank.TileCapBank;
import crazypants.enderio.machine.capbank.network.CapBankClientNetwork;
import crazypants.enderio.machine.power.PowerDisplayUtil;
import crazypants.render.BoundingBox;
import crazypants.render.ColorUtil;
import crazypants.render.RenderUtil;
import crazypants.vecmath.Vector3f;
import crazypants.vecmath.Vertex;
public class IoDisplay implements IInfoRenderer {
@Override
public void render(TileCapBank cb, ForgeDirection dir, double x, double y, double z, float partialTick) {
boolean selfIlum = true;
int brightness = 0;
if(!selfIlum) {
brightness = cb.getWorldObj().getLightBrightnessForSkyBlocks(cb.xCoord + dir.offsetX, cb.yCoord + dir.offsetY, cb.zCoord + dir.offsetZ, 0);
int l1 = brightness % 65536;
int l2 = brightness / 65536;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, l1, l2);
} else {
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
}
boolean drawBackground = true;
if(drawBackground) {
RenderUtil.bindBlockTexture();
Tessellator tes = Tessellator.instance;
tes.startDrawingQuads();
if(!selfIlum) {
tes.setBrightness(brightness);
}
tes.setColorOpaque_F(1, 1, 1);
double scale = 0.85;
BoundingBox bb = BoundingBox.UNIT_CUBE;
double xScale = dir.offsetX == 0 ? scale : 1;
double yScale = scale;
double zScale = dir.offsetZ == 0 ? scale : 1;
bb = bb.scale(xScale, yScale, zScale);
IIcon icon = EnderIO.blockCapBank.getInfoPanelIcon();
List<Vertex> verts = bb.getCornersWithUvForFace(dir, icon.getMinU(), icon.getMaxU(), icon.getMinV(), icon.getMaxV());
RenderUtil.addVerticesToTesselator(verts);
tes.draw();
}
CapBankClientNetwork nw = null;
if(cb.getNetwork() != null) {
nw = (CapBankClientNetwork) cb.getNetwork();
nw.requestPowerUpdate(cb, 20);
} else {
return;
}
int change = Math.round(nw.getAverageChangePerTick());
//change = 0;
Vector3f col = new Vector3f(0, 0, 0);
if(change > 0) {
col = new Vector3f(0, 0.025, 0);
} else if(change < 0) {
col = new Vector3f(0.05, 0, 0);
}
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
String changeText = getChangeText(change, fr);
String HeadingText = change > 0 ? "In" : change < 0 ? "Out" : "I/O";
float size = 0.15f;
float scale = size / fr.FONT_HEIGHT;
GL11.glPushMatrix();
GL11.glTranslatef(0.5f, 0.5f + (size / 2), 0.5f);
GL11.glTranslatef((float) (dir.offsetX * 1.01) / 2, 0, (float) (dir.offsetZ * 1.01) / 2);
GL11.glRotatef(-180, 1, 0, 0);
if(dir == ForgeDirection.NORTH) {
GL11.glRotatef(-180, 0, 1, 0);
} else if(dir == ForgeDirection.EAST) {
GL11.glRotatef(-90, 0, 1, 0);
} else if(dir == ForgeDirection.WEST) {
GL11.glRotatef(90, 0, 1, 0);
}
GL11.glPushMatrix();
GL11.glTranslatef(0, -size, 0);
GL11.glScalef(scale, scale, scale);
fr.drawString(HeadingText, -fr.getStringWidth(HeadingText) / 2, 0, ColorUtil.getRGB(col));
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glTranslatef(0, size / 2, 0);
GL11.glScalef(scale, scale, scale);
fr.drawString(changeText, -fr.getStringWidth(changeText) / 2, 0, ColorUtil.getRGB(col));
GL11.glPopMatrix();
GL11.glPopMatrix();
}
protected String getChangeText(int change, FontRenderer fr) {
change = Math.abs(change);
String txt = PowerDisplayUtil.INT_NF.format(change);
int width = fr.getStringWidth(txt);
if(width > 38 && change > 1000) {
change = change / 1000;
txt = PowerDisplayUtil.INT_NF.format(change) + "K";
}
return txt;
}
}
@@ -1,26 +1,19 @@
package crazypants.enderio.machine.farm;
import static org.lwjgl.opengl.GL11.GL_LIGHTING;
import static org.lwjgl.opengl.GL11.glDisable;
import static org.lwjgl.opengl.GL11.glEnable;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import crazypants.enderio.config.Config;
import crazypants.render.RenderUtil;
import crazypants.vecmath.Vector3f;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import static org.lwjgl.opengl.GL11.*;
public class FarmingStationSpecialRenderer extends TileEntitySpecialRenderer{
private void renderFarmStationAt(TileFarmStation tile, double x, double y, double z, float partialTickTime) {
Minecraft mc = Minecraft.getMinecraft();
FontRenderer fnt = mc.fontRenderer;
Tessellator tessellator = Tessellator.instance;
String toRender = tile.notification;
String toRender = tile.notification;
if ("".equals(toRender) || Config.disableFarmNotification) {
return;
}
@@ -10,8 +10,8 @@ import crazypants.util.Lang;
public class PowerDisplayUtil {
private static final NumberFormat INT_NF = NumberFormat.getIntegerInstance();
private static final NumberFormat FLOAT_NF = NumberFormat.getInstance();
public static final NumberFormat INT_NF = NumberFormat.getIntegerInstance();
public static final NumberFormat FLOAT_NF = NumberFormat.getInstance();
//Handle french local 'non breaking space' character used to separate thousands.
//This is not rendered correctly and cannot be parsed by minecraft so replace it with a regular space