Merge pull request #2295 from PewPewCricket/master

Add OpenComputers compat for fluid pump and fix CCGT allowing throttle over max when using OpenComputers callbacks
This commit is contained in:
HbmMods 2025-07-18 08:06:53 +02:00 committed by GitHub
commit 85bef7672e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 153 additions and 23 deletions

View File

@ -3,6 +3,12 @@ package com.hbm.blocks.network;
import java.util.ArrayList;
import java.util.List;
import com.hbm.handler.CompatHandler;
import cpw.mods.fml.common.Optional;
import li.cil.oc.api.machine.Arguments;
import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context;
import li.cil.oc.api.network.SimpleComponent;
import org.lwjgl.input.Keyboard;
import com.hbm.blocks.ILookOverlay;
@ -93,7 +99,7 @@ public class FluidPump extends BlockContainer implements INBTTransformable, ILoo
return true;
}
}
if(world.isRemote) FMLNetworkHandler.openGui(player, MainRegistry.instance, 0, world, x, y, z);
return true;
}
@ -123,40 +129,41 @@ public class FluidPump extends BlockContainer implements INBTTransformable, ILoo
public int transformMeta(int meta, int coordBaseMode) {
return INBTTransformable.transformMetaDeco(meta, coordBaseMode);
}
public static class TileEntityFluidPump extends TileEntityLoadedBase implements IFluidStandardTransceiverMK2, IControlReceiver {
@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
public static class TileEntityFluidPump extends TileEntityLoadedBase implements IFluidStandardTransceiverMK2, IControlReceiver, SimpleComponent, CompatHandler.OCComponent {
public int bufferSize = 100;
public FluidTank[] tank;
public ConnectionPriority priority = ConnectionPriority.NORMAL;
public boolean redstone = false;
public TileEntityFluidPump() {
this.tank = new FluidTank[1];
this.tank[0] = new FluidTank(Fluids.NONE, bufferSize);
}
@Override
public void updateEntity() {
if(!worldObj.isRemote) {
// if the capacity were changed directly, any excess buffered fluid would be destroyed
// when running a closed loop or handling hard to get fluids, that's quite bad
if(this.bufferSize != this.tank[0].getMaxFill()) {
int nextBuffer = Math.max(this.tank[0].getFill(), this.bufferSize);
this.tank[0].changeTankSize(nextBuffer);
}
this.redstone = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata());
ForgeDirection in = dir.getRotation(ForgeDirection.UP);
ForgeDirection out = in.getOpposite();
this.trySubscribe(tank[0].getTankType(), worldObj, xCoord + in.offsetX, yCoord, zCoord + in.offsetZ, in);
if(!redstone) this.tryProvide(tank[0], worldObj, xCoord + out.offsetX, yCoord, zCoord + out.offsetZ, out);
this.networkPackNT(15);
}
}
@ -192,7 +199,7 @@ public class FluidPump extends BlockContainer implements INBTTransformable, ILoo
priority = EnumUtil.grabEnumSafely(ConnectionPriority.class, buf.readByte());
bufferSize = buf.readInt();
}
@Override public ConnectionPriority getFluidPriority() { return priority; }
@Override public FluidTank[] getSendingTanks() { return redstone ? new FluidTank[0] : tank; }
@Override public FluidTank[] getReceivingTanks() { return this.bufferSize < this.tank[0].getFill() ? new FluidTank[0] : tank; }
@ -214,9 +221,129 @@ public class FluidPump extends BlockContainer implements INBTTransformable, ILoo
if(data.hasKey("priority")) {
priority = EnumUtil.grabEnumSafely(ConnectionPriority.class, data.getByte("priority"));
}
this.markDirty();
}
@Override
@Optional.Method(modid = "OpenComputers")
public String getComponentName() {
return "ntm_fluid_pump";
}
@Callback(direct = true, limit = 4)
@Optional.Method(modid = "OpenComputers")
public Object[] getFluid(Context context, Arguments args) {
return new Object[] {
tank[0].getTankType().getUnlocalizedName()
};
}
@Callback(direct = true, limit = 4)
@Optional.Method(modid = "OpenComputers")
public Object[] getPressure(Context context, Arguments args) {
return new Object[] {
tank[0].getPressure()
};
}
@Callback(direct = true, limit = 4)
@Optional.Method(modid = "OpenComputers")
public Object[] getFlow(Context context, Arguments args) {
return new Object[] {
bufferSize
};
}
@Callback(direct = true, limit = 4)
@Optional.Method(modid = "OpenComputers")
public Object[] getPriority(Context context, Arguments args) {
return new Object[] {
getFluidPriority()
};
}
@Callback(direct = true, limit = 4)
@Optional.Method(modid = "OpenComputers")
public Object[] getInfo(Context context, Arguments args) {
return new Object[] {
tank[0].getTankType().getUnlocalizedName(),
tank[0].getPressure(),
bufferSize,
getFluidPriority()
};
}
@Callback(direct = true, limit = 4)
@Optional.Method(modid = "OpenComputers")
public Object[] setPriority(Context context, Arguments args) {
int num = args.checkInteger(0);
switch (num) {
case 0:
priority = ConnectionPriority.LOWEST;
break;
case 1:
priority = ConnectionPriority.LOW;
break;
case 2:
priority = ConnectionPriority.NORMAL;
break;
case 3:
priority = ConnectionPriority.HIGH;
break;
case 4:
priority = ConnectionPriority.HIGHEST;
break;
default:
return new Object[] {null, "Not a valid Priority."};
}
return new Object[] {true};
}
@Callback(direct = true, limit = 4)
@Optional.Method(modid = "OpenComputers")
public Object[] setFlow(Context context, Arguments args) {
int input = args.checkInteger(0);
if (input > 10000 || input < 0)
return new Object[] {null, "Number outside of bounds."};
return new Object[] {true};
}
@Override
@Optional.Method(modid = "OpenComputers")
public String[] methods() {
return new String[] {
"getPriority",
"getPressure",
"getFluid",
"getFlow",
"getInfo",
"setPriority",
"setFlow"
};
}
@Override
@Optional.Method(modid = "OpenComputers")
public Object[] invoke(String method, Context context, Arguments args) throws Exception {
switch (method) {
case ("getPriority"):
return getPriority(context, args);
case ("getPressure"):
return getPressure(context, args);
case ("getFluid"):
return getFluid(context, args);
case ("getFlow"):
return getFlow(context, args);
case ("getInfo"):
return getInfo(context, args);
case ("setPriority"):
return setPriority(context, args);
case ("setFlow"):
return setFlow(context, args);
}
throw new NoSuchMethodException();
}
}
public static class GUIPump extends GuiScreen {
@ -261,7 +388,7 @@ public class FluidPump extends BlockContainer implements INBTTransformable, ILoo
drawString(fontRendererObj, "Priority:", this.width / 2 + 50, 80, 0xA0A0A0);
buttonPriority.drawButton(mc, mouseX, mouseY);
super.drawScreen(mouseX, mouseY, partialTicks);
}

