diff --git a/common/crazypants/enderio/ClientProxy.java b/common/crazypants/enderio/ClientProxy.java index 947ce52c..8d778c18 100644 --- a/common/crazypants/enderio/ClientProxy.java +++ b/common/crazypants/enderio/ClientProxy.java @@ -18,6 +18,7 @@ import crazypants.enderio.conduit.facade.FacadeRenderer; import crazypants.enderio.conduit.liquid.LiquidConduit; import crazypants.enderio.conduit.liquid.LiquidConduitRenderer; import crazypants.enderio.conduit.power.PowerConduit; +import crazypants.enderio.conduit.power.PowerConduitRenderer; import crazypants.enderio.conduit.redstone.RedstoneConduit; import crazypants.enderio.conduit.redstone.RedstoneSwitch; import crazypants.enderio.conduit.redstone.RedstoneSwitchRenderer; @@ -33,7 +34,6 @@ import crazypants.enderio.machine.light.ElectricLightRenderer; import crazypants.enderio.machine.painter.BlockCustomFenceGate; import crazypants.enderio.machine.painter.BlockCustomFenceGateRenderer; import crazypants.enderio.machine.painter.PaintedItemRenderer; -import crazypants.enderio.machine.power.BlockCapacitorBank; import crazypants.enderio.machine.power.CapacitorBankRenderer; import crazypants.enderio.machine.power.TileCapacitorBank; import crazypants.enderio.machine.reservoir.ReservoirRenderer; @@ -121,6 +121,7 @@ public class ClientProxy extends CommonProxy { ClientRegistry.bindTileEntitySpecialRenderer(TileConduitBundle.class, cbr); conduitRenderers.add(RedstoneSwitchRenderer.getInstance()); conduitRenderers.add(new LiquidConduitRenderer()); + conduitRenderers.add(new PowerConduitRenderer()); EnderIoRenderer eior = new EnderIoRenderer(); ClientRegistry.bindTileEntitySpecialRenderer(TileEnderIO.class, eior); diff --git a/common/crazypants/enderio/conduit/AbstractConduit.java b/common/crazypants/enderio/conduit/AbstractConduit.java index 10f0c2c4..8224b618 100644 --- a/common/crazypants/enderio/conduit/AbstractConduit.java +++ b/common/crazypants/enderio/conduit/AbstractConduit.java @@ -3,6 +3,7 @@ package crazypants.enderio.conduit; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.EnumMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -39,18 +40,39 @@ public abstract class AbstractConduit implements IConduit { protected boolean active; protected List collidables; + + protected final EnumMap conectionModes = new EnumMap(ForgeDirection.class); protected boolean collidablesDirty = true; private boolean clientStateDirty = true; private boolean dodgyChangeSinceLastCallFlagForBundle = true; + + private int lastNumConections = -1; protected AbstractConduit() { } - private int lastNumConections = -1; + @Override + public ConnectionMode getConectionMode(ForgeDirection dir) { + ConnectionMode res = conectionModes.get(dir); + if (res == null) { + return ConnectionMode.IN_OUT; + } + return res; + } + @Override + public boolean hasConnectionMode(ConnectionMode mode) { + for (ConnectionMode cm : conectionModes.values()) { + if (cm == mode) { + return true; + } + } + return false; + } + @Override public boolean haveCollidablesChangedSinceLastCall() { if (dodgyChangeSinceLastCallFlagForBundle) { @@ -171,6 +193,16 @@ public abstract class AbstractConduit implements IConduit { } nbtRoot.setIntArray("externalConnections", dirs); nbtRoot.setBoolean("signalActive", active); + + if (conectionModes.size() > 0) { + byte[] modes = new byte[6]; + int i = 0; + for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { + modes[i] = (byte) getConectionMode(dir).ordinal(); + i++; + } + nbtRoot.setByteArray("conModes", modes); + } } @Override @@ -187,7 +219,23 @@ public abstract class AbstractConduit implements IConduit { externalConnections.add(ForgeDirection.values()[dirs[i]]); } active = nbtRoot.getBoolean("signalActive"); - // collidablesDirty = true; + + conectionModes.clear(); + byte[] modes = nbtRoot.getByteArray("conModes"); + if (modes != null && modes.length == 6) { + int i = 0; + for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { + conectionModes.put(dir, ConnectionMode.values()[modes[i]]); + i++; + } + } + // Support for old code + dirs = nbtRoot.getIntArray("extractDirs"); + if (dirs != null) { + for (int i = 0; i < dirs.length; i++) { + conectionModes.put(ForgeDirection.values()[dirs[i]], ConnectionMode.INPUT); + } + } } @Override @@ -237,6 +285,10 @@ public abstract class AbstractConduit implements IConduit { clientStateDirty = true; dodgyChangeSinceLastCallFlagForBundle = true; } + + protected void setClientStateDirty() { + clientStateDirty = true; + } protected void updateNetwork(World world) { if (getNetwork() == null) { diff --git a/common/crazypants/enderio/conduit/ConnectionMode.java b/common/crazypants/enderio/conduit/ConnectionMode.java new file mode 100644 index 00000000..01be2de6 --- /dev/null +++ b/common/crazypants/enderio/conduit/ConnectionMode.java @@ -0,0 +1,16 @@ +package crazypants.enderio.conduit; + +public enum ConnectionMode { + + IN_OUT, + INPUT, + OUTPUT; + + public static ConnectionMode getNext(ConnectionMode mode) { + int ord = mode.ordinal() + 1; + if(ord >= mode.values().length) { + ord = 0; + } + return ConnectionMode.values()[ord]; + } +} diff --git a/common/crazypants/enderio/conduit/IConduit.java b/common/crazypants/enderio/conduit/IConduit.java index c76525ff..ed01fd72 100644 --- a/common/crazypants/enderio/conduit/IConduit.java +++ b/common/crazypants/enderio/conduit/IConduit.java @@ -71,6 +71,10 @@ public interface IConduit { void externalConnectionRemoved(ForgeDirection fromDirection); boolean isConnectedTo(ForgeDirection dir); + + ConnectionMode getConectionMode(ForgeDirection dir); + + boolean hasConnectionMode(ConnectionMode mode); // rendering, only needed us default rendering is used diff --git a/common/crazypants/enderio/conduit/liquid/LiquidConduit.java b/common/crazypants/enderio/conduit/liquid/LiquidConduit.java index 9a1b425d..230cca66 100644 --- a/common/crazypants/enderio/conduit/liquid/LiquidConduit.java +++ b/common/crazypants/enderio/conduit/liquid/LiquidConduit.java @@ -1,6 +1,7 @@ package crazypants.enderio.conduit.liquid; import java.util.ArrayList; +import java.util.EnumMap; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -29,6 +30,7 @@ import cpw.mods.fml.relauncher.SideOnly; import crazypants.enderio.ModObject; import crazypants.enderio.conduit.AbstractConduit; import crazypants.enderio.conduit.AbstractConduitNetwork; +import crazypants.enderio.conduit.ConnectionMode; import crazypants.enderio.conduit.ConduitUtil; import crazypants.enderio.conduit.IConduit; import crazypants.enderio.conduit.IConduitBundle; @@ -69,8 +71,6 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit { private float lastSyncRatio = -99; - private final Set extractDirs = new HashSet(); - private int currentPushToken; // ----------------------------- @@ -83,7 +83,7 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit { private int maxDrainPerTick = 50; private ForgeDirection startPushDir = ForgeDirection.DOWN; - + private final Set filledFromThisTick = new HashSet(); @Override @@ -187,34 +187,36 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit { private void doExtract() { BlockCoord loc = getLocation(); - if (!isPowered() || extractDirs.isEmpty()) { + if (!isPowered() || !hasConnectionMode(ConnectionMode.INPUT)) { return; } int token = network == null ? -1 : network.getNextPushToken(); - for (ForgeDirection dir : extractDirs) { - IFluidHandler extTank = getTankContainer(getLocation().getLocation(dir)); - if (extTank != null) { + for (ForgeDirection dir : externalConnections) { + if (isExtractingFromDir(dir)) { + IFluidHandler extTank = getTankContainer(getLocation().getLocation(dir)); + if (extTank != null) { - FluidStack couldDrain = extTank.drain(dir.getOpposite(), maxDrainPerTick, false); - if (couldDrain != null && couldDrain.amount > 0) { + FluidStack couldDrain = extTank.drain(dir.getOpposite(), maxDrainPerTick, false); + if (couldDrain != null && couldDrain.amount > 0) { - // if we drained all this, how much overflow do we need to push out - int requiredPush = (tank.getFluidAmount() + couldDrain.amount) - tank.getCapacity(); - if (requiredPush <= 0) { - FluidStack drained = extTank.drain(dir.getOpposite(), maxDrainPerTick, true); - if (drained != null) { - tank.fill(drained, true); - } - } else { - - // push as much as we can, to out target max - int pushed = pushLiquid(dir, requiredPush, true, token); - tank.addAmount(-pushed); - if (tank.getAvailableSpace() > 0) { - FluidStack drained = extTank.drain(dir.getOpposite(), Math.min(tank.getAvailableSpace(), maxDrainPerTick), true); + // if we drained all this, how much overflow do we need to push out + int requiredPush = (tank.getFluidAmount() + couldDrain.amount) - tank.getCapacity(); + if (requiredPush <= 0) { + FluidStack drained = extTank.drain(dir.getOpposite(), maxDrainPerTick, true); if (drained != null) { - tank.addAmount(drained.amount); + tank.fill(drained, true); + } + } else { + + // push as much as we can, to out target max + int pushed = pushLiquid(dir, requiredPush, true, token); + tank.addAmount(-pushed); + if (tank.getAvailableSpace() > 0) { + FluidStack drained = extTank.drain(dir.getOpposite(), Math.min(tank.getAvailableSpace(), maxDrainPerTick), true); + if (drained != null) { + tank.addAmount(drained.amount); + } } } } @@ -223,12 +225,13 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit { } } - + private boolean isPowered() { BlockCoord loc = getLocation(); IRedstoneConduit rsCon = getBundle().getConduit(IRedstoneConduit.class); - if(rsCon instanceof RedstoneSwitch && ((RedstoneSwitch)rsCon).isActive()) { - //Need to check for this manually as if we ask the tile if it is being powered it dies not check if it is providing power itself. + if (rsCon instanceof RedstoneSwitch && ((RedstoneSwitch) rsCon).isActive()) { + // Need to check for this manually as if we ask the tile if it is being + // powered it dies not check if it is providing power itself. return true; } return getBundle().getEntity().worldObj.isBlockIndirectlyGettingPowered(loc.x, loc.y, loc.z); @@ -257,7 +260,7 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit { @Override public boolean isExtractingFromDir(ForgeDirection dir) { - return extractDirs.contains(dir); + return getConectionMode(dir) == ConnectionMode.INPUT; } @Override @@ -266,9 +269,9 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit { return; } if (!extracting) { - extractDirs.remove(dir); + conectionModes.remove(dir); } else { - extractDirs.add(dir); + conectionModes.put(dir, ConnectionMode.INPUT); } stateDirty = true; } @@ -293,9 +296,10 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit { @Override public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { - //Note: This is just a guard against mekansims pipes that will continuously call - //fill on us if we push liquid to them. - if(filledFromThisTick.contains(getLocation().getLocation(from))) { + // Note: This is just a guard against mekansims pipes that will continuously + // call + // fill on us if we push liquid to them. + if (filledFromThisTick.contains(getLocation().getLocation(from))) { return 0; } filledFromThisTick.add(getLocation().getLocation(from)); @@ -446,13 +450,6 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit { if (tank.containsValidLiquid()) { nbtRoot.setTag("tank", tank.getFluid().writeToNBT(new NBTTagCompound())); } - - int[] dirs = new int[extractDirs.size()]; - Iterator cons = extractDirs.iterator(); - for (int i = 0; i < dirs.length; i++) { - dirs[i] = cons.next().ordinal(); - } - nbtRoot.setIntArray("extractDirs", dirs); } @Override @@ -461,12 +458,6 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit { updateTanksCapacity(); FluidStack liquid = FluidStack.loadFluidStackFromNBT(nbtRoot.getCompoundTag("tank")); tank.setLiquid(liquid); - - extractDirs.clear(); - int[] dirs = nbtRoot.getIntArray("extractDirs"); - for (int i = 0; i < dirs.length; i++) { - extractDirs.add(ForgeDirection.values()[dirs[i]]); - } } @Override diff --git a/common/crazypants/enderio/conduit/power/IPowerConduit.java b/common/crazypants/enderio/conduit/power/IPowerConduit.java index 48cf40c6..13f9312b 100644 --- a/common/crazypants/enderio/conduit/power/IPowerConduit.java +++ b/common/crazypants/enderio/conduit/power/IPowerConduit.java @@ -1,5 +1,6 @@ package crazypants.enderio.conduit.power; +import net.minecraft.util.Icon; import net.minecraftforge.common.ForgeDirection; import buildcraft.api.power.IPowerReceptor; import crazypants.enderio.conduit.IConduit; @@ -9,11 +10,21 @@ import crazypants.enderio.power.IInternalPowerReceptor; public interface IPowerConduit extends IConduit, IInternalPowerReceptor { public static final String ICON_KEY = "enderio:powerConduit"; + public static final String ICON_KEY_INPUT = "enderio:powerConduitInput"; + public static final String ICON_KEY_OUTPUT = "enderio:powerConduitOutput"; public static final String ICON_CORE_KEY = "enderio:powerConduitCore"; public static final String ICON_TRANSMISSION_KEY = "enderio:powerConduitTransmission"; IPowerReceptor getExternalPowerReceptor(ForgeDirection direction); ICapacitor getCapacitor(); + + float getMaxEnergyExtracted(ForgeDirection dir); + + float getMaxEnergyRecieved(ForgeDirection dir); + + Icon getTextureForInputMode(); + + Icon getTextureForOutputMode(); } diff --git a/common/crazypants/enderio/conduit/power/NetworkPowerManager.java b/common/crazypants/enderio/conduit/power/NetworkPowerManager.java index b079108e..ab3af97d 100644 --- a/common/crazypants/enderio/conduit/power/NetworkPowerManager.java +++ b/common/crazypants/enderio/conduit/power/NetworkPowerManager.java @@ -5,12 +5,8 @@ import java.util.HashMap; import java.util.List; import java.util.ListIterator; import java.util.Map; -import java.util.Set; import net.minecraft.world.World; -import net.minecraftforge.common.ForgeDirection; -import buildcraft.api.power.IPowerReceptor; -import buildcraft.api.power.PowerHandler; import buildcraft.api.power.PowerHandler.PowerReceiver; import buildcraft.api.power.PowerHandler.Type; import crazypants.enderio.conduit.power.PowerConduitNetwork.ReceptorEntry; @@ -77,11 +73,11 @@ public class NetworkPowerManager { float used = 0; float reservedForEntry = removeReservedEnergy(r); float canOffer = available + reservedForEntry; - canOffer = Math.min(r.emmiter.getCapacitor().getMaxEnergyExtracted(), canOffer); + canOffer = Math.min(r.emmiter.getMaxEnergyExtracted(r.direction), canOffer); float requested = pp.powerRequest(); // If it is possible to supply the minimum amount of energy - if (pp.getMinEnergyReceived() <= r.emmiter.getCapacitor().getMaxEnergyExtracted()) { + if (pp.getMinEnergyReceived() <= r.emmiter.getMaxEnergyExtracted(r.direction)) { // Buffer energy if we can't meet it now if (pp.getMinEnergyReceived() > canOffer && requested > 0) { reserveEnergy(r, canOffer); @@ -103,7 +99,7 @@ public class NetworkPowerManager { } appliedCount++; - } + } float used = wasAvailable - available; // use all the capacator storage first @@ -284,13 +280,14 @@ public class NetworkPowerManager { float canGet = 0; if (cb.isOutputEnabled()) { - canGet = Math.min(cb.getEnergyStored(), cb.getMaxIO()); - canGet = Math.min(canGet, rec.emmiter.getCapacitor().getMaxEnergyExtracted()); + canGet = Math.min(cb.getEnergyStored(), cb.getMaxIO()); + canGet = Math.min(canGet, rec.emmiter.getMaxEnergyRecieved(rec.direction)); canExtract += canGet; } float canFill = 0; if(cb.isInputEnabled()) { canFill = Math.min(cb.getMaxEnergyStored() - cb.getEnergyStored(), cb.getMaxIO()); + canFill = Math.min(canFill, rec.emmiter.getMaxEnergyExtracted(rec.direction)); this.canFill += canFill; } enteries.add(new CapBankSupplyEntry(cb, canGet, canFill)); diff --git a/common/crazypants/enderio/conduit/power/PowerConduit.java b/common/crazypants/enderio/conduit/power/PowerConduit.java index 099e7ac0..a27f8af2 100644 --- a/common/crazypants/enderio/conduit/power/PowerConduit.java +++ b/common/crazypants/enderio/conduit/power/PowerConduit.java @@ -20,6 +20,7 @@ import crazypants.enderio.ModObject; import crazypants.enderio.conduit.AbstractConduit; import crazypants.enderio.conduit.AbstractConduitNetwork; import crazypants.enderio.conduit.ConduitUtil; +import crazypants.enderio.conduit.ConnectionMode; import crazypants.enderio.conduit.IConduit; import crazypants.enderio.conduit.IConduitBundle; import crazypants.enderio.conduit.RaytraceResult; @@ -29,7 +30,7 @@ import crazypants.enderio.power.ICapacitor; import crazypants.enderio.power.PowerHandlerUtil; import crazypants.render.BoundingBox; import crazypants.render.IconUtil; -import crazypants.util.Util; +import crazypants.util.BlockCoord; import crazypants.vecmath.Vector3d; public class PowerConduit extends AbstractConduit implements IPowerConduit { @@ -57,6 +58,8 @@ public class PowerConduit extends AbstractConduit implements IPowerConduit { public void registerIcons(IconRegister register) { for (String pf : POSTFIX) { ICONS.put(ICON_KEY + pf, register.registerIcon(ICON_KEY + pf)); + ICONS.put(ICON_KEY_INPUT + pf, register.registerIcon(ICON_KEY_INPUT + pf)); + ICONS.put(ICON_KEY_OUTPUT + pf, register.registerIcon(ICON_KEY_OUTPUT + pf)); ICONS.put(ICON_CORE_KEY + pf, register.registerIcon(ICON_CORE_KEY + pf)); } ICONS.put(ICON_TRANSMISSION_KEY, register.registerIcon(ICON_TRANSMISSION_KEY)); @@ -80,6 +83,8 @@ public class PowerConduit extends AbstractConduit implements IPowerConduit { protected PowerConduitNetwork network; private PowerHandler powerHandler; + + private PowerHandler noInputPH; private int subtype; @@ -93,7 +98,20 @@ public class PowerConduit extends AbstractConduit implements IPowerConduit { @Override public boolean onBlockActivated(EntityPlayer player, RaytraceResult res) { - if(ConduitUtil.isToolEquipped(player)) { + if(ConduitUtil.isToolEquipped(player)) { + if (!getBundle().getEntity().worldObj.isRemote) { + if (res.component != null) { + ForgeDirection connDir = res.component.dir; + if(externalConnections.contains(connDir)) { + ConnectionMode curMode = getConectionMode(connDir); + ConnectionMode newMode = ConnectionMode.getNext(curMode); + System.out.println("PowerConduit.onBlockActivated: Setting mode to: " + newMode); + conectionModes.put(connDir, newMode); + BlockCoord bc = getLocation(); + setClientStateDirty(); + } + } + } if(network != null) { System.out.println("PowerConduit.onBlockActivated: Network contains " + network.getPowerManager().energyStored + " of max energy " + network.getPowerManager().maxEnergyStored); System.out.println("Conduit contains: " + powerHandler.getEnergyStored() + " of max " + powerHandler.getMaxEnergyStored()); @@ -102,7 +120,7 @@ public class PowerConduit extends AbstractConduit implements IPowerConduit { } return false; } - + @Override public ICapacitor getCapacitor() { return CAPACITORS[subtype]; @@ -131,8 +149,37 @@ public class PowerConduit extends AbstractConduit implements IPowerConduit { @Override public PowerReceiver getPowerReceiver(ForgeDirection side) { + if(getConectionMode(side) == ConnectionMode.OUTPUT) { + if(noInputPH == null) { + noInputPH = new PowerHandler(this, Type.PIPE); + noInputPH.configure(0, 0, 0, powerHandler.getMaxEnergyStored()); + } + return noInputPH.getPowerReceiver(); + } return powerHandler.getPowerReceiver(); } + + + + @Override + public float getMaxEnergyExtracted(ForgeDirection dir) { + ConnectionMode mode = getConectionMode(dir); + if(mode == ConnectionMode.INPUT) { + return 0; + } + return getCapacitor().getMaxEnergyExtracted(); + } + + + + @Override + public float getMaxEnergyRecieved(ForgeDirection dir) { + ConnectionMode mode = getConectionMode(dir); + if(mode == ConnectionMode.OUTPUT) { + return 0; + } + return getCapacitor().getMaxEnergyReceived(); + } @Override public PowerHandler getPowerHandler() { @@ -227,9 +274,18 @@ public class PowerConduit extends AbstractConduit implements IPowerConduit { return ICONS.get(ICON_KEY + POSTFIX[subtype]); } + @Override + public Icon getTextureForInputMode() { + return ICONS.get(ICON_KEY_INPUT + POSTFIX[subtype]); + } + + @Override + public Icon getTextureForOutputMode() { + return ICONS.get(ICON_KEY_OUTPUT + POSTFIX[subtype]); + } + @Override public Icon getTransmitionTextureForState(CollidableComponent component) { - // return ICONS.get(ICON_TRANSMISSION_KEY); return null; } diff --git a/common/crazypants/enderio/conduit/power/PowerConduitRenderer.java b/common/crazypants/enderio/conduit/power/PowerConduitRenderer.java new file mode 100644 index 00000000..eaf4c4bc --- /dev/null +++ b/common/crazypants/enderio/conduit/power/PowerConduitRenderer.java @@ -0,0 +1,156 @@ +package crazypants.enderio.conduit.power; + +import static crazypants.util.ForgeDirectionOffsets.offsetScaled; + +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.List; + +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.util.Icon; +import net.minecraftforge.common.ForgeDirection; +import crazypants.enderio.conduit.ConnectionMode; +import crazypants.enderio.conduit.IConduit; +import crazypants.enderio.conduit.IConduitBundle; +import crazypants.enderio.conduit.geom.ConduitGeometryUtil; +import crazypants.enderio.conduit.render.ConduitBundleRenderer; +import crazypants.enderio.conduit.render.DefaultConduitRenderer; +import crazypants.render.BoundingBox; +import crazypants.render.VertexRotation; +import crazypants.render.VertexTransform; +import crazypants.render.VertexTransformComposite; +import crazypants.render.VertexTranslation; +import crazypants.vecmath.Vector3d; +import crazypants.vecmath.Vertex; + +public class PowerConduitRenderer extends DefaultConduitRenderer { + + + private static final EnumMap> VERTS = new EnumMap>(ForgeDirection.class); + + static { + + float scale = 0.8f; + BoundingBox refBB = ConduitGeometryUtil.CORE_BOUNDS; + refBB = refBB.scale(scale, scale, scale); + refBB = refBB.scale(scale, 1, 1); + + double offset = (ConduitGeometryUtil.HWIDTH * scale * scale) + ConduitBundleRenderer.CONNECTOR_DEPTH; + + ForgeDirection dir; + Vector3d trans; + + VertexRotation vrot = new VertexRotation(Math.PI/2, new Vector3d(0, 1, 0), new Vector3d(0.5,0.5,0.5)); + VertexTranslation vtrans = new VertexTranslation(0,0,0); + VertexTransformComposite xform = new VertexTransformComposite(vrot, vtrans); + + dir = ForgeDirection.SOUTH; + trans = offsetScaled(dir, 0.5); + trans.sub(offsetScaled(dir, offset)); + vtrans.set(trans); + VERTS.put(dir, createVerticesForDir(refBB, xform)); + + dir = ForgeDirection.NORTH; + vrot.setAngle(Math.PI + Math.PI/2); + trans = offsetScaled(dir, 0.5); + trans.sub(offsetScaled(dir, offset)); + vtrans.set(trans); + VERTS.put(dir, createVerticesForDir(refBB, xform)); + + dir = ForgeDirection.EAST; + vrot.setAngle(Math.PI); + trans = offsetScaled(dir, 0.5); + trans.sub(offsetScaled(dir, offset)); + vtrans.set(trans); + VERTS.put(dir, createVerticesForDir(refBB, xform)); + + dir = ForgeDirection.WEST; + vrot.setAngle(0); + trans = offsetScaled(dir, 0.5); + trans.sub(offsetScaled(dir, offset)); + vtrans.set(trans); + VERTS.put(dir, createVerticesForDir(refBB, xform)); + + vrot.setAxis(new Vector3d(0,0,1)); + + dir = ForgeDirection.UP; + vrot.setAngle(-Math.PI/2); + trans = offsetScaled(dir, 0.5); + trans.sub(offsetScaled(dir, offset)); + vtrans.set(trans); + VERTS.put(dir, createVerticesForDir(refBB, xform)); + + dir = ForgeDirection.DOWN; + vrot.setAngle(Math.PI/2); + trans = offsetScaled(dir, 0.5); + trans.sub(offsetScaled(dir, offset)); + vtrans.set(trans); + VERTS.put(dir, createVerticesForDir(refBB, xform)); + + } + + @Override + public boolean isRendererForConduit(IConduit conduit) { + return conduit instanceof IPowerConduit; + } + + private static List createVerticesForDir(BoundingBox refBB, VertexTransform xform) { + List result = new ArrayList(24); + for(ForgeDirection face : ForgeDirection.VALID_DIRECTIONS) { + result.addAll(refBB.getCornersWithUvForFace(face)); + } + for(Vertex v : result) { + xform.apply(v.xyz); + //v.xyz.set(v.x(), v.y() + 1, v.z()); + xform.applyToNormal(v.normal); + + } + return result; + } + + + @Override + public void renderEntity(ConduitBundleRenderer conduitBundleRenderer, IConduitBundle te, IConduit conduit, double x, double y, double z, float partialTick, float worldLight) { + super.renderEntity(conduitBundleRenderer, te, conduit, x, y, z, partialTick, worldLight); + + if(!conduit.hasConnectionMode(ConnectionMode.INPUT) && !conduit.hasConnectionMode(ConnectionMode.OUTPUT)) { + return; + } + IPowerConduit pc = (IPowerConduit)conduit; + for(ForgeDirection dir : conduit.getExternalConnections()) { + Icon tex = null; + if(conduit.getConectionMode(dir) == ConnectionMode.INPUT) { + tex = pc.getTextureForInputMode(); + } else if(conduit.getConectionMode(dir) == ConnectionMode.OUTPUT) { + tex = pc.getTextureForOutputMode(); + } + if(tex != null) { + renderModeConnector(pc, dir, tex); + } + } + + } + + private void renderModeConnector(IPowerConduit pc, ForgeDirection dir, Icon tex) { + List verts = VERTS.get(dir); + if(verts == null) { + return; + } + + float uWidth = tex.getMaxU() - tex.getMinU(); + float uScale = uWidth * 0.64f; + float minU = tex.getMinU() + (uWidth - uScale); + float vScale = tex.getMaxV() - tex.getMinV(); + + Tessellator tes = Tessellator.instance; + for(Vertex v : verts) { + tes.setNormal(v.nx(), v.ny(), v.nz()); + tes.addVertexWithUV(v.x(), v.y(), v.z(), minU + (v.u() * uScale), tex.getMinV() + (v.v() * vScale)); + } + + } + + + + +} diff --git a/common/crazypants/enderio/conduit/render/ConduitBundleRenderer.java b/common/crazypants/enderio/conduit/render/ConduitBundleRenderer.java index e3954885..eb9d912e 100644 --- a/common/crazypants/enderio/conduit/render/ConduitBundleRenderer.java +++ b/common/crazypants/enderio/conduit/render/ConduitBundleRenderer.java @@ -37,14 +37,16 @@ public class ConduitBundleRenderer extends TileEntitySpecialRenderer implements private Map connectorBounds = new HashMap(); + public static final float CONNECTOR_DEPTH = 0.05f; + public ConduitBundleRenderer(float conduitScale) { - float connectorDepth = 0.05f; + //float connectorWidth = 0.3f; float connectorWidth = 0.25f + (conduitScale * 0.5f); for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { - connectorBounds.put(dir, createConnector(dir, connectorDepth, connectorWidth)); + connectorBounds.put(dir, createConnector(dir, CONNECTOR_DEPTH, connectorWidth)); } } diff --git a/common/crazypants/enderio/conduit/render/DefaultConduitRenderer.java b/common/crazypants/enderio/conduit/render/DefaultConduitRenderer.java index f6a81d0f..6008f85d 100644 --- a/common/crazypants/enderio/conduit/render/DefaultConduitRenderer.java +++ b/common/crazypants/enderio/conduit/render/DefaultConduitRenderer.java @@ -52,8 +52,10 @@ public class DefaultConduitRenderer implements ConduitRenderer { } tex = conduit.getTextureForState(component); - tessellator.setColorOpaque_F(selfIllum, selfIllum, selfIllum); - renderConduit(tex, component); + if(tex != null) { + tessellator.setColorOpaque_F(selfIllum, selfIllum, selfIllum); + renderConduit(tex, component); + } } } @@ -72,38 +74,6 @@ public class DefaultConduitRenderer implements ConduitRenderer { RoundedSegmentRenderer.renderSegment(component.dir, component.bound, tex.getMinU(), tex.getMaxU(), tex.getMinV(), tex.getMaxV()); } - // @Override - public void renderEntity2(ConduitBundleRenderer conduitBundleRenderer, IConduitBundle te, IConduit conduit, double x, double y, double z, float partialTick, - float worldLight) { - - Collection components = conduit.getCollidableComponents(); - Tessellator tessellator = Tessellator.instance; - - transmissionScaleFactor = conduit.getTransmitionGeometryScale(); - - Icon tex; - boolean active = conduit.isActive(); - for (CollidableComponent component : components) { - if (renderComponent(component)) { - float selfIllum = Math.max(worldLight, conduit.getSelfIlluminationForState(component)); - if (active && isNSEWUP(component.dir) && conduit.getTransmitionTextureForState(component) != null) { - tessellator.setColorRGBA_F(selfIllum + 0.1f, selfIllum + 0.1f, selfIllum + 0.1f, 0.75f); - tex = conduit.getTransmitionTextureForState(component); - drawSection(component.bound, tex.getMinU(), tex.getMaxU(), tex.getMinV(), tex.getMaxV(), component.dir, true); - } - - tex = conduit.getTextureForState(component); - tessellator.setColorOpaque_F(selfIllum, selfIllum, selfIllum); - BoundingBox[] cubes = toCubes(component.bound); - for (BoundingBox cube : cubes) { - drawSection(cube, tex.getMinU(), tex.getMaxU(), tex.getMinV(), tex.getMaxV(), component.dir, false); - } - } - - } - - } - protected boolean renderComponent(CollidableComponent component) { return true; } diff --git a/common/crazypants/enderio/conduit/render/RoundedSegmentRenderer.java b/common/crazypants/enderio/conduit/render/RoundedSegmentRenderer.java index 0cfebcbc..69783168 100644 --- a/common/crazypants/enderio/conduit/render/RoundedSegmentRenderer.java +++ b/common/crazypants/enderio/conduit/render/RoundedSegmentRenderer.java @@ -10,22 +10,21 @@ import net.minecraftforge.common.ForgeDirection; import crazypants.enderio.conduit.geom.ConduitGeometryUtil; import crazypants.render.BoundingBox; import crazypants.vecmath.Matrix4d; -import crazypants.vecmath.Vector2d; import crazypants.vecmath.Vector3d; -import crazypants.vecmath.Vector3f; +import crazypants.vecmath.Vertex; public class RoundedSegmentRenderer { - private static Coord[][] DIR_COORDS = new Coord[ForgeDirection.VALID_DIRECTIONS.length][]; + private static Vertex[][] DIR_COORDS = new Vertex[ForgeDirection.VALID_DIRECTIONS.length][]; private static final Vector3d REF_TRANS = new Vector3d(0.5, 0.5, 0.5); static { double circ = ConduitGeometryUtil.WIDTH * 0.7; - Coord[] refCoords = createUnitSectionQuads(16, -0.25, 0.25); + Vertex[] refCoords = createUnitSectionQuads(16, -0.25, 0.25); - for (Coord coord : refCoords) { + for (Vertex coord : refCoords) { coord.xyz.x = coord.xyz.x * circ; coord.xyz.y = coord.xyz.y * circ; } @@ -57,31 +56,29 @@ public class RoundedSegmentRenderer { } - private static Coord[] xformCoords(Coord[] refCoords, Matrix4d rotMat, Vector3d trans) { - Coord[] res = new Coord[refCoords.length]; + private static Vertex[] xformCoords(Vertex[] refCoords, Matrix4d rotMat, Vector3d trans) { + Vertex[] res = new Vertex[refCoords.length]; for (int i = 0; i < res.length; i++) { - res[i] = new Coord(refCoords[i]); - rotMat.transform(res[i].xyz); - rotMat.transformNormal(res[i].normal); - res[i].xyz.add(trans); + res[i] = new Vertex(refCoords[i]); + res[i].transform(rotMat); + res[i].translate(trans); } return res; } - private static Coord[] xformCoords(List refCoords, Matrix4d rotMat, Vector3d trans) { - Coord[] res = new Coord[refCoords.size()]; + private static Vertex[] xformCoords(List refCoords, Matrix4d rotMat, Vector3d trans) { + Vertex[] res = new Vertex[refCoords.size()]; for (int i = 0; i < res.length; i++) { - res[i] = new Coord(refCoords.get(i)); - rotMat.transform(res[i].xyz); - rotMat.transformNormal(res[i].normal); - res[i].xyz.add(trans); + res[i] = new Vertex(refCoords.get(i)); + res[i].transform(rotMat); + res[i].translate(trans); } return res; } - public static Coord[] createUnitCrossSection(double xOffset, double yOffset, double zOffset, int numCoords, int u) { + public static Vertex[] createUnitCrossSection(double xOffset, double yOffset, double zOffset, int numCoords, int u) { - Coord[] crossSection = new Coord[numCoords]; + Vertex[] crossSection = new Vertex[numCoords]; double angle = 0; double inc = (Math.PI * 2) / (crossSection.length - 1); @@ -89,7 +86,7 @@ public class RoundedSegmentRenderer { double x = Math.cos(angle) * 0.5; double y = Math.sin(angle) * 0.5; angle += inc; - crossSection[i] = new Coord(); + crossSection[i] = new Vertex(); crossSection[i].setXYZ(xOffset + x, yOffset + y, zOffset); crossSection[i].setNormal(x, y, 0); crossSection[i].setUV(u, y + 0.5); @@ -105,8 +102,8 @@ public class RoundedSegmentRenderer { Vector3d offset = calcOffset(dir, bounds); Tessellator tes = Tessellator.instance; - Coord[] coords = DIR_COORDS[dir.ordinal()]; - for (Coord coord : coords) { + Vertex[] coords = DIR_COORDS[dir.ordinal()]; + for (Vertex coord : coords) { double u = minU + (coord.uv.x * uScale); double v = minV + (coord.uv.y * vScale); tes.setNormal(coord.normal.x, coord.normal.y, coord.normal.z); @@ -125,56 +122,21 @@ public class RoundedSegmentRenderer { return res; } - public static Coord[] createUnitSectionQuads(int numCoords, double minZ, double maxZ) { + public static Vertex[] createUnitSectionQuads(int numCoords, double minZ, double maxZ) { - Coord[] z0 = createUnitCrossSection(0, 0, minZ, numCoords + 1, 0); - Coord[] z1 = createUnitCrossSection(0, 0, maxZ, numCoords + 1, 1); + Vertex[] z0 = createUnitCrossSection(0, 0, minZ, numCoords + 1, 0); + Vertex[] z1 = createUnitCrossSection(0, 0, maxZ, numCoords + 1, 1); - Coord[] result = new Coord[numCoords * 4]; + Vertex[] result = new Vertex[numCoords * 4]; for (int i = 0; i < numCoords; i++) { int index = i * 4; - result[index] = new Coord(z0[i]); - result[index + 1] = new Coord(z0[i + 1]); - result[index + 2] = new Coord(z1[i + 1]); - result[index + 3] = new Coord(z1[i]); + result[index] = new Vertex(z0[i]); + result[index + 1] = new Vertex(z0[i + 1]); + result[index + 2] = new Vertex(z1[i + 1]); + result[index + 3] = new Vertex(z1[i]); } return result; } - public static class Coord { - - Vector3d xyz = new Vector3d(); - Vector2d uv = new Vector2d(); - Vector3f normal = new Vector3f(); - - Coord() { - } - - Coord(Coord other) { - xyz.set(other.xyz); - uv.set(other.uv); - normal.set(other.normal); - } - - void setXYZ(double x, double y, double z) { - xyz.set(x, y, z); - } - - void setUV(double u, double v) { - uv.set(u, v); - } - - void setNormal(double x, double y, double z) { - normal.set((float) x, (float) y, (float) z); - normal.normalize(); - } - - @Override - public String toString() { - return "Coord [xyz=" + xyz + ", uv=" + uv + "]"; - } - - } - } diff --git a/common/crazypants/enderio/machine/power/CapacitorBankRenderer.java b/common/crazypants/enderio/machine/power/CapacitorBankRenderer.java index df8f7f1f..03aebb15 100644 --- a/common/crazypants/enderio/machine/power/CapacitorBankRenderer.java +++ b/common/crazypants/enderio/machine/power/CapacitorBankRenderer.java @@ -3,35 +3,26 @@ package crazypants.enderio.machine.power; import java.util.ArrayList; import java.util.List; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL12; - -import net.minecraft.block.Block; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; -import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; import net.minecraftforge.client.IItemRenderer; import net.minecraftforge.common.ForgeDirection; -import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; + +import org.lwjgl.opengl.GL11; + import crazypants.enderio.EnderIO; import crazypants.render.BoundingBox; import crazypants.render.CubeRenderer; import crazypants.render.RenderUtil; import crazypants.util.BlockCoord; -import crazypants.vecmath.CoordUV; -import crazypants.vecmath.VecmathUtil; import crazypants.vecmath.Vector2f; -import crazypants.vecmath.Vector3d; -import crazypants.vecmath.Vector3f; import crazypants.vecmath.Vector4d; +import crazypants.vecmath.Vertex; public class CapacitorBankRenderer extends TileEntitySpecialRenderer implements IItemRenderer { @@ -166,8 +157,9 @@ public class CapacitorBankRenderer extends TileEntitySpecialRenderer implements Tessellator tes = Tessellator.instance; tes.setNormal(gb.face.offsetX, gb.face.offsetY, gb.face.offsetZ); Vector2f u = gb.getMinMaxU(icon); - List corners = gb.bb.getCornersWithUvForFace(gb.face, u.x, u.y, icon.getMinV(), icon.getMaxV()); - for (CoordUV coord : corners) { + List corners = gb.bb.getCornersWithUvForFace(gb.face, u.x, u.y, icon.getMinV(), icon.getMaxV()); + for (Vertex coord : corners) { + tes.setNormal(coord.nx(), coord.ny(), coord.nz()); tes.addVertexWithUV(coord.x(), coord.y(), coord.z(), coord.u(), coord.v()); } } @@ -206,8 +198,8 @@ public class CapacitorBankRenderer extends TileEntitySpecialRenderer implements Tessellator tes = Tessellator.instance; tes.setNormal(gb.face.offsetX, gb.face.offsetY, gb.face.offsetZ); Vector2f u = gb.getMinMaxU(icon); - List corners = gb.bb.getCornersWithUvForFace(gb.face, u.x, u.y, icon.getMinV(), maxV); - for (CoordUV coord : corners) { + List corners = gb.bb.getCornersWithUvForFace(gb.face, u.x, u.y, icon.getMinV(), maxV); + for (Vertex coord : corners) { tes.addVertexWithUV(coord.x(), Math.min(coord.y(), maxY), coord.z(), coord.u(), coord.v()); } } diff --git a/common/crazypants/enderio/machine/power/TileCapacitorBank.java b/common/crazypants/enderio/machine/power/TileCapacitorBank.java index 0bbcc7e3..78eee02d 100644 --- a/common/crazypants/enderio/machine/power/TileCapacitorBank.java +++ b/common/crazypants/enderio/machine/power/TileCapacitorBank.java @@ -15,8 +15,9 @@ import buildcraft.api.power.PowerHandler.PowerReceiver; import buildcraft.api.power.PowerHandler.Type; import crazypants.enderio.ModObject; import crazypants.enderio.PacketHandler; +import crazypants.enderio.conduit.ConnectionMode; import crazypants.enderio.conduit.IConduitBundle; -import crazypants.enderio.conduit.TileConduitBundle; +import crazypants.enderio.conduit.power.IPowerConduit; import crazypants.enderio.machine.RedstoneControlMode; import crazypants.enderio.power.BasicCapacitor; import crazypants.enderio.power.IInternalPowerReceptor; @@ -167,7 +168,13 @@ public class TileCapacitorBank extends TileEntity implements IInternalPowerRecep if(! (receptor.receptor instanceof IConduitBundle) ) { //power conduits manage the exchange between them an the cap bank used = PowerHandlerUtil.transmitInternal((IInternalPowerReceptor) receptor.receptor, pp, canTransmit, Type.STORAGE, receptor.fromDir); } else { - used = 0; + IConduitBundle bundle = (IConduitBundle)receptor.receptor; + IPowerConduit conduit = bundle.getConduit(IPowerConduit.class); + if(conduit != null && conduit.getConectionMode(receptor.fromDir) == ConnectionMode.INPUT) { + used = PowerHandlerUtil.transmitInternal((IInternalPowerReceptor) receptor.receptor, pp, canTransmit, Type.STORAGE, receptor.fromDir); + } else { + used = 0; + } } } else { // System.out.println("TileEntityStirlingGenerator.transmitEnergy: Sending " diff --git a/common/crazypants/render/BoundingBox.java b/common/crazypants/render/BoundingBox.java index 32f03aef..f190fa9e 100644 --- a/common/crazypants/render/BoundingBox.java +++ b/common/crazypants/render/BoundingBox.java @@ -5,10 +5,10 @@ import java.util.List; import net.minecraftforge.common.ForgeDirection; import crazypants.util.BlockCoord; -import crazypants.vecmath.CoordUV; import crazypants.vecmath.Vector2f; import crazypants.vecmath.Vector3d; import crazypants.vecmath.Vector3f; +import crazypants.vecmath.Vertex; public final class BoundingBox { @@ -98,51 +98,50 @@ public final class BoundingBox { * @param face * @return */ - public List getCornersWithUvForFace(ForgeDirection face) { + public List getCornersWithUvForFace(ForgeDirection face) { return getCornersWithUvForFace(face, 0, 1, 0, 1); - } - - - public List getCornersWithUvForFace(ForgeDirection face, float minU, float maxU, float minV, float maxV) { - List result = new ArrayList(4); + } + + public List getCornersWithUvForFace(ForgeDirection face, float minU, float maxU, float minV, float maxV) { + List result = new ArrayList(4); switch(face) { case NORTH: - result.add(new CoordUV(new Vector3d(maxX, minY, minZ), new Vector2f(minU, minV))); - result.add(new CoordUV(new Vector3d(minX, minY, minZ), new Vector2f(maxU, minV))); - result.add(new CoordUV(new Vector3d(minX, maxY, minZ), new Vector2f(maxU, maxV))); - result.add(new CoordUV(new Vector3d(maxX, maxY, minZ), new Vector2f(minU, maxV))); + result.add(new Vertex(new Vector3d(maxX, minY, minZ), new Vector3f(0,0,-1), new Vector2f(minU, minV))); + result.add(new Vertex(new Vector3d(minX, minY, minZ), new Vector3f(0,0,-1), new Vector2f(maxU, minV))); + result.add(new Vertex(new Vector3d(minX, maxY, minZ), new Vector3f(0,0,-1), new Vector2f(maxU, maxV))); + result.add(new Vertex(new Vector3d(maxX, maxY, minZ), new Vector3f(0,0,-1), new Vector2f(minU, maxV))); break; case SOUTH: - result.add(new CoordUV(new Vector3d(minX, minY, maxZ), new Vector2f(minU, minV))); - result.add(new CoordUV(new Vector3d(maxX, minY, maxZ), new Vector2f(maxU, minV))); - result.add(new CoordUV(new Vector3d(maxX, maxY, maxZ), new Vector2f(maxU, maxV))); - result.add(new CoordUV(new Vector3d(minX, maxY, maxZ), new Vector2f(minU, maxV))); + result.add(new Vertex(new Vector3d(minX, minY, maxZ), new Vector3f(0,0,1), new Vector2f(maxU, minV))); + result.add(new Vertex(new Vector3d(maxX, minY, maxZ), new Vector3f(0,0,1), new Vector2f(minU, minV))); + result.add(new Vertex(new Vector3d(maxX, maxY, maxZ), new Vector3f(0,0,1), new Vector2f(minU, maxV))); + result.add(new Vertex(new Vector3d(minX, maxY, maxZ), new Vector3f(0,0,1), new Vector2f(maxU, maxV))); break; case EAST: - result.add(new CoordUV(new Vector3d(maxX, maxY, minZ), new Vector2f(minU, maxV))); - result.add(new CoordUV(new Vector3d(maxX, maxY, maxZ), new Vector2f(maxU, maxV))); - result.add(new CoordUV(new Vector3d(maxX, minY, maxZ), new Vector2f(maxU, minV))); - result.add(new CoordUV(new Vector3d(maxX, minY, minZ), new Vector2f(minU, minV))); + result.add(new Vertex(new Vector3d(maxX, maxY, minZ), new Vector3f(1,0,0), new Vector2f(maxU, maxV))); + result.add(new Vertex(new Vector3d(maxX, maxY, maxZ), new Vector3f(1,0,0), new Vector2f(minU, maxV))); + result.add(new Vertex(new Vector3d(maxX, minY, maxZ), new Vector3f(1,0,0), new Vector2f(minU, minV))); + result.add(new Vertex(new Vector3d(maxX, minY, minZ), new Vector3f(1,0,0), new Vector2f(maxU, minV))); break; case WEST: - result.add(new CoordUV(new Vector3d(minX, minY, minZ), new Vector2f(minU, minV))); - result.add(new CoordUV(new Vector3d(minX, minY, maxZ), new Vector2f(maxU, minV))); - result.add(new CoordUV(new Vector3d(minX, maxY, maxZ), new Vector2f(maxU, maxV))); - result.add(new CoordUV(new Vector3d(minX, maxY, minZ), new Vector2f(minU, maxV))); + result.add(new Vertex(new Vector3d(minX, minY, minZ), new Vector3f(-1,0,0), new Vector2f(maxU, minV))); + result.add(new Vertex(new Vector3d(minX, minY, maxZ), new Vector3f(-1,0,0), new Vector2f(minU, minV))); + result.add(new Vertex(new Vector3d(minX, maxY, maxZ), new Vector3f(-1,0,0), new Vector2f(minU, maxV))); + result.add(new Vertex(new Vector3d(minX, maxY, minZ), new Vector3f(-1,0,0), new Vector2f(maxU, maxV))); break; case UP: - result.add(new CoordUV(new Vector3d(maxX, maxY, maxZ), new Vector2f(minU, minV))); - result.add(new CoordUV(new Vector3d(maxX, maxY, minZ), new Vector2f(minU, maxV))); - result.add(new CoordUV(new Vector3d(minX, maxY, minZ), new Vector2f(maxU, maxV))); - result.add(new CoordUV(new Vector3d(minX, maxY, maxZ), new Vector2f(maxU, minV))); + result.add(new Vertex(new Vector3d(maxX, maxY, maxZ), new Vector3f(0,1,0), new Vector2f(minU, minV))); + result.add(new Vertex(new Vector3d(maxX, maxY, minZ), new Vector3f(0,1,0), new Vector2f(minU, maxV))); + result.add(new Vertex(new Vector3d(minX, maxY, minZ), new Vector3f(0,1,0), new Vector2f(maxU, maxV))); + result.add(new Vertex(new Vector3d(minX, maxY, maxZ), new Vector3f(0,1,0), new Vector2f(maxU, minV))); break; - case DOWN: + case DOWN: // case UNKNOWN: default: - result.add(new CoordUV(new Vector3d(minX, minY, minZ), new Vector2f(maxU, maxV))); - result.add(new CoordUV(new Vector3d(maxX, minY, minZ), new Vector2f(minU, maxV))); - result.add(new CoordUV(new Vector3d(maxX, minY, maxZ), new Vector2f(minU, minV))); - result.add(new CoordUV(new Vector3d(minX, minY, maxZ), new Vector2f(maxU, minV))); + result.add(new Vertex(new Vector3d(minX, minY, minZ), new Vector3f(0,-1,0), new Vector2f(maxU, maxV))); + result.add(new Vertex(new Vector3d(maxX, minY, minZ), new Vector3f(0,-1,0), new Vector2f(minU, maxV))); + result.add(new Vertex(new Vector3d(maxX, minY, maxZ), new Vector3f(0,-1,0), new Vector2f(minU, minV))); + result.add(new Vertex(new Vector3d(minX, minY, maxZ), new Vector3f(0,-1,0), new Vector2f(maxU, minV))); break; } return result; diff --git a/common/crazypants/render/VertexRotation.java b/common/crazypants/render/VertexRotation.java index a1b4507d..b4d1f2ce 100644 --- a/common/crazypants/render/VertexRotation.java +++ b/common/crazypants/render/VertexRotation.java @@ -2,14 +2,19 @@ package crazypants.render; import crazypants.vecmath.Quat4d; import crazypants.vecmath.Vector3d; +import crazypants.vecmath.Vector3f; public class VertexRotation implements VertexTransform { private final Vector3d center; - private final Quat4d quat; + private Quat4d quat; + private double angle; + private final Vector3d axis; public VertexRotation(double angle, Vector3d axis, Vector3d center) { - this.center = center; + this.center = new Vector3d(center); + this.axis = new Vector3d(axis); + this.angle = angle; quat = Quat4d.makeRotate(angle, axis); } @@ -20,4 +25,23 @@ public class VertexRotation implements VertexTransform { vec.add(center); } + public void setAngle(double angle) { + this.angle = angle; + quat = Quat4d.makeRotate(angle, axis); + } + + public void setAxis(Vector3d axis) { + this.axis.set(axis); + quat = Quat4d.makeRotate(angle, axis); + } + + public void setCenter(Vector3d cen) { + center.set(cen); + } + + @Override + public void applyToNormal(Vector3f vec) { + quat.rotate(vec); + } + } diff --git a/common/crazypants/render/VertexTransform.java b/common/crazypants/render/VertexTransform.java index bce8a73c..fe6f9c9b 100644 --- a/common/crazypants/render/VertexTransform.java +++ b/common/crazypants/render/VertexTransform.java @@ -1,9 +1,11 @@ package crazypants.render; import crazypants.vecmath.Vector3d; +import crazypants.vecmath.Vector3f; public interface VertexTransform { public abstract void apply(Vector3d vec); + public abstract void applyToNormal(Vector3f vec); } diff --git a/common/crazypants/render/VertexTransformComposite.java b/common/crazypants/render/VertexTransformComposite.java new file mode 100644 index 00000000..0d6ec52e --- /dev/null +++ b/common/crazypants/render/VertexTransformComposite.java @@ -0,0 +1,40 @@ +package crazypants.render; + +import java.util.Collection; + +import crazypants.vecmath.Vector3d; +import crazypants.vecmath.Vector3f; + +public class VertexTransformComposite implements VertexTransform { + + private final VertexTransform[] xforms; + + public VertexTransformComposite(VertexTransform... xforms){ + this.xforms = xforms; + } + + VertexTransformComposite(Collection xformsIn){ + xforms = new VertexTransform[xformsIn.size()]; + int i = 0; + for(VertexTransform xform : xformsIn) { + xforms[i] = xform; + i++; + } + } + + @Override + public void apply(Vector3d vec) { + for(VertexTransform xform : xforms) { + xform.apply(vec); + } + + } + + @Override + public void applyToNormal(Vector3f vec) { + for(VertexTransform xform : xforms) { + xform.applyToNormal(vec); + } + } + +} diff --git a/common/crazypants/render/VertexTranslation.java b/common/crazypants/render/VertexTranslation.java new file mode 100644 index 00000000..baa5b807 --- /dev/null +++ b/common/crazypants/render/VertexTranslation.java @@ -0,0 +1,55 @@ +package crazypants.render; + +import crazypants.vecmath.Vector3d; +import crazypants.vecmath.Vector3f; + +public class VertexTranslation implements VertexTransform { + + private double x; + private double y; + private double z; + + public VertexTranslation(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + } + + public VertexTranslation(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + } + + public VertexTranslation(Vector3d trans) { + this(trans.x, trans.y,trans.z); + } + + public VertexTranslation(Vector3f trans) { + this(trans.x, trans.y,trans.z); + } + + + @Override + public void apply(Vector3d vec) { + vec.x += x; + vec.y += y; + vec.z += z; + } + + public void set(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + } + + public void set(Vector3d trans) { + set(trans.x, trans.y,trans.z); + } + + @Override + public void applyToNormal(Vector3f vec) { + + } + +} diff --git a/common/crazypants/vecmath/CoordUV.java b/common/crazypants/vecmath/CoordUV.java deleted file mode 100644 index c832700b..00000000 --- a/common/crazypants/vecmath/CoordUV.java +++ /dev/null @@ -1,36 +0,0 @@ -package crazypants.vecmath; - -public class CoordUV { - - public Vector3d coord; - public Vector2f uv; - - public CoordUV() { - } - - public CoordUV(Vector3d coord, Vector2f uv) { - this.coord = coord; - this.uv = uv; - } - - public double x() { - return coord.x; - } - - public double y() { - return coord.y; - } - - public double z() { - return coord.z; - } - - public double u() { - return uv.x; - } - - public double v() { - return uv.y; - } - -} diff --git a/common/crazypants/vecmath/Quat4d.java b/common/crazypants/vecmath/Quat4d.java index 0f34656d..927de65a 100644 --- a/common/crazypants/vecmath/Quat4d.java +++ b/common/crazypants/vecmath/Quat4d.java @@ -44,4 +44,14 @@ public class Quat4d { vec.z = d3 * w - d * z - d1 * y + d2 * x; } + public void rotate(Vector3f vec) { + double d = -x * vec.x - y * vec.y - z * vec.z; + double d1 = w * vec.x + y * vec.z - z * vec.y; + double d2 = w * vec.y - x * vec.z + z * vec.x; + double d3 = w * vec.z + x * vec.y - y * vec.x; + vec.x = (float)(d1 * w - d * x - d2 * z + d3 * y); + vec.y = (float)(d2 * w - d * y + d1 * z - d3 * x); + vec.z = (float)(d3 * w - d * z - d1 * y + d2 * x); + } + } diff --git a/common/crazypants/vecmath/Vector2d.java b/common/crazypants/vecmath/Vector2d.java index d0a61a85..6fb147b5 100644 --- a/common/crazypants/vecmath/Vector2d.java +++ b/common/crazypants/vecmath/Vector2d.java @@ -23,6 +23,11 @@ public class Vector2d { this.x = x; this.y = y; } + + public void set(Vector2f vec) { + x = vec.x; + y = vec.y; + } public void set(Vector2d vec) { x = vec.x; @@ -39,6 +44,18 @@ public class Vector2d { y -= vec.y; } + + public void add(Vector2f vec) { + x += vec.x; + y += vec.y; + } + + public void sub(Vector2f vec) { + x -= vec.x; + y -= vec.y; + } + + public void negate() { x = -x; y = -y; diff --git a/common/crazypants/vecmath/Vertex.java b/common/crazypants/vecmath/Vertex.java new file mode 100644 index 00000000..85ea0568 --- /dev/null +++ b/common/crazypants/vecmath/Vertex.java @@ -0,0 +1,84 @@ +package crazypants.vecmath; + + +public class Vertex { + + public final Vector3d xyz = new Vector3d(); + public final Vector2f uv = new Vector2f(); + public final Vector3f normal = new Vector3f(); + + public Vertex() { + } + + public Vertex(Vertex other) { + xyz.set(other.xyz); + uv.set(other.uv); + normal.set(other.normal); + } + + public Vertex(Vector3d xyz, Vector3f normal, Vector2f uv) { + this.xyz.set(xyz); + this.normal.set(normal); + this.uv.set(uv); + } + + public void setXYZ(double x, double y, double z) { + xyz.set(x, y, z); + } + + public void setUV(double u, double v) { + uv.set(u, v); + } + + public void setNormal(double x, double y, double z) { + normal.set((float) x, (float) y, (float) z); + normal.normalize(); + } + + public void transform(Matrix4d xform) { + xform.transform(xyz); + xform.transformNormal(normal); + } + + public void translate(Vector3d trans) { + xyz.add(trans); + } + + public double x() { + return xyz.x; + } + + public double y() { + return xyz.y; + } + + public double z() { + return xyz.z; + } + + public float nx() { + return normal.x; + } + + public float ny() { + return normal.y; + } + + public float nz() { + return normal.z; + } + + public float u() { + return uv.x; + } + + public float v() { + return uv.y; + } + + @Override + public String toString() { + return "Vertex [xyz=" + xyz + ", uv=" + uv + "]"; + } + +} diff --git a/resources/assets/enderio/textures/blocks/powerConduitInput.png b/resources/assets/enderio/textures/blocks/powerConduitInput.png new file mode 100644 index 00000000..21188b78 Binary files /dev/null and b/resources/assets/enderio/textures/blocks/powerConduitInput.png differ diff --git a/resources/assets/enderio/textures/blocks/powerConduitInputEnder.png b/resources/assets/enderio/textures/blocks/powerConduitInputEnder.png new file mode 100644 index 00000000..3d470e7f Binary files /dev/null and b/resources/assets/enderio/textures/blocks/powerConduitInputEnder.png differ diff --git a/resources/assets/enderio/textures/blocks/powerConduitInputEnhanced.png b/resources/assets/enderio/textures/blocks/powerConduitInputEnhanced.png new file mode 100644 index 00000000..fe5c9929 Binary files /dev/null and b/resources/assets/enderio/textures/blocks/powerConduitInputEnhanced.png differ diff --git a/resources/assets/enderio/textures/blocks/powerConduitOutput.pdn b/resources/assets/enderio/textures/blocks/powerConduitOutput.pdn new file mode 100644 index 00000000..6c3481ec Binary files /dev/null and b/resources/assets/enderio/textures/blocks/powerConduitOutput.pdn differ diff --git a/resources/assets/enderio/textures/blocks/powerConduitOutput.png b/resources/assets/enderio/textures/blocks/powerConduitOutput.png new file mode 100644 index 00000000..db32a1e5 Binary files /dev/null and b/resources/assets/enderio/textures/blocks/powerConduitOutput.png differ diff --git a/resources/assets/enderio/textures/blocks/powerConduitOutputEnder.png b/resources/assets/enderio/textures/blocks/powerConduitOutputEnder.png new file mode 100644 index 00000000..31ff454e Binary files /dev/null and b/resources/assets/enderio/textures/blocks/powerConduitOutputEnder.png differ diff --git a/resources/assets/enderio/textures/blocks/powerConduitOutputEnhanced.png b/resources/assets/enderio/textures/blocks/powerConduitOutputEnhanced.png new file mode 100644 index 00000000..e3d3ecb8 Binary files /dev/null and b/resources/assets/enderio/textures/blocks/powerConduitOutputEnhanced.png differ