Merge pull request #2139 from Toshayo/opencomputers-steam-fluid-id-fix

Better steam turbine OpenComputers integration
This commit is contained in:
HbmMods 2025-05-10 16:43:23 +02:00 committed by GitHub
commit 763b6ec020
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 68 additions and 47 deletions

View File

@ -38,16 +38,15 @@ public class CompatHandler {
* @return Object[] array containing an int with the "compression level" * @return Object[] array containing an int with the "compression level"
*/ */
public static Object[] steamTypeToInt(FluidType type) { public static Object[] steamTypeToInt(FluidType type) {
switch(type.getID()) { final int typeId = type.getID();
case(4): // Fluids.HOTSTEAM if(typeId == Fluids.HOTSTEAM.getID()) {
return new Object[] {1}; return new Object[]{1};
case(5): // Fluids.SUPERHOTSTEAM } else if(typeId == Fluids.SUPERHOTSTEAM.getID()) {
return new Object[] {2}; return new Object[]{2};
case(6): // Fluids.ULTRAHOTSTEAM } else if(typeId == Fluids.ULTRAHOTSTEAM.getID()) {
return new Object[] {3}; return new Object[]{3};
default: }
return new Object[] {0}; return new Object[] {0};
}
} }
/** /**

View File

@ -139,7 +139,7 @@ public class TileEntityChungus extends TileEntityLoadedBase implements IEnergyPr
if(operational) turnTimer = 25; if(operational) turnTimer = 25;
networkPackNT(150); networkPackNT(150);
} else { } else {
this.lastRotor = this.rotor; this.lastRotor = this.rotor;
@ -297,29 +297,35 @@ public class TileEntityChungus extends TileEntityLoadedBase implements IEnergyPr
} }
} }
@Callback(direct = true) @Callback(direct = true, doc = "function():table -- Gets current tanks state. The format is the following: <input tank amount>, <input tank capacity>, <output tank amount>, <output tank capacity>")
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public Object[] getFluid(Context context, Arguments args) { public Object[] getFluid(Context context, Arguments args) {
return new Object[] {tanks[0].getFill(), tanks[0].getMaxFill(), tanks[1].getFill(), tanks[1].getMaxFill()}; return new Object[] {tanks[0].getFill(), tanks[0].getMaxFill(), tanks[1].getFill(), tanks[1].getMaxFill()};
} }
@Callback(direct = true) @Callback(direct = true, doc = "function():number -- Gets the current input tank fluid type. 0 stands for steam, 1 for dense steam, 2 for super dense steam and 3 for ultra dense steam.")
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public Object[] getType(Context context, Arguments args) { public Object[] getType(Context context, Arguments args) {
return CompatHandler.steamTypeToInt(tanks[1].getTankType()); return CompatHandler.steamTypeToInt(tanks[0].getTankType());
} }
@Callback(direct = true, limit = 4) @Callback(direct = true, limit = 4, doc = "function(type:number) -- Sets the input tank fluid type. Refer getType() for the accepted values information.")
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public Object[] setType(Context context, Arguments args) { public Object[] setType(Context context, Arguments args) {
tanks[0].setTankType(CompatHandler.intToSteamType(args.checkInteger(0))); tanks[0].setTankType(CompatHandler.intToSteamType(args.checkInteger(0)));
return new Object[] {}; return new Object[] {};
} }
@Callback(direct = true) @Callback(direct = true, doc = "function():number -- Gets the power buffer of the turbine.")
@Optional.Method(modid = "OpenComputers")
public Object[] getPower(Context context, Arguments args) {
return new Object[] {power};
}
@Callback(direct = true, doc = "function():table -- Gets information about this turbine. The format is the following: <input tank amount>, <input tank capacity>, <output tank amount>, <output tank capacity>, <input tank fluid type>, <power>")
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public Object[] getInfo(Context context, Arguments args) { public Object[] getInfo(Context context, Arguments args) {
return new Object[] {tanks[0].getFill(), tanks[0].getMaxFill(), tanks[1].getFill(), tanks[1].getMaxFill(), CompatHandler.steamTypeToInt(tanks[0].getTankType())}; return new Object[] {tanks[0].getFill(), tanks[0].getMaxFill(), tanks[1].getFill(), tanks[1].getMaxFill(), CompatHandler.steamTypeToInt(tanks[0].getTankType())[0], power};
} }
@Override @Override
@ -329,6 +335,7 @@ public class TileEntityChungus extends TileEntityLoadedBase implements IEnergyPr
"getFluid", "getFluid",
"getType", "getType",
"setType", "setType",
"getPower",
"getInfo" "getInfo"
}; };
} }
@ -343,6 +350,8 @@ public class TileEntityChungus extends TileEntityLoadedBase implements IEnergyPr
return getType(context, args); return getType(context, args);
case ("setType"): case ("setType"):
return setType(context, args); return setType(context, args);
case ("getPower"):
return getPower(context, args);
case ("getInfo"): case ("getInfo"):
return getInfo(context, args); return getInfo(context, args);
} }

View File

@ -49,7 +49,7 @@ public class TileEntityMachineLargeTurbine extends TileEntityMachineBase impleme
public long power; public long power;
public FluidTank[] tanks; public FluidTank[] tanks;
protected double[] info = new double[3]; protected double[] info = new double[3];
private boolean shouldTurn; private boolean shouldTurn;
public float rotor; public float rotor;
public float lastRotor; public float lastRotor;
@ -57,7 +57,7 @@ public class TileEntityMachineLargeTurbine extends TileEntityMachineBase impleme
private AudioWrapper audio; private AudioWrapper audio;
private float audioDesync; private float audioDesync;
//Configurable Values //Configurable Values
public static long maxPower = 100000000; public static long maxPower = 100000000;
public static int inputTankSize = 512_000; public static int inputTankSize = 512_000;
@ -67,7 +67,7 @@ public class TileEntityMachineLargeTurbine extends TileEntityMachineBase impleme
public TileEntityMachineLargeTurbine() { public TileEntityMachineLargeTurbine() {
super(7); super(7);
tanks = new FluidTank[2]; tanks = new FluidTank[2];
tanks[0] = new FluidTank(Fluids.STEAM, inputTankSize); tanks[0] = new FluidTank(Fluids.STEAM, inputTankSize);
tanks[1] = new FluidTank(Fluids.SPENTSTEAM, outputTankSize); tanks[1] = new FluidTank(Fluids.SPENTSTEAM, outputTankSize);
@ -107,11 +107,11 @@ public class TileEntityMachineLargeTurbine extends TileEntityMachineBase impleme
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.info = new double[3]; this.info = new double[3];
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
this.tryProvide(worldObj, xCoord + dir.offsetX * -4, yCoord, zCoord + dir.offsetZ * -4, dir.getOpposite()); this.tryProvide(worldObj, xCoord + dir.offsetX * -4, yCoord, zCoord + dir.offsetZ * -4, dir.getOpposite());
for(DirPos pos : getConPos()) this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); for(DirPos pos : getConPos()) this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
@ -144,7 +144,7 @@ public class TileEntityMachineLargeTurbine extends TileEntityMachineBase impleme
} }
if(!valid) tanks[1].setTankType(Fluids.NONE); if(!valid) tanks[1].setTankType(Fluids.NONE);
if(power > maxPower) power = maxPower; if(power > maxPower) power = maxPower;
tanks[1].unloadTank(5, 6, slots); tanks[1].unloadTank(5, 6, slots);
this.networkPackNT(50); this.networkPackNT(50);
@ -152,12 +152,12 @@ public class TileEntityMachineLargeTurbine extends TileEntityMachineBase impleme
} else { } else {
this.lastRotor = this.rotor; this.lastRotor = this.rotor;
this.rotor += this.fanAcceleration; this.rotor += this.fanAcceleration;
if(this.rotor >= 360) { if(this.rotor >= 360) {
this.rotor -= 360; this.rotor -= 360;
this.lastRotor -= 360; this.lastRotor -= 360;
} }
if(shouldTurn) { if(shouldTurn) {
// Fan accelerates with a random offset to ensure the audio doesn't perfectly align, makes for a more pleasant hum // Fan accelerates with a random offset to ensure the audio doesn't perfectly align, makes for a more pleasant hum
this.fanAcceleration = Math.max(0F, Math.min(15F, this.fanAcceleration += 0.075F + audioDesync)); this.fanAcceleration = Math.max(0F, Math.min(15F, this.fanAcceleration += 0.075F + audioDesync));
@ -172,7 +172,7 @@ public class TileEntityMachineLargeTurbine extends TileEntityMachineBase impleme
audio.updatePitch(0.25F + 0.75F * turbineSpeed); audio.updatePitch(0.25F + 0.75F * turbineSpeed);
} else { } else {
this.fanAcceleration = Math.max(0F, Math.min(15F, this.fanAcceleration -= 0.1F)); this.fanAcceleration = Math.max(0F, Math.min(15F, this.fanAcceleration -= 0.1F));
if(audio != null) { if(audio != null) {
if(this.fanAcceleration > 0) { if(this.fanAcceleration > 0) {
float turbineSpeed = this.fanAcceleration / 15F; float turbineSpeed = this.fanAcceleration / 15F;
@ -186,7 +186,7 @@ public class TileEntityMachineLargeTurbine extends TileEntityMachineBase impleme
} }
} }
} }
protected DirPos[] getConPos() { protected DirPos[] getConPos() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
@ -214,11 +214,11 @@ public class TileEntityMachineLargeTurbine extends TileEntityMachineBase impleme
tanks[0].deserialize(buf); tanks[0].deserialize(buf);
tanks[1].deserialize(buf); tanks[1].deserialize(buf);
} }
public long getPowerScaled(int i) { public long getPowerScaled(int i) {
return (power * i) / maxPower; return (power * i) / maxPower;
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
@ -226,7 +226,7 @@ public class TileEntityMachineLargeTurbine extends TileEntityMachineBase impleme
tanks[1].readFromNBT(nbt, "steam"); tanks[1].readFromNBT(nbt, "steam");
power = nbt.getLong("power"); power = nbt.getLong("power");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
@ -249,12 +249,12 @@ public class TileEntityMachineLargeTurbine extends TileEntityMachineBase impleme
public long getMaxPower() { public long getMaxPower() {
return this.maxPower; return this.maxPower;
} }
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
return TileEntity.INFINITE_EXTENT_AABB; return TileEntity.INFINITE_EXTENT_AABB;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -281,11 +281,11 @@ public class TileEntityMachineLargeTurbine extends TileEntityMachineBase impleme
public String getComponentName() { public String getComponentName() {
return "ntm_turbine"; return "ntm_turbine";
} }
@Override @Override
public void onChunkUnload() { public void onChunkUnload() {
super.onChunkUnload(); super.onChunkUnload();
if(audio != null) { if(audio != null) {
audio.stopSound(); audio.stopSound();
audio = null; audio = null;
@ -302,29 +302,35 @@ public class TileEntityMachineLargeTurbine extends TileEntityMachineBase impleme
} }
} }
@Callback(direct = true) @Callback(direct = true, doc = "function():table -- Gets current tanks state. The format is the following: <input tank amount>, <input tank capacity>, <output tank amount>, <output tank capacity>")
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public Object[] getFluid(Context context, Arguments args) { public Object[] getFluid(Context context, Arguments args) {
return new Object[] {tanks[0].getFill(), tanks[0].getMaxFill(), tanks[1].getFill(), tanks[1].getMaxFill()}; return new Object[] {tanks[0].getFill(), tanks[0].getMaxFill(), tanks[1].getFill(), tanks[1].getMaxFill()};
} }
@Callback(direct = true) @Callback(direct = true, doc = "function():number -- Gets the current input tank fluid type. 0 stands for steam, 1 for dense steam, 2 for super dense steam and 3 for ultra dense steam.")
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public Object[] getType(Context context, Arguments args) { public Object[] getType(Context context, Arguments args) {
return CompatHandler.steamTypeToInt(tanks[1].getTankType()); return CompatHandler.steamTypeToInt(tanks[0].getTankType());
} }
@Callback(direct = true, limit = 4) @Callback(direct = true, limit = 4, doc = "function(type:number) -- Sets the input tank fluid type. Refer getType() for the accepted values information.")
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public Object[] setType(Context context, Arguments args) { public Object[] setType(Context context, Arguments args) {
tanks[0].setTankType(CompatHandler.intToSteamType(args.checkInteger(0))); tanks[0].setTankType(CompatHandler.intToSteamType(args.checkInteger(0)));
return new Object[] {}; return new Object[] {};
} }
@Callback(direct = true) @Callback(direct = true, doc = "function():number -- Gets the power buffer of the turbine.")
@Optional.Method(modid = "OpenComputers")
public Object[] getPower(Context context, Arguments args) {
return new Object[] {power};
}
@Callback(direct = true, doc = "function():table -- Gets information about this turbine. The format is the following: <input tank amount>, <input tank capacity>, <output tank amount>, <output tank capacity>, <input tank fluid type>, <power>")
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public Object[] getInfo(Context context, Arguments args) { public Object[] getInfo(Context context, Arguments args) {
return new Object[] {tanks[0].getFill(), tanks[0].getMaxFill(), tanks[1].getFill(), tanks[1].getMaxFill(), CompatHandler.steamTypeToInt(tanks[0].getTankType())}; return new Object[] {tanks[0].getFill(), tanks[0].getMaxFill(), tanks[1].getFill(), tanks[1].getMaxFill(), CompatHandler.steamTypeToInt(tanks[0].getTankType())[0], power};
} }
@Override @Override
@ -334,6 +340,7 @@ public class TileEntityMachineLargeTurbine extends TileEntityMachineBase impleme
"getFluid", "getFluid",
"getType", "getType",
"setType", "setType",
"getPower",
"getInfo" "getInfo"
}; };
} }

View File

@ -355,29 +355,35 @@ public class TileEntityMachineTurbine extends TileEntityLoadedBase implements IS
return "ntm_turbine"; return "ntm_turbine";
} }
@Callback(direct = true) @Callback(direct = true, doc = "function():table -- Gets current tanks state. The format is the following: <input tank amount>, <input tank capacity>, <output tank amount>, <output tank capacity>")
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public Object[] getFluid(Context context, Arguments args) { public Object[] getFluid(Context context, Arguments args) {
return new Object[] {tanks[0].getFill(), tanks[0].getMaxFill(), tanks[1].getFill(), tanks[1].getMaxFill()}; return new Object[] {tanks[0].getFill(), tanks[0].getMaxFill(), tanks[1].getFill(), tanks[1].getMaxFill()};
} }
@Callback(direct = true) @Callback(direct = true, doc = "function():number -- Gets the current input tank fluid type. 0 stands for steam, 1 for dense steam, 2 for super dense steam and 3 for ultra dense steam.")
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public Object[] getType(Context context, Arguments args) { public Object[] getType(Context context, Arguments args) {
return CompatHandler.steamTypeToInt(tanks[1].getTankType()); return CompatHandler.steamTypeToInt(tanks[0].getTankType());
} }
@Callback(direct = true, limit = 4) @Callback(direct = true, limit = 4, doc = "function(type:number) -- Sets the input tank fluid type. Refer getType() for the accepted values information.")
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public Object[] setType(Context context, Arguments args) { public Object[] setType(Context context, Arguments args) {
tanks[0].setTankType(CompatHandler.intToSteamType(args.checkInteger(0))); tanks[0].setTankType(CompatHandler.intToSteamType(args.checkInteger(0)));
return new Object[] {true}; return new Object[] {true};
} }
@Callback(direct = true) @Callback(direct = true, doc = "function():number -- Gets the power buffer of the turbine.")
@Optional.Method(modid = "OpenComputers")
public Object[] getPower(Context context, Arguments args) {
return new Object[] {power};
}
@Callback(direct = true, doc = "function():table -- Gets information about this turbine. The format is the following: <input tank amount>, <input tank capacity>, <output tank amount>, <output tank capacity>, <input tank fluid type>, <power>")
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public Object[] getInfo(Context context, Arguments args) { public Object[] getInfo(Context context, Arguments args) {
return new Object[] {tanks[0].getFill(), tanks[0].getMaxFill(), tanks[1].getFill(), tanks[1].getMaxFill(), CompatHandler.steamTypeToInt(tanks[0].getTankType())}; return new Object[] {tanks[0].getFill(), tanks[0].getMaxFill(), tanks[1].getFill(), tanks[1].getMaxFill(), CompatHandler.steamTypeToInt(tanks[0].getTankType())[0], power};
} }
@Override @Override