Removed EnergyType.java
This commit is contained in:
parent
77b3fb454e
commit
10eb55bc74
|
@ -17,14 +17,13 @@ package malte0811.industrialwires;
|
||||||
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
|
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
|
||||||
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler;
|
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler;
|
||||||
import malte0811.industrialwires.util.ConversionUtil;
|
import malte0811.industrialwires.util.ConversionUtil;
|
||||||
import malte0811.industrialwires.wires.EnergyType;
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
|
||||||
public interface IMixedConnector extends IImmersiveConnectable {
|
public interface IMixedConnector extends IImmersiveConnectable {
|
||||||
/**
|
/**
|
||||||
* @return leftover energy.
|
* @return leftover energy.
|
||||||
*/
|
*/
|
||||||
double insertEnergy(double joules, boolean simulate, EnergyType type);
|
double insertEnergy(double joules, boolean simulate);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default float getDamageAmount(Entity e, ImmersiveNetHandler.Connection c)
|
default float getDamageAmount(Entity e, ImmersiveNetHandler.Connection c)
|
||||||
|
|
|
@ -41,7 +41,6 @@ import malte0811.industrialwires.network.MessageTileSyncIW;
|
||||||
import malte0811.industrialwires.util.ConversionUtil;
|
import malte0811.industrialwires.util.ConversionUtil;
|
||||||
import malte0811.industrialwires.util.JouleEnergyStorage;
|
import malte0811.industrialwires.util.JouleEnergyStorage;
|
||||||
import malte0811.industrialwires.util.MiscUtils;
|
import malte0811.industrialwires.util.MiscUtils;
|
||||||
import malte0811.industrialwires.wires.EnergyType;
|
|
||||||
import malte0811.industrialwires.wires.MixedWireType;
|
import malte0811.industrialwires.wires.MixedWireType;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
@ -568,7 +567,7 @@ public class TileEntityMarx extends TileEntityIWMultiblock implements ITickable,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double insertEnergy(double joules, boolean simulate, EnergyType type) {
|
public double insertEnergy(double joules, boolean simulate) {
|
||||||
TileEntityMarx master = master(this);
|
TileEntityMarx master = master(this);
|
||||||
if (master!=null) {
|
if (master!=null) {
|
||||||
double ret = master.storage.insert(joules, 1, simulate, master.leftover);
|
double ret = master.storage.insert(joules, 1, simulate, master.leftover);
|
||||||
|
|
|
@ -31,7 +31,6 @@ import malte0811.industrialwires.blocks.IBlockBoundsIW;
|
||||||
import malte0811.industrialwires.compat.Compat;
|
import malte0811.industrialwires.compat.Compat;
|
||||||
import malte0811.industrialwires.util.ConversionUtil;
|
import malte0811.industrialwires.util.ConversionUtil;
|
||||||
import malte0811.industrialwires.util.MiscUtils;
|
import malte0811.industrialwires.util.MiscUtils;
|
||||||
import malte0811.industrialwires.wires.EnergyType;
|
|
||||||
import malte0811.industrialwires.wires.MixedWireType;
|
import malte0811.industrialwires.wires.MixedWireType;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
@ -51,7 +50,6 @@ import javax.annotation.Nullable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import static malte0811.industrialwires.wires.EnergyType.*;
|
|
||||||
import static malte0811.industrialwires.wires.MixedWireType.TIN;
|
import static malte0811.industrialwires.wires.MixedWireType.TIN;
|
||||||
|
|
||||||
@Optional.InterfaceList({
|
@Optional.InterfaceList({
|
||||||
|
@ -72,7 +70,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
|
||||||
private double bufferToMachine = 0;
|
private double bufferToMachine = 0;
|
||||||
private double externalInputInTick = 0;
|
private double externalInputInTick = 0;
|
||||||
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 maxIO;
|
private final double maxIO;
|
||||||
private final MixedWireType wireType;
|
private final MixedWireType wireType;
|
||||||
|
@ -135,9 +133,6 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (externalInputInTick ==0 && potentialIEInputInTick == 0 && bufferToNet == 0 && bufferToMachine == 0) {
|
|
||||||
energyType = NONE;
|
|
||||||
}
|
|
||||||
if (bufferToNet < maxToNet) {
|
if (bufferToNet < maxToNet) {
|
||||||
maxToNet = bufferToNet;
|
maxToNet = bufferToNet;
|
||||||
}
|
}
|
||||||
|
@ -161,7 +156,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
|
||||||
if (bufferToNet >EPS) {
|
if (bufferToNet >EPS) {
|
||||||
notifyAvailableEnergy(bufferToNet);
|
notifyAvailableEnergy(bufferToNet);
|
||||||
}
|
}
|
||||||
if (bufferToMachine > EPS && energyType==FE_AC) {
|
if (bufferToMachine > EPS) {
|
||||||
transferPowerToFEMachine();
|
transferPowerToFEMachine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,7 +172,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
|
||||||
IImmersiveConnectable iic = ApiUtils.toIIC(c.end, world);
|
IImmersiveConnectable iic = ApiUtils.toIIC(c.end, world);
|
||||||
if (iic instanceof IMixedConnector) {
|
if (iic instanceof IMixedConnector) {
|
||||||
double extract =
|
double extract =
|
||||||
outputMax - ((IMixedConnector) iic).insertEnergy(outputMax, true, energyType);
|
outputMax - ((IMixedConnector) iic).insertEnergy(outputMax, true);
|
||||||
if (extract > EPS) {
|
if (extract > EPS) {
|
||||||
maxOutputs.put(c, new ImmutablePair<>((IMixedConnector) iic, extract));
|
maxOutputs.put(c, new ImmutablePair<>((IMixedConnector) iic, extract));
|
||||||
sum += extract;
|
sum += extract;
|
||||||
|
@ -191,11 +186,11 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
|
||||||
Pair<IMixedConnector, Double> p = entry.getValue();
|
Pair<IMixedConnector, Double> p = entry.getValue();
|
||||||
AbstractConnection c = entry.getKey();
|
AbstractConnection c = entry.getKey();
|
||||||
double out = outputMax * p.getRight() / sum;
|
double out = outputMax * p.getRight() / sum;
|
||||||
double loss = energyType.getLoss(getAverageLossRate(c), bufferToNet, out);
|
double loss = Math.min(getAverageLossRate(c), 1)*out;
|
||||||
out = Math.min(out, bufferToNet -loss);
|
out = Math.min(out, bufferToNet -loss);
|
||||||
if (out<=0)
|
if (out<=0)
|
||||||
continue;
|
continue;
|
||||||
double inserted = out - p.getLeft().insertEnergy(out, false, energyType);
|
double inserted = out - p.getLeft().insertEnergy(out, false);
|
||||||
double energyAtConn = inserted + loss;
|
double energyAtConn = inserted + loss;
|
||||||
bufferToNet -= energyAtConn;
|
bufferToNet -= energyAtConn;
|
||||||
float intermediaryLoss = 0;
|
float intermediaryLoss = 0;
|
||||||
|
@ -203,7 +198,7 @@ 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;
|
||||||
double wireLoad = energyAtConn/(energyType==FE_AC?IWConfig.wireRatio:1);
|
double wireLoad = energyAtConn;
|
||||||
transferedPerConn.put(sub, (int) (transferredPerCon + wireLoad));
|
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);
|
||||||
|
@ -257,7 +252,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
|
||||||
for (Connection c : conn.subConnections) {
|
for (Connection c : conn.subConnections) {
|
||||||
WireType type = c.cableType;
|
WireType type = c.cableType;
|
||||||
if (type instanceof MixedWireType) {
|
if (type instanceof MixedWireType) {
|
||||||
f += c.length * ((MixedWireType)type).getLoss(energyType);
|
f += c.length * ((MixedWireType)type).getLoss();
|
||||||
} else {
|
} else {
|
||||||
f = Double.POSITIVE_INFINITY;
|
f = Double.POSITIVE_INFINITY;
|
||||||
}
|
}
|
||||||
|
@ -267,13 +262,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
|
||||||
|
|
||||||
//Input through the net
|
//Input through the net
|
||||||
@Override
|
@Override
|
||||||
public double insertEnergy(double joules, boolean simulate, EnergyType type) {
|
public double insertEnergy(double joules, boolean simulate) {
|
||||||
if (energyType==NONE) {
|
|
||||||
energyType = type;
|
|
||||||
} else if (energyType!=type) {
|
|
||||||
shouldBreak = true;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
double insert = Math.min(getMaxIO() - bufferToMachine, joules);
|
double insert = Math.min(getMaxIO() - bufferToMachine, joules);
|
||||||
insert = Math.min(getMaxIO()-actualIEInputInTick, insert);
|
insert = Math.min(getMaxIO()-actualIEInputInTick, insert);
|
||||||
if (!simulate) {
|
if (!simulate) {
|
||||||
|
@ -287,7 +276,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getMaxIO() {
|
private double getMaxIO() {
|
||||||
return maxIO*(energyType==FE_AC?IWConfig.wireRatio:1);
|
return maxIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -364,24 +353,18 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
|
||||||
@Override
|
@Override
|
||||||
@Optional.Method(modid="ic2")
|
@Optional.Method(modid="ic2")
|
||||||
public double injectEnergy(EnumFacing directionFrom, double amount, double voltage) {
|
public double injectEnergy(EnumFacing directionFrom, double amount, double voltage) {
|
||||||
return amount-ConversionUtil.euPerJoule()*addToIn(ConversionUtil.joulesPerEu()*amount, false, EU_DC);
|
return amount-ConversionUtil.euPerJoule()*addToIn(ConversionUtil.joulesPerEu()*amount, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Optional.Method(modid="ic2")
|
@Optional.Method(modid="ic2")
|
||||||
public double getOfferedEnergy() {
|
public double getOfferedEnergy() {
|
||||||
if (energyType != NONE && energyType != EU_DC) {
|
|
||||||
return .01;
|
|
||||||
}
|
|
||||||
return Math.min(maxToMachine, bufferToMachine) * ConversionUtil.euPerJoule();
|
return Math.min(maxToMachine, bufferToMachine) * ConversionUtil.euPerJoule();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Optional.Method(modid="ic2")
|
@Optional.Method(modid="ic2")
|
||||||
public void drawEnergy(double amount) {
|
public void drawEnergy(double amount) {
|
||||||
if (energyType != NONE && energyType != EU_DC) {
|
|
||||||
shouldBreak = true;
|
|
||||||
}
|
|
||||||
bufferToMachine -= amount*ConversionUtil.joulesPerEu();
|
bufferToMachine -= amount*ConversionUtil.joulesPerEu();
|
||||||
markDirty();
|
markDirty();
|
||||||
}
|
}
|
||||||
|
@ -405,12 +388,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns amount of energy consumed
|
// Returns amount of energy consumed
|
||||||
private double addToIn(double joules, boolean simulate, EnergyType type) {
|
private double addToIn(double joules, boolean simulate) {
|
||||||
if (energyType==NONE) {
|
|
||||||
energyType = type;
|
|
||||||
} else if (energyType!=type) {
|
|
||||||
shouldBreak = true;
|
|
||||||
}
|
|
||||||
joules = Math.min(getMaxIO() - externalInputInTick + .5, joules);
|
joules = Math.min(getMaxIO() - externalInputInTick + .5, joules);
|
||||||
if (bufferToNet < getMaxIO()) {
|
if (bufferToNet < getMaxIO()) {
|
||||||
if (!simulate) {
|
if (!simulate) {
|
||||||
|
@ -442,7 +420,6 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
|
||||||
} else {
|
} else {
|
||||||
maxToMachine = bufferToMachine;
|
maxToMachine = bufferToMachine;
|
||||||
}
|
}
|
||||||
energyType = EnergyType.values()[nbt.getInteger("energyType")];
|
|
||||||
if (version==0) {
|
if (version==0) {
|
||||||
bufferToNet *= ConversionUtil.joulesPerEu();
|
bufferToNet *= ConversionUtil.joulesPerEu();
|
||||||
bufferToMachine *= ConversionUtil.joulesPerEu();
|
bufferToMachine *= ConversionUtil.joulesPerEu();
|
||||||
|
@ -460,7 +437,6 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
|
||||||
nbt.setDouble("outBuffer", bufferToMachine);
|
nbt.setDouble("outBuffer", bufferToMachine);
|
||||||
nbt.setDouble("maxToNet", maxToNet);
|
nbt.setDouble("maxToNet", maxToNet);
|
||||||
nbt.setDouble("maxToMachine", maxToMachine);
|
nbt.setDouble("maxToMachine", maxToMachine);
|
||||||
nbt.setInteger("energyType", energyType.ordinal());
|
|
||||||
nbt.setInteger("version", 1);
|
nbt.setInteger("version", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -582,15 +558,12 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
double joules = maxReceive*ConversionUtil.joulesPerIf();
|
double joules = maxReceive*ConversionUtil.joulesPerIf();
|
||||||
double accepted = addToIn(joules, simulate, FE_AC);
|
double accepted = addToIn(joules, simulate);
|
||||||
return MathHelper.ceil(accepted*ConversionUtil.ifPerJoule());
|
return MathHelper.ceil(accepted*ConversionUtil.ifPerJoule());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int extractEnergy(int maxExtract, boolean simulate) {
|
public int extractEnergy(int maxExtract, boolean simulate) {
|
||||||
if (energyType!=FE_AC) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
double joules = maxExtract*ConversionUtil.joulesPerIf();
|
double joules = maxExtract*ConversionUtil.joulesPerIf();
|
||||||
if (joules>maxToMachine) {
|
if (joules>maxToMachine) {
|
||||||
joules = maxToMachine;
|
joules = maxToMachine;
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is part of Industrial Wires.
|
|
||||||
* Copyright (C) 2016-2018 malte0811
|
|
||||||
* Industrial Wires is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
* Industrial Wires is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package malte0811.industrialwires.wires;
|
|
||||||
|
|
||||||
import malte0811.industrialwires.util.ConversionUtil;
|
|
||||||
|
|
||||||
public enum EnergyType {
|
|
||||||
FE_AC() {
|
|
||||||
@Override
|
|
||||||
public double getLoss(double averageLossRate, double available, double outMax) {
|
|
||||||
return Math.min(averageLossRate, 1)*outMax;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
EU_DC() {
|
|
||||||
@Override
|
|
||||||
public double getLoss(double averageLossRate, double available, double outMax) {
|
|
||||||
return averageLossRate * ConversionUtil.joulesPerEu();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
NONE;
|
|
||||||
|
|
||||||
public double getLoss(double averageLossRate, double available, double outMax) {
|
|
||||||
return available;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -168,16 +168,7 @@ public class MixedWireType extends WireType {
|
||||||
return this==HV||this==GLASS;
|
return this==HV||this==GLASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getLoss(EnergyType energyType) {
|
public double getLoss() {
|
||||||
switch (energyType) {
|
return getLossRatio();
|
||||||
|
|
||||||
case FE_AC:
|
|
||||||
return getLossRatio();
|
|
||||||
case EU_DC:
|
|
||||||
return getLossRateEU();
|
|
||||||
case NONE:
|
|
||||||
default:
|
|
||||||
return 10;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue