mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
Merge pull request #1584 from FOlkvangrField/Configurable-Converter
Added conversion ratio configuration options for Rf and He in hbmMachines.json for the two converters
This commit is contained in:
commit
eaaa78c384
@ -1,6 +1,9 @@
|
|||||||
package com.hbm.tileentity.network;
|
package com.hbm.tileentity.network;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.stream.JsonWriter;
|
||||||
import com.hbm.calc.Location;
|
import com.hbm.calc.Location;
|
||||||
|
import com.hbm.tileentity.IConfigurableMachine;
|
||||||
import com.hbm.tileentity.TileEntityLoadedBase;
|
import com.hbm.tileentity.TileEntityLoadedBase;
|
||||||
|
|
||||||
import api.hbm.energymk2.IEnergyReceiverMK2;
|
import api.hbm.energymk2.IEnergyReceiverMK2;
|
||||||
@ -11,12 +14,15 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
public class TileEntityConverterHeRf extends TileEntityLoadedBase implements IEnergyReceiverMK2, IEnergyHandler {
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class TileEntityConverterHeRf extends TileEntityLoadedBase implements IEnergyReceiverMK2, IEnergyHandler, IConfigurableMachine {
|
||||||
|
|
||||||
//Thanks to the great people of Fusion Warfare for helping me with the original implementation of the RF energy API
|
//Thanks to the great people of Fusion Warfare for helping me with the original implementation of the RF energy API
|
||||||
|
|
||||||
public long power;
|
public long power;
|
||||||
public final long maxPower = 5_000_000;
|
public final long maxPower = 5_000_000;
|
||||||
|
public static long ratio = 5;
|
||||||
public EnergyStorage storage = new EnergyStorage(1_000_000, 1_000_000, 1_000_000);
|
public EnergyStorage storage = new EnergyStorage(1_000_000, 1_000_000, 1_000_000);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -24,8 +30,8 @@ public class TileEntityConverterHeRf extends TileEntityLoadedBase implements IEn
|
|||||||
|
|
||||||
if (!worldObj.isRemote) {
|
if (!worldObj.isRemote) {
|
||||||
|
|
||||||
long rfCreated = Math.min(storage.getMaxEnergyStored() - storage.getEnergyStored(), power / 5);
|
long rfCreated = Math.min(storage.getMaxEnergyStored() - storage.getEnergyStored(), power / ratio);
|
||||||
this.power -= rfCreated * 5;
|
this.power -= rfCreated * ratio;
|
||||||
this.storage.setEnergyStored((int) (storage.getEnergyStored() + rfCreated));
|
this.storage.setEnergyStored((int) (storage.getEnergyStored() + rfCreated));
|
||||||
if(power > 0) this.power *= 0.95;
|
if(power > 0) this.power *= 0.95;
|
||||||
if(rfCreated > 0) this.worldObj.markTileEntityChunkModified(this.xCoord, this.yCoord, this.zCoord, this);
|
if(rfCreated > 0) this.worldObj.markTileEntityChunkModified(this.xCoord, this.yCoord, this.zCoord, this);
|
||||||
@ -75,4 +81,19 @@ public class TileEntityConverterHeRf extends TileEntityLoadedBase implements IEn
|
|||||||
nbt.setLong("power", power);
|
nbt.setLong("power", power);
|
||||||
storage.writeToNBT(nbt);
|
storage.writeToNBT(nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getConfigName() {
|
||||||
|
return "He->RfConverter";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readIfPresent(JsonObject obj) {
|
||||||
|
ratio = IConfigurableMachine.grab(obj, "L:Rf/He ratio", ratio);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeConfig(JsonWriter writer) throws IOException {
|
||||||
|
writer.name("L:Rf/He ratio").value(ratio);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
package com.hbm.tileentity.network;
|
package com.hbm.tileentity.network;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
import com.hbm.tileentity.IConfigurableMachine;
|
||||||
import com.hbm.tileentity.TileEntityLoadedBase;
|
import com.hbm.tileentity.TileEntityLoadedBase;
|
||||||
|
|
||||||
import api.hbm.energymk2.IEnergyProviderMK2;
|
import api.hbm.energymk2.IEnergyProviderMK2;
|
||||||
@ -8,10 +11,14 @@ import cofh.api.energy.IEnergyHandler;
|
|||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
public class TileEntityConverterRfHe extends TileEntityLoadedBase implements IEnergyProviderMK2, IEnergyHandler {
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class TileEntityConverterRfHe extends TileEntityLoadedBase implements IEnergyProviderMK2, IEnergyHandler, IConfigurableMachine {
|
||||||
|
|
||||||
public long power;
|
public long power;
|
||||||
public final long maxPower = 5_000_000;
|
public final long maxPower = 5_000_000;
|
||||||
|
public static long ratio = 5;
|
||||||
|
|
||||||
public EnergyStorage storage = new EnergyStorage(1_000_000, 1_000_000, 1_000_000);
|
public EnergyStorage storage = new EnergyStorage(1_000_000, 1_000_000, 1_000_000);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -19,9 +26,9 @@ public class TileEntityConverterRfHe extends TileEntityLoadedBase implements IEn
|
|||||||
|
|
||||||
if (!worldObj.isRemote) {
|
if (!worldObj.isRemote) {
|
||||||
|
|
||||||
long rfCreated = Math.min(storage.getEnergyStored(), (maxPower - power) / 5);
|
long rfCreated = Math.min(storage.getEnergyStored(), (maxPower - power) / ratio);
|
||||||
storage.setEnergyStored((int) (storage.getEnergyStored() - rfCreated));
|
storage.setEnergyStored((int) (storage.getEnergyStored() - rfCreated));
|
||||||
power += rfCreated * 5;
|
power += rfCreated * ratio;
|
||||||
if(storage.getEnergyStored() > 0) storage.extractEnergy((int) Math.ceil(storage.getEnergyStored() * 0.05), false);
|
if(storage.getEnergyStored() > 0) storage.extractEnergy((int) Math.ceil(storage.getEnergyStored() * 0.05), false);
|
||||||
if(rfCreated > 0) this.worldObj.markTileEntityChunkModified(this.xCoord, this.yCoord, this.zCoord, this);
|
if(rfCreated > 0) this.worldObj.markTileEntityChunkModified(this.xCoord, this.yCoord, this.zCoord, this);
|
||||||
|
|
||||||
@ -56,4 +63,19 @@ public class TileEntityConverterRfHe extends TileEntityLoadedBase implements IEn
|
|||||||
nbt.setLong("power", power);
|
nbt.setLong("power", power);
|
||||||
storage.writeToNBT(nbt);
|
storage.writeToNBT(nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getConfigName() {
|
||||||
|
return "Rf->HeConverter";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readIfPresent(JsonObject obj) {
|
||||||
|
ratio = IConfigurableMachine.grab(obj, "L:Rf/He ratio", ratio);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeConfig(JsonWriter writer) throws IOException {
|
||||||
|
writer.name("L:Rf/He ratio").value(ratio);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user