From 76e328a0093ec2d1ff934ba81b1c5e61fdd57e24 Mon Sep 17 00:00:00 2001 From: DTK-MrRaccoon Date: Mon, 20 Apr 2026 10:36:38 +0200 Subject: [PATCH] OpenComputers methods for rbmk indicator and lever --- .../machine/rbmk/TileEntityRBMKIndicator.java | 86 ++++++++++++++++++- .../machine/rbmk/TileEntityRBMKLever.java | 53 +++++++++++- 2 files changed, 137 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKIndicator.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKIndicator.java index dab98af0e..daef35044 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKIndicator.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKIndicator.java @@ -1,5 +1,6 @@ package com.hbm.tileentity.machine.rbmk; +import com.hbm.handler.CompatHandler; import com.hbm.interfaces.IControlReceiver; import com.hbm.inventory.gui.GUIScreenRBMKIndicator; import com.hbm.tileentity.IGUIProvider; @@ -8,14 +9,20 @@ import com.hbm.tileentity.network.RTTYSystem; import com.hbm.tileentity.network.RTTYSystem.RTTYChannel; import com.hbm.util.BufferUtil; +import cpw.mods.fml.common.Optional; import io.netty.buffer.ByteBuf; +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.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.MathHelper; import net.minecraft.world.World; -public class TileEntityRBMKIndicator extends TileEntityLoadedBase implements IGUIProvider, IControlReceiver { +@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")}) +public class TileEntityRBMKIndicator extends TileEntityLoadedBase implements IGUIProvider, IControlReceiver, SimpleComponent, CompatHandler.OCComponent { /* __________ * / /| @@ -195,4 +202,81 @@ public class TileEntityRBMKIndicator extends TileEntityLoadedBase implements IGU indicator.max = data.hasKey("max" + i) ? data.getInteger("max" + i) : Integer.MAX_VALUE; } } + + // OpenComputers methods + @Override + @Optional.Method(modid = "OpenComputers") + public String getComponentName() { + return "rbmk_indicator"; + } + + @Callback(direct = true) + @Optional.Method(modid = "OpenComputers") + public Object[] getIndicatorInfo(Context context, Arguments args) { + int idx = args.checkInteger(0) - 1; + if(idx < 0 || idx >= 6) return new Object[] {null, "Invalid index (1-6)"}; + java.util.LinkedHashMap map = new java.util.LinkedHashMap<>(); + map.put("active", indicators[idx].active); + map.put("polling", indicators[idx].polling); + map.put("light", indicators[idx].light); + map.put("color", indicators[idx].color); + map.put("label", indicators[idx].label); + map.put("channel", indicators[idx].rtty); + map.put("min", indicators[idx].min); + map.put("max", indicators[idx].max); + return new Object[] {map}; + } + + @Callback(direct = true, limit = 2) + @Optional.Method(modid = "OpenComputers") + public Object[] setIndicatorActive(Context context, Arguments args) { + int idx = args.checkInteger(0) - 1; + if(idx < 0 || idx >= 6) return new Object[] {false, "Invalid index (1-6)"}; + indicators[idx].active = args.checkBoolean(1); + markDirty(); + return new Object[] {true}; + } + + @Callback(direct = true, limit = 2) + @Optional.Method(modid = "OpenComputers") + public Object[] setIndicatorLight(Context context, Arguments args) { + int idx = args.checkInteger(0) - 1; + if(idx < 0 || idx >= 6) return new Object[] {false, "Invalid index (1-6)"}; + indicators[idx].light = args.checkBoolean(1); + markDirty(); + return new Object[] {true}; + } + + @Callback(direct = true, limit = 2) + @Optional.Method(modid = "OpenComputers") + public Object[] setIndicatorColor(Context context, Arguments args) { + int idx = args.checkInteger(0) - 1; + if(idx < 0 || idx >= 6) return new Object[] {false, "Invalid index (1-6)"}; + indicators[idx].color = MathHelper.clamp_int(args.checkInteger(1), 0, 0xffffff); + markDirty(); + return new Object[] {true}; + } + + @Callback(direct = true, limit = 2) + @Optional.Method(modid = "OpenComputers") + public Object[] setIndicatorLabel(Context context, Arguments args) { + int idx = args.checkInteger(0) - 1; + if(idx < 0 || idx >= 6) return new Object[] {false, "Invalid index (1-6)"}; + indicators[idx].label = args.checkString(1); + markDirty(); + return new Object[] {true}; + } + + @Callback(direct = true, limit = 2) + @Optional.Method(modid = "OpenComputers") + public Object[] setIndicatorBounds(Context context, Arguments args) { + int idx = args.checkInteger(0) - 1; + if(idx < 0 || idx >= 6) return new Object[] {false, "Invalid index (1-6)"}; + long min = (long) args.checkInteger(1); + long max = (long) args.checkInteger(2); + indicators[idx].min = min; + indicators[idx].max = max; + markDirty(); + return new Object[] {true}; + } } diff --git a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKLever.java b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKLever.java index 865fae9ba..e07a2315c 100644 --- a/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKLever.java +++ b/src/main/java/com/hbm/tileentity/machine/rbmk/TileEntityRBMKLever.java @@ -1,5 +1,6 @@ package com.hbm.tileentity.machine.rbmk; +import com.hbm.handler.CompatHandler; import com.hbm.handler.threading.PacketThreading; import com.hbm.interfaces.IControlReceiver; import com.hbm.inventory.gui.GUIScreenRBMKLever; @@ -10,15 +11,21 @@ import com.hbm.tileentity.TileEntityLoadedBase; import com.hbm.tileentity.network.RTTYSystem; import com.hbm.util.BufferUtil; +import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; import io.netty.buffer.ByteBuf; +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.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -public class TileEntityRBMKLever extends TileEntityLoadedBase implements IGUIProvider, IControlReceiver { +@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")}) +public class TileEntityRBMKLever extends TileEntityLoadedBase implements IGUIProvider, IControlReceiver, SimpleComponent, CompatHandler.OCComponent { /* __________ * / /| @@ -230,4 +237,48 @@ public class TileEntityRBMKLever extends TileEntityLoadedBase implements IGUIPro this.markDirty(); } + + // OpenComputers methods + @Override + @Optional.Method(modid = "OpenComputers") + public String getComponentName() { + return "rbmk_lever"; + } + + @Callback(direct = true) + @Optional.Method(modid = "OpenComputers") + public Object[] getLeverInfo(Context context, Arguments args) { + int idx = args.checkInteger(0) - 1; + if(idx < 0 || idx >= 2) return new Object[] {null, "Invalid index (1-2)"}; + java.util.LinkedHashMap map = new java.util.LinkedHashMap<>(); + map.put("active", levers[idx].active); + map.put("polling", levers[idx].polling); + map.put("state", levers[idx].flipProgress >= 1.0); + map.put("progress", levers[idx].flipProgress); + map.put("label", levers[idx].label); + map.put("channel", levers[idx].rtty); + map.put("commandOn", levers[idx].commandOn); + map.put("commandOff", levers[idx].commandOff); + return new Object[] {map}; + } + + @Callback(direct = true, limit = 2) + @Optional.Method(modid = "OpenComputers") + public Object[] setLeverActive(Context context, Arguments args) { + int idx = args.checkInteger(0) - 1; + if(idx < 0 || idx >= 2) return new Object[] {false, "Invalid index (1-2)"}; + levers[idx].active = args.checkBoolean(1); + markDirty(); + return new Object[] {true}; + } + + @Callback(direct = true, limit = 2) + @Optional.Method(modid = "OpenComputers") + public Object[] setLeverLabel(Context context, Arguments args) { + int idx = args.checkInteger(0) - 1; + if(idx < 0 || idx >= 2) return new Object[] {false, "Invalid index (1-2)"}; + levers[idx].label = args.checkString(1); + markDirty(); + return new Object[] {true}; + } }