diff --git a/src/main/java/resonantinduction/MultipartRI.java b/src/main/java/resonantinduction/MultipartRI.java index 9d661d9f..a8ae993f 100644 --- a/src/main/java/resonantinduction/MultipartRI.java +++ b/src/main/java/resonantinduction/MultipartRI.java @@ -2,8 +2,8 @@ package resonantinduction; import resonantinduction.multimeter.PartMultimeter; import resonantinduction.transformer.PartTransformer; -import resonantinduction.wire.part.PartFlatSwitchWire; -import resonantinduction.wire.part.PartFlatWire; +import resonantinduction.wire.flat.PartFlatSwitchWire; +import resonantinduction.wire.flat.PartFlatWire; import codechicken.multipart.MultiPartRegistry; import codechicken.multipart.MultiPartRegistry.IPartFactory; import codechicken.multipart.MultipartGenerator; diff --git a/src/main/java/resonantinduction/wire/ItemWire.java b/src/main/java/resonantinduction/wire/ItemWire.java index 3654b541..a77e1ee2 100644 --- a/src/main/java/resonantinduction/wire/ItemWire.java +++ b/src/main/java/resonantinduction/wire/ItemWire.java @@ -16,7 +16,8 @@ import org.lwjgl.input.Keyboard; import resonantinduction.ResonantInduction; import resonantinduction.TabRI; import resonantinduction.Utility; -import resonantinduction.wire.part.PartFlatWire; +import resonantinduction.wire.flat.PartFlatWire; +import resonantinduction.wire.flat.RenderFlatWire; import universalelectricity.api.energy.UnitDisplay; import universalelectricity.api.energy.UnitDisplay.Unit; import calclavia.lib.Calclavia; diff --git a/src/main/java/resonantinduction/wire/part/PartAdvancedWire.java b/src/main/java/resonantinduction/wire/PartAdvancedWire.java similarity index 98% rename from src/main/java/resonantinduction/wire/part/PartAdvancedWire.java rename to src/main/java/resonantinduction/wire/PartAdvancedWire.java index 4142a315..b9fb6d97 100644 --- a/src/main/java/resonantinduction/wire/part/PartAdvancedWire.java +++ b/src/main/java/resonantinduction/wire/PartAdvancedWire.java @@ -1,4 +1,4 @@ -package resonantinduction.wire.part; +package resonantinduction.wire; import java.util.ArrayList; import java.util.Collections; @@ -13,7 +13,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.MovingObjectPosition; import resonantinduction.Utility; -import resonantinduction.wire.EnumWireMaterial; +import resonantinduction.wire.flat.PartFlatWire; import universalelectricity.api.CompatibilityModule; import universalelectricity.api.energy.IConductor; import calclavia.lib.prefab.CustomDamageSource; diff --git a/src/main/java/resonantinduction/wire/part/PartConductor.java b/src/main/java/resonantinduction/wire/PartConductor.java similarity index 99% rename from src/main/java/resonantinduction/wire/part/PartConductor.java rename to src/main/java/resonantinduction/wire/PartConductor.java index 78693089..a15775ba 100644 --- a/src/main/java/resonantinduction/wire/part/PartConductor.java +++ b/src/main/java/resonantinduction/wire/PartConductor.java @@ -1,4 +1,4 @@ -package resonantinduction.wire.part; +package resonantinduction.wire; import ic2.api.energy.event.EnergyTileLoadEvent; import ic2.api.energy.event.EnergyTileUnloadEvent; diff --git a/src/main/java/resonantinduction/wire/part/PartFlatSwitchWire.java b/src/main/java/resonantinduction/wire/flat/PartFlatSwitchWire.java similarity index 98% rename from src/main/java/resonantinduction/wire/part/PartFlatSwitchWire.java rename to src/main/java/resonantinduction/wire/flat/PartFlatSwitchWire.java index e3314ff4..6422ed64 100644 --- a/src/main/java/resonantinduction/wire/part/PartFlatSwitchWire.java +++ b/src/main/java/resonantinduction/wire/flat/PartFlatSwitchWire.java @@ -1,4 +1,4 @@ -package resonantinduction.wire.part; +package resonantinduction.wire.flat; import java.util.Collections; diff --git a/src/main/java/resonantinduction/wire/part/PartFlatWire.java b/src/main/java/resonantinduction/wire/flat/PartFlatWire.java similarity index 99% rename from src/main/java/resonantinduction/wire/part/PartFlatWire.java rename to src/main/java/resonantinduction/wire/flat/PartFlatWire.java index 3ae4532f..2738a4c4 100644 --- a/src/main/java/resonantinduction/wire/part/PartFlatWire.java +++ b/src/main/java/resonantinduction/wire/flat/PartFlatWire.java @@ -1,4 +1,4 @@ -package resonantinduction.wire.part; +package resonantinduction.wire.flat; import java.util.Arrays; @@ -18,7 +18,7 @@ import org.lwjgl.opengl.GL11; import resonantinduction.ResonantInduction; import resonantinduction.Utility; import resonantinduction.wire.EnumWireMaterial; -import resonantinduction.wire.RenderFlatWire; +import resonantinduction.wire.PartAdvancedWire; import codechicken.lib.colour.Colour; import codechicken.lib.data.MCDataInput; import codechicken.lib.data.MCDataOutput; diff --git a/src/main/java/resonantinduction/wire/RenderFlatWire.java b/src/main/java/resonantinduction/wire/flat/RenderFlatWire.java similarity index 99% rename from src/main/java/resonantinduction/wire/RenderFlatWire.java rename to src/main/java/resonantinduction/wire/flat/RenderFlatWire.java index 25e4d5dc..f36bd65a 100644 --- a/src/main/java/resonantinduction/wire/RenderFlatWire.java +++ b/src/main/java/resonantinduction/wire/flat/RenderFlatWire.java @@ -1,10 +1,9 @@ -package resonantinduction.wire; +package resonantinduction.wire.flat; import java.util.Arrays; import java.util.LinkedList; import net.minecraft.util.Icon; -import resonantinduction.wire.part.PartFlatWire; import codechicken.lib.lighting.LightModel; import codechicken.lib.math.MathHelper; import codechicken.lib.render.CCModel; diff --git a/src/main/java/resonantinduction/wire/framed/PartWire.java b/src/main/java/resonantinduction/wire/framed/PartWire.java new file mode 100644 index 00000000..5d637ba4 --- /dev/null +++ b/src/main/java/resonantinduction/wire/framed/PartWire.java @@ -0,0 +1,440 @@ +package resonantinduction.wire.framed; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import net.minecraft.client.particle.EffectRenderer; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.Icon; +import net.minecraft.util.MovingObjectPosition; +import net.minecraftforge.common.ForgeDirection; +import resonantinduction.wire.EnumWireMaterial; +import resonantinduction.wire.PartAdvancedWire; +import universalelectricity.api.CompatibilityModule; +import universalelectricity.api.energy.IConductor; +import universalelectricity.api.vector.Vector3; +import universalelectricity.api.vector.VectorHelper; +import codechicken.lib.lighting.LazyLightMatrix; +import codechicken.lib.raytracer.IndexedCuboid6; +import codechicken.lib.render.CCRenderState; +import codechicken.lib.render.IconTransformation; +import codechicken.lib.render.RenderUtils; +import codechicken.lib.vec.Cuboid6; +import codechicken.lib.vec.Translation; +import codechicken.microblock.IHollowConnect; +import codechicken.multipart.IconHitEffects; +import codechicken.multipart.JIconHitEffects; +import codechicken.multipart.JNormalOcclusion; +import codechicken.multipart.NormalOcclusionTest; +import codechicken.multipart.PartMap; +import codechicken.multipart.TMultiPart; +import codechicken.multipart.TSlottedPart; +import codechicken.multipart.TileMultipart; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class PartWire extends PartAdvancedWire implements TSlottedPart, JNormalOcclusion, IHollowConnect, JIconHitEffects +{ + /** Client Side Connection Check */ + private ForgeDirection testingSide; + + public static IndexedCuboid6[] sides = new IndexedCuboid6[7]; + public static IndexedCuboid6[] insulatedSides = new IndexedCuboid6[7]; + + /** + * Bitmask connections + */ + public byte currentWireConnections = 0x00; + public byte currentAcceptorConnections = 0x00; + + public PartWire() + { + super(); + } + + public PartWire(int typeID) + { + this(EnumWireMaterial.values()[typeID]); + } + + public PartWire(EnumWireMaterial type) + { + super(); + material = type; + } + + static + { + sides[0] = new IndexedCuboid6(0, new Cuboid6(0.36, 0.000, 0.36, 0.64, 0.36, 0.64)); + sides[1] = new IndexedCuboid6(1, new Cuboid6(0.36, 0.64, 0.36, 0.64, 1.000, 0.64)); + sides[2] = new IndexedCuboid6(2, new Cuboid6(0.36, 0.36, 0.000, 0.64, 0.64, 0.36)); + sides[3] = new IndexedCuboid6(3, new Cuboid6(0.36, 0.36, 0.64, 0.64, 0.64, 1.000)); + sides[4] = new IndexedCuboid6(4, new Cuboid6(0.000, 0.36, 0.36, 0.36, 0.64, 0.64)); + sides[5] = new IndexedCuboid6(5, new Cuboid6(0.64, 0.36, 0.36, 1.000, 0.64, 0.64)); + sides[6] = new IndexedCuboid6(6, new Cuboid6(0.36, 0.36, 0.36, 0.64, 0.64, 0.64)); + insulatedSides[0] = new IndexedCuboid6(0, new Cuboid6(0.3, 0.0, 0.3, 0.7, 0.3, 0.7)); + insulatedSides[1] = new IndexedCuboid6(1, new Cuboid6(0.3, 0.7, 0.3, 0.7, 1.0, 0.7)); + insulatedSides[2] = new IndexedCuboid6(2, new Cuboid6(0.3, 0.3, 0.0, 0.7, 0.7, 0.3)); + insulatedSides[3] = new IndexedCuboid6(3, new Cuboid6(0.3, 0.3, 0.7, 0.7, 0.7, 1.0)); + insulatedSides[4] = new IndexedCuboid6(4, new Cuboid6(0.0, 0.3, 0.3, 0.3, 0.7, 0.7)); + insulatedSides[5] = new IndexedCuboid6(5, new Cuboid6(0.7, 0.3, 0.3, 1.0, 0.7, 0.7)); + insulatedSides[6] = new IndexedCuboid6(6, new Cuboid6(0.3, 0.3, 0.3, 0.7, 0.7, 0.7)); + } + + @Override + public String getType() + { + return "resonant_induction_wire"; + } + + @Override + public boolean occlusionTest(TMultiPart other) + { + return NormalOcclusionTest.apply(this, other); + } + + @Override + public Iterable getSubParts() + { + Set subParts = new HashSet(); + IndexedCuboid6[] currentSides = isInsulated() ? insulatedSides : sides; + + if (tile() != null) + { + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + { + int ord = side.ordinal(); + if (connectionMapContainsSide(getAllCurrentConnections(), side) || side == testingSide) + subParts.add(currentSides[ord]); + } + } + + subParts.add(currentSides[6]); + return subParts; + } + + @Override + public Iterable getCollisionBoxes() + { + Set collisionBoxes = new HashSet(); + collisionBoxes.addAll((Collection) getSubParts()); + + return collisionBoxes; + } + + @Override + public float getStrength(MovingObjectPosition hit, EntityPlayer player) + { + return 10F; + } + + @Override + @SideOnly(Side.CLIENT) + public void renderStatic(codechicken.lib.vec.Vector3 pos, LazyLightMatrix olm, int pass) + { + if (pass == 0) + { + RenderPartWire.INSTANCE.renderStatic(this); + } + } + + @Override + @SideOnly(Side.CLIENT) + public void renderDynamic(codechicken.lib.vec.Vector3 pos, float frame, int pass) + { + if (getMaterial() == EnumWireMaterial.SILVER) + { + RenderPartWire.INSTANCE.renderShine(this, pos.x, pos.y, pos.z, frame); + } + } + + @Override + public void drawBreaking(RenderBlocks renderBlocks) + { + CCRenderState.reset(); + RenderUtils.renderBlock(sides[6], 0, new Translation(x(), y(), z()), new IconTransformation(renderBlocks.overrideBlockTexture), null); + } + + @Override + public Iterable getOcclusionBoxes() + { + return getCollisionBoxes(); + } + + @Override + public int getSlotMask() + { + return PartMap.CENTER.mask; + } + + @Override + public int getHollowSize() + { + return isInsulated ? 8 : 6; + } + + @Override + public Cuboid6 getBounds() + { + return new Cuboid6(0.375, 0.375, 0.375, 0.625, 0.625, 0.625); + } + + @Override + public Icon getBreakingIcon(Object subPart, int side) + { + return RenderPartWire.breakIcon; + } + + @Override + public Icon getBrokenIcon(int side) + { + return RenderPartWire.breakIcon; + } + + @Override + public void addHitEffects(MovingObjectPosition hit, EffectRenderer effectRenderer) + { + IconHitEffects.addHitEffects(this, hit, effectRenderer); + } + + @Override + public void addDestroyEffects(EffectRenderer effectRenderer) + { + IconHitEffects.addDestroyEffects(this, effectRenderer, false); + } + + @Override + public void onPartChanged(TMultiPart part) + { + refresh(); + } + + public boolean isBlockedOnSide(ForgeDirection side) + { + TMultiPart blocker = tile().partMap(side.ordinal()); + testingSide = side; + boolean expandable = NormalOcclusionTest.apply(this, blocker); + testingSide = null; + return !expandable; + } + + public byte getAllCurrentConnections() + { + return (byte) (currentWireConnections | currentAcceptorConnections); + } + + public static boolean connectionMapContainsSide(byte connections, ForgeDirection side) + { + byte tester = (byte) (1 << side.ordinal()); + return ((connections & tester) > 0); + } + + @Override + public void bind(TileMultipart t) + { + if (tile() != null && this.getNetwork() != null) + { + getNetwork().getConnectors().remove(tile()); + super.bind(t); + getNetwork().getConnectors().add((IConductor) tile()); + } + else + { + super.bind(t); + } + } + + /** + * CONNECTION LOGIC CODE + */ + + public boolean canConnectBothSides(TileEntity tile, ForgeDirection side) + { + boolean notPrevented = !isConnectionPrevented(tile, side); + + if (tile instanceof IConductor) + { + notPrevented &= ((IConductor) tile).canConnect(side.getOpposite()); + } + + return notPrevented; + } + + /** + * Override if there are ways of preventing a connection + * + * @param tile The TileEntity on the given side + * @param side The side we're checking + * @return Whether we're preventing connections on given side or to given tileEntity + */ + public boolean isConnectionPrevented(TileEntity tile, ForgeDirection side) + { + return (tile instanceof IConductor ? this.canConnectTo((IConductor) tile) : false) || (isBlockedOnSide(side));// || + // tile + // instanceof + // IBlockableConnection + // && + // ((IBlockableConnection) + // tile).isBlockedOnSide(side.getOpposite()))*/; + } + + public byte getPossibleWireConnections() + { + if (world().isBlockIndirectlyGettingPowered(x(), y(), z())) + { + return 0x00; + } + + byte connections = 0x00; + + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + { + TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side); + + if (tileEntity instanceof IConductor && canConnectBothSides(tileEntity, side)) + { + connections |= 1 << side.ordinal(); + } + } + + return connections; + } + + public byte getPossibleAcceptorConnections() + { + if (world().isBlockIndirectlyGettingPowered(x(), y(), z())) + { + return 0x00; + } + + byte connections = 0x00; + + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + { + TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side); + + if (CompatibilityModule.canConnect(tileEntity, side.getOpposite()) && canConnectBothSides(tileEntity, side)) + { + connections |= 1 << side.ordinal(); + } + } + + return connections; + } + + public void refresh() + { + if (!world().isRemote) + { + byte possibleWireConnections = getPossibleWireConnections(); + byte possibleAcceptorConnections = getPossibleAcceptorConnections(); + + if (possibleWireConnections != this.currentWireConnections) + { + byte or = (byte) (possibleWireConnections | this.currentWireConnections); + + // Connections have been removed + if (or != possibleWireConnections) + { + this.getNetwork().split((IConductor) tile()); + this.setNetwork(null); + } + + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + { + if (connectionMapContainsSide(possibleWireConnections, side)) + { + TileEntity tileEntity = VectorHelper.getConnectorFromSide(world(), new Vector3(tile()), side); + + if (tileEntity instanceof IConductor) + { + this.getNetwork().merge(((IConductor) tileEntity).getNetwork()); + } + } + } + + this.currentWireConnections = possibleWireConnections; + } + + this.currentAcceptorConnections = possibleAcceptorConnections; + this.getNetwork().reconstruct(); + // this.sendDescUpdate(); + } + + tile().markRender(); + } + + /** + * Should include connections that are in the current connection maps even if those connections + * aren't allowed any more. This is so that networks split correctly. + */ + @Override + public TileEntity[] getConnections() + { + TileEntity[] cachedConnections = new TileEntity[6]; + + for (byte i = 0; i < 6; i++) + { + ForgeDirection side = ForgeDirection.getOrientation(i); + TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side); + + if (isCurrentlyConnected(side)) + { + cachedConnections[i] = tileEntity; + } + } + + return cachedConnections; + } + + public boolean isCurrentlyConnected(ForgeDirection side) + { + return connectionMapContainsSide(getAllCurrentConnections(), side); + } + + /** + * Shouldn't need to be overridden. Override connectionPrevented instead + */ + @Override + public boolean canConnect(ForgeDirection direction) + { + if (world().isBlockIndirectlyGettingPowered(x(), y(), z())) + { + return false; + } + + Vector3 connectPos = new Vector3(tile()).modifyPositionFromSide(direction); + TileEntity connectTile = connectPos.getTileEntity(world()); + return !isConnectionPrevented(connectTile, direction); + } + + @Override + public void onAdded() + { + super.onAdded(); + refresh(); + } + + @Override + public void onMoved() + { + this.refresh(); + } + + @Override + public void onChunkLoad() + { + super.onChunkLoad(); + refresh(); + } + + @Override + public void onNeighborChanged() + { + super.onNeighborChanged(); + refresh(); + } +} \ No newline at end of file diff --git a/src/main/java/resonantinduction/wire/framed/RenderPartWire.java b/src/main/java/resonantinduction/wire/framed/RenderPartWire.java new file mode 100644 index 00000000..3c1c67ca --- /dev/null +++ b/src/main/java/resonantinduction/wire/framed/RenderPartWire.java @@ -0,0 +1,190 @@ +package resonantinduction.wire.framed; + +import java.nio.FloatBuffer; +import java.util.Map; + +import net.minecraft.client.renderer.texture.IconRegister; +import net.minecraft.util.Icon; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.ForgeDirection; + +import org.lwjgl.BufferUtils; +import org.lwjgl.opengl.GL11; + +import resonantinduction.ResonantInduction; +import resonantinduction.render.InvertX; +import codechicken.lib.colour.Colour; +import codechicken.lib.lighting.LightModel; +import codechicken.lib.render.CCModel; +import codechicken.lib.render.CCRenderState; +import codechicken.lib.render.ColourMultiplier; +import codechicken.lib.render.IconTransformation; +import codechicken.lib.render.TextureUtils; +import codechicken.lib.vec.Rotation; +import codechicken.lib.vec.Translation; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +/** + * + * @author unpairedbracket + * + */ +@SideOnly(Side.CLIENT) +public class RenderPartWire +{ + private static final ResourceLocation WIRE_SHINE = new ResourceLocation(ResonantInduction.DOMAIN, ResonantInduction.MODEL_TEXTURE_DIRECTORY + "white.png"); + public static final Map models; + public static final Map shinyModels; + public static Icon wireIcon; + public static Icon lainWireIcon; + public static Icon insulationIcon; + public static Icon breakIcon; + public static FloatBuffer location = BufferUtils.createFloatBuffer(4); + public static FloatBuffer specular = BufferUtils.createFloatBuffer(4); + public static FloatBuffer zero = BufferUtils.createFloatBuffer(4); + public static FloatBuffer defaultAmbient = BufferUtils.createFloatBuffer(4); + public static final RenderPartWire INSTANCE = new RenderPartWire(); + + static + { + models = CCModel.parseObjModels(new ResourceLocation("resonantinduction", "models/wire.obj"), 7, new InvertX()); + for (CCModel c : models.values()) + { + c.apply(new Translation(.5, 0, .5)); + c.computeLighting(LightModel.standardLightModel); + c.shrinkUVs(0.0005); + } + + shinyModels = CCModel.parseObjModels(new ResourceLocation("resonantinduction", "models/wireShine.obj"), 7, new InvertX()); + for (CCModel c : shinyModels.values()) + { + c.apply(new Translation(.5, 0, .5)); + c.computeLighting(LightModel.standardLightModel); + c.shrinkUVs(0.0005); + } + + loadBuffer(location, 0, 0, 0, 1); + loadBuffer(specular, 1, 1, 1, 1); + loadBuffer(zero, 0, 0, 0, 0); + loadBuffer(defaultAmbient, 0.4F, 0.4F, 0.4F, 1); + + GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, zero); + + GL11.glLight(GL11.GL_LIGHT3, GL11.GL_SPECULAR, specular); + + GL11.glMaterial(GL11.GL_FRONT, GL11.GL_SPECULAR, specular); + GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT, zero); + GL11.glMaterial(GL11.GL_FRONT, GL11.GL_DIFFUSE, zero); + GL11.glMaterialf(GL11.GL_FRONT, GL11.GL_SHININESS, 128f); + + } + + public static void loadBuffer(FloatBuffer buffer, float... src) + { + buffer.clear(); + buffer.put(src); + buffer.flip(); + } + + public void renderShine(PartWire wire, double x, double y, double z, float f) + { + if (wire != null) + { + GL11.glPushMatrix(); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE_MINUS_SRC_COLOR); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_LIGHT0); + GL11.glDisable(GL11.GL_LIGHT1); + GL11.glEnable(GL11.GL_LIGHT3); + GL11.glLight(GL11.GL_LIGHT3, GL11.GL_POSITION, location); + + GL11.glTranslatef((float) x, (float) y, (float) z); + GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, zero); + + CCRenderState.reset(); + CCRenderState.useNormals(true); + CCRenderState.changeTexture(WIRE_SHINE); + CCRenderState.startDrawing(7); + renderSideShine(ForgeDirection.UNKNOWN, wire); + + byte renderSides = wire.getAllCurrentConnections(); + + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + { + if (PartWire.connectionMapContainsSide(renderSides, side)) + renderSideShine(side, wire); + } + CCRenderState.draw(); + + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_LIGHT0); + GL11.glEnable(GL11.GL_LIGHT1); + GL11.glDisable(GL11.GL_LIGHT3); + + GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, defaultAmbient); + + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + + GL11.glPopMatrix(); + } + } + + public static void registerIcons(IconRegister iconReg) + { + wireIcon = iconReg.registerIcon(ResonantInduction.PREFIX + "models/wire"); + lainWireIcon = iconReg.registerIcon(ResonantInduction.PREFIX + "models/lainWire"); + insulationIcon = iconReg.registerIcon(ResonantInduction.PREFIX + "models/insulation" + (ResonantInduction.LO_FI_INSULATION ? "tiny" : "")); + breakIcon = iconReg.registerIcon(ResonantInduction.PREFIX + "wire"); + } + + public void renderStatic(PartWire wire) + { + TextureUtils.bindAtlas(0); + CCRenderState.reset(); + CCRenderState.useModelColours(true); + CCRenderState.setBrightness(wire.world(), wire.x(), wire.y(), wire.z()); + renderSide(ForgeDirection.UNKNOWN, wire); + byte renderSides = wire.getAllCurrentConnections(); + + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + { + if (PartWire.connectionMapContainsSide(renderSides, side)) + { + renderSide(side, wire); + } + } + } + + public void renderSide(ForgeDirection side, PartWire wire) + { + String name = side.name().toLowerCase(); + name = name.equals("unknown") ? "center" : name; + Colour colour = wire.getMaterial().color; + renderPart(wireIcon, models.get(name), wire.x(), wire.y(), wire.z(), colour); + + if (wire.isInsulated()) + { + Colour insulationColour = ResonantInduction.DYE_COLORS[wire.getColor()]; + renderPart(insulationIcon, models.get(name + "Insulation"), wire.x(), wire.y(), wire.z(), insulationColour); + } + } + + public void renderSideShine(ForgeDirection side, PartWire wire) + { + String name = side.name().toLowerCase(); + name = name.equals("unknown") ? "center" : name; + renderPartShine(shinyModels.get(name)); + } + + public void renderPart(Icon icon, CCModel cc, double x, double y, double z, Colour colour) + { + cc.render(0, cc.verts.length, Rotation.sideOrientation(0, Rotation.rotationTo(0, 2)).at(codechicken.lib.vec.Vector3.center).with(new Translation(x, y, z)), new IconTransformation(icon), new ColourMultiplier(colour)); + } + + public void renderPartShine(CCModel cc) + { + cc.render(null, 0, 0); + } +} \ No newline at end of file diff --git a/src/main/java/resonantinduction/wire/part/TraitConductor.java b/src/main/java/resonantinduction/wire/trait/TraitConductor.java similarity index 98% rename from src/main/java/resonantinduction/wire/part/TraitConductor.java rename to src/main/java/resonantinduction/wire/trait/TraitConductor.java index ce1921ac..bbaf6d98 100644 --- a/src/main/java/resonantinduction/wire/part/TraitConductor.java +++ b/src/main/java/resonantinduction/wire/trait/TraitConductor.java @@ -1,4 +1,4 @@ -package resonantinduction.wire.part; +package resonantinduction.wire.trait; import java.util.HashSet; import java.util.Set; diff --git a/src/main/java/resonantinduction/wire/part/TraitEnergyHandler.java b/src/main/java/resonantinduction/wire/trait/TraitEnergyHandler.java similarity index 98% rename from src/main/java/resonantinduction/wire/part/TraitEnergyHandler.java rename to src/main/java/resonantinduction/wire/trait/TraitEnergyHandler.java index de5f62df..a52819c8 100644 --- a/src/main/java/resonantinduction/wire/part/TraitEnergyHandler.java +++ b/src/main/java/resonantinduction/wire/trait/TraitEnergyHandler.java @@ -1,4 +1,4 @@ -package resonantinduction.wire.part; +package resonantinduction.wire.trait; import java.util.HashSet; import java.util.Set; diff --git a/src/main/java/resonantinduction/wire/part/TraitEnergySink.java b/src/main/java/resonantinduction/wire/trait/TraitEnergySink.java similarity index 98% rename from src/main/java/resonantinduction/wire/part/TraitEnergySink.java rename to src/main/java/resonantinduction/wire/trait/TraitEnergySink.java index e77d0725..2c6efc5d 100644 --- a/src/main/java/resonantinduction/wire/part/TraitEnergySink.java +++ b/src/main/java/resonantinduction/wire/trait/TraitEnergySink.java @@ -1,4 +1,4 @@ -package resonantinduction.wire.part; +package resonantinduction.wire.trait; import ic2.api.energy.tile.IEnergySink;