From 10eb55bc743d94c65026ea07c04e29ba309daf2a Mon Sep 17 00:00:00 2001 From: Timo Ley Date: Fri, 20 Mar 2020 22:15:39 +0100 Subject: [PATCH] Removed EnergyType.java --- .../industrialwires/IMixedConnector.java | 3 +- .../blocks/hv/TileEntityMarx.java | 3 +- .../wire/TileEntityIC2ConnectorTin.java | 51 +++++-------------- .../industrialwires/wires/EnergyType.java | 38 -------------- .../industrialwires/wires/MixedWireType.java | 13 +---- 5 files changed, 16 insertions(+), 92 deletions(-) delete mode 100644 src/main/java/malte0811/industrialwires/wires/EnergyType.java diff --git a/src/main/java/malte0811/industrialwires/IMixedConnector.java b/src/main/java/malte0811/industrialwires/IMixedConnector.java index 2ce79f2..462bd47 100644 --- a/src/main/java/malte0811/industrialwires/IMixedConnector.java +++ b/src/main/java/malte0811/industrialwires/IMixedConnector.java @@ -17,14 +17,13 @@ package malte0811.industrialwires; import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable; import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler; import malte0811.industrialwires.util.ConversionUtil; -import malte0811.industrialwires.wires.EnergyType; import net.minecraft.entity.Entity; public interface IMixedConnector extends IImmersiveConnectable { /** * @return leftover energy. */ - double insertEnergy(double joules, boolean simulate, EnergyType type); + double insertEnergy(double joules, boolean simulate); @Override default float getDamageAmount(Entity e, ImmersiveNetHandler.Connection c) diff --git a/src/main/java/malte0811/industrialwires/blocks/hv/TileEntityMarx.java b/src/main/java/malte0811/industrialwires/blocks/hv/TileEntityMarx.java index 8e7fb13..9229a0a 100644 --- a/src/main/java/malte0811/industrialwires/blocks/hv/TileEntityMarx.java +++ b/src/main/java/malte0811/industrialwires/blocks/hv/TileEntityMarx.java @@ -41,7 +41,6 @@ import malte0811.industrialwires.network.MessageTileSyncIW; import malte0811.industrialwires.util.ConversionUtil; import malte0811.industrialwires.util.JouleEnergyStorage; import malte0811.industrialwires.util.MiscUtils; -import malte0811.industrialwires.wires.EnergyType; import malte0811.industrialwires.wires.MixedWireType; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; @@ -568,7 +567,7 @@ public class TileEntityMarx extends TileEntityIWMultiblock implements ITickable, } @Override - public double insertEnergy(double joules, boolean simulate, EnergyType type) { + public double insertEnergy(double joules, boolean simulate) { TileEntityMarx master = master(this); if (master!=null) { double ret = master.storage.insert(joules, 1, simulate, master.leftover); diff --git a/src/main/java/malte0811/industrialwires/blocks/wire/TileEntityIC2ConnectorTin.java b/src/main/java/malte0811/industrialwires/blocks/wire/TileEntityIC2ConnectorTin.java index 48a4ac5..ebbb3af 100644 --- a/src/main/java/malte0811/industrialwires/blocks/wire/TileEntityIC2ConnectorTin.java +++ b/src/main/java/malte0811/industrialwires/blocks/wire/TileEntityIC2ConnectorTin.java @@ -31,7 +31,6 @@ import malte0811.industrialwires.blocks.IBlockBoundsIW; import malte0811.industrialwires.compat.Compat; import malte0811.industrialwires.util.ConversionUtil; import malte0811.industrialwires.util.MiscUtils; -import malte0811.industrialwires.wires.EnergyType; import malte0811.industrialwires.wires.MixedWireType; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; @@ -51,7 +50,6 @@ import javax.annotation.Nullable; import java.util.*; import java.util.function.Consumer; -import static malte0811.industrialwires.wires.EnergyType.*; import static malte0811.industrialwires.wires.MixedWireType.TIN; @Optional.InterfaceList({ @@ -72,7 +70,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im private double bufferToMachine = 0; private double externalInputInTick = 0; private double maxToMachine = 0; - private EnergyType energyType = NONE; + //private EnergyType energyType = NONE; private boolean shouldBreak = false; private final double maxIO; private final MixedWireType wireType; @@ -135,9 +133,6 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im } return; } - if (externalInputInTick ==0 && potentialIEInputInTick == 0 && bufferToNet == 0 && bufferToMachine == 0) { - energyType = NONE; - } if (bufferToNet < maxToNet) { maxToNet = bufferToNet; } @@ -161,7 +156,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im if (bufferToNet >EPS) { notifyAvailableEnergy(bufferToNet); } - if (bufferToMachine > EPS && energyType==FE_AC) { + if (bufferToMachine > EPS) { transferPowerToFEMachine(); } } @@ -177,7 +172,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im IImmersiveConnectable iic = ApiUtils.toIIC(c.end, world); if (iic instanceof IMixedConnector) { double extract = - outputMax - ((IMixedConnector) iic).insertEnergy(outputMax, true, energyType); + outputMax - ((IMixedConnector) iic).insertEnergy(outputMax, true); if (extract > EPS) { maxOutputs.put(c, new ImmutablePair<>((IMixedConnector) iic, extract)); sum += extract; @@ -191,11 +186,11 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im Pair p = entry.getValue(); AbstractConnection c = entry.getKey(); 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); if (out<=0) continue; - double inserted = out - p.getLeft().insertEnergy(out, false, energyType); + double inserted = out - p.getLeft().insertEnergy(out, false); double energyAtConn = inserted + loss; bufferToNet -= energyAtConn; float intermediaryLoss = 0; @@ -203,7 +198,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im for (Connection sub : c.subConnections) { int transferredPerCon = transferedPerConn.getOrDefault(sub, 0); energyAtConn -= sub.cableType.getLossRatio() * sub.length; - double wireLoad = energyAtConn/(energyType==FE_AC?IWConfig.wireRatio:1); + double wireLoad = energyAtConn; transferedPerConn.put(sub, (int) (transferredPerCon + wireLoad)); IImmersiveConnectable subStart = ApiUtils.toIIC(sub.start, world); IImmersiveConnectable subEnd = ApiUtils.toIIC(sub.end, world); @@ -257,7 +252,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im for (Connection c : conn.subConnections) { WireType type = c.cableType; if (type instanceof MixedWireType) { - f += c.length * ((MixedWireType)type).getLoss(energyType); + f += c.length * ((MixedWireType)type).getLoss(); } else { f = Double.POSITIVE_INFINITY; } @@ -267,13 +262,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im //Input through the net @Override - public double insertEnergy(double joules, boolean simulate, EnergyType type) { - if (energyType==NONE) { - energyType = type; - } else if (energyType!=type) { - shouldBreak = true; - return 0; - } + public double insertEnergy(double joules, boolean simulate) { double insert = Math.min(getMaxIO() - bufferToMachine, joules); insert = Math.min(getMaxIO()-actualIEInputInTick, insert); if (!simulate) { @@ -287,7 +276,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im } private double getMaxIO() { - return maxIO*(energyType==FE_AC?IWConfig.wireRatio:1); + return maxIO; } @Override @@ -364,24 +353,18 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im @Override @Optional.Method(modid="ic2") 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 @Optional.Method(modid="ic2") public double getOfferedEnergy() { - if (energyType != NONE && energyType != EU_DC) { - return .01; - } return Math.min(maxToMachine, bufferToMachine) * ConversionUtil.euPerJoule(); } @Override @Optional.Method(modid="ic2") public void drawEnergy(double amount) { - if (energyType != NONE && energyType != EU_DC) { - shouldBreak = true; - } bufferToMachine -= amount*ConversionUtil.joulesPerEu(); markDirty(); } @@ -405,12 +388,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im } // Returns amount of energy consumed - private double addToIn(double joules, boolean simulate, EnergyType type) { - if (energyType==NONE) { - energyType = type; - } else if (energyType!=type) { - shouldBreak = true; - } + private double addToIn(double joules, boolean simulate) { joules = Math.min(getMaxIO() - externalInputInTick + .5, joules); if (bufferToNet < getMaxIO()) { if (!simulate) { @@ -442,7 +420,6 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im } else { maxToMachine = bufferToMachine; } - energyType = EnergyType.values()[nbt.getInteger("energyType")]; if (version==0) { bufferToNet *= ConversionUtil.joulesPerEu(); bufferToMachine *= ConversionUtil.joulesPerEu(); @@ -460,7 +437,6 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im nbt.setDouble("outBuffer", bufferToMachine); nbt.setDouble("maxToNet", maxToNet); nbt.setDouble("maxToMachine", maxToMachine); - nbt.setInteger("energyType", energyType.ordinal()); nbt.setInteger("version", 1); } @@ -582,15 +558,12 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im return 0; } double joules = maxReceive*ConversionUtil.joulesPerIf(); - double accepted = addToIn(joules, simulate, FE_AC); + double accepted = addToIn(joules, simulate); return MathHelper.ceil(accepted*ConversionUtil.ifPerJoule()); } @Override public int extractEnergy(int maxExtract, boolean simulate) { - if (energyType!=FE_AC) { - return 0; - } double joules = maxExtract*ConversionUtil.joulesPerIf(); if (joules>maxToMachine) { joules = maxToMachine; diff --git a/src/main/java/malte0811/industrialwires/wires/EnergyType.java b/src/main/java/malte0811/industrialwires/wires/EnergyType.java deleted file mode 100644 index b8c3193..0000000 --- a/src/main/java/malte0811/industrialwires/wires/EnergyType.java +++ /dev/null @@ -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 . - */ - -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; - } -} diff --git a/src/main/java/malte0811/industrialwires/wires/MixedWireType.java b/src/main/java/malte0811/industrialwires/wires/MixedWireType.java index a8829b2..4d58dcc 100644 --- a/src/main/java/malte0811/industrialwires/wires/MixedWireType.java +++ b/src/main/java/malte0811/industrialwires/wires/MixedWireType.java @@ -168,16 +168,7 @@ public class MixedWireType extends WireType { 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; - } + public double getLoss() { + return getLossRatio(); } }