Compare commits

..

2 Commits

Author SHA1 Message Date
HbmMods
6b7628dc07
Merge pull request #2851 from DTK-MrRaccoon/octhing
OpenComputers methods for rbmk gauges, graphs, keypads and numitrons
2026-04-17 08:58:06 +02:00
DTK-MrRaccoon
4169e9094e OpenComputers methods for rbmk gauges, graphs, keypads and numitrons 2026-04-15 22:10:38 +02:00
4 changed files with 413 additions and 4 deletions

View File

@ -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.GUIScreenRBMKGauge;
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 TileEntityRBMKGauge extends TileEntityLoadedBase implements IGUIProvider, IControlReceiver {
@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
public class TileEntityRBMKGauge extends TileEntityLoadedBase implements IGUIProvider, IControlReceiver, SimpleComponent, CompatHandler.OCComponent {
/* __________
* / /|
@ -200,4 +207,108 @@ public class TileEntityRBMKGauge extends TileEntityLoadedBase implements IGUIPro
gauge.max = data.getInteger("max" + i);
}
}
// OpenComputers methods
@Override
@Optional.Method(modid = "OpenComputers")
public String getComponentName() {
return "rbmk_gauge";
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getGaugeInfo(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 4) return new Object[] {null, "Invalid index (1-4)"};
java.util.LinkedHashMap<String, Object> map = new java.util.LinkedHashMap<>();
map.put("active", gauges[idx].active);
map.put("polling", gauges[idx].polling);
map.put("color", gauges[idx].color);
map.put("label", gauges[idx].label);
map.put("channel", gauges[idx].rtty);
map.put("min", gauges[idx].min);
map.put("max", gauges[idx].max);
map.put("value", gauges[idx].value);
return new Object[] {map};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setGaugeActive(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 4) return new Object[] {false, "Invalid index (1-4)"};
gauges[idx].active = args.checkBoolean(1);
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setGaugePolling(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 4) return new Object[] {false, "Invalid index (1-4)"};
gauges[idx].polling = args.checkBoolean(1);
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setGaugeColor(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 4) return new Object[] {false, "Invalid index (1-4)"};
gauges[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[] setGaugeLabel(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 4) return new Object[] {false, "Invalid index (1-4)"};
gauges[idx].label = args.checkString(1);
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setGaugeChannel(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 4) return new Object[] {false, "Invalid index (1-4)"};
gauges[idx].rtty = args.checkString(1);
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setGaugeMin(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 4) return new Object[] {false, "Invalid index (1-4)"};
gauges[idx].min = (long) args.checkInteger(1);
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setGaugeMax(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 4) return new Object[] {false, "Invalid index (1-4)"};
gauges[idx].max = (long) args.checkInteger(1);
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setGaugeValue(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 4) return new Object[] {false, "Invalid index (1-4)"};
gauges[idx].value = (long) args.checkInteger(1);
markDirty();
return new Object[] {true};
}
}

View File

@ -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.GUIScreenRBMKGraph;
import com.hbm.tileentity.IGUIProvider;
@ -8,13 +9,19 @@ 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.world.World;
public class TileEntityRBMKGraph extends TileEntityLoadedBase implements IGUIProvider, IControlReceiver {
@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
public class TileEntityRBMKGraph extends TileEntityLoadedBase implements IGUIProvider, IControlReceiver, SimpleComponent, CompatHandler.OCComponent {
/* __________
* / /|
@ -173,4 +180,107 @@ public class TileEntityRBMKGraph extends TileEntityLoadedBase implements IGUIPro
graph.rtty = data.getString("rtty" + i);
}
}
// OpenComputers methods
@Override
@Optional.Method(modid = "OpenComputers")
public String getComponentName() {
return "rbmk_graph";
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getGraphInfo(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<String, Object> map = new java.util.LinkedHashMap<>();
map.put("active", graphs[idx].active);
map.put("polling", graphs[idx].polling);
map.put("label", graphs[idx].label);
map.put("channel", graphs[idx].rtty);
map.put("values", graphs[idx].values);
return new Object[] {map};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getGraphMin(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 2) return new Object[] {0L, "Invalid index (1-2)"};
long min = Long.MAX_VALUE;
for(long v : graphs[idx].values) if(v < min) min = v;
return new Object[] {min == Long.MAX_VALUE ? 0 : min};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getGraphMax(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 2) return new Object[] {0L, "Invalid index (1-2)"};
long max = Long.MIN_VALUE;
for(long v : graphs[idx].values) if(v > max) max = v;
return new Object[] {max == Long.MIN_VALUE ? 0 : max};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getGraphAvg(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 2) return new Object[] {0.0, "Invalid index (1-2)"};
long sum = 0;
int count = 0;
for(long v : graphs[idx].values) { sum += v; count++; }
return new Object[] {count > 0 ? (double)sum / count : 0.0};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setGraphActive(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 2) return new Object[] {false, "Invalid index (1-2)"};
graphs[idx].active = args.checkBoolean(1);
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setGraphPolling(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 2) return new Object[] {false, "Invalid index (1-2)"};
graphs[idx].polling = args.checkBoolean(1);
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setGraphLabel(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 2) return new Object[] {false, "Invalid index (1-2)"};
graphs[idx].label = args.checkString(1);
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setGraphChannel(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 2) return new Object[] {false, "Invalid index (1-2)"};
graphs[idx].rtty = args.checkString(1);
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] pushGraphValue(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 2) return new Object[] {false, "Invalid index (1-2)"};
long val = (long) args.checkInteger(1);
graphs[idx].pushValue(val);
markDirty();
return new Object[] {true};
}
}

View File

@ -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.GUIScreenRBMKKeyPad;
import com.hbm.tileentity.IGUIProvider;
@ -7,14 +8,20 @@ import com.hbm.tileentity.TileEntityLoadedBase;
import com.hbm.tileentity.network.RTTYSystem;
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 TileEntityRBMKKeyPad extends TileEntityLoadedBase implements IGUIProvider, IControlReceiver {
@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
public class TileEntityRBMKKeyPad extends TileEntityLoadedBase implements IGUIProvider, IControlReceiver, SimpleComponent, CompatHandler.OCComponent {
/* __________
* / /|
@ -196,4 +203,106 @@ public class TileEntityRBMKKeyPad extends TileEntityLoadedBase implements IGUIPr
key.command = data.getString("cmd" + i);
}
}
// OpenComputers methods
@Override
@Optional.Method(modid = "OpenComputers")
public String getComponentName() {
return "rbmk_keypad";
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getKeyInfo(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 4) return new Object[] {null, "Invalid index (1-4)"};
java.util.LinkedHashMap<String, Object> map = new java.util.LinkedHashMap<>();
map.put("active", keys[idx].active);
map.put("polling", keys[idx].polling);
map.put("pressed", keys[idx].isPressed);
map.put("color", keys[idx].color);
map.put("label", keys[idx].label);
map.put("channel", keys[idx].rtty);
map.put("command", keys[idx].command);
return new Object[] {map};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setKeyActive(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 4) return new Object[] {false, "Invalid index (1-4)"};
keys[idx].active = args.checkBoolean(1);
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setKeyPolling(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 4) return new Object[] {false, "Invalid index (1-4)"};
keys[idx].polling = args.checkBoolean(1);
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setKeyColor(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 4) return new Object[] {false, "Invalid index (1-4)"};
keys[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[] setKeyLabel(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 4) return new Object[] {false, "Invalid index (1-4)"};
keys[idx].label = args.checkString(1);
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setKeyChannel(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 4) return new Object[] {false, "Invalid index (1-4)"};
keys[idx].rtty = args.checkString(1);
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setKeyCommand(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 4) return new Object[] {false, "Invalid index (1-4)"};
keys[idx].command = args.checkString(1);
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 1)
@Optional.Method(modid = "OpenComputers")
public Object[] pressKey(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 4) return new Object[] {false, "Invalid index (1-4)"};
if(!keys[idx].active) return new Object[] {false, "Key is not active"};
keys[idx].click();
markDirty();
return new Object[] {true};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getKeyPressed(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 4) return new Object[] {false, "Invalid index (1-4)"};
return new Object[] {keys[idx].isPressed};
}
}

View File

@ -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.GUIScreenRBMKDisplay;
import com.hbm.tileentity.IGUIProvider;
@ -8,13 +9,19 @@ 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.world.World;
public class TileEntityRBMKNumitron extends TileEntityLoadedBase implements IGUIProvider, IControlReceiver {
@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
public class TileEntityRBMKNumitron extends TileEntityLoadedBase implements IGUIProvider, IControlReceiver, SimpleComponent, CompatHandler.OCComponent {
/* __________
* / /|
@ -162,4 +169,76 @@ public class TileEntityRBMKNumitron extends TileEntityLoadedBase implements IGUI
display.rtty = data.getString("rtty" + i);
}
}
// OpenComputers methods
@Override
@Optional.Method(modid = "OpenComputers")
public String getComponentName() {
return "rbmk_numitron";
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getDisplayInfo(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<String, Object> map = new java.util.LinkedHashMap<>();
map.put("active", displays[idx].active);
map.put("polling", displays[idx].polling);
map.put("label", displays[idx].label);
map.put("channel", displays[idx].rtty);
map.put("value", displays[idx].value);
return new Object[] {map};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setDisplayActive(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 2) return new Object[] {false, "Invalid index (1-2)"};
displays[idx].active = args.checkBoolean(1);
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setDisplayPolling(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 2) return new Object[] {false, "Invalid index (1-2)"};
displays[idx].polling = args.checkBoolean(1);
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setDisplayLabel(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 2) return new Object[] {false, "Invalid index (1-2)"};
displays[idx].label = args.checkString(1);
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setDisplayChannel(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 2) return new Object[] {false, "Invalid index (1-2)"};
displays[idx].rtty = args.checkString(1);
markDirty();
return new Object[] {true};
}
@Callback(direct = true, limit = 2)
@Optional.Method(modid = "OpenComputers")
public Object[] setDisplayValue(Context context, Arguments args) {
int idx = args.checkInteger(0) - 1;
if(idx < 0 || idx >= 2) return new Object[] {false, "Invalid index (1-2)"};
long val = (long) args.checkInteger(1);
displays[idx].value = val;
markDirty();
return new Object[] {true};
}
}