Probably actually works now

This commit is contained in:
malte0811 2018-08-25 16:25:43 +02:00
parent c8bba65ad4
commit d51562b937
17 changed files with 99 additions and 467 deletions

View file

@ -30,6 +30,9 @@ public class IWConfig {
public static int[] maxLengthPerConn = {16, 16, 16, 32, 32}; public static int[] maxLengthPerConn = {16, 16, 16, 32, 32};
@Comment({"The maximum length of wire a coil item.", "Order: Tin, Copper, Gold, HV, Glass Fiber (as above)"}) @Comment({"The maximum length of wire a coil item.", "Order: Tin, Copper, Gold, HV, Glass Fiber (as above)"})
public static int[] maxLengthOnCoil = {1024, 1024, 1024, 2048, 2048}; public static int[] maxLengthOnCoil = {1024, 1024, 1024, 2048, 2048};
@Comment({"The factor between the IF transfer rate of the wires and the IF transfer rate corresponding to the EU transfer rate.",
"The default value results in the same transfer rates as the standard IE wires"})
public static double wireRatio = .5;
@Comment({"Set this to false to completely disable any conversion between IF and EU (default: true)"}) @Comment({"Set this to false to completely disable any conversion between IF and EU (default: true)"})
@RequiresMcRestart @RequiresMcRestart

View file

@ -18,6 +18,7 @@ import blusunrize.immersiveengineering.api.IEProperties;
import malte0811.industrialWires.IndustrialWires; import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.BlockIWBase; import malte0811.industrialWires.blocks.BlockIWBase;
import malte0811.industrialWires.blocks.IMetaEnum; import malte0811.industrialWires.blocks.IMetaEnum;
import malte0811.industrialWires.util.ConversionUtil;
import malte0811.industrialWires.wires.MixedWireType; import malte0811.industrialWires.wires.MixedWireType;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
@ -161,8 +162,8 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
int type = stack.getMetadata() / 2; int type = stack.getMetadata() / 2;
tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.power_tier", (type%5) + 1)); tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.power_tier", (type%5) + 1));
MixedWireType wire = MixedWireType.ALL[type]; MixedWireType wire = MixedWireType.ALL[type];
tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.eu_per_tick", tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.energy_per_tick",
wire.getTransferRate() / wire.getFactor())); wire.getIORate()*ConversionUtil.euPerJoule(), wire.getIORate()*ConversionUtil.ifPerJoule()));
} }
} }

View file

