Fixed #247 - Transformer not transferring energy
This commit is contained in:
parent
2ab0cf924d
commit
cbaf9884e6
7 changed files with 76 additions and 51 deletions
|
@ -22,6 +22,7 @@ public class MultipartElectrical implements IPartFactory
|
||||||
public MultipartElectrical()
|
public MultipartElectrical()
|
||||||
{
|
{
|
||||||
MultiPartRegistry.registerParts(this, PART_TYPES);
|
MultiPartRegistry.registerParts(this, PART_TYPES);
|
||||||
|
MultipartGenerator.registerPassThroughInterface("universalelectricity.api.electricity.IVoltageOutput");
|
||||||
MultipartGenerator.registerTrait("universalelectricity.api.energy.IConductor", "resonantinduction.electrical.wire.trait.TraitConductor");
|
MultipartGenerator.registerTrait("universalelectricity.api.energy.IConductor", "resonantinduction.electrical.wire.trait.TraitConductor");
|
||||||
MultipartGenerator.registerTrait("cofh.api.energy.IEnergyHandler", "resonantinduction.electrical.wire.trait.TraitEnergyHandler");
|
MultipartGenerator.registerTrait("cofh.api.energy.IEnergyHandler", "resonantinduction.electrical.wire.trait.TraitEnergyHandler");
|
||||||
MultipartGenerator.registerTrait("ic2.api.energy.tile.IEnergySink", "resonantinduction.electrical.wire.trait.TraitEnergySink");
|
MultipartGenerator.registerTrait("ic2.api.energy.tile.IEnergySink", "resonantinduction.electrical.wire.trait.TraitEnergySink");
|
||||||
|
|
|
@ -8,6 +8,9 @@ import net.minecraft.util.MovingObjectPosition;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import resonantinduction.core.prefab.part.PartFace;
|
import resonantinduction.core.prefab.part.PartFace;
|
||||||
import resonantinduction.electrical.Electrical;
|
import resonantinduction.electrical.Electrical;
|
||||||
|
import universalelectricity.api.CompatibilityModule;
|
||||||
|
import universalelectricity.api.UniversalClass;
|
||||||
|
import universalelectricity.api.UniversalElectricity;
|
||||||
import universalelectricity.api.electricity.IElectricalNetwork;
|
import universalelectricity.api.electricity.IElectricalNetwork;
|
||||||
import universalelectricity.api.electricity.IVoltageInput;
|
import universalelectricity.api.electricity.IVoltageInput;
|
||||||
import universalelectricity.api.electricity.IVoltageOutput;
|
import universalelectricity.api.electricity.IVoltageOutput;
|
||||||
|
@ -17,10 +20,7 @@ import universalelectricity.api.vector.VectorHelper;
|
||||||
import calclavia.lib.utility.WrenchUtility;
|
import calclavia.lib.utility.WrenchUtility;
|
||||||
import codechicken.lib.data.MCDataInput;
|
import codechicken.lib.data.MCDataInput;
|
||||||
import codechicken.lib.data.MCDataOutput;
|
import codechicken.lib.data.MCDataOutput;
|
||||||
import codechicken.lib.vec.Rotation;
|
|
||||||
import codechicken.lib.vec.Vector3;
|
import codechicken.lib.vec.Vector3;
|
||||||
import codechicken.multipart.JNormalOcclusion;
|
|
||||||
import codechicken.multipart.TFacePart;
|
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
@ -30,11 +30,12 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||||
* @author Calclavia
|
* @author Calclavia
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@UniversalClass
|
||||||
public class PartTransformer extends PartFace implements IVoltageOutput, IEnergyInterface
|
public class PartTransformer extends PartFace implements IVoltageOutput, IEnergyInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
/** Step the voltage up */
|
/** Step the voltage up */
|
||||||
private boolean stepUp;
|
private boolean stepUp = true;
|
||||||
|
|
||||||
/** Amount to mulitply the step by (up x2. down /2) */
|
/** Amount to mulitply the step by (up x2. down /2) */
|
||||||
public byte multiplier = 2;
|
public byte multiplier = 2;
|
||||||
|
@ -97,7 +98,7 @@ public class PartTransformer extends PartFace implements IVoltageOutput, IEnergy
|
||||||
public void save(NBTTagCompound nbt)
|
public void save(NBTTagCompound nbt)
|
||||||
{
|
{
|
||||||
super.save(nbt);
|
super.save(nbt);
|
||||||
nbt.setBoolean("stepUp", this.stepUp);
|
nbt.setBoolean("stepUp", stepUp);
|
||||||
nbt.setByte("multiplier", multiplier);
|
nbt.setByte("multiplier", multiplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,22 +117,24 @@ public class PartTransformer extends PartFace implements IVoltageOutput, IEnergy
|
||||||
@Override
|
@Override
|
||||||
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive)
|
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive)
|
||||||
{
|
{
|
||||||
if (from == this.getFacing().getOpposite())
|
if (from == getAbsoluteFacing())
|
||||||
{
|
{
|
||||||
TileEntity entity = VectorHelper.getTileEntityFromSide(this.world(), new universalelectricity.api.vector.Vector3(this.x(), this.y(), this.z()), this.getFacing());
|
TileEntity tile = VectorHelper.getTileEntityFromSide(this.world(), new universalelectricity.api.vector.Vector3(x(), y(), z()), from.getOpposite());
|
||||||
if (entity instanceof IEnergyInterface)
|
|
||||||
|
if (CompatibilityModule.isHandler(tile))
|
||||||
{
|
{
|
||||||
if (entity instanceof IVoltageInput)
|
if (tile instanceof IVoltageInput)
|
||||||
{
|
{
|
||||||
long voltage = this.getVoltageOutput(from.getOpposite());
|
long voltage = this.getVoltageOutput(from.getOpposite());
|
||||||
if (voltage != ((IVoltageInput) entity).getVoltageInput(from))
|
|
||||||
|
if (voltage != ((IVoltageInput) tile).getVoltageInput(from))
|
||||||
{
|
{
|
||||||
((IVoltageInput) entity).onWrongVoltage(from, voltage);
|
((IVoltageInput) tile).onWrongVoltage(from, voltage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ((IEnergyInterface) entity).onReceiveEnergy(from, receive, doReceive);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return CompatibilityModule.receiveEnergy(tile, from, receive, doReceive);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -143,28 +146,36 @@ public class PartTransformer extends PartFace implements IVoltageOutput, IEnergy
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getVoltageOutput(ForgeDirection side)
|
public long getVoltageOutput(ForgeDirection from)
|
||||||
{
|
{
|
||||||
if (side == this.getFacing())
|
if (from == getAbsoluteFacing().getOpposite())
|
||||||
{
|
{
|
||||||
TileEntity entity = VectorHelper.getTileEntityFromSide(this.world(), new universalelectricity.api.vector.Vector3(this.x(), this.y(), this.z()), this.getFacing().getOpposite());
|
TileEntity inputTile = VectorHelper.getTileEntityFromSide(this.world(), new universalelectricity.api.vector.Vector3(x(), y(), z()), getAbsoluteFacing());
|
||||||
if (entity instanceof IConductor && ((IConductor) entity).getNetwork() instanceof IElectricalNetwork)
|
|
||||||
|
long inputVoltage = UniversalElectricity.DEFAULT_VOLTAGE;
|
||||||
|
|
||||||
|
if (inputTile instanceof IConductor)
|
||||||
{
|
{
|
||||||
long voltage = ((IElectricalNetwork) ((IConductor) entity).getNetwork()).getVoltage();
|
IConductor conductor = (IConductor) ((IConductor) inputTile).getInstance(placementSide);
|
||||||
|
|
||||||
|
if (conductor != null)
|
||||||
|
if (conductor.getNetwork() instanceof IElectricalNetwork)
|
||||||
|
inputVoltage = ((IElectricalNetwork) conductor.getNetwork()).getVoltage();
|
||||||
|
}
|
||||||
|
else if (inputTile instanceof IVoltageOutput)
|
||||||
|
{
|
||||||
|
inputVoltage = ((IVoltageOutput) inputTile).getVoltageOutput(from);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inputVoltage <= 0)
|
||||||
|
inputVoltage = UniversalElectricity.DEFAULT_VOLTAGE;
|
||||||
|
|
||||||
if (this.stepUp())
|
if (this.stepUp())
|
||||||
{
|
return inputVoltage * (this.multiplier + 2);
|
||||||
return voltage * this.multiplier;
|
else
|
||||||
}
|
return inputVoltage / (this.multiplier + 2);
|
||||||
else if (voltage > 0)
|
|
||||||
{
|
|
||||||
return voltage / this.multiplier;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (entity instanceof IVoltageOutput)
|
|
||||||
{
|
|
||||||
return ((IVoltageOutput) entity).getVoltageOutput(side);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,16 +196,18 @@ public class PartTransformer extends PartFace implements IVoltageOutput, IEnergy
|
||||||
WrenchUtility.damageWrench(player, player.inventory.getCurrentItem(), x(), y(), z());
|
WrenchUtility.damageWrench(player, player.inventory.getCurrentItem(), x(), y(), z());
|
||||||
|
|
||||||
facing = (byte) ((facing + 1) % 4);
|
facing = (byte) ((facing + 1) % 4);
|
||||||
|
|
||||||
sendDescUpdate();
|
sendDescUpdate();
|
||||||
|
|
||||||
tile().notifyPartChange(this);
|
tile().notifyPartChange(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
stepUp = !stepUp;
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!world().isRemote)
|
||||||
|
player.addChatMessage("Transformer set to step " + (stepUp ? "up" : "down") + ".");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -408,11 +408,11 @@ public class PartFlatWire extends PartAdvancedWire implements TFacePart, JNormal
|
||||||
BlockCoord pos = new BlockCoord(tile()).offset(absSide);
|
BlockCoord pos = new BlockCoord(tile()).offset(absSide);
|
||||||
|
|
||||||
/** Look for an external wire connection. */
|
/** Look for an external wire connection. */
|
||||||
TileMultipart t = MultipartUtility.getMultipartTile(world(), pos);
|
TileMultipart tileMultiPart = MultipartUtility.getMultipartTile(world(), pos);
|
||||||
|
|
||||||
if (t != null && r != -1)
|
if (tileMultiPart != null && r != -1)
|
||||||
{
|
{
|
||||||
TMultiPart tp = t.partMap(this.side);
|
TMultiPart tp = tileMultiPart.partMap(this.side);
|
||||||
|
|
||||||
if (this.canConnectTo(tp, ForgeDirection.getOrientation(absSide)))
|
if (this.canConnectTo(tp, ForgeDirection.getOrientation(absSide)))
|
||||||
{
|
{
|
||||||
|
@ -422,8 +422,17 @@ public class PartFlatWire extends PartAdvancedWire implements TFacePart, JNormal
|
||||||
if (tp instanceof PartFlatWire && ((PartFlatWire) tp).canConnectTo(this, ForgeDirection.getOrientation(absSide).getOpposite()) && ((PartFlatWire) tp).maskOpen(otherR))
|
if (tp instanceof PartFlatWire && ((PartFlatWire) tp).canConnectTo(this, ForgeDirection.getOrientation(absSide).getOpposite()) && ((PartFlatWire) tp).maskOpen(otherR))
|
||||||
{
|
{
|
||||||
// We found a wire! Merge connection.
|
// We found a wire! Merge connection.
|
||||||
this.connections[absSide] = tp;
|
connections[absSide] = tp;
|
||||||
this.getNetwork().merge(((PartFlatWire) tp).getNetwork());
|
getNetwork().merge(((PartFlatWire) tp).getNetwork());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for a micro-energy block
|
||||||
|
*/
|
||||||
|
if (canConnectTo(tp))
|
||||||
|
{
|
||||||
|
connections[absSide] = tp;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,27 +170,29 @@ public class TraitConductor extends TileMultipart implements IConductor
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IConnector<IEnergyNetwork> getInstance(ForgeDirection from)
|
public IConductor getInstance(ForgeDirection from)
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Try out different sides to try to inject energy into.
|
* Try out different sides to try to inject energy into.
|
||||||
*/
|
*/
|
||||||
if (this.partMap(from.ordinal()) == null)
|
if (partMap(from.ordinal()) instanceof IConductor)
|
||||||
{
|
{
|
||||||
|
return (IConductor) partMap(from.ordinal());
|
||||||
|
}
|
||||||
|
|
||||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||||
{
|
{
|
||||||
TMultiPart part = this.partMap(dir.ordinal());
|
TMultiPart part = this.partMap(dir.ordinal());
|
||||||
|
|
||||||
if (this.ueInterfaces.contains(part))
|
if (this.ueInterfaces.contains(part))
|
||||||
{
|
{
|
||||||
return ((IConductor) part).getInstance(from);
|
return (IConductor) ((IConductor) part).getInstance(from);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (partMap(PartMap.CENTER.ordinal()) instanceof IConductor)
|
if (partMap(PartMap.CENTER.ordinal()) instanceof IConductor)
|
||||||
{
|
{
|
||||||
return (IConnector<IEnergyNetwork>) partMap(PartMap.CENTER.ordinal());
|
return (IConductor) (IConnector<IEnergyNetwork>) partMap(PartMap.CENTER.ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -11,9 +11,9 @@ import resonantinduction.core.Reference;
|
||||||
import resonantinduction.core.ResonantInduction;
|
import resonantinduction.core.ResonantInduction;
|
||||||
import resonantinduction.core.Settings;
|
import resonantinduction.core.Settings;
|
||||||
import resonantinduction.core.TabRI;
|
import resonantinduction.core.TabRI;
|
||||||
import resonantinduction.core.prefab.fluid.ItemBlockFluidContainer;
|
|
||||||
import resonantinduction.mechanical.belt.BlockConveyorBelt;
|
import resonantinduction.mechanical.belt.BlockConveyorBelt;
|
||||||
import resonantinduction.mechanical.belt.TileConveyorBelt;
|
import resonantinduction.mechanical.belt.TileConveyorBelt;
|
||||||
|
import resonantinduction.mechanical.fluid.pipe.ItemBlockFluidContainer;
|
||||||
import resonantinduction.mechanical.fluid.pipe.ItemPipe;
|
import resonantinduction.mechanical.fluid.pipe.ItemPipe;
|
||||||
import resonantinduction.mechanical.fluid.tank.BlockTank;
|
import resonantinduction.mechanical.fluid.tank.BlockTank;
|
||||||
import resonantinduction.mechanical.fluid.tank.TileTank;
|
import resonantinduction.mechanical.fluid.tank.TileTank;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package resonantinduction.core.prefab.fluid;
|
package resonantinduction.mechanical.fluid.pipe;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
import resonantinduction.core.prefab.fluid.TileFluidNetwork;
|
||||||
import resonantinduction.mechanical.Mechanical;
|
import resonantinduction.mechanical.Mechanical;
|
||||||
import resonantinduction.mechanical.fluid.pipe.EnumPipeMaterial;
|
|
||||||
import resonantinduction.mechanical.fluid.tank.TileTank;
|
import resonantinduction.mechanical.fluid.tank.TileTank;
|
||||||
import universalelectricity.api.energy.UnitDisplay;
|
import universalelectricity.api.energy.UnitDisplay;
|
||||||
import universalelectricity.api.energy.UnitDisplay.Unit;
|
import universalelectricity.api.energy.UnitDisplay.Unit;
|
|
@ -11,8 +11,8 @@ import net.minecraft.util.MovingObjectPosition;
|
||||||
import net.minecraft.world.IBlockAccess;
|
import net.minecraft.world.IBlockAccess;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import resonantinduction.core.prefab.fluid.BlockFluidNetwork;
|
import resonantinduction.core.prefab.fluid.BlockFluidNetwork;
|
||||||
import resonantinduction.core.prefab.fluid.ItemBlockFluidContainer;
|
|
||||||
import resonantinduction.core.render.RIBlockRenderingHandler;
|
import resonantinduction.core.render.RIBlockRenderingHandler;
|
||||||
|
import resonantinduction.mechanical.fluid.pipe.ItemBlockFluidContainer;
|
||||||
import universalelectricity.api.UniversalElectricity;
|
import universalelectricity.api.UniversalElectricity;
|
||||||
import universalelectricity.api.vector.Vector3;
|
import universalelectricity.api.vector.Vector3;
|
||||||
import calclavia.lib.utility.FluidUtility;
|
import calclavia.lib.utility.FluidUtility;
|
||||||
|
|
Loading…
Reference in a new issue