Skip to content

Commit

Permalink
Merge pull request #64 from Thorfusion/ic2-compat-config
Browse files Browse the repository at this point in the history
Ic2 compat config
  • Loading branch information
DrParadox7 authored Dec 23, 2022
2 parents 84438f7 + 1feb81d commit 28fadd5
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 21 deletions.
4 changes: 2 additions & 2 deletions build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ FMP_version=1.2.0.347
CCLIB_version=1.1.3.141
NEI_version=1.0.5.120
CCC_version=1.0.7.48
mod_version=9.10.20
alt_version=9, 10, 20
mod_version=9.10.21
alt_version=9, 10, 21
4 changes: 3 additions & 1 deletion src/main/java/mekanism/api/MekanismConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ public static class general
public static boolean OreDictOsmium;
public static boolean OreDictPlatinum;
public static boolean enableSiliconCompat;
public static int digitalMinerMaxRadius;
public static int IC2SinkTier;
public static int IC2SourceTier;
public static int digitalMinerMaxRadius;
}

public static class client
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/mekanism/common/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,10 @@ public void loadConfiguration()
general.enableSiliconCompat = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "EnableSiliconCompat", true).getBoolean();
general.digitalMinerMaxRadius = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "DigitalMinerMaxRadius", 32, "Select range from 1 to 64, we do not recommend going over 32", 1, 64).getInt();

general.IC2SinkTier = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "IC2SinkTier", 4, "Tier level for machines, we recommend setting it to tier 2 for ic2 classic", 1, 4).getInt();
general.IC2SourceTier = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "IC2SourceTier", 4, "Tier level for generators, we recommend setting it to tier 2 for ic2 classic", 1, 4).getInt();

String s = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "EnergyType", "J", null, new String[]{"J", "RF", "MJ", "EU"}).getString();
String s = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "EnergyType", "RF", null, new String[]{"J", "RF", "MJ", "EU"}).getString();