@ -26,6 +26,7 @@ import ic2.api.energy.tile.IEnergyEmitter;
import ic2.api.energy.tile.IEnergySink; import ic2.api.energy.tile.IEnergySink;
import ic2.api.energy.tile.IEnergySource; import ic2.api.energy.tile.IEnergySource;
import malte0811.industrialWires.IMixedConnector; import malte0811.industrialWires.IMixedConnector;
import malte0811.industrialWires.IWConfig;
import malte0811.industrialWires.IndustrialWires; import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.IBlockBoundsIW; import malte0811.industrialWires.blocks.IBlockBoundsIW;
import malte0811.industrialWires.compat.Compat; import malte0811.industrialWires.compat.Compat;
@ -64,10 +65,10 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
private static final double EPS = .1; private static final double EPS = .1;
private EnumFacing facing = EnumFacing.NORTH; private EnumFacing facing = EnumFacing.NORTH;
private boolean relay; private boolean relay;
private boolean first = true;
// external net to IE net buffer // external net to IE net buffer
private double bufferToNet = 0; private double bufferToNet = 0;
private double ieInputInTick = 0; private double potentialIEInputInTick = 0;
private double actualIEInputInTick = 0;
private double maxToNet = 0; private double maxToNet = 0;
//IE net to external net buffer //IE net to external net buffer
private double bufferToMachine = 0; private double bufferToMachine = 0;
@ -75,7 +76,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
private double maxToMachine = 0; private double maxToMachine = 0;
private EnergyType energyType = NONE; private EnergyType energyType = NONE;
private boolean shouldBreak = false; private boolean shouldBreak = false;
private final double maxStored; private final double maxIO;
private final MixedWireType wireType; private final MixedWireType wireType;
private final int tier; private final int tier;
private final double relayOffset; private final double relayOffset;
@ -84,7 +85,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
protected TileEntityIC2ConnectorTin(boolean relay, MixedWireType type, int tier, double relayLength, double connLength) { protected TileEntityIC2ConnectorTin(boolean relay, MixedWireType type, int tier, double relayLength, double connLength) {
this.relay = relay; this.relay = relay;
wireType = type; wireType = type;
maxStored = type.getIORate(); maxIO = type.getIORate();
this.tier = tier; this.tier = tier;
this.relayOffset = relayLength-.5; this.relayOffset = relayLength-.5;
this.connOffset = connLength-.5; this.connOffset = connLength-.5;
@ -136,18 +137,9 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
} }
return; return;
} }
if (externalInputInTick==0 && ieInputInTick == 0 && bufferToNet == 0 && bufferToMachine == 0) { if (externalInputInTick ==0 && potentialIEInputInTick == 0 && bufferToNet == 0 && bufferToMachine == 0) {
energyType = NONE; energyType = NONE;
} }
if (bufferToNet > EPS) {
transferPowerToNet();
}
if (bufferToNet >EPS) {
notifyAvailableEnergy(bufferToNet);
}
if (bufferToMachine > EPS && energyType==FE_AC) {
transferPowerToFEMachine();
}
if (bufferToNet < maxToNet) { if (bufferToNet < maxToNet) {
maxToNet = bufferToNet; maxToNet = bufferToNet;
} }
@ -159,15 +151,24 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
if (bufferToMachine < maxToMachine) { if (bufferToMachine < maxToMachine) {
maxToMachine = bufferToMachine; maxToMachine = bufferToMachine;
} }
if (ieInputInTick > maxToMachine) { potentialIEInputInTick = Math.max(Math.max(potentialIEInputInTick, actualIEInputInTick), getMaxIO());
maxToMachine = ieInputInTick; if (potentialIEInputInTick > maxToMachine) {
maxToMachine = potentialIEInputInTick;
}
potentialIEInputInTick = 0;
actualIEInputInTick = 0;
if (bufferToNet > EPS) {
transferPowerToNet();
}
if (bufferToNet >EPS) {
notifyAvailableEnergy(bufferToNet);
}
if (bufferToMachine > EPS && energyType==FE_AC) {
transferPowerToFEMachine();
} }
ieInputInTick = 0;
} }
} }
//TODO push FE
private void transferPowerToNet() { private void transferPowerToNet() {
Set<AbstractConnection> conns = ImmersiveNetHandler.INSTANCE.getIndirectEnergyConnections(pos, world, true); Set<AbstractConnection> conns = ImmersiveNetHandler.INSTANCE.getIndirectEnergyConnections(pos, world, true);
Map<AbstractConnection, Pair<IMixedConnector, Double>> maxOutputs = new HashMap<>(); Map<AbstractConnection, Pair<IMixedConnector, Double>> maxOutputs = new HashMap<>();
@ -204,7 +205,8 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
for (Connection sub : c.subConnections) { for (Connection sub : c.subConnections) {
int transferredPerCon = transferedPerConn.getOrDefault(sub, 0); int transferredPerCon = transferedPerConn.getOrDefault(sub, 0);
energyAtConn -= sub.cableType.getLossRatio() * sub.length; energyAtConn -= sub.cableType.getLossRatio() * sub.length;
ImmersiveNetHandler.INSTANCE.getTransferedRates(world.provider.getDimension()).put(sub, (int) (transferredPerCon + energyAtConn)); double wireLoad = energyAtConn/(energyType==FE_AC?IWConfig.wireRatio:1);
transferedPerConn.put(sub, (int) (transferredPerCon + wireLoad));
IImmersiveConnectable subStart = ApiUtils.toIIC(sub.start, world); IImmersiveConnectable subStart = ApiUtils.toIIC(sub.start, world);
IImmersiveConnectable subEnd = ApiUtils.toIIC(sub.end, world); IImmersiveConnectable subEnd = ApiUtils.toIIC(sub.end, world);
if (subStart != null && passedConnectors.add(subStart)) if (subStart != null && passedConnectors.add(subStart))
@ -222,7 +224,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
if (te!=null && te.hasCapability(CapabilityEnergy.ENERGY, facing.getOpposite())) { if (te!=null && te.hasCapability(CapabilityEnergy.ENERGY, facing.getOpposite())) {
IEnergyStorage handler = te.getCapability(CapabilityEnergy.ENERGY, facing.getOpposite()); IEnergyStorage handler = te.getCapability(CapabilityEnergy.ENERGY, facing.getOpposite());
assert handler!=null; assert handler!=null;
double outJoules = Math.min(bufferToMachine, maxToMachine); double outJoules = Math.min(bufferToMachine, maxToMachine*IWConfig.wireRatio);
int outFE = MathHelper.floor(outJoules*ConversionUtil.ifPerJoule()); int outFE = MathHelper.floor(outJoules*ConversionUtil.ifPerJoule());
int received = handler.receiveEnergy(outFE, false); int received = handler.receiveEnergy(outFE, false);
bufferToMachine -= received*ConversionUtil.joulesPerIf(); bufferToMachine -= received*ConversionUtil.joulesPerIf();
@ -255,7 +257,12 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
private double getAverageLossRate(AbstractConnection conn) { private double getAverageLossRate(AbstractConnection conn) {
double f = 0; double f = 0;
for (Connection c : conn.subConnections) { for (Connection c : conn.subConnections) {
f += c.length * c.cableType.getLossRatio(); WireType type = c.cableType;
if (type instanceof MixedWireType) {
f += c.length * ((MixedWireType)type).getLoss(energyType);
} else {
f = Double.POSITIVE_INFINITY;
}
} }
return f; return f;
} }
@ -269,16 +276,22 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
shouldBreak = true; shouldBreak = true;
return 0; return 0;
} }
final double insert = Math.min(maxStored - bufferToMachine, joules); double insert = Math.min(getMaxIO() - bufferToMachine, joules);
insert = Math.min(getMaxIO()-actualIEInputInTick, insert);
if (!simulate) { if (!simulate) {
bufferToMachine += insert; bufferToMachine += insert;
actualIEInputInTick += insert;
} else { } else {
//Yes, this is weird. But it works, otherwise the system can get stuck at a lower output rate with a full buffer //Yes, this is weird. But it works, otherwise the system can get stuck at a lower output rate with a full buffer
ieInputInTick += insert; potentialIEInputInTick += Math.min(joules, getMaxIO());
} }
return joules - insert; return joules - insert;
} }
private double getMaxIO() {
return maxIO*(energyType==FE_AC?IWConfig.wireRatio:1);
}
@Override @Override
public void invalidate() { public void invalidate() {
if (!world.isRemote) if (!world.isRemote)
@ -338,7 +351,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
@Override @Override
@Optional.Method(modid="ic2") @Optional.Method(modid="ic2")
public double getDemandedEnergy() { public double getDemandedEnergy() {
double ret = (maxStored - bufferToNet) *ConversionUtil.euPerJoule() + .5; double ret = (getMaxIO() - bufferToNet) *ConversionUtil.euPerJoule() + .5;
if (ret < .1) if (ret < .1)
ret = 0; ret = 0;
return ret; return ret;
@ -394,7 +407,8 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
} else if (energyType!=type) { } else if (energyType!=type) {
shouldBreak = true; shouldBreak = true;
} }
if (bufferToNet < maxStored) { joules = Math.min(getMaxIO()-externalInputInTick, joules);
if (bufferToNet < getMaxIO()) {
if (!simulate) { if (!simulate) {
bufferToNet += joules; bufferToNet += joules;
externalInputInTick += joules; externalInputInTick += joules;
@ -560,6 +574,9 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
@Override @Override
public int receiveEnergy(int maxReceive, boolean simulate) { public int receiveEnergy(int maxReceive, boolean simulate) {
if (bufferToNet>=getMaxIO()) {
return 0;
}
double joules = maxReceive*ConversionUtil.joulesPerIf(); double joules = maxReceive*ConversionUtil.joulesPerIf();
double accepted = addToIn(joules, simulate, FE_AC); double accepted = addToIn(joules, simulate, FE_AC);
return MathHelper.ceil(accepted*ConversionUtil.ifPerJoule()); return MathHelper.ceil(accepted*ConversionUtil.ifPerJoule());
@ -590,7 +607,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
@Override @Override
public int getMaxEnergyStored() { public int getMaxEnergyStored() {
return (int) (2*maxStored*ConversionUtil.ifPerJoule()); return (int) (2* getMaxIO() *ConversionUtil.ifPerJoule());
} }
@Override @Override

View file

@ -16,44 +16,28 @@ package malte0811.industrialWires.items;
import blusunrize.immersiveengineering.api.ApiUtils; import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.api.Lib; import blusunrize.immersiveengineering.api.Lib;
import blusunrize.immersiveengineering.api.TargetingInfo;
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
import blusunrize.immersiveengineering.api.energy.wires.IWireCoil; import blusunrize.immersiveengineering.api.energy.wires.IWireCoil;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection;
import blusunrize.immersiveengineering.common.IESaveData;
import blusunrize.immersiveengineering.common.blocks.metal.TileEntityBreakerSwitch;
import blusunrize.immersiveengineering.common.blocks.metal.TileEntityRedstoneBreaker;
import blusunrize.immersiveengineering.common.util.ItemNBTHelper; import blusunrize.immersiveengineering.common.util.ItemNBTHelper;
import blusunrize.immersiveengineering.common.util.Utils;
import malte0811.industrialWires.IWConfig; import malte0811.industrialWires.IWConfig;
import malte0811.industrialWires.IndustrialWires; import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.util.ConversionUtil; import malte0811.industrialWires.util.ConversionUtil;
import malte0811.industrialWires.wires.MixedWireType; import malte0811.industrialWires.wires.MixedWireType;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt; import net.minecraft.nbt.NBTTagInt;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*; import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3i;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
public class ItemIC2Coil extends Item implements IWireCoil { public class ItemIC2Coil extends Item implements IWireCoil {
public final static String[] subNames = { public final static String[] subNames = {
@ -102,9 +86,9 @@ public class ItemIC2Coil extends Item implements IWireCoil {
double ioRate = wireType.getIORate(); double ioRate = wireType.getIORate();
double transferRate = ioRate*wireType.getFactor(); double transferRate = ioRate*wireType.getFactor();
tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.transfer_rate", tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.transfer_rate",
transferRate*ConversionUtil.euPerJoule(), transferRate*ConversionUtil.ifPerJoule())); transferRate*ConversionUtil.euPerJoule(), transferRate*ConversionUtil.ifPerJoule()*IWConfig.wireRatio));
tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.input_rate", tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.input_rate",
ioRate*ConversionUtil.euPerJoule(), ioRate*ConversionUtil.ifPerJoule())); ioRate*ConversionUtil.euPerJoule(), ioRate*ConversionUtil.ifPerJoule()*IWConfig.wireRatio));
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("linkingPos")) { if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("linkingPos")) {
int[] link = stack.getTagCompound().getIntArray("linkingPos"); int[] link = stack.getTagCompound().getIntArray("linkingPos");
if (link.length > 3) { if (link.length > 3) {
@ -118,135 +102,7 @@ public class ItemIC2Coil extends Item implements IWireCoil {
@Nonnull @Nonnull
@Override @Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) { public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand); return ApiUtils.doCoilUse(this, player, world, pos, hand, side, hitX, hitY, hitZ);
if (!stack.isEmpty()) {
if (stack.getCount() > 1) {
player.sendMessage(new TextComponentTranslation(IndustrialWires.MODID + ".chat.stackSize"));
return EnumActionResult.FAIL;
}
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof IImmersiveConnectable && ((IImmersiveConnectable) tileEntity).canConnect()) {
TargetingInfo target = new TargetingInfo(side, hitX, hitY, hitZ);
MixedWireType wire = getWireType(stack);
BlockPos masterPos = ((IImmersiveConnectable) tileEntity).getConnectionMaster(wire, target);
Vec3i offset = pos.subtract(masterPos);
tileEntity = world.getTileEntity(masterPos);
if (!(tileEntity instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntity).canConnect())
return EnumActionResult.PASS;
boolean canConnect = ((IImmersiveConnectable) tileEntity).canConnectCable(wire, target, offset);
if (canConnect&&tileEntity instanceof TileEntityBreakerSwitch) {
canConnect = !wire.isHV()||tileEntity instanceof TileEntityRedstoneBreaker;
}
if (!canConnect) {
if (!world.isRemote)
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "wrongCable"));
return EnumActionResult.FAIL;
}
if (!world.isRemote)
if (!ItemNBTHelper.hasKey(stack, "linkingPos")) {
ItemNBTHelper.setIntArray(stack, "linkingPos", new int[]{world.provider.getDimension(), masterPos.getX(), masterPos.getY(), masterPos.getZ(),
offset.getX(), offset.getY(), offset.getZ()});
NBTTagCompound targetNbt = new NBTTagCompound();
target.writeToNBT(targetNbt);
ItemNBTHelper.setTagCompound(stack, "targettingInfo", targetNbt);
} else {
int[] array = ItemNBTHelper.getIntArray(stack, "linkingPos");
BlockPos linkPos = new BlockPos(array[1], array[2], array[3]);
Vec3i offsetLink = BlockPos.NULL_VECTOR;
if (array.length == 7)
offsetLink = new Vec3i(array[4], array[5], array[6]);
TileEntity tileEntityLinkingPos = world.getTileEntity(linkPos);
int distanceSq = (int) Math.ceil(linkPos.distanceSq(masterPos));
if (array[0] != world.provider.getDimension()) {
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "wrongDimension"));
} else if (linkPos.equals(masterPos)) {
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "sameConnection"));
} else if (distanceSq > (wire.getMaxLength() * wire.getMaxLength())) {
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "tooFar"));
} else {
TargetingInfo targetLink = TargetingInfo.readFromNBT(ItemNBTHelper.getTagCompound(stack, "targettingInfo"));
if (!(tileEntityLinkingPos instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntityLinkingPos).canConnectCable(wire, targetLink, offset)) {
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "invalidPoint"));
} else {
IImmersiveConnectable nodeHere = (IImmersiveConnectable) tileEntity;
IImmersiveConnectable nodeLink = (IImmersiveConnectable) tileEntityLinkingPos;
boolean connectionExists = false;
Set<Connection> outputs = ImmersiveNetHandler.INSTANCE.getConnections(world, Utils.toCC(nodeHere));
if (outputs != null) {
for (Connection con : outputs) {
if (con.end.equals(Utils.toCC(nodeLink))) {
connectionExists = true;
}
}
}
if (connectionExists) {
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "connectionExists"));
} else {
Set<BlockPos> ignore = new HashSet<>();
ignore.addAll(nodeHere.getIgnored(nodeLink));
ignore.addAll(nodeLink.getIgnored(nodeHere));
Connection tmpConn = new Connection(Utils.toCC(nodeHere), Utils.toCC(nodeLink), wire,
(int) Math.sqrt(distanceSq));
Vec3d start = nodeHere.getConnectionOffset(tmpConn, target, pos.subtract(masterPos)).addVector(tileEntity.getPos().getX(),
tileEntity.getPos().getY(), tileEntity.getPos().getZ());
Vec3d end = nodeLink.getConnectionOffset(tmpConn, targetLink, offsetLink).addVector(tileEntityLinkingPos.getPos().getX(),
tileEntityLinkingPos.getPos().getY(), tileEntityLinkingPos.getPos().getZ());
boolean canSee = ApiUtils.raytraceAlongCatenary(tmpConn, (p) -> {
if (ignore.contains(p.getLeft())) {
return false;
}
IBlockState state = world.getBlockState(p.getLeft());
return ApiUtils.preventsConnection(world, p.getLeft(), state, p.getMiddle(), p.getRight());
}, (p) -> {
}, start, end);
if (canSee) {
int lengthOnStack = getLength(stack);
int length = (int) Math.sqrt(distanceSq);
if (length <= lengthOnStack) {
Connection conn = ImmersiveNetHandler.INSTANCE.addAndGetConnection(world, Utils.toCC(nodeHere), Utils.toCC(nodeLink),
(int) Math.sqrt(distanceSq), wire);
nodeHere.connectCable(wire, target, nodeLink, offset);
nodeLink.connectCable(wire, targetLink, nodeHere, offsetLink);
ImmersiveNetHandler.INSTANCE.addBlockData(world, conn);
IESaveData.setDirty(world.provider.getDimension());
Utils.unlockIEAdvancement(player, "main/connect_wire");
if (!player.capabilities.isCreativeMode) {
if (length < lengthOnStack) {
setLength(stack, lengthOnStack - length);
} else {
player.setHeldItem(hand, ItemStack.EMPTY);
}
}
((TileEntity) nodeHere).markDirty();
world.addBlockEvent(masterPos, ((TileEntity) nodeHere).getBlockType(), -1, 0);
IBlockState state = world.getBlockState(masterPos);
world.notifyBlockUpdate(masterPos, state, state, 3);
((TileEntity) nodeLink).markDirty();
world.addBlockEvent(linkPos, ((TileEntity) nodeLink).getBlockType(), -1, 0);
state = world.getBlockState(linkPos);
world.notifyBlockUpdate(linkPos, state, state, 3);
} else {
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "tooFar"));
}
} else {
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "cantSee"));
}
}
}
}
ItemNBTHelper.remove(stack, "linkingPos");
ItemNBTHelper.remove(stack, "targettingInfo");
}
return EnumActionResult.SUCCESS;
}
return EnumActionResult.PASS;
}
return EnumActionResult.PASS;
} }
public static void setLength(ItemStack i, int blocks) { public static void setLength(ItemStack i, int blocks) {
@ -263,4 +119,19 @@ public class ItemIC2Coil extends Item implements IWireCoil {
public static int getMaxWireLength(ItemStack i) { public static int getMaxWireLength(ItemStack i) {
return IWConfig.maxLengthOnCoil[i.getItemDamage()%5]; return IWConfig.maxLengthOnCoil[i.getItemDamage()%5];
} }
@Override
public int getMaxLength(ItemStack stack) {
return getLength(stack);
}
@Override
public void consumeWire(ItemStack stack, int lengthConsumed) {
int lengthOnStack = getLength(stack);
if (lengthConsumed < lengthOnStack) {
setLength(stack, lengthOnStack - lengthConsumed);
} else {
stack.shrink(1);
}
}
} }

View file

@ -29,11 +29,11 @@ public class ConversionUtil {
return Config.IEConfig.Machines.dynamo_output; return Config.IEConfig.Machines.dynamo_output;
} }
public static double euPerIfIdeal() { public static double euPerIf() {
return MechConversion.euPerIf; return MechConversion.euPerIf;
} }
public static double ifPerEuIdeal() { public static double ifPerEu() {
return 1 / MechConversion.euPerIf; return 1 / MechConversion.euPerIf;
} }
@ -46,7 +46,7 @@ public class ConversionUtil {
} }
public static double kinPerRot() { public static double kinPerRot() {
return kinPerEu() * euPerIfIdeal() * ifPerRot(); return kinPerEu() * euPerIf() * ifPerRot();
} }
public static double rotPerKin() { public static double rotPerKin() {
@ -62,10 +62,10 @@ public class ConversionUtil {
} }
public static double joulesPerEu() { public static double joulesPerEu() {
return joulesPerIf()*ifPerEuIdeal(); return joulesPerIf()* ifPerEu();
} }
public static double euPerJoule() { public static double euPerJoule() {
return euPerIfIdeal()*ifPerJoule(); return euPerIf()*ifPerJoule();
} }
} }

View file

@ -40,7 +40,8 @@ public class MixedWireType extends WireType {
private final int[] ic2Colors = {0xa5bcc7, 0xbc7945, 0xfeff73, 0xb9d6d9, 0xf1f1f1}; private final int[] ic2Colors = {0xa5bcc7, 0xbc7945, 0xfeff73, 0xb9d6d9, 0xf1f1f1};
private final String[] ic2Names = {"ic2Tin", "ic2Copper", "ic2Gold", "ic2Hv", "ic2Glass", private final String[] ic2Names = {"ic2Tin", "ic2Copper", "ic2Gold", "ic2Hv", "ic2Glass",
"ic2TinIns", "ic2CopperIns", "ic2GoldIns"}; "ic2TinIns", "ic2CopperIns", "ic2GoldIns"};
private final double[] lossPerBlock = {.2, .2, .4, .8, .025}; private final double[] euLossPerBlock = {.2, .2, .4, .8, .025};
private final double[] ifLossRate = new double[euLossPerBlock.length];
private final double[] ic2RenderDiameter = { private final double[] ic2RenderDiameter = {
.03125, .03125, .046875, .0625, .75 * .03125, .0625, .0625, 2*.046875 .03125, .03125, .046875, .0625, .75 * .03125, .0625, .0625, 2*.046875
}; };
@ -61,14 +62,20 @@ public class MixedWireType extends WireType {
super(); super();
this.type = ordinal; this.type = ordinal;
WireApi.registerWireType(this); WireApi.registerWireType(this);
for (int i = 0;i<ifLossRate.length;i++) {
//Loss is the same at full single-connector load
double lossPerBlockIF = euLossPerBlock[i] * ConversionUtil.ifPerEu();
ifLossRate[i] = lossPerBlockIF/(getIORate()*ConversionUtil.ifPerJoule());
}
} }
/**
* In this case, this does not return the loss RATIO but the loss PER BLOCK
*/
@Override @Override
public double getLossRatio() { public double getLossRatio() {
return lossPerBlock[type%5]; return ifLossRate[type%5];
}
public double getLossRateEU() {
return euLossPerBlock[type%5];
} }
@Override @Override
@ -167,4 +174,17 @@ public class MixedWireType extends WireType {
public boolean isHV() { public boolean isHV() {
return this==HV||this==GLASS; return this==HV||this==GLASS;
} }
public double getLoss(EnergyType energyType) {
switch (energyType) {
case FE_AC:
return getLossRatio();
case EU_DC:
return getLossRateEU();
case NONE:
default:
return 10;
}
}
} }

