back at it again with the OC compat

Now including:
Optimizations
Turbine Compat
Compat handler for general functions
other compat
This commit is contained in:
BallOfEnergy 2023-11-14 19:18:43 -06:00
parent 34865547c4
commit 0f25aac3a2
13 changed files with 177 additions and 75 deletions

View File

@ -0,0 +1,31 @@
package com.hbm.handler;
import com.hbm.inventory.fluid.FluidType;
import com.hbm.inventory.fluid.Fluids;
/**
* General handler for OpenComputers compatibility.
* <p/>
* Mostly just functions used across many TEs.
*/
public class CompatHandler {
public static Object[] steamTypeToInt(FluidType type) {
if(type == Fluids.STEAM) {return new Object[] {0};}
else if(type == Fluids.HOTSTEAM) {return new Object[] {1};}
else if(type == Fluids.SUPERHOTSTEAM) {return new Object[] {2};}
return new Object[] {3};
}
public static FluidType intToSteamType(int arg) {
switch(arg) {
default:
return Fluids.STEAM;
case(1):
return Fluids.HOTSTEAM;
case(2):
return Fluids.SUPERHOTSTEAM;
case(3):
return Fluids.ULTRAHOTSTEAM;
}
}
}

View File

@ -5,6 +5,7 @@ import java.util.List;
import java.util.Random;
import com.hbm.blocks.BlockDummyable;
import com.hbm.handler.CompatHandler;
import com.hbm.interfaces.IFluidAcceptor;
import com.hbm.interfaces.IFluidSource;
import com.hbm.inventory.fluid.FluidType;
@ -22,15 +23,20 @@ import com.hbm.util.fauxpointtwelve.DirPos;
import api.hbm.energy.IEnergyGenerator;
import api.hbm.fluid.IFluidStandardTransceiver;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
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 net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityChungus extends TileEntityLoadedBase implements IFluidAcceptor, IFluidSource, IEnergyGenerator, INBTPacketReceiver, IFluidStandardTransceiver {
public class TileEntityChungus extends TileEntityLoadedBase implements IFluidAcceptor, IFluidSource, IEnergyGenerator, INBTPacketReceiver, IFluidStandardTransceiver, SimpleComponent {
public long power;
public static final long maxPower = 100000000000L;
@ -275,6 +281,31 @@ public class TileEntityChungus extends TileEntityLoadedBase implements IFluidAcc
this.power = power;
}
@Override
public String getComponentName() {
return "ntm_large_turbine";
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getFluid(Context context, Arguments args) {
return new Object[] {tanks[0].getFill(), tanks[1].getFill()};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getType(Context context, Arguments args) {
return CompatHandler.steamTypeToInt(tanks[1].getTankType());
}
@Callback(direct = true, limit = 4)
@Optional.Method(modid = "OpenComputers")
public Object[] setType(Context context, Arguments args) {
tanks[1].setTankType(CompatHandler.intToSteamType(args.checkInteger(0)));
return new Object[] {true};
}
@Override
public FluidTank[] getSendingTanks() {
return new FluidTank[] {tanks[1]};

View File

@ -315,12 +315,7 @@ public class TileEntityCoreEmitter extends TileEntityMachineBase implements IEne
@Optional.Method(modid = "OpenComputers")
public Object[] setInput(Context context, Arguments args) {
int newOutput = args.checkInteger(0);
if (newOutput > 100) {
newOutput = 100;
} else if (newOutput < 0) {
newOutput = 0;
}
watts = newOutput;
watts = MathHelper.clamp_int(newOutput, 0, 100);
return new Object[] {};
}

View File

@ -209,12 +209,7 @@ public class TileEntityCoreStabilizer extends TileEntityMachineBase implements I
@Optional.Method(modid = "OpenComputers")
public Object[] setInput(Context context, Arguments args) {
int newOutput = args.checkInteger(0);
if (newOutput > 100) {
newOutput = 100;
} else if (newOutput < 0) {
newOutput = 0;
}
watts = newOutput;
watts = MathHelper.clamp_int(newOutput, 0, 100);
return new Object[] {};
}

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import com.hbm.blocks.BlockDummyable;
import com.hbm.handler.CompatHandler;
import com.hbm.interfaces.IFluidAcceptor;
import com.hbm.interfaces.IFluidContainer;
import com.hbm.interfaces.IFluidSource;
@ -21,8 +22,13 @@ import com.hbm.util.fauxpointtwelve.DirPos;
import api.hbm.energy.IEnergyGenerator;
import api.hbm.fluid.IFluidStandardTransceiver;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
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 net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
@ -32,7 +38,8 @@ import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityMachineLargeTurbine extends TileEntityMachineBase implements IFluidContainer, IFluidAcceptor, IFluidSource, IEnergyGenerator, IFluidStandardTransceiver, IGUIProvider {
@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
public class TileEntityMachineLargeTurbine extends TileEntityMachineBase implements IFluidContainer, IFluidAcceptor, IFluidSource, IEnergyGenerator, IFluidStandardTransceiver, IGUIProvider, SimpleComponent {
public long power;
public static final long maxPower = 100000000;
@ -280,6 +287,36 @@ public class TileEntityMachineLargeTurbine extends TileEntityMachineBase impleme
return new FluidTank[] {tanks[0]};
}
@Override
public String getComponentName() {
return "ntm_turbine";
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getFluid(Context context, Arguments args) {
return new Object[] {tanks[0].getFill(), tanks[0].getMaxFill(), tanks[1].getFill(), tanks[1].getMaxFill()};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getType(Context context, Arguments args) {
return CompatHandler.steamTypeToInt(tanks[1].getTankType());
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getInfo(Context context, Arguments args) {
return new Object[] {tanks[0].getFill(), tanks[0].getMaxFill(), tanks[1].getFill(), tanks[1].getMaxFill(), tanks[1].getTankType()};
}
@Callback(direct = true, limit = 4)
@Optional.Method(modid = "OpenComputers")
public Object[] setType(Context context, Arguments args) {
tanks[1].setTankType(CompatHandler.intToSteamType(args.checkInteger(0)));
return new Object[] {true};
}
@Override
public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new ContainerMachineLargeTurbine(player.inventory, this);

View File

@ -3,6 +3,7 @@ package com.hbm.tileentity.machine;
import java.util.ArrayList;
import java.util.List;
import com.hbm.handler.CompatHandler;
import com.hbm.interfaces.IFluidAcceptor;
import com.hbm.interfaces.IFluidContainer;
import com.hbm.interfaces.IFluidSource;
@ -22,9 +23,14 @@ import com.hbm.tileentity.TileEntityLoadedBase;
import api.hbm.energy.IBatteryItem;
import api.hbm.energy.IEnergyGenerator;
import api.hbm.fluid.IFluidStandardTransceiver;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
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 net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
@ -35,7 +41,8 @@ import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityMachineTurbine extends TileEntityLoadedBase implements ISidedInventory, IFluidContainer, IFluidAcceptor, IFluidSource, IEnergyGenerator, IFluidStandardTransceiver, IGUIProvider {
@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
public class TileEntityMachineTurbine extends TileEntityLoadedBase implements ISidedInventory, IFluidContainer, IFluidAcceptor, IFluidSource, IEnergyGenerator, IFluidStandardTransceiver, IGUIProvider, SimpleComponent {
private ItemStack slots[];
@ -376,6 +383,30 @@ public class TileEntityMachineTurbine extends TileEntityLoadedBase implements IS
return tanks;
}
@Override
public String getComponentName() {
return "ntm_small_turbine";
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getFluid(Context context, Arguments args) {
return new Object[] {tanks[0].getFill(), tanks[1].getFill()};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getType(Context context, Arguments args) {
return CompatHandler.steamTypeToInt(tanks[1].getTankType());
}
@Callback(direct = true, limit = 4)
@Optional.Method(modid = "OpenComputers")
public Object[] setType(Context context, Arguments args) {
tanks[1].setTankType(CompatHandler.intToSteamType(args.checkInteger(0)));
return new Object[] {true};
}
@Override
public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new ContainerMachineTurbine(player.inventory, this);

View File

@ -7,8 +7,13 @@ import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.TileEntityMachineBase;
import api.hbm.energy.IEnergyUser;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
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 net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
@ -19,7 +24,8 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
public class TileEntityMicrowave extends TileEntityMachineBase implements IEnergyUser, IGUIProvider {
@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
public class TileEntityMicrowave extends TileEntityMachineBase implements IEnergyUser, IGUIProvider, SimpleComponent {
public long power;
public static final long maxPower = 50000;
@ -209,6 +215,17 @@ public class TileEntityMicrowave extends TileEntityMachineBase implements IEnerg
nbt.setInteger("speed", speed);
}
@Override
public String getComponentName() {
return "microwave";
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] test(Context context, Arguments args) {
return new Object[] {"This is a testing device for everything OC."};
}
@Override
public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new ContainerMicrowave(player.inventory, this);

View File

@ -272,36 +272,15 @@ public class TileEntityReactorControl extends TileEntityMachineBase implements I
@Optional.Method(modid = "OpenComputers")
public Object[] setParams(Context context, Arguments args) { //i hate my life
int newFunction = args.checkInteger(0);
double newMaxheat = args.checkDouble(1);
double newMinheat = args.checkDouble(2);
double newMaxlevel = args.checkDouble(3)/100.0;
double newMinlevel = args.checkDouble(4)/100.0;
if (newFunction > 2) { //no more out of bounds for you (and yes there's integer values for functions, sue me)
newFunction = 0;
} else if (newFunction < 0) {
newFunction = 0;
}
if (newMaxheat < 0.0) {
newMaxheat = 0.0;
}
if (newMinheat < 0.0) {
newMinheat = 0.0;
}
if (newMaxlevel < 0.0) {
newMaxlevel = 0.0;
} else if (newMaxlevel > 1.0) {
newMaxlevel = 1.0;
}
if (newMinlevel < 0.0) {
newMinlevel = 0.0;
} else if (newMinlevel > 1.0) {
newMinlevel = 1.0;
}
function = RodFunction.values()[newFunction];
heatUpper = newMaxheat;
heatLower = newMinheat;
levelUpper = newMaxlevel;
levelLower = newMinlevel;
double newMaxHeat = args.checkDouble(1);
double newMinHeat = args.checkDouble(2);
double newMaxLevel = args.checkDouble(3)/100.0;
double newMinLevel = args.checkDouble(4)/100.0;
function = RodFunction.values()[MathHelper.clamp_int(newFunction, 0, 2)];
heatUpper = MathHelper.clamp_double(newMaxHeat, 0, 9999);
heatLower = MathHelper.clamp_double(newMinHeat, 0, 9999);
levelUpper = MathHelper.clamp_double(newMaxLevel, 0, 1);
levelLower = MathHelper.clamp_double(newMinLevel, 0, 1);
return new Object[] {};
}

View File

@ -32,6 +32,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
@ -429,12 +430,7 @@ public class TileEntityReactorResearch extends TileEntityMachineBase implements
@Optional.Method(modid = "OpenComputers")
public Object[] setLevel(Context context, Arguments args) {
double newLevel = args.checkDouble(0)/100.0;
if (newLevel > 1.0) {
newLevel = 1.0;
} else if (newLevel < 0.0) {
newLevel = 0.0;
}
targetLevel = newLevel;
targetLevel = MathHelper.clamp_double(newLevel, 0, 100.0);
return new Object[] {};
}

View File

@ -5,6 +5,7 @@ import api.hbm.fluid.IFluidUser;
import api.hbm.fluid.IPipeNet;
import com.hbm.blocks.ModBlocks;
import com.hbm.entity.projectile.EntityRBMKDebris.DebrisType;
import com.hbm.handler.CompatHandler;
import com.hbm.interfaces.IControlReceiver;
import com.hbm.interfaces.IFluidAcceptor;
import com.hbm.interfaces.IFluidSource;
@ -369,25 +370,14 @@ public class TileEntityRBMKBoiler extends TileEntityRBMKSlottedBase implements I
@Callback(direct = true, limit = 16)
@Optional.Method(modid = "OpenComputers")
public Object[] getInfo(Context context, Arguments args) {
FluidType type = steam.getTankType();
Object type_1;
if(type == Fluids.STEAM) {type_1 = "0";}
else if(type == Fluids.HOTSTEAM) {type_1 = "1";}
else if(type == Fluids.SUPERHOTSTEAM) {type_1 = "2";}
else if(type == Fluids.ULTRAHOTSTEAM) {type_1 = "3";}
else {type_1 = "Unknown Error";}
int type_1 = (int) CompatHandler.steamTypeToInt(steam.getTankType())[0];
return new Object[] {heat, steam.getFill(), steam.getMaxFill(), feed.getFill(), feed.getMaxFill(), type_1, xCoord, yCoord, zCoord};
}
@Callback(direct = true, limit = 16)
@Optional.Method(modid = "OpenComputers")
public Object[] getSteamType(Context context, Arguments args) {
FluidType type = steam.getTankType();
if(type == Fluids.STEAM) {return new Object[] {0};}
else if(type == Fluids.HOTSTEAM) {return new Object[] {1};}
else if(type == Fluids.SUPERHOTSTEAM) {return new Object[] {2};}
else if(type == Fluids.ULTRAHOTSTEAM) {return new Object[] {3};}
else {return new Object[] {"Unknown Error"};}
return CompatHandler.steamTypeToInt(steam.getTankType());
}
@Callback(direct = true, limit = 16)

View File

@ -393,25 +393,25 @@ public class TileEntityBarrel extends TileEntityMachineBase implements IFluidAcc
return "ntm_fluid_tank";
}
@Callback(direct = true, limit = 4)
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getFluidStored(Context context, Arguments args) {
return new Object[] {tank.getFill()};
}
@Callback(direct = true, limit = 4)
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getMaxStored(Context context, Arguments args) {
return new Object[] {tank.getMaxFill()};
}
@Callback(direct = true, limit = 4)
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getTypeStored(Context context, Arguments args) {
return new Object[] {tank.getTankType().getName()};
}
@Callback(direct = true, limit = 4)
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getInfo(Context context, Arguments args) {
return new Object[]{tank.getFill(), tank.getMaxFill(), tank.getTankType().getName()};

View File

@ -420,13 +420,13 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
return "ntm_energy_storage"; //ok if someone else can figure out how to do this that'd be nice (change the component name based on the type of storage block)
}
@Callback(direct = true, limit = 8)
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getEnergyInfo(Context context, Arguments args) {
return new Object[] {getPower(), getMaxPower()};
}
@Callback(direct = true, limit = 8)
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getInfo(Context context, Arguments args) {
return new Object[] {getPower(), getMaxPower()};

View File

@ -473,25 +473,25 @@ public class TileEntityMachineFluidTank extends TileEntityMachineBase implements
return "ntm_tank";
}
@Callback(direct = true, limit = 4)
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getFluidStored(Context context, Arguments args) {
return new Object[] {tank.getFill()};
}
@Callback(direct = true, limit = 4)
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getMaxStored(Context context, Arguments args) {
return new Object[] {tank.getMaxFill()};
}
@Callback(direct = true, limit = 4)
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getTypeStored(Context context, Arguments args) {
return new Object[] {tank.getTankType().getName()};
}
@Callback(direct = true, limit = 4)
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getInfo(Context context, Arguments args) {
return new Object[]{tank.getFill(), tank.getMaxFill(), tank.getTankType().getName()};