View File

@ -105,11 +105,11 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
tanks[0].setTankType(fluid);
}
}
if(autoMode) { //power production depending on power requirement and fuel level
int powerSliderTarget;
//when low on fuel, decrease consumption linearly
if(tanks[0].getFill() * 10 > tanks[0].getMaxFill()) {
powerSliderTarget = 60 - (int) (60 * power / maxPower); //scales the slider proportionally to the power gauge
@ -117,7 +117,7 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
else {
powerSliderTarget = (int) ( tanks[0].getFill() * 0.0001 * (60 - (int) (60 * power / maxPower)) );
}
if(powerSliderTarget > powerSliderPos) { //makes the auto slider slide instead of snapping into position
powerSliderPos++;
}
@ -403,12 +403,12 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
double waterPerTick = (consMax * energy * (temp - tempIdle) / 220000); //it just works fuck you
this.waterToBoil = waterPerTick; //caching in a field for the EC compat to use
int heatCycles = (int) Math.floor(waterToBoil);
int waterCycles = tanks[2].getFill();
int steamCycles = (tanks[3].getMaxFill() - tanks[3].getFill()) / 10;
int cycles = BobMathUtil.min(heatCycles, waterCycles, steamCycles);
tanks[2].setFill(tanks[2].getFill() - cycles);
tanks[3].setFill(tanks[3].getFill() + cycles * 10);
}
@ -619,8 +619,11 @@ public class TileEntityMachineTurbineGas extends TileEntityMachineBase implement
@Callback(direct = true, limit = 4)
@Optional.Method(modid = "OpenComputers")
public Object[] setThrottle(Context context, Arguments args) {
powerSliderPos = (int) (args.checkInteger(0) * 60D / 100D);
return new Object[] {};
double input = args.checkInteger(0) * 60D / 100D;
if (input < 0 || input > 100)
return new Object[] {null, "Input out of range."};
powerSliderPos = (int) (input);
return new Object[] {true};
}
@Callback(direct = true, limit = 4)