View file

@ -103,7 +103,7 @@ industrialwires.tooltip.latching=Stays on indefinitely
industrialwires.tooltip.instantaneous=Turns off after half a second industrialwires.tooltip.instantaneous=Turns off after half a second
industrialwires.tooltip.length=Length: %1s industrialwires.tooltip.length=Length: %1s
industrialwires.tooltip.power_tier=Power Tier: %s industrialwires.tooltip.power_tier=Power Tier: %s
industrialwires.tooltip.eu_per_tick=%s EU/t industrialwires.tooltip.energy_per_tick=%s EU/t=%s IF/t
industrialwires.tooltip.transfer_rate=Burns at %s EU/t (%s IF/t) industrialwires.tooltip.transfer_rate=Burns at %s EU/t (%s IF/t)
industrialwires.tooltip.input_rate=%s EU/t (%s IF/t) per connector industrialwires.tooltip.input_rate=%s EU/t (%s IF/t) per connector

View file

@ -1,29 +0,0 @@
{
"result": {
"item": "industrialwires:ic2_connector",
"data": 2,
"count": 4
},
"pattern": [
" c ",
"rcr",
"rcr"
],
"type": "forge:ore_shaped",
"key": {
"r": {
"type": "forge:ore_dict",
"ore": "itemRubber"
},
"c": {
"type": "forge:ore_dict",
"ore": "ingotCopper"
}
},
"conditions": [
{
"type": "forge:mod_loaded",
"modid": "ic2"
}
]
}