if(s != null)
{
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/mekanism/common/base/EnergyAcceptorWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import mekanism.api.Coord4D;
import mekanism.api.MekanismConfig.general;
import mekanism.api.energy.IStrictEnergyAcceptor;
import mekanism.common.util.CableUtils;
import mekanism.common.util.MekanismUtils;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
Expand All @@ -30,9 +31,9 @@ else if(MekanismUtils.useRF() && tileEntity instanceof IEnergyReceiver)
{
wrapper = new RFAcceptor((IEnergyReceiver)tileEntity);
}
else if(MekanismUtils.useIC2() && tileEntity instanceof IEnergySink)
else if(MekanismUtils.useIC2() && CableUtils.getIC2Tile(tileEntity) instanceof IEnergySink)
{
wrapper = new IC2Acceptor((IEnergySink)tileEntity);
wrapper = new IC2Acceptor((IEnergySink)CableUtils.getIC2Tile(tileEntity));
}

if(wrapper != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ else if(MekanismUtils.useRF() && outputter instanceof IEnergyProvider)

((IEnergyProvider)outputter).extractEnergy(side.getOpposite(), (int)(toDraw*general.TO_TE), false);
}
else if(MekanismUtils.useIC2() && outputter instanceof IEnergySource)
else if(MekanismUtils.useIC2() && CableUtils.getIC2Tile(outputter) instanceof IEnergySource)
{
double received = Math.min(((IEnergySource)outputter).getOfferedEnergy() * general.FROM_IC2, canDraw);
double received = Math.min(((IEnergySource)CableUtils.getIC2Tile(outputter)).getOfferedEnergy() * general.FROM_IC2, canDraw);
double toDraw = received;

if(received > 0)
{
toDraw -= takeEnergy(received, true);
}

((IEnergySource)outputter).drawEnergy(toDraw * general.TO_IC2);
((IEnergySource)CableUtils.getIC2Tile(outputter)).drawEnergy(toDraw * general.TO_IC2);
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/mekanism/common/network/PacketConfigSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ public void toBytes(ByteBuf dataStream)
dataStream.writeBoolean(recipes.enableFlamethrower);
dataStream.writeBoolean(recipes.enableGaugeDropper);
dataStream.writeBoolean(recipes.enableTierInstaller);

dataStream.writeInt(general.IC2SinkTier);
dataStream.writeInt(general.IC2SourceTier);


Tier.writeConfig(dataStream);
Expand Down Expand Up @@ -273,6 +274,8 @@ public void fromBytes(ByteBuf dataStream)
general.OreDictOsmium = dataStream.readBoolean();
general.OreDictPlatinum = dataStream.readBoolean();
general.enableSiliconCompat = dataStream.readBoolean();
general.IC2SinkTier = dataStream.readInt();
general.IC2SourceTier = dataStream.readInt();
general.digitalMinerMaxRadius = dataStream.readInt();

for(MachineType type : MachineType.getValidMachines())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.EnumSet;

import mekanism.api.Coord4D;
import mekanism.api.MekanismConfig;
import mekanism.api.MekanismConfig.general;
import mekanism.api.transmitters.ITransmitterTile;
import mekanism.common.base.IEnergyWrapper;
Expand Down Expand Up @@ -268,14 +269,14 @@ public int getMaxEnergyStored(ForgeDirection from)
@Method(modid = "IC2")
public int getSinkTier()
{
return 4;
return general.IC2SinkTier;
}

@Override
@Method(modid = "IC2")
public int getSourceTier()
{
return 4;
return general.IC2SourceTier;
}

@Override
Expand Down
25 changes: 16 additions & 9 deletions src/main/java/mekanism/common/util/CableUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public final class CableUtils
public static boolean isEnergyAcceptor(TileEntity tileEntity)
{
return (tileEntity instanceof IStrictEnergyAcceptor ||
(MekanismUtils.useIC2() && tileEntity instanceof IEnergySink) ||
(MekanismUtils.useIC2() && getIC2Tile(tileEntity) instanceof IEnergySink) ||
(MekanismUtils.useRF() && tileEntity instanceof IEnergyReceiver));
}

Expand Down Expand Up @@ -108,7 +108,7 @@ public static TileEntity[] getConnectedOutputters(TileEntity tileEntity)
public static boolean isOutputter(TileEntity tileEntity, ForgeDirection side)
{
return (tileEntity instanceof ICableOutputter && ((ICableOutputter)tileEntity).canOutputTo(side.getOpposite())) ||
(MekanismUtils.useIC2() && tileEntity instanceof IEnergySource && ((IEnergySource)tileEntity).emitsEnergyTo(null, side.getOpposite())) ||
(MekanismUtils.useIC2() && getIC2Tile(tileEntity) instanceof IEnergySource && ((IEnergySource)getIC2Tile(tileEntity)).emitsEnergyTo(null, side.getOpposite())) ||
(MekanismUtils.useRF() && tileEntity instanceof IEnergyProvider && ((IEnergyConnection)tileEntity).canConnectEnergy(side.getOpposite()));
}

Expand All @@ -126,9 +126,9 @@ public static boolean isConnectable(TileEntity orig, TileEntity tileEntity, Forg
return true;
}
}
else if(MekanismUtils.useIC2() && tileEntity instanceof IEnergyAcceptor)
else if(MekanismUtils.useIC2() && getIC2Tile(tileEntity) instanceof IEnergyAcceptor)
{
if(((IEnergyAcceptor)tileEntity).acceptsEnergyFrom(orig, side.getOpposite()))
if(((IEnergyAcceptor)getIC2Tile(tileEntity)).acceptsEnergyFrom(orig, side.getOpposite()))
{
return true;
}
Expand Down Expand Up @@ -246,16 +246,23 @@ else if(MekanismUtils.useRF() && tileEntity instanceof IEnergyReceiver)
sent += used*general.FROM_TE;
}
}
else if(MekanismUtils.useIC2() && tileEntity instanceof IEnergySink)
else if(MekanismUtils.useIC2() && getIC2Tile(tileEntity) instanceof IEnergySink)
{
if(((IEnergySink)tileEntity).acceptsEnergyFrom((TileEntity)from, side.getOpposite()))
IEnergySink sink = (IEnergySink) getIC2Tile(tileEntity);
if(sink.acceptsEnergyFrom((TileEntity)from, side.getOpposite()))
{
double toSend = Math.min(currentSending, EnergyNet.instance.getPowerFromTier(((IEnergySink)tileEntity).getSinkTier())*general.FROM_IC2);
toSend = Math.min(Math.min(toSend, ((IEnergySink)tileEntity).getDemandedEnergy()*general.FROM_IC2), Integer.MAX_VALUE);
sent += (toSend - (((IEnergySink)tileEntity).injectEnergy(side.getOpposite(), toSend*general.TO_IC2, 0)*general.FROM_IC2));
double toSend = Math.min(currentSending, EnergyNet.instance.getPowerFromTier(sink.getSinkTier())*general.FROM_IC2);
toSend = Math.min(Math.min(toSend, sink.getDemandedEnergy()*general.FROM_IC2), Integer.MAX_VALUE);
sent += (toSend - (sink.injectEnergy(side.getOpposite(), toSend*general.TO_IC2, 0)*general.FROM_IC2));
}
}

return sent;
}

public static TileEntity getIC2Tile(TileEntity tileEntity) {
if (tileEntity == null) return null;
return EnergyNet.instance.getTileEntity(tileEntity.getWorldObj(), tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
}

}

0 comments on commit 28fadd5

Please sign in to comment.