From a53a40470c35d4b324ad2c9f06ef412d1aae479d Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sun, 22 Dec 2013 12:06:29 +0800 Subject: [PATCH] Fixed wire render having alpha of "1" --- src/resonantinduction/MultipartRI.java | 4 +- .../wire/EnumWireMaterial.java | 2 +- src/resonantinduction/wire/ItemPartWire.java | 4 +- .../part/{PartFlatWire.java => FlatWire.java} | 45 +++++++++-------- .../wire/part/PartConductor.java | 50 +++++++++---------- .../wire/part/PartWireBase.java | 4 ++ ...enderLainWire.java => RenderFlatWire.java} | 21 ++++---- 7 files changed, 64 insertions(+), 66 deletions(-) rename src/resonantinduction/wire/part/{PartFlatWire.java => FlatWire.java} (91%) rename src/resonantinduction/wire/render/{RenderLainWire.java => RenderFlatWire.java} (96%) diff --git a/src/resonantinduction/MultipartRI.java b/src/resonantinduction/MultipartRI.java index a9ad628b..c3240487 100644 --- a/src/resonantinduction/MultipartRI.java +++ b/src/resonantinduction/MultipartRI.java @@ -2,7 +2,7 @@ package resonantinduction; import resonantinduction.wire.IAdvancedConductor; import resonantinduction.wire.IBlockableConnection; -import resonantinduction.wire.part.PartFlatWire; +import resonantinduction.wire.part.FlatWire; import buildcraft.api.power.IPowerReceptor; import codechicken.multipart.MultiPartRegistry; import codechicken.multipart.MultiPartRegistry.IPartFactory; @@ -27,7 +27,7 @@ public class MultipartRI implements IPartFactory { if (name.equals("resonant_induction_flat_wire")) { - return new PartFlatWire(); + return new FlatWire(); } return null; diff --git a/src/resonantinduction/wire/EnumWireMaterial.java b/src/resonantinduction/wire/EnumWireMaterial.java index 62872167..76c6d870 100644 --- a/src/resonantinduction/wire/EnumWireMaterial.java +++ b/src/resonantinduction/wire/EnumWireMaterial.java @@ -34,7 +34,7 @@ public enum EnumWireMaterial resistance = resist; damage = electrocution; maxAmps = max; - color = new ColourRGBA(r, g, b, 1); + color = new ColourRGBA(r, g, b, 255); } public String getName() diff --git a/src/resonantinduction/wire/ItemPartWire.java b/src/resonantinduction/wire/ItemPartWire.java index 6f8507dc..b47eb9e1 100644 --- a/src/resonantinduction/wire/ItemPartWire.java +++ b/src/resonantinduction/wire/ItemPartWire.java @@ -13,7 +13,7 @@ import net.minecraftforge.common.ForgeDirection; import resonantinduction.ResonantInduction; import resonantinduction.TabRI; import resonantinduction.Utility; -import resonantinduction.wire.part.PartFlatWire; +import resonantinduction.wire.part.FlatWire; import resonantinduction.wire.render.RenderPartWire; import universalelectricity.api.energy.UnitDisplay; import universalelectricity.api.energy.UnitDisplay.Unit; @@ -48,7 +48,7 @@ public class ItemPartWire extends JItemMultiPart return null; } - PartFlatWire wire = (PartFlatWire) MultiPartRegistry.createPart("resonant_induction_flat_wire", false); + FlatWire wire = (FlatWire) MultiPartRegistry.createPart("resonant_induction_flat_wire", false); if (wire != null) { diff --git a/src/resonantinduction/wire/part/PartFlatWire.java b/src/resonantinduction/wire/part/FlatWire.java similarity index 91% rename from src/resonantinduction/wire/part/PartFlatWire.java rename to src/resonantinduction/wire/part/FlatWire.java index 1b9786ac..63e18fbb 100644 --- a/src/resonantinduction/wire/part/PartFlatWire.java +++ b/src/resonantinduction/wire/part/FlatWire.java @@ -14,8 +14,9 @@ import org.lwjgl.opengl.GL11; import resonantinduction.Utility; import resonantinduction.wire.EnumWireMaterial; import resonantinduction.wire.IAdvancedConductor; -import resonantinduction.wire.render.RenderLainWire; +import resonantinduction.wire.render.RenderFlatWire; import resonantinduction.wire.render.RenderPartWire; +import codechicken.lib.colour.Colour; import codechicken.lib.data.MCDataInput; import codechicken.lib.data.MCDataOutput; import codechicken.lib.lighting.LazyLightMatrix; @@ -44,7 +45,7 @@ import cpw.mods.fml.relauncher.SideOnly; * @author Modified by Calclavia, MrTJP * */ -public class PartFlatWire extends PartWireBase implements TFacePart, JNormalOcclusion +public class FlatWire extends PartWireBase implements TFacePart, JNormalOcclusion { public static Cuboid6[][] selectionBounds = new Cuboid6[3][6]; public static Cuboid6[][] occlusionBounds = new Cuboid6[3][6]; @@ -82,17 +83,17 @@ public class PartFlatWire extends PartWireBase implements TFacePart, JNormalOccl */ public int connMap; - public PartFlatWire() + public FlatWire() { super(); } - public PartFlatWire(int typeID) + public FlatWire(int typeID) { this(EnumWireMaterial.values()[typeID]); } - public PartFlatWire(EnumWireMaterial type) + public FlatWire(EnumWireMaterial type) { super(); material = type; @@ -314,7 +315,7 @@ public class PartFlatWire extends PartWireBase implements TFacePart, JNormalOccl { int absDir = Rotation.rotateSide(side, r); TMultiPart facePart = tile().partMap(absDir); - if (facePart != null && (!(facePart instanceof PartFlatWire) || !canConnectToType((PartFlatWire) facePart))) + if (facePart != null && (!(facePart instanceof FlatWire) || !canConnectToType((FlatWire) facePart))) return false; if (tile().partMap(PartMap.edgeBetween(side, absDir)) != null) @@ -346,11 +347,11 @@ public class PartFlatWire extends PartWireBase implements TFacePart, JNormalOccl TMultiPart tp = t.partMap(absDir ^ 1); if (tp instanceof IAdvancedConductor) { - boolean b = ((PartFlatWire) tp).connectCorner(this, Rotation.rotationTo(absDir ^ 1, side ^ 1)); + boolean b = ((FlatWire) tp).connectCorner(this, Rotation.rotationTo(absDir ^ 1, side ^ 1)); if (b) { // let them connect to us - if (tp instanceof PartFlatWire && !renderThisCorner((PartFlatWire) tp)) + if (tp instanceof FlatWire && !renderThisCorner((FlatWire) tp)) return 1; return 2; @@ -381,8 +382,8 @@ public class PartFlatWire extends PartWireBase implements TFacePart, JNormalOccl if (t != null) { TMultiPart tp = t.partMap(side); - if (tp instanceof PartFlatWire) - return ((PartFlatWire) tp).connectStraight(this, (r + 2) % 4); + if (tp instanceof FlatWire) + return ((FlatWire) tp).connectStraight(this, (r + 2) % 4); } return connectStraightOverride(absDir); @@ -401,8 +402,8 @@ public class PartFlatWire extends PartWireBase implements TFacePart, JNormalOccl return false; TMultiPart tp = tile().partMap(absDir); - if (tp instanceof PartFlatWire) - return ((PartFlatWire) tp).connectInternal(this, Rotation.rotationTo(absDir, side)); + if (tp instanceof FlatWire) + return ((FlatWire) tp).connectInternal(this, Rotation.rotationTo(absDir, side)); return connectInternalOverride(tp, r); } @@ -415,18 +416,18 @@ public class PartFlatWire extends PartWireBase implements TFacePart, JNormalOccl public boolean connectCenter() { TMultiPart t = tile().partMap(6); - if (t instanceof PartFlatWire) - return ((PartFlatWire) t).connectInternal(this, side); + if (t instanceof FlatWire) + return ((FlatWire) t).connectInternal(this, side); return false; } public boolean renderThisCorner(IAdvancedConductor part) { - if (!(part instanceof PartFlatWire)) + if (!(part instanceof FlatWire)) return false; - PartFlatWire wire = (PartFlatWire) part; + FlatWire wire = (FlatWire) part; if (wire.getThickness() == getThickness()) return side < wire.side; @@ -575,14 +576,14 @@ public class PartFlatWire extends PartWireBase implements TFacePart, JNormalOccl return RenderPartWire.lainWireIcon; } - public int getColour() + public Colour getColour() { - return this.getMaterial().color.pack(); + return this.getMaterial().color; } public boolean useStaticRenderer() { - return true; + return false; } @Override @@ -592,7 +593,7 @@ public class PartFlatWire extends PartWireBase implements TFacePart, JNormalOccl if (pass == 0 && useStaticRenderer()) { CCRenderState.setBrightness(world(), x(), y(), z()); - RenderLainWire.render(this, pos); + RenderFlatWire.render(this, pos); CCRenderState.setColour(-1); } } @@ -607,7 +608,7 @@ public class PartFlatWire extends PartWireBase implements TFacePart, JNormalOccl TextureUtils.bindAtlas(0); CCRenderState.useModelColours(true); CCRenderState.startDrawing(7); - RenderLainWire.render(this, pos); + RenderFlatWire.render(this, pos); CCRenderState.draw(); CCRenderState.setColour(-1); GL11.glEnable(GL11.GL_LIGHTING); @@ -619,7 +620,7 @@ public class PartFlatWire extends PartWireBase implements TFacePart, JNormalOccl public void drawBreaking(RenderBlocks renderBlocks) { CCRenderState.reset(); - RenderLainWire.renderBreakingOverlay(renderBlocks.overrideBlockTexture, this); + RenderFlatWire.renderBreakingOverlay(renderBlocks.overrideBlockTexture, this); } } \ No newline at end of file diff --git a/src/resonantinduction/wire/part/PartConductor.java b/src/resonantinduction/wire/part/PartConductor.java index c97c1f42..bf67001a 100644 --- a/src/resonantinduction/wire/part/PartConductor.java +++ b/src/resonantinduction/wire/part/PartConductor.java @@ -17,7 +17,6 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon { private IEnergyNetwork network; - public TileEntity[] cachedConnections = null; public byte currentWireConnections = 0x00; public byte currentAcceptorConnections = 0x00; @@ -64,12 +63,6 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon return ((connections & tester) > 0); } - @Override - public void onMoved() - { - this.refresh(); - } - @Override public void bind(TileMultipart t) { @@ -164,19 +157,18 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon { if (!world().isRemote) { - this.cachedConnections = null; - byte possibleWireConnections = getPossibleWireConnections(); byte possibleAcceptorConnections = getPossibleAcceptorConnections(); if (possibleWireConnections != this.currentWireConnections) { - byte or = (byte) (possibleWireConnections | currentWireConnections); + byte or = (byte) (possibleWireConnections | this.currentWireConnections); - if (or != possibleWireConnections) // Connections have been removed + // Connections have been removed + if (or != possibleWireConnections) { - getNetwork().split((IConductor) tile()); - setNetwork(null); + this.getNetwork().split((IConductor) tile()); + this.setNetwork(null); } for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) @@ -187,7 +179,7 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon if (tileEntity instanceof IConductor) { - getNetwork().merge(((IConductor) tileEntity).getNetwork()); + this.getNetwork().merge(((IConductor) tileEntity).getNetwork()); } } } @@ -196,7 +188,8 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon } this.currentAcceptorConnections = possibleAcceptorConnections; - //this.sendDescUpdate(); + this.getNetwork().reconstruct(); + // this.sendDescUpdate(); } tile().markRender(); @@ -209,22 +202,20 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon @Override public TileEntity[] getConnections() { - if (this.cachedConnections == null) + TileEntity[] cachedConnections = new TileEntity[6]; + + for (byte i = 0; i < 6; i++) { - this.cachedConnections = new TileEntity[6]; + ForgeDirection side = ForgeDirection.getOrientation(i); + TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side); - for (byte i = 0; i < 6; i++) + if (isCurrentlyConnected(side)) { - ForgeDirection side = ForgeDirection.getOrientation(i); - TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side); - - if (isCurrentlyConnected(side)) - { - this.cachedConnections[i] = tileEntity; - } + cachedConnections[i] = tileEntity; } } - return this.cachedConnections; + + return cachedConnections; } public boolean isCurrentlyConnected(ForgeDirection side) @@ -250,6 +241,12 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon refresh(); } + @Override + public void onMoved() + { + this.refresh(); + } + @Override public void onChunkLoad() { @@ -263,5 +260,4 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon super.onNeighborChanged(); refresh(); } - } diff --git a/src/resonantinduction/wire/part/PartWireBase.java b/src/resonantinduction/wire/part/PartWireBase.java index 5a6a1eb3..cb3b839c 100644 --- a/src/resonantinduction/wire/part/PartWireBase.java +++ b/src/resonantinduction/wire/part/PartWireBase.java @@ -170,6 +170,10 @@ public abstract class PartWireBase extends PartConductor implements IBlockableCo return true; } } + + if (!world().isRemote) + System.out.println(this.getNetwork()); + return false; } diff --git a/src/resonantinduction/wire/render/RenderLainWire.java b/src/resonantinduction/wire/render/RenderFlatWire.java similarity index 96% rename from src/resonantinduction/wire/render/RenderLainWire.java rename to src/resonantinduction/wire/render/RenderFlatWire.java index d234851d..bc81228c 100644 --- a/src/resonantinduction/wire/render/RenderLainWire.java +++ b/src/resonantinduction/wire/render/RenderFlatWire.java @@ -4,7 +4,7 @@ import java.util.Arrays; import java.util.LinkedList; import net.minecraft.util.Icon; -import resonantinduction.wire.part.PartFlatWire; +import resonantinduction.wire.part.FlatWire; import codechicken.lib.lighting.LightModel; import codechicken.lib.math.MathHelper; import codechicken.lib.render.CCModel; @@ -24,12 +24,7 @@ import codechicken.lib.vec.Transformation; import codechicken.lib.vec.Translation; import codechicken.lib.vec.Vector3; -/** - * - * @author MrTJP, ChickenBones - * - */ -public class RenderLainWire +public class RenderFlatWire { public static class UVT implements IUVTransformation { @@ -58,6 +53,7 @@ public class RenderLainWire * 2 = side 2 = -Z = NORTH * 3 = side 5 = +X = EAST */ + private static class WireModelGenerator { int side; @@ -399,7 +395,7 @@ public class RenderLainWire return key; } - public static int modelKey(PartFlatWire w) + public static int modelKey(FlatWire w) { return modelKey(w.side, w.getThickness(), w.connMap); } @@ -412,10 +408,11 @@ public class RenderLainWire return m; } - public static void render(PartFlatWire w, Vector3 pos) + public static void render(FlatWire w, Vector3 pos) { - IVertexModifier m = w.getColour() == -1 ? ColourModifier.instance : new ColourMultiplier(w.getColour()); - getOrGenerateModel(modelKey(w)).render(new Translation(pos), new IconTransformation(w.getIcon()), m); + IVertexModifier m = w.getColour().pack() == -1 ? ColourModifier.instance : new ColourMultiplier(w.getColour()); + CCModel model = getOrGenerateModel(modelKey(w)); + model.render(new Translation(pos), new IconTransformation(w.getIcon()), m); } public static void renderInv(int thickness, Transformation t, Icon icon) @@ -427,7 +424,7 @@ public class RenderLainWire m.render(t, new IconTransformation(icon)); } - public static void renderBreakingOverlay(Icon icon, PartFlatWire wire) + public static void renderBreakingOverlay(Icon icon, FlatWire wire) { int key = modelKey(wire); int side = (key >> 8) % 6;