View file

@ -1,26 +0,0 @@
{
"result": {
"item": "industrialwires:ic2_connector",
"data": 3,
"count": 4
},
"pattern": [
" c ",
"rcr"
],
"type": "forge:ore_shaped",
"key": {
"r": {
"type": "forge:ore_dict", "ore": "itemRubber"
},
"c": {
"type": "forge:ore_dict", "ore": "ingotCopper"
}
},
"conditions": [
{
"type": "forge:mod_loaded",
"modid": "ic2"
}
]
}

View file

@ -1,29 +0,0 @@
{
"result": {
"item": "industrialwires:ic2_connector",
"data": 8,
"count": 4
},
"pattern": [
" c ",
"rcr",
"rcr"
],
"type": "forge:ore_shaped",
"key": {
"r": {
"type": "forge:ore_dict", "ore": "itemRubber"
},
"c": {
"type": "industrialwires:ic2_item",
"name": "cable",
"variant": "type:glass,insulation:0"
}
},
"conditions": [
{
"type": "forge:mod_loaded",
"modid": "ic2"
}
]
}

View file

@ -1,33 +0,0 @@
{
"result": {
"item": "industrialwires:ic2_connector",
"data": 9,
"count": 4
},
"pattern": [
" c ",
"grg",
"grg"
],
"type": "forge:ore_shaped",
"key": {
"r": {
"type": "forge:ore_dict", "ore": "itemRubber"
},
"c": {
"type": "industrialwires:ic2_item",
"name": "cable",
"variant": "type:glass,insulation:0"
},
"g": {
"item": "immersiveengineering:stone_decoration",
"data": 8
}
},
"conditions": [
{
"type": "forge:mod_loaded",
"modid": "ic2"
}
]
}

