mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-25 14:24:35 +00:00
Emitting logic overhaul (#5422)
* First pass improving performance of EnergyNetwork emitting Only sends power once per tick per accept now. Lots of comments of design included so that I have a backup of my thought process/solutions if I run into some blocker. * Optimized implementation slightly, still more to be done * Cleanup some comments * Move send energy to acceptor logic to CableUtils Replace old emit logic in CableUtils with using the newer logic * Inline getConnections to slightly cut down on number of operations ran * Fix a couple bugs with targets that have multiple sides Also improve performance reducing frequency at amountPerChanged needs to be ran * Improve performance of CableUtils.emit by faking we have one 6 sided target as opposed to having 6 one sided targets * Allow simulating insertion into the EnergyAcceptorWrapper for IC2 * Fix using wrong value for total acceptor count when acceptors have multiple sides * Use an EnumMap instead of a HashMap for the Target * First pass converting gas and fluid network emission to target system * Improve general fluid and gas emitting using the utility method Change a couple things to using Sets rather than lists for emitting so that we can ensure each side is only done once. * Document and cleanup method/variable names of target classes * Start deduplicating emitting code into a EmitUtils file Logic for Gas and Fluid emitting fully generic now * Partially extract how we keep track of the split to make it easier to deduplicate the common code * Start moving shifting needed to given to the targets themselves * Use generics to deduplicate a lot of the remaining duplication in the new emitting code * Fix having broke energy emitting and also further cleanup some code * Half the number of loops the HeatNetwork does onUpdate * Fix potentially divide by zero errors * Deprecate and remove implementations of getAcceptors as it is no longer needed * Never round up from doubles for sending power stops energy networks going negative. * Fix more spots where we were accidentally rounding upwards/clamping improperly for energy * Cleanup impl to use less memory and adjust better as sending if the possible amount changed/should be adjusted Also removed the need for a specific IntegerTypeTarget intermediary class * Cleanup the docs of some of the changed things * Given tickEmit is private now we already know it is only being called serverside * Improve documentation slightly and rename a method to be more accurate * Remove limit on IC2 given it uses doubles as well now * Rename amountPer to amountPerTarget
This commit is contained in:
1 parent
445556fef7
commit
b3663a37a9
37 files changed
+689
-641
No files matched your search
@@ -18,7 +18,7 @@ public class MekanismAPI {
|
||||
/**
|
||||
* The version of the api classes - may not always match the mod's version
|
||||
*/
|
||||
public static final String API_VERSION = "9.7.2";
|
||||
public static final String API_VERSION = "9.7.3";
|
||||
|
||||
/**
|
||||
* Mekanism debug mode
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
@@ -294,7 +295,13 @@ public abstract class DynamicNetwork<ACCEPTOR, NETWORK extends DynamicNetwork<AC
|
||||
return world;
|
||||
}
|
||||
|
||||
public abstract Set<Pair<Coord4D, ACCEPTOR>> getAcceptors(Object data);
|
||||
/**
|
||||
* @deprecated No longer used or implemented. To be removed
|
||||
*/
|
||||
@Deprecated
|
||||
public Set<Pair<Coord4D, ACCEPTOR>> getAcceptors(Object data) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
onUpdate();
|
||||
|
||||
@@ -107,7 +107,7 @@ public abstract class EnergyAcceptorWrapper implements IStrictEnergyAcceptor {
|
||||
|
||||
@Override
|
||||
public double acceptEnergy(EnumFacing side, double amount, boolean simulate) {
|
||||
return fromRF(acceptor.receiveEnergy(side, Math.min(Integer.MAX_VALUE, toRF(amount)), simulate));
|
||||
return fromRF(acceptor.receiveEnergy(side, toRF(amount), simulate));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -121,7 +121,7 @@ public abstract class EnergyAcceptorWrapper implements IStrictEnergyAcceptor {
|
||||
}
|
||||
|
||||
public int toRF(double joules) {
|
||||
return (int) Math.round(joules * MekanismConfig.current().general.TO_RF.val());
|
||||
return MekanismUtils.clampToInt(joules * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
public double fromRF(int rf) {
|
||||
@@ -139,7 +139,11 @@ public abstract class EnergyAcceptorWrapper implements IStrictEnergyAcceptor {
|
||||
|
||||
@Override
|
||||
public double acceptEnergy(EnumFacing side, double amount, boolean simulate) {
|
||||
double toTransfer = Math.min(Math.min(acceptor.getDemandedEnergy(), toEU(amount)), Integer.MAX_VALUE);
|
||||
double toTransfer = Math.min(acceptor.getDemandedEnergy(), toEU(amount));
|
||||
if (simulate) {
|
||||
//IC2 has no built in way to simulate, so we have to calculate it ourselves
|
||||
return toTransfer;
|
||||
}
|
||||
double rejects = acceptor.injectEnergy(side, toTransfer, 0);
|
||||
|
||||
return fromEU(toTransfer - rejects);
|
||||
@@ -174,7 +178,7 @@ public abstract class EnergyAcceptorWrapper implements IStrictEnergyAcceptor {
|
||||
|
||||
@Override
|
||||
public double acceptEnergy(EnumFacing side, double amount, boolean simulate) {
|
||||
return fromTesla(acceptor.givePower(toTesla(amount), false));
|
||||
return fromTesla(acceptor.givePower(toTesla(amount), simulate));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -206,7 +210,7 @@ public abstract class EnergyAcceptorWrapper implements IStrictEnergyAcceptor {
|
||||
|
||||
@Override
|
||||
public double acceptEnergy(EnumFacing side, double amount, boolean simulate) {
|
||||
return fromForge(acceptor.receiveEnergy(Math.min(Integer.MAX_VALUE, toForge(amount)), simulate));
|
||||
return fromForge(acceptor.receiveEnergy(toForge(amount), simulate));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -220,7 +224,7 @@ public abstract class EnergyAcceptorWrapper implements IStrictEnergyAcceptor {
|
||||
}
|
||||
|
||||
public int toForge(double joules) {
|
||||
return (int) Math.round(joules * MekanismConfig.current().general.TO_FORGE.val());
|
||||
return MekanismUtils.clampToInt(joules * MekanismConfig.current().general.TO_FORGE.val());
|
||||
}
|
||||
|
||||
public double fromForge(double forge) {
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
package mekanism.common.base;
|
||||
|
||||
public abstract class SplitInfo<TYPE extends Number & Comparable<TYPE>> {
|
||||
|
||||
protected int toSplitAmong;
|
||||
public boolean amountPerChanged = false;
|
||||
|
||||
private SplitInfo(int totalTargets) {
|
||||
this.toSplitAmong = totalTargets;
|
||||
}
|
||||
|
||||
public abstract void send(TYPE amountNeeded);
|
||||
|
||||
public abstract TYPE getAmountPerTarget();
|
||||
|
||||
public abstract TYPE getTotalSent();
|
||||
|
||||
public boolean shouldRecheck() {
|
||||
return amountPerChanged && toSplitAmong > 0;
|
||||
}
|
||||
|
||||
public static class IntegerSplitInfo extends SplitInfo<Integer> {
|
||||
private int amountToSplit;
|
||||
//AmountPer is the one that needs to be int or double
|
||||
private int amountPerTarget;
|
||||
private int sentSoFar;
|
||||
|
||||
//Amount to split also should be int or double
|
||||
public IntegerSplitInfo(int amountToSplit, int totalTargets) {
|
||||
super(totalTargets);
|
||||
this.amountToSplit = amountToSplit;
|
||||
amountPerTarget = toSplitAmong == 0 ? 0 : amountToSplit / toSplitAmong;
|
||||
sentSoFar = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Integer amountNeeded) {
|
||||
//If we are giving it, then lower the amount we are checking/splitting
|
||||
amountToSplit -= amountNeeded;
|
||||
sentSoFar += amountNeeded;
|
||||
toSplitAmong--;
|
||||
//Only recalculate it if it is not willing to accept/doesn't want the
|
||||
// full per side split
|
||||
if (amountNeeded != amountPerTarget && toSplitAmong != 0) {
|
||||
int amountPerLast = amountPerTarget;
|
||||
amountPerTarget = amountToSplit / toSplitAmong;
|
||||
if (!amountPerChanged && amountPerTarget != amountPerLast) {
|
||||
amountPerChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getAmountPerTarget() {
|
||||
return amountPerTarget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getTotalSent() {
|
||||
return sentSoFar;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DoubleSplitInfo extends SplitInfo<Double> {
|
||||
private double amountToSplit;
|
||||
private double amountPerTarget;
|
||||
private double sentSoFar;
|
||||
|
||||
public DoubleSplitInfo(double amountToSplit, int totalTargets) {
|
||||
super(totalTargets);
|
||||
this.amountToSplit = amountToSplit;
|
||||
amountPerTarget = toSplitAmong == 0 ? 0 : amountToSplit / toSplitAmong;
|
||||
sentSoFar = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Double amountNeeded) {
|
||||
//If we are giving it, then lower the amount we are checking/splitting
|
||||
amountToSplit -= amountNeeded;
|
||||
sentSoFar += amountNeeded;
|
||||
toSplitAmong--;
|
||||
//Only recalculate it if it is not willing to accept/doesn't want the
|
||||
// full per side split
|
||||
if (amountNeeded != amountPerTarget && toSplitAmong != 0) {
|
||||
double amountPerLast = amountPerTarget;
|
||||
amountPerTarget = amountToSplit / toSplitAmong;
|
||||
if (!amountPerChanged && amountPerTarget != amountPerLast) {
|
||||
amountPerChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getAmountPerTarget() {
|
||||
return amountPerTarget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getTotalSent() {
|
||||
return sentSoFar;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package mekanism.common.base.target;
|
||||
|
||||
import mekanism.common.base.EnergyAcceptorWrapper;
|
||||
import mekanism.common.base.SplitInfo;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
public class EnergyAcceptorTarget extends Target<EnergyAcceptorWrapper, Double, Double> {
|
||||
|
||||
@Override
|
||||
protected void acceptAmount(EnumFacing side, SplitInfo<Double> splitInfo, Double amount) {
|
||||
splitInfo.send(handlers.get(side).acceptEnergy(side, amount, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Double simulate(EnergyAcceptorWrapper wrapper, EnumFacing side, Double energyToSend) {
|
||||
return wrapper.acceptEnergy(side, energyToSend, true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package mekanism.common.base.target;
|
||||
|
||||
import mekanism.common.base.SplitInfo;
|
||||
import mekanism.common.util.PipeUtils;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
|
||||
public class FluidHandlerTarget extends Target<IFluidHandler, Integer, FluidStack> {
|
||||
|
||||
public FluidHandlerTarget(FluidStack type) {
|
||||
this.extra = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void acceptAmount(EnumFacing side, SplitInfo<Integer> splitInfo, Integer amount) {
|
||||
splitInfo.send(handlers.get(side).fill(PipeUtils.copy(extra, amount), true));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Integer simulate(IFluidHandler handler, EnumFacing side, FluidStack fluidStack) {
|
||||
return handler.fill(fluidStack, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package mekanism.common.base.target;
|
||||
|
||||
import mekanism.api.gas.GasStack;
|
||||
import mekanism.api.gas.IGasHandler;
|
||||
import mekanism.common.base.SplitInfo;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
public class GasHandlerTarget extends Target<IGasHandler, Integer, GasStack> {
|
||||
|
||||
public GasHandlerTarget(GasStack type) {
|
||||
this.extra = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void acceptAmount(EnumFacing side, SplitInfo<Integer> splitInfo, Integer amount) {
|
||||
splitInfo.send(handlers.get(side).receiveGas(side, new GasStack(extra.getGas(), amount), true));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Integer simulate(IGasHandler handler, EnumFacing side, GasStack gasStack) {
|
||||
return handler.receiveGas(side, gasStack, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package mekanism.common.base.target;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import mekanism.common.base.SplitInfo;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
/**
|
||||
* Keeps track of a target for emitting from various networks.
|
||||
*
|
||||
* @param <HANDLER> The Handler this target keeps track of.
|
||||
* @param <TYPE> The type that is being transferred.
|
||||
* @param <EXTRA> Any extra information this target may need to keep track of.
|
||||
*/
|
||||
public abstract class Target<HANDLER, TYPE extends Number & Comparable<TYPE>, EXTRA> {
|
||||
|
||||
/**
|
||||
* Map of the sides to the handler for that side.
|
||||
*/
|
||||
protected final Map<EnumFacing, HANDLER> handlers = new EnumMap<>(EnumFacing.class);
|
||||
/**
|
||||
* Map of sides that want more than we can/are willing to provide. Value is the amount they want.
|
||||
*/
|
||||
protected final Map<EnumFacing, TYPE> needed = new EnumMap<>(EnumFacing.class);
|
||||
|
||||
protected EXTRA extra;
|
||||
|
||||
public void addHandler(EnumFacing side, HANDLER handler) {
|
||||
handlers.put(side, handler);
|
||||
}
|
||||
|
||||
public Map<EnumFacing, HANDLER> getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the remaining amount to each handler we still have not settled on an amount for. We increment the amount
|
||||
* sent in splitInfo as well as adjust the split as needed if one ends up accepting less than it originally wanted.
|
||||
* (The most likely case this would change is with multi-blocks where it may return the same desire to all
|
||||
* connections, but get satisfied by our first connection).
|
||||
*
|
||||
* @param splitInfo Keeps track of the current amount sent and the default each one can get.
|
||||
*/
|
||||
public void sendRemainingSplit(SplitInfo<TYPE> splitInfo) {
|
||||
//If needed is not empty then we default it to the given calculated fair split amount of remaining energy
|
||||
for (EnumFacing side : needed.keySet()) {
|
||||
acceptAmount(side, splitInfo, splitInfo.getAmountPerTarget());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives the handler on the specified side the given amount.
|
||||
*
|
||||
* @param side Side of handler to give.
|
||||
* @param splitInfo Information about current overall split. The given split will be increased by the actual amount
|
||||
* accepted, in case it is less than the offered amount.
|
||||
* @param amount Amount to give.
|
||||
* @implNote Must call {@link SplitInfo#send(Number)} with the amount actually accepted.
|
||||
*/
|
||||
protected abstract void acceptAmount(EnumFacing side, SplitInfo<TYPE> splitInfo, TYPE amount);
|
||||
|
||||
/**
|
||||
* Simulate inserting into the handler.
|
||||
*
|
||||
* @param handler The handler (should correspond with the side we are simulating).
|
||||
* @param side The side we are simulating
|
||||
* @param extra All the information we are inserting.
|
||||
* @return The amount it was actually willing to accept.
|
||||
*/
|
||||
protected abstract TYPE simulate(HANDLER handler, EnumFacing side, EXTRA extra);
|
||||
|
||||
/**
|
||||
* Calculates how much each handler can take of toSend. If the amount requested is less than the amount per
|
||||
* handler/target in splitInfo it immediately sends the requested amount to the handler via {@link
|
||||
* #acceptAmount(EnumFacing, SplitInfo, Number)}
|
||||
*
|
||||
* @param toSend The total amount getting sent.
|
||||
* @param splitInfo Information about current overall split.
|
||||
*/
|
||||
public void sendPossible(EXTRA toSend, SplitInfo<TYPE> splitInfo) {
|
||||
for (Entry<EnumFacing, HANDLER> entry : handlers.entrySet()) {
|
||||
TYPE amountNeeded = simulate(entry.getValue(), entry.getKey(), toSend);
|
||||
if (amountNeeded.compareTo(splitInfo.getAmountPerTarget()) <= 0) {
|
||||
//Add the amount, in case something changed from simulation only mark actual sent amount
|
||||
// in split info
|
||||
acceptAmount(entry.getKey(), splitInfo, amountNeeded);
|
||||
} else {
|
||||
needed.put(entry.getKey(), amountNeeded);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rechecks to see if any of the needed amounts is able to fit under the new split and if so gives them the
|
||||
* requested amount.
|
||||
*
|
||||
* @param splitInfo The new split to (re)check.
|
||||
*/
|
||||
public void shiftNeeded(SplitInfo<TYPE> splitInfo) {
|
||||
Iterator<Entry<EnumFacing, TYPE>> iterator = needed.entrySet().iterator();
|
||||
//Use an iterator rather than a copy of the keyset of the needed submap
|
||||
// This allows for us to remove it once we find it without having to
|
||||
// start looping again or make a large number of copies of the set
|
||||
while (iterator.hasNext()) {
|
||||
Entry<EnumFacing, TYPE> needInfo = iterator.next();
|
||||
TYPE amountNeeded = needInfo.getValue();
|
||||
if (amountNeeded.compareTo(splitInfo.getAmountPerTarget()) <= 0) {
|
||||
acceptAmount(needInfo.getKey(), splitInfo, amountNeeded);
|
||||
//Remove it as it has now been sent
|
||||
iterator.remove();
|
||||
//Continue checking things in case we happen to be
|
||||
// getting things in a bad order so that we don't recheck
|
||||
// the same values many times
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,18 +197,16 @@ public class EntityRobit extends EntityCreature implements IInventory, ISustaine
|
||||
IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
|
||||
|
||||
if (storage.canExtract()) {
|
||||
int needed = (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE,
|
||||
(MAX_ELECTRICITY - getEnergy()) * MekanismConfig.current().general.TO_FORGE.val()));
|
||||
int needed = MekanismUtils.clampToInt(
|
||||
(MAX_ELECTRICITY - getEnergy()) * MekanismConfig.current().general.TO_FORGE.val());
|
||||
setEnergy(getEnergy() + storage.extractEnergy(needed, false) * MekanismConfig
|
||||
.current().general.FROM_FORGE.val());
|
||||
}
|
||||
} else if (MekanismUtils.useRF() && stack.getItem() instanceof IEnergyContainerItem) {
|
||||
IEnergyContainerItem item = (IEnergyContainerItem) stack.getItem();
|
||||
|
||||
int needed = (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE,
|
||||
(MAX_ELECTRICITY - getEnergy()) * MekanismConfig.current().general.TO_RF.val()));
|
||||
int needed = MekanismUtils
|
||||
.clampToInt((MAX_ELECTRICITY - getEnergy()) * MekanismConfig.current().general.TO_RF.val());
|
||||
setEnergy(getEnergy() + (item.extractEnergy(stack, needed, false) * MekanismConfig
|
||||
.current().general.FROM_RF.val()));
|
||||
} else if (MekanismUtils.useIC2() && stack.getItem() instanceof IElectricItem) {
|
||||
@@ -312,7 +310,9 @@ public class EntityRobit extends EntityCreature implements IInventory, ISustaine
|
||||
setFollowing(false);
|
||||
|
||||
if (world.provider.getDimension() != homeLocation.dimensionId) {
|
||||
changeDimension(homeLocation.dimensionId, (world1, entity, yaw) -> entity.setLocationAndAngles(homeLocation.x + 0.5, homeLocation.y + 0.3, homeLocation.z + 0.5, yaw, rotationPitch));
|
||||
changeDimension(homeLocation.dimensionId, (world1, entity, yaw) -> entity
|
||||
.setLocationAndAngles(homeLocation.x + 0.5, homeLocation.y + 0.3, homeLocation.z + 0.5, yaw,
|
||||
rotationPitch));
|
||||
} else {
|
||||
setPositionAndUpdate(homeLocation.x + 0.5, homeLocation.y + 0.3, homeLocation.z + 0.5);
|
||||
}
|
||||
|
||||
+4
-6
@@ -2,6 +2,7 @@ package mekanism.common.integration.forgeenergy;
|
||||
|
||||
import mekanism.common.config.MekanismConfig;
|
||||
import mekanism.common.tile.transmitter.TileEntityUniversalCable;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
|
||||
@@ -18,8 +19,7 @@ public class ForgeEnergyCableIntegration implements IEnergyStorage {
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(int maxReceive, boolean simulate) {
|
||||
return (int) Math
|
||||
.round(tileEntity
|
||||
return MekanismUtils.clampToInt(tileEntity
|
||||
.acceptEnergy(side, maxReceive * MekanismConfig.current().general.FROM_FORGE.val(), simulate)
|
||||
* MekanismConfig.current().general.TO_FORGE.val());
|
||||
}
|
||||
@@ -31,14 +31,12 @@ public class ForgeEnergyCableIntegration implements IEnergyStorage {
|
||||
|
||||
@Override
|
||||
public int getEnergyStored() {
|
||||
return (int) Math.round(
|
||||
Math.min(Integer.MAX_VALUE, tileEntity.getEnergy() * MekanismConfig.current().general.TO_FORGE.val()));
|
||||
return MekanismUtils.clampToInt(tileEntity.getEnergy() * MekanismConfig.current().general.TO_FORGE.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
return (int) Math.round(
|
||||
Math.min(Integer.MAX_VALUE, tileEntity.getMaxEnergy() * MekanismConfig.current().general.TO_FORGE.val()));
|
||||
return MekanismUtils.clampToInt(tileEntity.getMaxEnergy() * MekanismConfig.current().general.TO_FORGE.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,7 @@ package mekanism.common.integration.forgeenergy;
|
||||
|
||||
import mekanism.common.base.IEnergyWrapper;
|
||||
import mekanism.common.config.MekanismConfig;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
|
||||
@@ -21,7 +22,7 @@ public class ForgeEnergyIntegration implements IEnergyStorage {
|
||||
}
|
||||
|
||||
public static int mekToForge(double mek) {
|
||||
return (int) Math.round(mek * MekanismConfig.current().general.TO_FORGE.val());
|
||||
return MekanismUtils.clampToInt(mek * MekanismConfig.current().general.TO_FORGE.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,7 +40,7 @@ public class IC2Integration {
|
||||
if (tile instanceof IEnergySink && ((IEnergySink) tile).acceptsEnergyFrom(from, side.getOpposite())) {
|
||||
double toSend = Math.min(currentSending * MekanismConfig.current().general.TO_IC2.val(),
|
||||
EnergyNet.instance.getPowerFromTier(((IEnergySink) tile).getSinkTier()));
|
||||
toSend = Math.min(Math.min(toSend, ((IEnergySink) tile).getDemandedEnergy()), Integer.MAX_VALUE);
|
||||
toSend = Math.min(toSend, ((IEnergySink) tile).getDemandedEnergy());
|
||||
return (toSend - (((IEnergySink) tile).injectEnergy(side.getOpposite(), toSend, 0))) * MekanismConfig
|
||||
.current().general.FROM_IC2.val();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package mekanism.common.integration.ic2;
|
||||
import ic2.api.item.IElectricItemManager;
|
||||
import mekanism.api.energy.IEnergizedItem;
|
||||
import mekanism.common.config.MekanismConfig;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@@ -29,7 +30,7 @@ public class IC2ItemManager implements IElectricItemManager {
|
||||
energizedItem.setEnergy(itemStack, energizedItem.getEnergy(itemStack) + energyToStore);
|
||||
}
|
||||
|
||||
return (int) Math.round(energyToStore * MekanismConfig.current().general.TO_IC2.val());
|
||||
return MekanismUtils.clampToInt(energyToStore * MekanismConfig.current().general.TO_IC2.val());
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -47,7 +48,7 @@ public class IC2ItemManager implements IElectricItemManager {
|
||||
energizedItem.setEnergy(itemStack, energizedItem.getEnergy(itemStack) - energyToGive);
|
||||
}
|
||||
|
||||
return (int) Math.round(energyToGive * MekanismConfig.current().general.TO_IC2.val());
|
||||
return MekanismUtils.clampToInt(energyToGive * MekanismConfig.current().general.TO_IC2.val());
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -60,7 +61,7 @@ public class IC2ItemManager implements IElectricItemManager {
|
||||
|
||||
@Override
|
||||
public double getCharge(ItemStack itemStack) {
|
||||
return (int) Math.round(energizedItem.getEnergy(itemStack) * MekanismConfig.current().general.TO_IC2.val());
|
||||
return MekanismUtils.clampToInt(energizedItem.getEnergy(itemStack) * MekanismConfig.current().general.TO_IC2.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,6 +3,7 @@ package mekanism.common.integration.tesla;
|
||||
import mekanism.common.base.IEnergyWrapper;
|
||||
import mekanism.common.config.MekanismConfig;
|
||||
import mekanism.common.integration.MekanismHooks;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import net.darkhax.tesla.api.ITeslaConsumer;
|
||||
import net.darkhax.tesla.api.ITeslaHolder;
|
||||
import net.darkhax.tesla.api.ITeslaProducer;
|
||||
@@ -57,8 +58,7 @@ public class TeslaIntegration implements ITeslaHolder, ITeslaConsumer, ITeslaPro
|
||||
}
|
||||
|
||||
public int teslaToRF(long tesla) {
|
||||
return (int) Math.round(Math.min(Integer.MAX_VALUE,
|
||||
tesla * MekanismConfig.current().general.FROM_TESLA.val() * MekanismConfig.current().general.TO_RF
|
||||
.val()));
|
||||
return MekanismUtils.clampToInt(
|
||||
tesla * MekanismConfig.current().general.FROM_TESLA.val() * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
}
|
||||
@@ -244,7 +244,7 @@ public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, IS
|
||||
setEnergy(theItem, getEnergy(theItem) + toReceive);
|
||||
}
|
||||
|
||||
return (int) Math.round(toReceive * MekanismConfig.current().general.TO_RF.val());
|
||||
return MekanismUtils.clampToInt(toReceive * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -261,7 +261,7 @@ public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, IS
|
||||
setEnergy(theItem, getEnergy(theItem) - toSend);
|
||||
}
|
||||
|
||||
return (int) Math.round(toSend * MekanismConfig.current().general.TO_RF.val());
|
||||
return MekanismUtils.clampToInt(toSend * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -679,7 +679,7 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, ISpec
|
||||
setEnergy(theItem, getEnergy(theItem) + toReceive);
|
||||
}
|
||||
|
||||
return (int) Math.round(toReceive * MekanismConfig.current().general.TO_RF.val());
|
||||
return MekanismUtils.clampToInt(toReceive * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -696,7 +696,7 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, ISpec
|
||||
setEnergy(theItem, getEnergy(theItem) - toSend);
|
||||
}
|
||||
|
||||
return (int) Math.round(toSend * MekanismConfig.current().general.TO_RF.val());
|
||||
return MekanismUtils.clampToInt(toSend * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -129,7 +129,7 @@ public class ItemEnergized extends ItemMekanism implements IEnergizedItem, ISpec
|
||||
setEnergy(theItem, getEnergy(theItem) + toReceive);
|
||||
}
|
||||
|
||||
return (int) Math.round(toReceive * MekanismConfig.current().general.TO_RF.val());
|
||||
return MekanismUtils.clampToInt(toReceive * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -145,7 +145,7 @@ public class ItemEnergized extends ItemMekanism implements IEnergizedItem, ISpec
|
||||
setEnergy(theItem, getEnergy(theItem) - toSend);
|
||||
}
|
||||
|
||||
return (int) Math.round(toSend * MekanismConfig.current().general.TO_RF.val());
|
||||
return MekanismUtils.clampToInt(toSend * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -153,12 +153,12 @@ public class ItemEnergized extends ItemMekanism implements IEnergizedItem, ISpec
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ItemStack theItem) {
|
||||
return (int) Math.round(getEnergy(theItem) * MekanismConfig.current().general.TO_RF.val());
|
||||
return MekanismUtils.clampToInt(getEnergy(theItem) * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ItemStack theItem) {
|
||||
return (int) Math.round(getMaxEnergy(theItem) * MekanismConfig.current().general.TO_RF.val());
|
||||
return MekanismUtils.clampToInt(getMaxEnergy(theItem) * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -147,7 +147,7 @@ public class ItemFreeRunners extends ItemArmor implements IEnergizedItem, ISpeci
|
||||
setEnergy(theItem, getEnergy(theItem) + toReceive);
|
||||
}
|
||||
|
||||
return (int) Math.round(toReceive * MekanismConfig.current().general.TO_RF.val());
|
||||
return MekanismUtils.clampToInt(toReceive * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -164,7 +164,7 @@ public class ItemFreeRunners extends ItemArmor implements IEnergizedItem, ISpeci
|
||||
setEnergy(theItem, getEnergy(theItem) - toSend);
|
||||
}
|
||||
|
||||
return (int) Math.round(toSend * MekanismConfig.current().general.TO_RF.val());
|
||||
return MekanismUtils.clampToInt(toSend * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -173,13 +173,13 @@ public class ItemFreeRunners extends ItemArmor implements IEnergizedItem, ISpeci
|
||||
@Override
|
||||
@Method(modid = MekanismHooks.REDSTONEFLUX_MOD_ID)
|
||||
public int getEnergyStored(ItemStack theItem) {
|
||||
return (int) Math.round(getEnergy(theItem) * MekanismConfig.current().general.TO_RF.val());
|
||||
return MekanismUtils.clampToInt(getEnergy(theItem) * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = MekanismHooks.REDSTONEFLUX_MOD_ID)
|
||||
public int getMaxEnergyStored(ItemStack theItem) {
|
||||
return (int) Math.round(getMaxEnergy(theItem) * MekanismConfig.current().general.TO_RF.val());
|
||||
return MekanismUtils.clampToInt(getMaxEnergy(theItem) * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package mekanism.common.tile;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -157,7 +157,7 @@ public class TileEntityElectrolyticSeparator extends TileEntityMachine implement
|
||||
if (tank.getGas() != null) {
|
||||
if (mode != GasMode.DUMPING) {
|
||||
GasStack toSend = new GasStack(tank.getGas().getGas(), Math.min(tank.getStored(), output));
|
||||
tank.draw(GasUtils.emit(toSend, this, Collections.singletonList(side)), true);
|
||||
tank.draw(GasUtils.emit(toSend, this, EnumSet.of(side)), true);
|
||||
} else {
|
||||
tank.draw(dumpAmount, true);
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement
|
||||
structure.remainingInput -= toAdd;
|
||||
}
|
||||
|
||||
return (int) Math.round(Math.min(Integer.MAX_VALUE, toAdd * MekanismConfig.current().general.TO_RF.val()));
|
||||
return MekanismUtils.clampToInt(toAdd * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -236,7 +236,7 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement
|
||||
structure.remainingOutput -= toSend;
|
||||
}
|
||||
|
||||
return (int) Math.round(Math.min(Integer.MAX_VALUE, toSend * MekanismConfig.current().general.TO_RF.val()));
|
||||
return MekanismUtils.clampToInt(toSend * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -251,15 +251,13 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement
|
||||
@Override
|
||||
@Method(modid = MekanismHooks.REDSTONEFLUX_MOD_ID)
|
||||
public int getEnergyStored(EnumFacing from) {
|
||||
return (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE, getEnergy() * MekanismConfig.current().general.TO_RF.val()));
|
||||
return MekanismUtils.clampToInt(getEnergy() * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = MekanismHooks.REDSTONEFLUX_MOD_ID)
|
||||
public int getMaxEnergyStored(EnumFacing from) {
|
||||
return (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE, getMaxEnergy() * MekanismConfig.current().general.TO_RF.val()));
|
||||
return MekanismUtils.clampToInt(getMaxEnergy() * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -281,8 +279,7 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement
|
||||
amount * MekanismConfig.current().general.FROM_IC2.val());
|
||||
setEnergy(getEnergy() + toUse);
|
||||
structure.remainingInput -= toUse;
|
||||
return (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE, getEnergy() * MekanismConfig.current().general.TO_IC2.val()));
|
||||
return MekanismUtils.clampToInt(getEnergy() * MekanismConfig.current().general.TO_IC2.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -311,8 +308,7 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement
|
||||
@Override
|
||||
@Method(modid = MekanismHooks.IC2_MOD_ID)
|
||||
public int getStored() {
|
||||
return (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE, getEnergy() * MekanismConfig.current().general.TO_IC2.val()));
|
||||
return MekanismUtils.clampToInt(getEnergy() * MekanismConfig.current().general.TO_IC2.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -324,15 +320,13 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement
|
||||
@Override
|
||||
@Method(modid = MekanismHooks.IC2_MOD_ID)
|
||||
public int getCapacity() {
|
||||
return (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE, getMaxEnergy() * MekanismConfig.current().general.TO_IC2.val()));
|
||||
return MekanismUtils.clampToInt(getMaxEnergy() * MekanismConfig.current().general.TO_IC2.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = MekanismHooks.IC2_MOD_ID)
|
||||
public int getOutput() {
|
||||
return (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE, getMaxOutput() * MekanismConfig.current().general.TO_IC2.val()));
|
||||
return MekanismUtils.clampToInt(getMaxOutput() * MekanismConfig.current().general.TO_IC2.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nonnull;
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.api.TileNetworkList;
|
||||
@@ -61,8 +62,8 @@ public class TileComponentConfig implements ITileComponent {
|
||||
canEject.put(type, true);
|
||||
}
|
||||
|
||||
public EnumSet<EnumFacing> getSidesForData(TransmissionType type, EnumFacing facing, int dataIndex) {
|
||||
EnumSet<EnumFacing> ret = EnumSet.noneOf(EnumFacing.class);
|
||||
public Set<EnumFacing> getSidesForData(TransmissionType type, EnumFacing facing, int dataIndex) {
|
||||
Set<EnumFacing> ret = EnumSet.noneOf(EnumFacing.class);
|
||||
SideConfig config = getConfig(type);
|
||||
EnumFacing[] translatedFacings = MekanismUtils.getBaseOrientations(facing);
|
||||
|
||||
|
||||
@@ -2,11 +2,14 @@ package mekanism.common.tile.component;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.api.TileNetworkList;
|
||||
import mekanism.api.gas.GasStack;
|
||||
import mekanism.api.gas.GasTank;
|
||||
import mekanism.api.transmitters.TransmissionType;
|
||||
@@ -14,7 +17,6 @@ import mekanism.common.SideData;
|
||||
import mekanism.common.base.ISideConfiguration;
|
||||
import mekanism.common.base.ITankManager;
|
||||
import mekanism.common.base.ITileComponent;
|
||||
import mekanism.api.TileNetworkList;
|
||||
import mekanism.common.capabilities.Capabilities;
|
||||
import mekanism.common.content.transporter.TransitRequest;
|
||||
import mekanism.common.content.transporter.TransitRequest.TransitResponse;
|
||||
@@ -65,7 +67,7 @@ public class TileComponentEjector implements ITileComponent {
|
||||
sideData = ejector.sideData;
|
||||
}
|
||||
|
||||
private List<EnumFacing> getTrackedOutputs(TransmissionType type, int index, List<EnumFacing> dirs) {
|
||||
private List<EnumFacing> getTrackedOutputs(TransmissionType type, int index, Set<EnumFacing> dirs) {
|
||||
List<EnumFacing> sides = new ArrayList<>();
|
||||
|
||||
for (int i = trackers.get(type)[index] + 1; i <= trackers.get(type)[index] + 6; i++) {
|
||||
@@ -92,7 +94,7 @@ public class TileComponentEjector implements ITileComponent {
|
||||
if (!tileEntity.getWorld().isRemote) {
|
||||
if (sideData.get(TransmissionType.GAS) != null && getEjecting(TransmissionType.GAS)) {
|
||||
SideData data = sideData.get(TransmissionType.GAS);
|
||||
List<EnumFacing> outputSides = getOutputSides(TransmissionType.GAS, data);
|
||||
Set<EnumFacing> outputSides = getOutputSides(TransmissionType.GAS, data);
|
||||
|
||||
if (((ITankManager) tileEntity).getTanks() != null) {
|
||||
GasTank tank = (GasTank) ((ITankManager) tileEntity).getTanks()[data.availableSlots[0]];
|
||||
@@ -107,7 +109,7 @@ public class TileComponentEjector implements ITileComponent {
|
||||
|
||||
if (sideData.get(TransmissionType.FLUID) != null && getEjecting(TransmissionType.FLUID)) {
|
||||
SideData data = sideData.get(TransmissionType.FLUID);
|
||||
List<EnumFacing> outputSides = getOutputSides(TransmissionType.FLUID, data);
|
||||
Set<EnumFacing> outputSides = getOutputSides(TransmissionType.FLUID, data);
|
||||
|
||||
if (((ITankManager) tileEntity).getTanks() != null) {
|
||||
FluidTank tank = (FluidTank) ((ITankManager) tileEntity).getTanks()[data.availableSlots[0]];
|
||||
@@ -123,18 +125,15 @@ public class TileComponentEjector implements ITileComponent {
|
||||
}
|
||||
}
|
||||
|
||||
public List<EnumFacing> getOutputSides(TransmissionType type, SideData data) {
|
||||
List<EnumFacing> outputSides = new ArrayList<>();
|
||||
ISideConfiguration configurable = (ISideConfiguration) tileEntity;
|
||||
|
||||
SideConfig sideConfig = configurable.getConfig().getConfig(type);
|
||||
ArrayList<SideData> outputs = configurable.getConfig().getOutputs(type);
|
||||
|
||||
public Set<EnumFacing> getOutputSides(TransmissionType type, SideData data) {
|
||||
Set<EnumFacing> outputSides = EnumSet.noneOf(EnumFacing.class);
|
||||
TileComponentConfig config = ((ISideConfiguration) tileEntity).getConfig();
|
||||
SideConfig sideConfig = config.getConfig(type);
|
||||
ArrayList<SideData> outputs = config.getOutputs(type);
|
||||
EnumFacing[] facings = MekanismUtils.getBaseOrientations(tileEntity.facing);
|
||||
|
||||
for (int i = 0; i < EnumFacing.VALUES.length; i++) {
|
||||
EnumFacing side = facings[i];
|
||||
|
||||
if (sideConfig.get(side) == outputs.indexOf(data)) {
|
||||
outputSides.add(EnumFacing.VALUES[i]);
|
||||
}
|
||||
@@ -149,7 +148,7 @@ public class TileComponentEjector implements ITileComponent {
|
||||
}
|
||||
|
||||
SideData data = sideData.get(TransmissionType.ITEM);
|
||||
List<EnumFacing> outputSides = getOutputSides(TransmissionType.ITEM, data);
|
||||
Set<EnumFacing> outputSides = getOutputSides(TransmissionType.ITEM, data);
|
||||
|
||||
for (int index = 0; index < sideData.get(TransmissionType.ITEM).availableSlots.length; index++) {
|
||||
int slotID = sideData.get(TransmissionType.ITEM).availableSlots[index];
|
||||
|
||||
@@ -200,19 +200,17 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
|
||||
@Override
|
||||
@Method(modid = MekanismHooks.REDSTONEFLUX_MOD_ID)
|
||||
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) {
|
||||
return (int) Math.round(
|
||||
Math.min(Integer.MAX_VALUE,
|
||||
return MekanismUtils.clampToInt(
|
||||
acceptEnergy(from, maxReceive * MekanismConfig.current().general.FROM_RF.val(), simulate)
|
||||
* MekanismConfig.current().general.TO_RF.val()));
|
||||
* MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = MekanismHooks.REDSTONEFLUX_MOD_ID)
|
||||
public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate) {
|
||||
return (int) Math.round(
|
||||
Math.min(Integer.MAX_VALUE,
|
||||
return MekanismUtils.clampToInt(
|
||||
pullEnergy(from, maxExtract * MekanismConfig.current().general.FROM_RF.val(), simulate)
|
||||
* MekanismConfig.current().general.TO_RF.val()));
|
||||
* MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -224,15 +222,13 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
|
||||
@Override
|
||||
@Method(modid = MekanismHooks.REDSTONEFLUX_MOD_ID)
|
||||
public int getEnergyStored(EnumFacing from) {
|
||||
return (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE, getEnergy() * MekanismConfig.current().general.TO_RF.val()));
|
||||
return MekanismUtils.clampToInt(getEnergy() * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = MekanismHooks.REDSTONEFLUX_MOD_ID)
|
||||
public int getMaxEnergyStored(EnumFacing from) {
|
||||
return (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE, getMaxEnergy() * MekanismConfig.current().general.TO_RF.val()));
|
||||
return MekanismUtils.clampToInt(getMaxEnergy() * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -252,8 +248,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
|
||||
public int addEnergy(int amount) {
|
||||
if (!MekanismConfig.current().general.blacklistIC2.val()) {
|
||||
setEnergy(getEnergy() + amount * MekanismConfig.current().general.FROM_IC2.val());
|
||||
return (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE, getEnergy() * MekanismConfig.current().general.TO_IC2.val()));
|
||||
return MekanismUtils.clampToInt(getEnergy() * MekanismConfig.current().general.TO_IC2.val());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -285,8 +280,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
|
||||
@Override
|
||||
@Method(modid = MekanismHooks.IC2_MOD_ID)
|
||||
public int getStored() {
|
||||
return (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE, getEnergy() * MekanismConfig.current().general.TO_IC2.val()));
|
||||
return MekanismUtils.clampToInt(getEnergy() * MekanismConfig.current().general.TO_IC2.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -300,15 +294,13 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
|
||||
@Override
|
||||
@Method(modid = MekanismHooks.IC2_MOD_ID)
|
||||
public int getCapacity() {
|
||||
return (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE, getMaxEnergy() * MekanismConfig.current().general.TO_IC2.val()));
|
||||
return MekanismUtils.clampToInt(getMaxEnergy() * MekanismConfig.current().general.TO_IC2.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = MekanismHooks.IC2_MOD_ID)
|
||||
public int getOutput() {
|
||||
return (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE, getMaxOutput() * MekanismConfig.current().general.TO_IC2.val()));
|
||||
return MekanismUtils.clampToInt(getMaxOutput() * MekanismConfig.current().general.TO_IC2.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,8 +14,6 @@ import mekanism.api.energy.EnergyStack;
|
||||
import mekanism.api.energy.IStrictEnergyAcceptor;
|
||||
import mekanism.api.energy.IStrictEnergyStorage;
|
||||
import mekanism.api.transmitters.TransmissionType;
|
||||
import mekanism.common.tier.BaseTier;
|
||||
import mekanism.common.tier.CableTier;
|
||||
import mekanism.common.base.EnergyAcceptorWrapper;
|
||||
import mekanism.common.block.states.BlockStateTransmitter.TransmitterType;
|
||||
import mekanism.common.capabilities.Capabilities;
|
||||
@@ -24,6 +22,8 @@ import mekanism.common.config.MekanismConfig;
|
||||
import mekanism.common.integration.MekanismHooks;
|
||||
import mekanism.common.integration.forgeenergy.ForgeEnergyCableIntegration;
|
||||
import mekanism.common.integration.tesla.TeslaCableIntegration;
|
||||
import mekanism.common.tier.BaseTier;
|
||||
import mekanism.common.tier.CableTier;
|
||||
import mekanism.common.transmitters.grid.EnergyNetwork;
|
||||
import mekanism.common.util.CableUtils;
|
||||
import mekanism.common.util.CapabilityUtils;
|
||||
@@ -40,7 +40,8 @@ import net.minecraftforge.fml.common.Optional;
|
||||
@Optional.InterfaceList(
|
||||
@Optional.Interface(iface = "cofh.redstoneflux.api.IEnergyReceiver", modid = MekanismHooks.REDSTONEFLUX_MOD_ID)
|
||||
)
|
||||
public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyAcceptorWrapper, EnergyNetwork, EnergyStack> implements
|
||||
public class TileEntityUniversalCable extends
|
||||
TileEntityTransmitter<EnergyAcceptorWrapper, EnergyNetwork, EnergyStack> implements
|
||||
IStrictEnergyAcceptor, IStrictEnergyStorage, IEnergyReceiver {
|
||||
|
||||
public CableTier tier = CableTier.BASIC;
|
||||
@@ -106,8 +107,8 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyAccept
|
||||
ITeslaProducer producer = CapabilityUtils
|
||||
.getCapability(outputter, Capabilities.TESLA_PRODUCER_CAPABILITY, side.getOpposite());
|
||||
double toDraw = producer
|
||||
.takePower(Math.round(Math.min(Integer.MAX_VALUE,
|
||||
canDraw * MekanismConfig.current().general.TO_TESLA.val())), true)
|
||||
.takePower(MekanismUtils
|
||||
.clampToInt(canDraw * MekanismConfig.current().general.TO_TESLA.val()), true)
|
||||
* MekanismConfig.current().general.FROM_TESLA.val();
|
||||
|
||||
if (toDraw > 0) {
|
||||
@@ -121,7 +122,8 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyAccept
|
||||
IEnergyStorage storage = CapabilityUtils
|
||||
.getCapability(outputter, CapabilityEnergy.ENERGY, side.getOpposite());
|
||||
double toDraw = storage.extractEnergy(
|
||||
(int) Math.round(canDraw * MekanismConfig.current().general.TO_FORGE.val()), true)
|
||||
MekanismUtils.clampToInt(canDraw * MekanismConfig.current().general.TO_FORGE.val()),
|
||||
true)
|
||||
* MekanismConfig.current().general.FROM_FORGE.val();
|
||||
|
||||
if (toDraw > 0) {
|
||||
@@ -129,20 +131,21 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyAccept
|
||||
}
|
||||
|
||||
storage.extractEnergy(
|
||||
(int) Math.round(toDraw * MekanismConfig.current().general.TO_TESLA.val()), false);
|
||||
MekanismUtils.clampToInt(toDraw * MekanismConfig.current().general.TO_TESLA.val()),
|
||||
false);
|
||||
} else if (MekanismUtils.useRF() && outputter instanceof IEnergyProvider) {
|
||||
double toDraw = ((IEnergyProvider) outputter).extractEnergy(side.getOpposite(),
|
||||
(int) Math.round(Math.min(Integer.MAX_VALUE,
|
||||
canDraw * MekanismConfig.current().general.TO_RF.val())), true)
|
||||
MekanismUtils.clampToInt(canDraw * MekanismConfig.current().general.TO_RF.val()),
|
||||
true)
|
||||
* MekanismConfig.current().general.FROM_RF.val();
|
||||
|
||||
if (toDraw > 0) {
|
||||
toDraw -= takeEnergy(toDraw, true);
|
||||
}
|
||||
|
||||
((IEnergyProvider) outputter)
|
||||
.extractEnergy(side.getOpposite(),
|
||||
(int) Math.round(toDraw * MekanismConfig.current().general.TO_RF.val()), false);
|
||||
((IEnergyProvider) outputter).extractEnergy(side.getOpposite(),
|
||||
MekanismUtils.clampToInt(toDraw * MekanismConfig.current().general.TO_RF.val()),
|
||||
false);
|
||||
} else if (MekanismUtils.useIC2()) {
|
||||
IEnergyTile tile = EnergyNet.instance.getSubTile(outputter.getWorld(), outputter.getPos());
|
||||
|
||||
@@ -255,10 +258,9 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyAccept
|
||||
@Override
|
||||
@Optional.Method(modid = MekanismHooks.REDSTONEFLUX_MOD_ID)
|
||||
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) {
|
||||
return maxReceive - (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE,
|
||||
takeEnergy(maxReceive * MekanismConfig.current().general.FROM_RF.val(), !simulate) * MekanismConfig
|
||||
.current().general.TO_RF.val()));
|
||||
return maxReceive - MekanismUtils.clampToInt(
|
||||
takeEnergy(maxReceive * MekanismConfig.current().general.FROM_RF.val(), !simulate) * MekanismConfig
|
||||
.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -270,15 +272,13 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyAccept
|
||||
@Override
|
||||
@Optional.Method(modid = MekanismHooks.REDSTONEFLUX_MOD_ID)
|
||||
public int getEnergyStored(EnumFacing from) {
|
||||
return (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE, getEnergy() * MekanismConfig.current().general.TO_RF.val()));
|
||||
return MekanismUtils.clampToInt(getEnergy() * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = MekanismHooks.REDSTONEFLUX_MOD_ID)
|
||||
public int getMaxEnergyStored(EnumFacing from) {
|
||||
return (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE, getMaxEnergy() * MekanismConfig.current().general.TO_RF.val()));
|
||||
return MekanismUtils.clampToInt(getMaxEnergy() * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
package mekanism.common.transmitters.grid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
import mekanism.api.Coord4D;
|
||||
@@ -13,13 +10,14 @@ import mekanism.api.energy.EnergyStack;
|
||||
import mekanism.api.transmitters.DynamicNetwork;
|
||||
import mekanism.api.transmitters.IGridTransmitter;
|
||||
import mekanism.common.base.EnergyAcceptorWrapper;
|
||||
import mekanism.common.base.target.EnergyAcceptorTarget;
|
||||
import mekanism.common.util.EmitUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
public class EnergyNetwork extends DynamicNetwork<EnergyAcceptorWrapper, EnergyNetwork, EnergyStack> {
|
||||
|
||||
@@ -103,27 +101,33 @@ public class EnergyNetwork extends DynamicNetwork<EnergyAcceptorWrapper, EnergyN
|
||||
return getCapacity() - buffer.amount;
|
||||
}
|
||||
|
||||
public double tickEmit(double energyToSend) {
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
|
||||
return 0;
|
||||
private double tickEmit(double energyToSend) {
|
||||
Set<EnergyAcceptorTarget> targets = new HashSet<>();
|
||||
int totalHandlers = 0;
|
||||
for (Coord4D coord : possibleAcceptors.keySet()) {
|
||||
EnumSet<EnumFacing> sides = acceptorDirections.get(coord);
|
||||
if (sides == null || sides.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
TileEntity tile = coord.getTileEntity(getWorld());
|
||||
if (tile == null) {
|
||||
continue;
|
||||
}
|
||||
EnergyAcceptorTarget target = new EnergyAcceptorTarget();
|
||||
for (EnumFacing side : sides) {
|
||||
EnergyAcceptorWrapper acceptor = EnergyAcceptorWrapper.get(tile, side);
|
||||
if (acceptor != null && acceptor.canReceiveEnergy(side) && acceptor.needsEnergy(side)) {
|
||||
target.addHandler(side, acceptor);
|
||||
}
|
||||
}
|
||||
int curHandlers = target.getHandlers().size();
|
||||
if (curHandlers > 0) {
|
||||
targets.add(target);
|
||||
totalHandlers += curHandlers;
|
||||
}
|
||||
}
|
||||
|
||||
double sent = 0;
|
||||
boolean tryAgain;
|
||||
int i = 0;
|
||||
|
||||
do {
|
||||
double prev = sent;
|
||||
sent += doEmit(energyToSend - sent);
|
||||
|
||||
tryAgain = energyToSend - sent > 0 && sent - prev > 0 && i < 100;
|
||||
|
||||
i++;
|
||||
} while (tryAgain);
|
||||
|
||||
joulesTransmitted = sent;
|
||||
|
||||
return sent;
|
||||
return EmitUtils.sendToAcceptors(targets, totalHandlers, energyToSend);
|
||||
}
|
||||
|
||||
public double emit(double energyToSend, boolean doEmit) {
|
||||
@@ -136,77 +140,6 @@ public class EnergyNetwork extends DynamicNetwork<EnergyAcceptorWrapper, EnergyN
|
||||
return energyToSend - toUse;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return sent
|
||||
*/
|
||||
public double doEmit(double energyToSend) {
|
||||
double sent = 0;
|
||||
|
||||
List<Pair<Coord4D, EnergyAcceptorWrapper>> availableAcceptors = new ArrayList<>(getAcceptors(null));
|
||||
|
||||
Collections.shuffle(availableAcceptors);
|
||||
|
||||
if (!availableAcceptors.isEmpty()) {
|
||||
int divider = availableAcceptors.size();
|
||||
double remaining = energyToSend % divider;
|
||||
double sending = (energyToSend - remaining) / divider;
|
||||
|
||||
for (Pair<Coord4D, EnergyAcceptorWrapper> pair : availableAcceptors) {
|
||||
EnergyAcceptorWrapper acceptor = pair.getRight();
|
||||
double currentSending = sending + remaining;
|
||||
EnumSet<EnumFacing> sides = acceptorDirections.get(pair.getLeft());
|
||||
|
||||
if (sides == null || sides.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (EnumFacing side : sides) {
|
||||
double prev = sent;
|
||||
|
||||
sent += acceptor.acceptEnergy(side, currentSending, false);
|
||||
|
||||
if (sent > prev) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Pair<Coord4D, EnergyAcceptorWrapper>> getAcceptors(Object data) {
|
||||
Set<Pair<Coord4D, EnergyAcceptorWrapper>> toReturn = new HashSet<>();
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
for (Coord4D coord : possibleAcceptors.keySet()) {
|
||||
EnumSet<EnumFacing> sides = acceptorDirections.get(coord);
|
||||
|
||||
if (sides == null || sides.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TileEntity tile = coord.getTileEntity(getWorld());
|
||||
|
||||
for (EnumFacing side : sides) {
|
||||
EnergyAcceptorWrapper acceptor = EnergyAcceptorWrapper.get(tile, side);
|
||||
|
||||
if (acceptor != null) {
|
||||
if (acceptor.canReceiveEnergy(side) && acceptor.needsEnergy(side)) {
|
||||
toReturn.add(Pair.of(coord, acceptor));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[EnergyNetwork] " + transmitters.size() + " transmitters, " + possibleAcceptors.size() + " acceptors.";
|
||||
@@ -233,7 +166,8 @@ public class EnergyNetwork extends DynamicNetwork<EnergyAcceptorWrapper, EnergyN
|
||||
}
|
||||
|
||||
if (buffer.amount > 0) {
|
||||
buffer.amount -= tickEmit(buffer.amount);
|
||||
joulesTransmitted = tickEmit(buffer.amount);
|
||||
buffer.amount -= joulesTransmitted;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
package mekanism.common.transmitters.grid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.transmitters.DynamicNetwork;
|
||||
import mekanism.api.transmitters.IGridTransmitter;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.base.target.FluidHandlerTarget;
|
||||
import mekanism.common.util.CapabilityUtils;
|
||||
import mekanism.common.util.EmitUtils;
|
||||
import mekanism.common.util.LangUtils;
|
||||
import mekanism.common.util.PipeUtils;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -24,7 +22,6 @@ import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork, FluidStack> {
|
||||
|
||||
@@ -127,57 +124,38 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork, Fl
|
||||
return getCapacity() - (buffer != null ? buffer.amount : 0);
|
||||
}
|
||||
|
||||
public int tickEmit(FluidStack fluidToSend, boolean doTransfer) {
|
||||
List<Pair<Coord4D, IFluidHandler>> availableAcceptors = new ArrayList<>(getAcceptors(fluidToSend));
|
||||
private int tickEmit(FluidStack fluidToSend) {
|
||||
Set<FluidHandlerTarget> availableAcceptors = new HashSet<>();
|
||||
int totalHandlers = 0;
|
||||
for (Coord4D coord : possibleAcceptors.keySet()) {
|
||||
EnumSet<EnumFacing> sides = acceptorDirections.get(coord);
|
||||
if (sides == null || sides.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
TileEntity tile = coord.getTileEntity(getWorld());
|
||||
if (tile == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Collections.shuffle(availableAcceptors);
|
||||
FluidHandlerTarget target = new FluidHandlerTarget(fluidToSend);
|
||||
|
||||
int fluidSent = 0;
|
||||
|
||||
if (!availableAcceptors.isEmpty()) {
|
||||
int divider = availableAcceptors.size();
|
||||
int remaining = fluidToSend.amount % divider;
|
||||
int sending = (fluidToSend.amount - remaining) / divider;
|
||||
|
||||
for (Pair<Coord4D, IFluidHandler> pair : availableAcceptors) {
|
||||
int currentSending = sending;
|
||||
IFluidHandler acceptor = pair.getRight();
|
||||
EnumSet<EnumFacing> sides = acceptorDirections.get(pair.getLeft());
|
||||
|
||||
if (remaining > 0) {
|
||||
currentSending++;
|
||||
remaining--;
|
||||
}
|
||||
|
||||
for (EnumFacing side : sides) {
|
||||
int prev = fluidSent;
|
||||
|
||||
if (acceptor != null) {
|
||||
fluidSent += acceptor.fill(PipeUtils.copy(fluidToSend, currentSending), doTransfer);
|
||||
}
|
||||
|
||||
if (fluidSent > prev) {
|
||||
break;
|
||||
for (EnumFacing side : sides) {
|
||||
if (CapabilityUtils.hasCapability(tile, CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) {
|
||||
IFluidHandler acceptor = CapabilityUtils
|
||||
.getCapability(tile, CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
|
||||
if (acceptor != null && PipeUtils.canFill(acceptor, fluidToSend)) {
|
||||
target.addHandler(side, acceptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (doTransfer && fluidSent > 0 && FMLCommonHandler.instance().getEffectiveSide().isServer()) {
|
||||
didTransfer = true;
|
||||
transferDelay = 2;
|
||||
}
|
||||
|
||||
if (fluidSent > fluidToSend.amount) {
|
||||
Mekanism.logger.error("Some fluid handler took more fluid than we gave it?!");
|
||||
Mekanism.logger.error("Handler list:");
|
||||
for (Pair<Coord4D, IFluidHandler> pair : availableAcceptors) {
|
||||
Mekanism.logger.error(pair.getRight().toString());
|
||||
int curHandlers = target.getHandlers().size();
|
||||
if (curHandlers > 0) {
|
||||
availableAcceptors.add(target);
|
||||
totalHandlers += curHandlers;
|
||||
}
|
||||
fluidSent = fluidToSend.amount;
|
||||
}
|
||||
|
||||
return fluidSent;
|
||||
return EmitUtils.sendToAcceptors(availableAcceptors, totalHandlers, fluidToSend.amount, fluidToSend);
|
||||
}
|
||||
|
||||
public int emit(FluidStack fluidToSend, boolean doTransfer) {
|
||||
@@ -228,7 +206,11 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork, Fl
|
||||
prevTransfer = didTransfer;
|
||||
|
||||
if (buffer != null) {
|
||||
prevTransferAmount = tickEmit(buffer, true);
|
||||
prevTransferAmount = tickEmit(buffer);
|
||||
if (prevTransferAmount > 0) {
|
||||
didTransfer = true;
|
||||
transferDelay = 2;
|
||||
}
|
||||
|
||||
if (buffer != null) {
|
||||
buffer.amount -= prevTransferAmount;
|
||||
@@ -258,41 +240,6 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork, Fl
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Pair<Coord4D, IFluidHandler>> getAcceptors(Object data) {
|
||||
FluidStack fluidToSend = (FluidStack) data;
|
||||
Set<Pair<Coord4D, IFluidHandler>> toReturn = new HashSet<>();
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
for (Coord4D coord : possibleAcceptors.keySet()) {
|
||||
EnumSet<EnumFacing> sides = acceptorDirections.get(coord);
|
||||
TileEntity tile = coord.getTileEntity(getWorld());
|
||||
|
||||
if (sides == null || sides.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (EnumFacing side : sides) {
|
||||
if (!CapabilityUtils.hasCapability(tile, CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
IFluidHandler acceptor = CapabilityUtils
|
||||
.getCapability(tile, CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
|
||||
|
||||
if (acceptor != null && PipeUtils.canFill(acceptor, fluidToSend)) {
|
||||
toReturn.add(Pair.of(coord, acceptor));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public float getScale() {
|
||||
return Math.min(1, (buffer == null || getCapacity() == 0 ? 0 : (float) buffer.amount / getCapacity()));
|
||||
}
|
||||
@@ -325,7 +272,8 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork, Fl
|
||||
|
||||
@Override
|
||||
public boolean compatibleWithBuffer(FluidStack buffer) {
|
||||
return super.compatibleWithBuffer(buffer) && (this.buffer == null || buffer == null || this.buffer.isFluidEqual(buffer));
|
||||
return super.compatibleWithBuffer(buffer) && (this.buffer == null || buffer == null || this.buffer
|
||||
.isFluidEqual(buffer));
|
||||
}
|
||||
|
||||
public static class FluidTransferEvent extends Event {
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
package mekanism.common.transmitters.grid;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
import mekanism.api.Coord4D;
|
||||
@@ -14,14 +11,15 @@ import mekanism.api.gas.GasStack;
|
||||
import mekanism.api.gas.IGasHandler;
|
||||
import mekanism.api.transmitters.DynamicNetwork;
|
||||
import mekanism.api.transmitters.IGridTransmitter;
|
||||
import mekanism.common.base.target.GasHandlerTarget;
|
||||
import mekanism.common.capabilities.Capabilities;
|
||||
import mekanism.common.util.CapabilityUtils;
|
||||
import mekanism.common.util.EmitUtils;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
/**
|
||||
* A DynamicNetwork extension created specifically for the transfer of Gasses. By default this is server-only, but if
|
||||
@@ -130,51 +128,38 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork, GasStack
|
||||
return getCapacity() - (buffer != null ? buffer.amount : 0);
|
||||
}
|
||||
|
||||
public int tickEmit(GasStack stack) {
|
||||
List<Pair<Coord4D, IGasHandler>> availableAcceptors = Lists.newArrayList();
|
||||
private int tickEmit(GasStack stack) {
|
||||
Set<GasHandlerTarget> availableAcceptors = new HashSet<>();
|
||||
int totalHandlers = 0;
|
||||
Gas type = stack.getGas();
|
||||
for (Coord4D coord : possibleAcceptors.keySet()) {
|
||||
EnumSet<EnumFacing> sides = acceptorDirections.get(coord);
|
||||
if (sides == null || sides.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
TileEntity tile = coord.getTileEntity(getWorld());
|
||||
if (tile == null) {
|
||||
continue;
|
||||
}
|
||||
GasHandlerTarget target = new GasHandlerTarget(stack);
|
||||
for (EnumFacing side : sides) {
|
||||
if (CapabilityUtils.hasCapability(tile, Capabilities.GAS_HANDLER_CAPABILITY, side)) {
|
||||
IGasHandler acceptor = CapabilityUtils
|
||||
.getCapability(tile, Capabilities.GAS_HANDLER_CAPABILITY, side);
|
||||
|
||||
availableAcceptors.addAll(getAcceptors(stack.getGas()));
|
||||
|
||||
Collections.shuffle(availableAcceptors);
|
||||
|
||||
int toSend = stack.amount;
|
||||
int prevSending = toSend;
|
||||
|
||||
if (!availableAcceptors.isEmpty()) {
|
||||
int divider = availableAcceptors.size();
|
||||
int remaining = toSend % divider;
|
||||
int sending = (toSend - remaining) / divider;
|
||||
|
||||
for (Pair<Coord4D, IGasHandler> pair : availableAcceptors) {
|
||||
IGasHandler acceptor = pair.getRight();
|
||||
int currentSending = sending;
|
||||
EnumSet<EnumFacing> sides = acceptorDirections.get(pair.getLeft());
|
||||
|
||||
if (remaining > 0) {
|
||||
currentSending++;
|
||||
remaining--;
|
||||
}
|
||||
|
||||
for (EnumFacing side : sides) {
|
||||
int prev = toSend;
|
||||
|
||||
toSend -= acceptor.receiveGas(side, new GasStack(stack.getGas(), currentSending), true);
|
||||
|
||||
if (toSend < prev) {
|
||||
break;
|
||||
if (acceptor != null && acceptor.canReceiveGas(side, type)) {
|
||||
target.addHandler(side, acceptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
int curHandlers = target.getHandlers().size();
|
||||
if (curHandlers > 0) {
|
||||
availableAcceptors.add(target);
|
||||
totalHandlers += curHandlers;
|
||||
}
|
||||
}
|
||||
|
||||
int sent = prevSending - toSend;
|
||||
|
||||
if (sent > 0 && FMLCommonHandler.instance().getEffectiveSide().isServer()) {
|
||||
didTransfer = true;
|
||||
transferDelay = 2;
|
||||
}
|
||||
|
||||
return sent;
|
||||
return EmitUtils.sendToAcceptors(availableAcceptors, totalHandlers, stack.amount, stack);
|
||||
}
|
||||
|
||||
public int emit(GasStack stack, boolean doTransfer) {
|
||||
@@ -226,6 +211,10 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork, GasStack
|
||||
|
||||
if (buffer != null) {
|
||||
prevTransferAmount = tickEmit(buffer);
|
||||
if (prevTransferAmount > 0) {
|
||||
didTransfer = true;
|
||||
transferDelay = 2;
|
||||
}
|
||||
buffer.amount -= prevTransferAmount;
|
||||
|
||||
if (buffer.amount <= 0) {
|
||||
@@ -252,40 +241,6 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork, GasStack
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Pair<Coord4D, IGasHandler>> getAcceptors(Object data) {
|
||||
Gas type = (Gas) data;
|
||||
Set<Pair<Coord4D, IGasHandler>> toReturn = new HashSet<>();
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
for (Coord4D coord : possibleAcceptors.keySet()) {
|
||||
EnumSet<EnumFacing> sides = acceptorDirections.get(coord);
|
||||
TileEntity tile = coord.getTileEntity(getWorld());
|
||||
|
||||
if (sides == null || sides.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (EnumFacing side : sides) {
|
||||
if (!CapabilityUtils.hasCapability(tile, Capabilities.GAS_HANDLER_CAPABILITY, side)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
IGasHandler acceptor = CapabilityUtils.getCapability(tile, Capabilities.GAS_HANDLER_CAPABILITY, side);
|
||||
|
||||
if (acceptor != null && acceptor.canReceiveGas(side, type)) {
|
||||
toReturn.add(Pair.of(coord, acceptor));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public float getScale() {
|
||||
return Math.min(1, (buffer == null || getCapacity() == 0 ? 0 : (float) buffer.amount / getCapacity()));
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package mekanism.common.transmitters.grid;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.IHeatTransfer;
|
||||
import mekanism.api.transmitters.DynamicNetwork;
|
||||
import mekanism.api.transmitters.IGridTransmitter;
|
||||
@@ -11,9 +9,6 @@ import mekanism.common.transmitters.TransmitterImpl;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.UnitDisplayUtils.TemperatureUnit;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
//import mekanism.common.multipart.MultipartTransmitter;
|
||||
|
||||
public class HeatNetwork extends DynamicNetwork<IHeatTransfer, HeatNetwork, Void> {
|
||||
|
||||
@@ -62,11 +57,6 @@ public class HeatNetwork extends DynamicNetwork<IHeatTransfer, HeatNetwork, Void
|
||||
public void clampBuffer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Pair<Coord4D, IHeatTransfer>> getAcceptors(Object data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
super.onUpdate();
|
||||
@@ -84,14 +74,6 @@ public class HeatNetwork extends DynamicNetwork<IHeatTransfer, HeatNetwork, Void
|
||||
double[] d = heatTransmitter.simulateHeat();
|
||||
newHeatTransferred += d[0];
|
||||
newHeatLost += d[1];
|
||||
}
|
||||
}
|
||||
|
||||
for (IGridTransmitter<IHeatTransfer, HeatNetwork, Void> transmitter : transmitters) {
|
||||
if (transmitter instanceof TransmitterImpl && ((TransmitterImpl) transmitter).getTileEntity()
|
||||
.hasCapability(Capabilities.HEAT_TRANSFER_CAPABILITY, null)) {
|
||||
IHeatTransfer heatTransmitter = (IHeatTransfer) ((TransmitterImpl) transmitter).getTileEntity()
|
||||
.getCapability(Capabilities.HEAT_TRANSFER_CAPABILITY, null);
|
||||
newSumTemp += heatTransmitter.applyTemperatureChange();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,7 @@ package mekanism.common.transmitters.grid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.transmitters.DynamicNetwork;
|
||||
import mekanism.api.transmitters.IGridTransmitter;
|
||||
@@ -89,17 +86,6 @@ public class InventoryNetwork extends DynamicNetwork<TileEntity, InventoryNetwor
|
||||
public void clampBuffer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Pair<Coord4D, TileEntity>> getAcceptors(Object data) {
|
||||
Set<Pair<Coord4D, TileEntity>> toReturn = new HashSet<>();
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[InventoryNetwork] " + transmitters.size() + " transmitters, " + possibleAcceptors.size()
|
||||
|
||||
@@ -3,25 +3,21 @@ package mekanism.common.util;
|
||||
import cofh.redstoneflux.api.IEnergyConnection;
|
||||
import cofh.redstoneflux.api.IEnergyProvider;
|
||||
import cofh.redstoneflux.api.IEnergyReceiver;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.energy.IStrictEnergyAcceptor;
|
||||
import mekanism.api.energy.IStrictEnergyOutputter;
|
||||
import mekanism.api.transmitters.TransmissionType;
|
||||
import mekanism.common.base.EnergyAcceptorWrapper;
|
||||
import mekanism.common.base.IEnergyWrapper;
|
||||
import mekanism.common.base.target.EnergyAcceptorTarget;
|
||||
import mekanism.common.capabilities.Capabilities;
|
||||
import mekanism.common.config.MekanismConfig;
|
||||
import mekanism.common.integration.ic2.IC2Integration;
|
||||
import net.darkhax.tesla.api.ITeslaConsumer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.energy.CapabilityEnergy;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
|
||||
public final class CableUtils {
|
||||
|
||||
@@ -35,29 +31,6 @@ public final class CableUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the adjacent connections to a TileEntity, from a subset of its sides.
|
||||
*
|
||||
* @param tileEntity - center TileEntity
|
||||
* @param sideFunction - set of sides to check
|
||||
* @return boolean[] of adjacent connections
|
||||
*/
|
||||
public static boolean[] getConnections(TileEntity tileEntity, Function<EnumFacing, Boolean> sideFunction) {
|
||||
boolean[] connectable = new boolean[]{false, false, false, false, false, false};
|
||||
Coord4D coord = Coord4D.get(tileEntity);
|
||||
|
||||
for (EnumFacing side : EnumFacing.values()) {
|
||||
if (sideFunction.apply(side)) {
|
||||
TileEntity tile = coord.offset(side).getTileEntity(tileEntity.getWorld());
|
||||
|
||||
connectable[side.ordinal()] = isValidAcceptorOnSide(tileEntity, tile, side);
|
||||
connectable[side.ordinal()] |= isCable(tile);
|
||||
}
|
||||
}
|
||||
|
||||
return connectable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the adjacent connections to a TileEntity, from a subset of its sides.
|
||||
*
|
||||
@@ -159,103 +132,38 @@ public final class CableUtils {
|
||||
}
|
||||
|
||||
public static void emit(IEnergyWrapper emitter) {
|
||||
if (!((TileEntity) emitter).getWorld().isRemote && MekanismUtils.canFunction((TileEntity) emitter)) {
|
||||
TileEntity tileEntity = (TileEntity) emitter;
|
||||
if (!tileEntity.getWorld().isRemote && MekanismUtils.canFunction(tileEntity)) {
|
||||
double energyToSend = Math.min(emitter.getEnergy(), emitter.getMaxOutput());
|
||||
|
||||
if (energyToSend > 0) {
|
||||
List<EnumFacing> outputtingSides = new LinkedList<>();
|
||||
boolean[] connectable = getConnections((TileEntity) emitter, emitter::sideIsOutput);
|
||||
|
||||
Coord4D coord = Coord4D.get(tileEntity);
|
||||
//Fake that we have one target given we know that no sides will overlap
|
||||
// This allows us to have slightly better performance
|
||||
EnergyAcceptorTarget target = new EnergyAcceptorTarget();
|
||||
for (EnumFacing side : EnumFacing.values()) {
|
||||
if (connectable[side.ordinal()]) {
|
||||
outputtingSides.add(side);
|
||||
if (emitter.sideIsOutput(side)) {
|
||||
TileEntity tile = coord.offset(side).getTileEntity(tileEntity.getWorld());
|
||||
//If it can accept energy or it is a cable
|
||||
if (tile != null && (isValidAcceptorOnSide(tileEntity, tile, side) || isCable(tile))) {
|
||||
//Get the opposite side as the current side is relative to us
|
||||
EnumFacing opposite = side.getOpposite();
|
||||
EnergyAcceptorWrapper acceptor = EnergyAcceptorWrapper.get(tile, opposite);
|
||||
if (acceptor != null && acceptor.canReceiveEnergy(opposite) && acceptor
|
||||
.needsEnergy(opposite)) {
|
||||
target.addHandler(opposite, acceptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!outputtingSides.isEmpty()) {
|
||||
double sent = 0;
|
||||
boolean tryAgain = false;
|
||||
int i = 0;
|
||||
|
||||
do {
|
||||
double prev = sent;
|
||||
sent += emit_do(emitter, outputtingSides, energyToSend - sent, tryAgain);
|
||||
|
||||
tryAgain = energyToSend - sent > 0 && sent - prev > 0 && i < 100;
|
||||
|
||||
i++;
|
||||
} while (tryAgain);
|
||||
|
||||
int curHandlers = target.getHandlers().size();
|
||||
if (curHandlers > 0) {
|
||||
Set<EnergyAcceptorTarget> targets = new HashSet<>();
|
||||
targets.add(target);
|
||||
double sent = EmitUtils.sendToAcceptors(targets, curHandlers, energyToSend);
|
||||
emitter.setEnergy(emitter.getEnergy() - sent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static double emit_do(IEnergyWrapper emitter, List<EnumFacing> outputtingSides, double totalToSend,
|
||||
boolean tryAgain) {
|
||||
double remains = totalToSend % outputtingSides.size();
|
||||
double splitSend = (totalToSend - remains) / outputtingSides.size();
|
||||
double sent = 0;
|
||||
|
||||
for (Iterator<EnumFacing> it = outputtingSides.iterator(); it.hasNext(); ) {
|
||||
EnumFacing side = it.next();
|
||||
|
||||
TileEntity tileEntity = Coord4D.get((TileEntity) emitter).offset(side)
|
||||
.getTileEntity(((TileEntity) emitter).getWorld());
|
||||
double toSend = splitSend + remains;
|
||||
remains = 0;
|
||||
|
||||
double prev = sent;
|
||||
sent += emit_do_do(emitter, tileEntity, side, toSend, tryAgain);
|
||||
|
||||
if (sent - prev == 0) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
return sent;
|
||||
}
|
||||
|
||||
private static double emit_do_do(IEnergyWrapper from, TileEntity tileEntity, EnumFacing side, double currentSending,
|
||||
boolean tryAgain) {
|
||||
double sent = 0;
|
||||
|
||||
if (CapabilityUtils.hasCapability(tileEntity, Capabilities.ENERGY_ACCEPTOR_CAPABILITY, side.getOpposite())) {
|
||||
IStrictEnergyAcceptor acceptor = CapabilityUtils
|
||||
.getCapability(tileEntity, Capabilities.ENERGY_ACCEPTOR_CAPABILITY, side.getOpposite());
|
||||
|
||||
if (acceptor.canReceiveEnergy(side.getOpposite())) {
|
||||
sent += acceptor.acceptEnergy(side.getOpposite(), currentSending, false);
|
||||
}
|
||||
} else if (MekanismUtils.useTesla() && CapabilityUtils
|
||||
.hasCapability(tileEntity, Capabilities.TESLA_CONSUMER_CAPABILITY, side.getOpposite())) {
|
||||
ITeslaConsumer consumer = CapabilityUtils
|
||||
.getCapability(tileEntity, Capabilities.TESLA_CONSUMER_CAPABILITY, side.getOpposite());
|
||||
sent += consumer
|
||||
.givePower(Math.round(currentSending * MekanismConfig.current().general.TO_TESLA.val()), false)
|
||||
* MekanismConfig.current().general.FROM_TESLA.val();
|
||||
} else if (MekanismUtils.useForge() && CapabilityUtils
|
||||
.hasCapability(tileEntity, CapabilityEnergy.ENERGY, side.getOpposite())) {
|
||||
IEnergyStorage storage = CapabilityUtils
|
||||
.getCapability(tileEntity, CapabilityEnergy.ENERGY, side.getOpposite());
|
||||
sent += storage
|
||||
.receiveEnergy((int) Math.round(
|
||||
Math.min(Integer.MAX_VALUE, currentSending * MekanismConfig.current().general.TO_FORGE.val())),
|
||||
false) * MekanismConfig.current().general.FROM_FORGE.val();
|
||||
} else if (MekanismUtils.useRF() && tileEntity instanceof IEnergyReceiver) {
|
||||
IEnergyReceiver handler = (IEnergyReceiver) tileEntity;
|
||||
|
||||
if (handler.canConnectEnergy(side.getOpposite())) {
|
||||
int toSend = Math.min((int) Math.round(currentSending * MekanismConfig.current().general.TO_RF.val()),
|
||||
Integer.MAX_VALUE);
|
||||
int used = handler.receiveEnergy(side.getOpposite(), toSend, false);
|
||||
sent += used * MekanismConfig.current().general.FROM_RF.val();
|
||||
}
|
||||
} else if (MekanismUtils.useIC2()) {
|
||||
sent += IC2Integration.emitEnergy(from, tileEntity, side, currentSending);
|
||||
}
|
||||
|
||||
return sent;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,26 +44,33 @@ public final class ChargeUtils {
|
||||
} else if (MekanismUtils.useForge() && stack.hasCapability(CapabilityEnergy.ENERGY, null)) {
|
||||
IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
|
||||
if (storage.canExtract()) {
|
||||
int needed = (int) Math.round(
|
||||
Math.min(Integer.MAX_VALUE, (storer.getMaxEnergy() - storer.getEnergy()) * MekanismConfig.current().general.TO_FORGE.val()));
|
||||
storer.setEnergy(storer.getEnergy() + storage.extractEnergy(needed, false) * MekanismConfig.current().general.FROM_FORGE.val());
|
||||
int needed = MekanismUtils.clampToInt((storer.getMaxEnergy() - storer.getEnergy()) *
|
||||
MekanismConfig.current().general.TO_FORGE.val());
|
||||
storer.setEnergy(storer.getEnergy() + storage.extractEnergy(needed, false) * MekanismConfig
|
||||
.current().general.FROM_FORGE.val());
|
||||
}
|
||||
} else if (MekanismUtils.useRF() && stack.getItem() instanceof IEnergyContainerItem) {
|
||||
IEnergyContainerItem item = (IEnergyContainerItem) stack.getItem();
|
||||
int needed = (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE, (storer.getMaxEnergy() - storer.getEnergy()) * MekanismConfig.current().general.TO_RF.val()));
|
||||
storer.setEnergy(storer.getEnergy() + (item.extractEnergy(stack, needed, false) * MekanismConfig.current().general.FROM_RF.val()));
|
||||
int needed = MekanismUtils.clampToInt((storer.getMaxEnergy() - storer.getEnergy()) *
|
||||
MekanismConfig.current().general.TO_RF.val());
|
||||
storer.setEnergy(storer.getEnergy() + (item.extractEnergy(stack, needed, false) * MekanismConfig
|
||||
.current().general.FROM_RF.val()));
|
||||
} else if (MekanismUtils.useTesla() && stack.hasCapability(Capabilities.TESLA_PRODUCER_CAPABILITY, null)) {
|
||||
ITeslaProducer producer = stack.getCapability(Capabilities.TESLA_PRODUCER_CAPABILITY, null);
|
||||
|
||||
long needed = Math.round((storer.getMaxEnergy() - storer.getEnergy()) * MekanismConfig.current().general.TO_TESLA.val());
|
||||
storer.setEnergy(storer.getEnergy() + producer.takePower(needed, false) * MekanismConfig.current().general.FROM_TESLA.val());
|
||||
long needed = Math.round(
|
||||
(storer.getMaxEnergy() - storer.getEnergy()) * MekanismConfig.current().general.TO_TESLA.val());
|
||||
storer.setEnergy(storer.getEnergy() + producer.takePower(needed, false) * MekanismConfig
|
||||
.current().general.FROM_TESLA.val());
|
||||
} else if (MekanismUtils.useIC2() && isIC2Dischargeable(stack)) {
|
||||
double gain = ElectricItem.manager
|
||||
.discharge(stack, (storer.getMaxEnergy() - storer.getEnergy()) * MekanismConfig.current().general.TO_IC2.val(), 4, true, true,
|
||||
.discharge(stack,
|
||||
(storer.getMaxEnergy() - storer.getEnergy()) * MekanismConfig.current().general.TO_IC2
|
||||
.val(), 4, true, true,
|
||||
false) * MekanismConfig.current().general.FROM_IC2.val();
|
||||
storer.setEnergy(storer.getEnergy() + gain);
|
||||
} else if (stack.getItem() == Items.REDSTONE && storer.getEnergy() + MekanismConfig.current().general.ENERGY_PER_REDSTONE.val() <= storer
|
||||
} else if (stack.getItem() == Items.REDSTONE
|
||||
&& storer.getEnergy() + MekanismConfig.current().general.ENERGY_PER_REDSTONE.val() <= storer
|
||||
.getMaxEnergy()) {
|
||||
storer.setEnergy(storer.getEnergy() + MekanismConfig.current().general.ENERGY_PER_REDSTONE.val());
|
||||
stack.shrink(1);
|
||||
@@ -95,19 +102,25 @@ public final class ChargeUtils {
|
||||
} else if (MekanismUtils.useForge() && stack.hasCapability(CapabilityEnergy.ENERGY, null)) {
|
||||
IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
|
||||
if (storage.canReceive()) {
|
||||
int stored = (int) Math.round(Math.min(Integer.MAX_VALUE, storer.getEnergy() * MekanismConfig.current().general.TO_FORGE.val()));
|
||||
storer.setEnergy(storer.getEnergy() - storage.receiveEnergy(stored, false) * MekanismConfig.current().general.FROM_FORGE.val());
|
||||
int stored = MekanismUtils
|
||||
.clampToInt(storer.getEnergy() * MekanismConfig.current().general.TO_FORGE.val());
|
||||
storer.setEnergy(storer.getEnergy() - storage.receiveEnergy(stored, false) * MekanismConfig
|
||||
.current().general.FROM_FORGE.val());
|
||||
}
|
||||
} else if (MekanismUtils.useRF() && stack.getItem() instanceof IEnergyContainerItem) {
|
||||
IEnergyContainerItem item = (IEnergyContainerItem) stack.getItem();
|
||||
int toTransfer = (int) Math.round(storer.getEnergy() * MekanismConfig.current().general.TO_RF.val());
|
||||
storer.setEnergy(storer.getEnergy() - (item.receiveEnergy(stack, toTransfer, false) * MekanismConfig.current().general.FROM_RF.val()));
|
||||
int toTransfer = MekanismUtils
|
||||
.clampToInt(storer.getEnergy() * MekanismConfig.current().general.TO_RF.val());
|
||||
storer.setEnergy(storer.getEnergy() - (item.receiveEnergy(stack, toTransfer, false) * MekanismConfig
|
||||
.current().general.FROM_RF.val()));
|
||||
} else if (MekanismUtils.useTesla() && stack.hasCapability(Capabilities.TESLA_CONSUMER_CAPABILITY, null)) {
|
||||
ITeslaConsumer consumer = stack.getCapability(Capabilities.TESLA_CONSUMER_CAPABILITY, null);
|
||||
long stored = Math.round(storer.getEnergy() * MekanismConfig.current().general.TO_TESLA.val());
|
||||
storer.setEnergy(storer.getEnergy() - consumer.givePower(stored, false) * MekanismConfig.current().general.FROM_TESLA.val());
|
||||
storer.setEnergy(storer.getEnergy() - consumer.givePower(stored, false) * MekanismConfig
|
||||
.current().general.FROM_TESLA.val());
|
||||
} else if (MekanismUtils.useIC2() && isIC2Chargeable(stack)) {
|
||||
double sent = ElectricItem.manager.charge(stack, storer.getEnergy() * MekanismConfig.current().general.TO_IC2.val(), 4, true, false)
|
||||
double sent = ElectricItem.manager
|
||||
.charge(stack, storer.getEnergy() * MekanismConfig.current().general.TO_IC2.val(), 4, true, false)
|
||||
* MekanismConfig.current().general.FROM_IC2.val();
|
||||
storer.setEnergy(storer.getEnergy() - sent);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package mekanism.common.util;
|
||||
|
||||
import java.util.Set;
|
||||
import mekanism.common.base.SplitInfo;
|
||||
import mekanism.common.base.SplitInfo.DoubleSplitInfo;
|
||||
import mekanism.common.base.SplitInfo.IntegerSplitInfo;
|
||||
import mekanism.common.base.target.EnergyAcceptorTarget;
|
||||
import mekanism.common.base.target.Target;
|
||||
|
||||
public class EmitUtils {
|
||||
|
||||
/**
|
||||
* @param <HANDLER> The handler of our target.
|
||||
* @param <TYPE> The type of the number
|
||||
* @param <EXTRA> Any extra information we may need.
|
||||
* @param <TARGET> The emitter target.
|
||||
* @param availableTargets The targets to distribute toSend fairly among.
|
||||
* @param totalTargets The total number of targets. Note: this number is bigger than availableTargets.size if any
|
||||
* targets have more than one acceptor.
|
||||
* @param splitInfo Information containing the split.
|
||||
* @param toSend Any extra information such as gas stack or fluid stack.
|
||||
* @return The amount that actually got sent.
|
||||
*/
|
||||
private static <HANDLER, TYPE extends Number & Comparable<TYPE>, EXTRA, TARGET extends Target<HANDLER, TYPE, EXTRA>>
|
||||
TYPE sendToAcceptors(Set<TARGET> availableTargets, int totalTargets, SplitInfo<TYPE> splitInfo, EXTRA toSend) {
|
||||
if (availableTargets.isEmpty() || totalTargets == 0) {
|
||||
return splitInfo.getTotalSent();
|
||||
}
|
||||
|
||||
//Simulate addition, sending when the requested amount is less than the amountPer
|
||||
// splitInfo gets adjusted to account for how much is actually sent
|
||||
availableTargets.forEach(target -> target.sendPossible(toSend, splitInfo));
|
||||
|
||||
//Only run this if we changed the amountPer from when we first/last ran things
|
||||
while (splitInfo.amountPerChanged) {
|
||||
splitInfo.amountPerChanged = false;
|
||||
//splitInfo gets adjusted to account for how much is actually sent,
|
||||
// and if amountPer got changed again and we need to rerun this
|
||||
availableTargets.forEach(target -> target.shiftNeeded(splitInfo));
|
||||
}
|
||||
|
||||
//Evenly distribute the remaining amount we have to give between all targets and handlers
|
||||
// splitInfo gets adjusted to account for how much is actually sent
|
||||
availableTargets.forEach(target -> target.sendRemainingSplit(splitInfo));
|
||||
return splitInfo.getTotalSent();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param <HANDLER> The handler of our target.
|
||||
* @param <EXTRA> Any extra information we may need
|
||||
* @param <TARGET> The emitter target
|
||||
* @param availableTargets The targets to distribute toSend fairly among.
|
||||
* @param totalTargets The total number of targets. Note: this number is bigger than availableTargets.size if any
|
||||
* targets have more than one acceptor.
|
||||
* @param amountToSplit The amount to split between all the targets
|
||||
* @param toSend Any extra information such as gas stack or fluid stack.
|
||||
* @return The amount that actually got sent.
|
||||
*/
|
||||
public static <HANDLER, EXTRA, TARGET extends Target<HANDLER, Integer, EXTRA>> int sendToAcceptors(
|
||||
Set<TARGET> availableTargets, int totalTargets, int amountToSplit, EXTRA toSend) {
|
||||
return sendToAcceptors(availableTargets, totalTargets, new IntegerSplitInfo(amountToSplit, totalTargets),
|
||||
toSend);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param availableTargets The EnergyAcceptorWrapper targets to send energy fairly to.
|
||||
* @param totalTargets The total number of targets. Note: this number is bigger than availableTargets.size if any
|
||||
* targets have more than one acceptor.
|
||||
* @param amountToSplit The amount of energy to attempt to send
|
||||
* @return The amount that actually got sent
|
||||
*/
|
||||
public static double sendToAcceptors(Set<EnergyAcceptorTarget> availableTargets, int totalTargets,
|
||||
double amountToSplit) {
|
||||
return sendToAcceptors(availableTargets, totalTargets, new DoubleSplitInfo(amountToSplit, totalTargets),
|
||||
amountToSplit);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
package mekanism.common.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
import mekanism.api.gas.Gas;
|
||||
import mekanism.api.gas.GasStack;
|
||||
@@ -13,8 +14,9 @@ import mekanism.api.gas.IGasHandler;
|
||||
import mekanism.api.gas.IGasItem;
|
||||
import mekanism.common.MekanismFluids;
|
||||
import mekanism.common.OreDictCache;
|
||||
import mekanism.common.tier.GasTankTier;
|
||||
import mekanism.common.base.target.GasHandlerTarget;
|
||||
import mekanism.common.capabilities.Capabilities;
|
||||
import mekanism.common.tier.GasTankTier;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -31,11 +33,7 @@ import net.minecraftforge.oredict.OreDictionary;
|
||||
*/
|
||||
public final class GasUtils {
|
||||
|
||||
public static IGasHandler[] getConnectedAcceptors(TileEntity tileEntity, Collection<EnumFacing> sides) {
|
||||
return getConnectedAcceptors(tileEntity.getPos(), tileEntity.getWorld(), sides);
|
||||
}
|
||||
|
||||
public static IGasHandler[] getConnectedAcceptors(BlockPos pos, World world, Collection<EnumFacing> sides) {
|
||||
public static IGasHandler[] getConnectedAcceptors(BlockPos pos, World world, Set<EnumFacing> sides) {
|
||||
IGasHandler[] acceptors = new IGasHandler[]{null, null, null, null, null, null};
|
||||
|
||||
for (EnumFacing orientation : sides) {
|
||||
@@ -54,15 +52,10 @@ public final class GasUtils {
|
||||
/**
|
||||
* Gets all the acceptors around a tile entity.
|
||||
*
|
||||
* @param tileEntity - center tile entity
|
||||
* @return array of IGasAcceptors
|
||||
*/
|
||||
public static IGasHandler[] getConnectedAcceptors(TileEntity tileEntity) {
|
||||
return getConnectedAcceptors(tileEntity.getPos(), tileEntity.getWorld(), Arrays.asList(EnumFacing.VALUES));
|
||||
}
|
||||
|
||||
public static IGasHandler[] getConnectedAcceptors(BlockPos pos, World world) {
|
||||
return getConnectedAcceptors(pos, world, Arrays.asList(EnumFacing.VALUES));
|
||||
return getConnectedAcceptors(pos, world, EnumSet.allOf(EnumFacing.class));
|
||||
}
|
||||
|
||||
public static boolean isValidAcceptorOnSide(TileEntity tile, EnumFacing side) {
|
||||
@@ -120,46 +113,35 @@ public final class GasUtils {
|
||||
* @param sides - the list of sides to output from
|
||||
* @return the amount of gas emitted
|
||||
*/
|
||||
public static int emit(GasStack stack, TileEntity from, Collection<EnumFacing> sides) {
|
||||
if (stack == null) {
|
||||
public static int emit(GasStack stack, TileEntity from, Set<EnumFacing> sides) {
|
||||
if (stack == null || stack.amount == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
List<IGasHandler> availableAcceptors = new ArrayList<>();
|
||||
IGasHandler[] possibleAcceptors = getConnectedAcceptors(from, sides);
|
||||
|
||||
for (int i = 0; i < possibleAcceptors.length; i++) {
|
||||
IGasHandler handler = possibleAcceptors[i];
|
||||
|
||||
if (handler != null && handler.canReceiveGas(EnumFacing.byIndex(i).getOpposite(), stack.getGas())) {
|
||||
availableAcceptors.add(handler);
|
||||
//Fake that we have one target given we know that no sides will overlap
|
||||
// This allows us to have slightly better performance
|
||||
GasHandlerTarget target = new GasHandlerTarget(stack);
|
||||
for (EnumFacing orientation : sides) {
|
||||
TileEntity acceptor = from.getWorld().getTileEntity(from.getPos().offset(orientation));
|
||||
if (acceptor == null) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Collections.shuffle(availableAcceptors);
|
||||
|
||||
int toSend = stack.amount;
|
||||
int prevSending = toSend;
|
||||
|
||||
if (!availableAcceptors.isEmpty()) {
|
||||
int divider = availableAcceptors.size();
|
||||
int remaining = toSend % divider;
|
||||
int sending = (toSend - remaining) / divider;
|
||||
|
||||
for (IGasHandler acceptor : availableAcceptors) {
|
||||
int currentSending = sending;
|
||||
|
||||
if (remaining > 0) {
|
||||
currentSending++;
|
||||
remaining--;
|
||||
EnumFacing opposite = orientation.getOpposite();
|
||||
if (CapabilityUtils.hasCapability(acceptor, Capabilities.GAS_HANDLER_CAPABILITY, opposite)) {
|
||||
IGasHandler handler = CapabilityUtils.getCapability(acceptor, Capabilities.GAS_HANDLER_CAPABILITY,
|
||||
opposite);
|
||||
if (handler != null && handler.canReceiveGas(opposite, stack.getGas())) {
|
||||
target.addHandler(opposite, handler);
|
||||
}
|
||||
|
||||
EnumFacing dir = EnumFacing.byIndex(Arrays.asList(possibleAcceptors).indexOf(acceptor)).getOpposite();
|
||||
toSend -= acceptor.receiveGas(dir, new GasStack(stack.getGas(), currentSending), true);
|
||||
}
|
||||
}
|
||||
|
||||
return prevSending - toSend;
|
||||
int curHandlers = target.getHandlers().size();
|
||||
if (curHandlers > 0) {
|
||||
Set<GasHandlerTarget> targets = new HashSet<>();
|
||||
targets.add(target);
|
||||
return EmitUtils.sendToAcceptors(targets, curHandlers, stack.amount, stack);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void writeSustainedData(GasTank gasTank, ItemStack itemStack) {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package mekanism.common.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import mekanism.common.base.target.FluidHandlerTarget;
|
||||
import mekanism.common.capabilities.Capabilities;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
@@ -50,13 +49,8 @@ public final class PipeUtils {
|
||||
/**
|
||||
* Gets all the acceptors around a tile entity.
|
||||
*
|
||||
* @param tileEntity - center tile entity
|
||||
* @return array of IFluidHandlers
|
||||
*/
|
||||
public static IFluidHandler[] getConnectedAcceptors(TileEntity tileEntity) {
|
||||
return getConnectedAcceptors(tileEntity.getPos(), tileEntity.getWorld());
|
||||
}
|
||||
|
||||
public static IFluidHandler[] getConnectedAcceptors(BlockPos pos, World world) {
|
||||
IFluidHandler[] acceptors = new IFluidHandler[]{null, null, null, null, null, null};
|
||||
|
||||
@@ -83,44 +77,34 @@ public final class PipeUtils {
|
||||
* @param from - the TileEntity to output from
|
||||
* @return the amount of gas emitted
|
||||
*/
|
||||
public static int emit(List<EnumFacing> sides, FluidStack stack, TileEntity from) {
|
||||
if (stack == null) {
|
||||
public static int emit(Set<EnumFacing> sides, FluidStack stack, TileEntity from) {
|
||||
if (stack == null || stack.amount == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
List<IFluidHandler> availableAcceptors = new ArrayList<>();
|
||||
IFluidHandler[] possibleAcceptors = getConnectedAcceptors(from);
|
||||
|
||||
for (IFluidHandler handler : possibleAcceptors) {
|
||||
if (handler != null && canFill(handler, stack)) {
|
||||
availableAcceptors.add(handler);
|
||||
//Fake that we have one target given we know that no sides will overlap
|
||||
// This allows us to have slightly better performance
|
||||
FluidHandlerTarget target = new FluidHandlerTarget(stack);
|
||||
for (EnumFacing orientation : sides) {
|
||||
TileEntity acceptor = from.getWorld().getTileEntity(from.getPos().offset(orientation));
|
||||
if (acceptor == null) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Collections.shuffle(availableAcceptors);
|
||||
|
||||
int toSend = stack.amount;
|
||||
int prevSending = toSend;
|
||||
|
||||
if (!availableAcceptors.isEmpty()) {
|
||||
int divider = availableAcceptors.size();
|
||||
int remaining = toSend % divider;
|
||||
int sending = (toSend - remaining) / divider;
|
||||
|
||||
for (IFluidHandler acceptor : availableAcceptors) {
|
||||
int currentSending = sending;
|
||||
|
||||
if (remaining > 0) {
|
||||
currentSending++;
|
||||
remaining--;
|
||||
EnumFacing opposite = orientation.getOpposite();
|
||||
if (CapabilityUtils.hasCapability(acceptor, CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, opposite)) {
|
||||
IFluidHandler handler = CapabilityUtils.getCapability(acceptor,
|
||||
CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, opposite);
|
||||
if (handler != null && canFill(handler, stack)) {
|
||||
target.addHandler(opposite, handler);
|
||||
}
|
||||
|
||||
EnumFacing dir = EnumFacing.byIndex(Arrays.asList(possibleAcceptors).indexOf(acceptor)).getOpposite();
|
||||
toSend -= acceptor.fill(copy(stack, currentSending), true);
|
||||
}
|
||||
}
|
||||
|
||||
return prevSending - toSend;
|
||||
int curHandlers = target.getHandlers().size();
|
||||
if (curHandlers > 0) {
|
||||
Set<FluidHandlerTarget> targets = new HashSet<>();
|
||||
targets.add(target);
|
||||
return EmitUtils.sendToAcceptors(targets, curHandlers, stack.amount, stack);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static FluidStack copy(FluidStack fluid, int amount) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package mekanism.common.util;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import mekanism.api.TileNetworkList;
|
||||
import mekanism.api.gas.GasStack;
|
||||
import mekanism.api.gas.GasTank;
|
||||
import mekanism.common.PacketHandler;
|
||||
import mekanism.api.TileNetworkList;
|
||||
import mekanism.common.tile.prefab.TileEntityBasicBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -80,7 +80,7 @@ public class TileUtils {
|
||||
public static void emitGas(TileEntityBasicBlock tile, GasTank tank, int gasOutput, EnumFacing facing) {
|
||||
if (tank.getGas() != null) {
|
||||
GasStack toSend = new GasStack(tank.getGas().getGas(), Math.min(tank.getStored(), gasOutput));
|
||||
tank.draw(GasUtils.emit(toSend, tile, Arrays.asList(facing)), true);
|
||||
tank.draw(GasUtils.emit(toSend, tile, EnumSet.of(facing)), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -327,7 +327,7 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, ISp
|
||||
setEnergy(theItem, getEnergy(theItem) + toReceive);
|
||||
}
|
||||
|
||||
return (int) Math.round(toReceive * MekanismConfig.current().general.TO_RF.val());
|
||||
return MekanismUtils.clampToInt(toReceive * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -344,7 +344,7 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, ISp
|
||||
setEnergy(theItem, getEnergy(theItem) - toSend);
|
||||
}
|
||||
|
||||
return (int) Math.round(toSend * MekanismConfig.current().general.TO_RF.val());
|
||||
return MekanismUtils.clampToInt(toSend * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -353,13 +353,13 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, ISp
|
||||
@Override
|
||||
@Method(modid = MekanismHooks.REDSTONEFLUX_MOD_ID)
|
||||
public int getEnergyStored(ItemStack theItem) {
|
||||
return (int) (getEnergy(theItem) * MekanismConfig.current().general.TO_RF.val());
|
||||
return MekanismUtils.clampToInt(getEnergy(theItem) * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = MekanismHooks.REDSTONEFLUX_MOD_ID)
|
||||
public int getMaxEnergyStored(ItemStack theItem) {
|
||||
return (int) (getMaxEnergy(theItem) * MekanismConfig.current().general.TO_RF.val());
|
||||
return MekanismUtils.clampToInt(getMaxEnergy(theItem) * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -161,7 +161,7 @@ public class TileEntityTurbineValve extends TileEntityTurbineCasing implements I
|
||||
setEnergy(getEnergy() - toSend);
|
||||
}
|
||||
|
||||
return (int) Math.round(Math.min(Integer.MAX_VALUE, toSend * MekanismConfig.current().general.TO_RF.val()));
|
||||
return MekanismUtils.clampToInt(toSend * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -176,15 +176,13 @@ public class TileEntityTurbineValve extends TileEntityTurbineCasing implements I
|
||||
@Override
|
||||
@Method(modid = MekanismHooks.REDSTONEFLUX_MOD_ID)
|
||||
public int getEnergyStored(EnumFacing from) {
|
||||
return (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE, getEnergy() * MekanismConfig.current().general.TO_RF.val()));
|
||||
return MekanismUtils.clampToInt(getEnergy() * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = MekanismHooks.REDSTONEFLUX_MOD_ID)
|
||||
public int getMaxEnergyStored(EnumFacing from) {
|
||||
return (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE, getMaxEnergy() * MekanismConfig.current().general.TO_RF.val()));
|
||||
return MekanismUtils.clampToInt(getMaxEnergy() * MekanismConfig.current().general.TO_RF.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -231,8 +229,7 @@ public class TileEntityTurbineValve extends TileEntityTurbineCasing implements I
|
||||
@Override
|
||||
@Method(modid = MekanismHooks.IC2_MOD_ID)
|
||||
public int getStored() {
|
||||
return (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE, getEnergy() * MekanismConfig.current().general.TO_IC2.val()));
|
||||
return MekanismUtils.clampToInt(getEnergy() * MekanismConfig.current().general.TO_IC2.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -244,15 +241,13 @@ public class TileEntityTurbineValve extends TileEntityTurbineCasing implements I
|
||||
@Override
|
||||
@Method(modid = MekanismHooks.IC2_MOD_ID)
|
||||
public int getCapacity() {
|
||||
return (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE, getMaxEnergy() * MekanismConfig.current().general.TO_IC2.val()));
|
||||
return MekanismUtils.clampToInt(getMaxEnergy() * MekanismConfig.current().general.TO_IC2.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = MekanismHooks.IC2_MOD_ID)
|
||||
public int getOutput() {
|
||||
return (int) Math
|
||||
.round(Math.min(Integer.MAX_VALUE, getMaxOutput() * MekanismConfig.current().general.TO_IC2.val()));
|
||||
return MekanismUtils.clampToInt(getMaxOutput() * MekanismConfig.current().general.TO_IC2.val());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user