View file

@ -1,27 +0,0 @@
{
"result": {
"item": "industrialwires:ic2_connector",
"data": 4,
"count": 4
},
"pattern": [
" g ",
"rgr",
"rgr"
],
"type": "forge:ore_shaped",
"key": {
"r": {
"type": "forge:ore_dict", "ore": "itemRubber"
},
"g": {
"type": "forge:ore_dict", "ore": "ingotGold"
}
},
"conditions": [
{
"type": "forge:mod_loaded",
"modid": "ic2"
}
]
}

View file

@ -1,26 +0,0 @@
{
"result": {
"item": "industrialwires:ic2_connector",
"data": 5,
"count": 4
},
"pattern": [
" g ",
"rgr"
],
"type": "forge:ore_shaped",
"key": {
"r": {
"type": "forge:ore_dict", "ore": "itemRubber"
},
"g": {
"type": "forge:ore_dict", "ore": "ingotGold"
}
},
"conditions": [
{
"type": "forge:mod_loaded",
"modid": "ic2"
}
]
}

View file

@ -1,27 +0,0 @@
{
"result": {
"item": "industrialwires:ic2_connector",
"data": 6,
"count": 4
},
"pattern": [
" i ",
"rir",
"rir"
],
"type": "forge:ore_shaped",
"key": {
"r": {
"type": "forge:ore_dict", "ore": "itemRubber"
},
"i": {
"type": "forge:ore_dict", "ore": "ingotIron"
}
},
"conditions": [
{
"type": "forge:mod_loaded",
"modid": "ic2"
}
]
}

View file

@ -1,28 +0,0 @@
{
"result": {
"item": "industrialwires:ic2_connector",
"data": 7,
"count": 4
},
"pattern": [
" i ",
"gig",
"gig"
],
"type": "forge:ore_shaped",
"key": {
"g": {
"item": "immersiveengineering:stone_decoration",
"data": 8
},
"i": {
"type": "forge:ore_dict", "ore": "ingotIron"
}
},
"conditions": [
{
"type": "forge:mod_loaded",
"modid": "ic2"
}
]
}

View file

@ -1,29 +0,0 @@
{
"result": {
"item": "industrialwires:ic2_connector",
"data": 0,
"count": 4
},
"pattern": [
" t ",
"rtr",
"rtr"
],
"type": "forge:ore_shaped",
"key": {
"r": {
"type": "forge:ore_dict",
"ore": "itemRubber"
},
"t": {
"type": "forge:ore_dict",
"ore": "ingotTin"
}
},
"conditions": [
{
"type": "forge:mod_loaded",
"modid": "ic2"
}
]
}

View file

@ -1,26 +0,0 @@
{
"result": {
"item": "industrialwires:ic2_connector",
"data": 1,
"count": 4
},
"pattern": [
" t ",
"rtr"
],
"type": "forge:ore_shaped",
"key": {
"r": {
"type": "forge:ore_dict", "ore": "itemRubber"
},
"t": {
"type": "forge:ore_dict", "ore": "ingotTin"
}
},
"conditions": [
{
"type": "forge:mod_loaded",
"modid": "ic2"
}
]
}