mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-02-26 20:04:41 +01:00
Changed Display Link Peripheral API
- Changed the Display Link Peripheral API to be more in line with the Monitor API - Added write, setCursorPos, getCursorPos, getSize, isColor, isColour, clearLine - Removed void writeLine, setLine, writeLines, setLines
This commit is contained in:
parent
18bfb216b1
commit
1091f3227c
3 changed files with 55 additions and 72 deletions
|
@ -1,15 +1,13 @@
|
||||||
package com.simibubi.create.compat.computercraft;
|
package com.simibubi.create.compat.computercraft;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import com.simibubi.create.content.logistics.block.display.DisplayLinkContext;
|
||||||
import com.simibubi.create.content.logistics.block.display.DisplayLinkTileEntity;
|
import com.simibubi.create.content.logistics.block.display.DisplayLinkTileEntity;
|
||||||
|
import com.simibubi.create.content.logistics.block.display.target.DisplayTargetStats;
|
||||||
|
|
||||||
import dan200.computercraft.api.lua.IArguments;
|
|
||||||
import dan200.computercraft.api.lua.LuaException;
|
|
||||||
import dan200.computercraft.api.lua.LuaFunction;
|
import dan200.computercraft.api.lua.LuaFunction;
|
||||||
import net.minecraft.nbt.ListTag;
|
import net.minecraft.nbt.ListTag;
|
||||||
import net.minecraft.nbt.StringTag;
|
import net.minecraft.nbt.StringTag;
|
||||||
|
@ -18,103 +16,85 @@ import net.minecraft.nbt.Tag;
|
||||||
public class DisplayLinkPeripheral extends PeripheralBase<DisplayLinkTileEntity> {
|
public class DisplayLinkPeripheral extends PeripheralBase<DisplayLinkTileEntity> {
|
||||||
|
|
||||||
public static final String TAG_KEY = "ComputerSourceList";
|
public static final String TAG_KEY = "ComputerSourceList";
|
||||||
|
private final AtomicInteger cursorX = new AtomicInteger();
|
||||||
|
private final AtomicInteger cursorY = new AtomicInteger();
|
||||||
|
|
||||||
public DisplayLinkPeripheral(DisplayLinkTileEntity tile) {
|
public DisplayLinkPeripheral(DisplayLinkTileEntity tile) {
|
||||||
super(tile);
|
super(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@LuaFunction
|
@LuaFunction
|
||||||
public void writeLine(String line) {
|
public void setCursorPos(int x, int y) {
|
||||||
ListTag tag = this.tile.getSourceConfig().getList(TAG_KEY, Tag.TAG_STRING);
|
cursorX.set(x - 1);
|
||||||
tag.add(StringTag.valueOf(line));
|
cursorY.set(y - 1);
|
||||||
|
|
||||||
this.tile.getSourceConfig().put(TAG_KEY, tag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@LuaFunction
|
@LuaFunction
|
||||||
public void setLine(int lineNumber, String line) {
|
public Object[] getCursorPos() {
|
||||||
ListTag tag = this.tile.getSourceConfig().getList(TAG_KEY, Tag.TAG_STRING);
|
return new Object[] {cursorX.get() + 1, cursorY.get() + 1};
|
||||||
int size = tag.size();
|
}
|
||||||
|
|
||||||
if (lineNumber < size) {
|
@LuaFunction(mainThread = true)
|
||||||
tag.set(lineNumber, StringTag.valueOf(line));
|
public Object[] getSize() {
|
||||||
|
DisplayTargetStats stats = tile.activeTarget.provideStats(new DisplayLinkContext(tile.getLevel(), tile));
|
||||||
} else {
|
return new Object[]{stats.maxRows(), stats.maxColumns()};
|
||||||
for (int i = 0; i < lineNumber - size; i++) {
|
|
||||||
tag.add(StringTag.valueOf(""));
|
|
||||||
}
|
|
||||||
|
|
||||||
tag.add(StringTag.valueOf(line));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.tile.getSourceConfig().put(TAG_KEY, tag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@LuaFunction
|
@LuaFunction
|
||||||
public void writeLines(IArguments arguments) throws LuaException {
|
public boolean isColor() {
|
||||||
ListTag tag = this.tile.getSourceConfig().getList(TAG_KEY, Tag.TAG_STRING);
|
return false;
|
||||||
List<String> lines = getLinesFromArguments(arguments, 0);
|
|
||||||
|
|
||||||
for (String line : lines) {
|
|
||||||
tag.add(StringTag.valueOf(line));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.tile.getSourceConfig().put(TAG_KEY, tag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@LuaFunction
|
@LuaFunction
|
||||||
public void setLines(IArguments arguments) throws LuaException {
|
public boolean isColour() {
|
||||||
ListTag tag = this.tile.getSourceConfig().getList(TAG_KEY, Tag.TAG_STRING);
|
return false;
|
||||||
List<String> lines = getLinesFromArguments(arguments, 1);
|
}
|
||||||
|
|
||||||
int size = tag.size();
|
@LuaFunction
|
||||||
int lineNumber = arguments.getInt(0);
|
public void write(String text) {
|
||||||
int i = 0;
|
ListTag tag = tile.getSourceConfig().getList(TAG_KEY, Tag.TAG_STRING);
|
||||||
|
|
||||||
for (int j = lineNumber; j < Math.min(size, lines.size()); j++) {
|
int x = cursorX.get();
|
||||||
tag.set(j, StringTag.valueOf(lines.get(i)));
|
int y = cursorY.get();
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int j = 0; j < lineNumber - size; j++) {
|
for (int i = tag.size(); i <= y; i++) {
|
||||||
tag.add(StringTag.valueOf(""));
|
tag.add(StringTag.valueOf(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = i; j < lines.size(); j++) {
|
StringBuilder builder = new StringBuilder(tag.getString(y));
|
||||||
tag.add(StringTag.valueOf(lines.get(i)));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.tile.getSourceConfig().put(TAG_KEY, tag);
|
builder.append(" ".repeat(Math.max(0, x - builder.length())));
|
||||||
|
builder.replace(x, x + text.length(), text);
|
||||||
|
|
||||||
|
tag.set(y, StringTag.valueOf(builder.toString()));
|
||||||
|
|
||||||
|
synchronized (tile) {
|
||||||
|
tile.getSourceConfig().put(TAG_KEY, tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@LuaFunction
|
||||||
|
public void clearLine() {
|
||||||
|
ListTag tag = tile.getSourceConfig().getList(TAG_KEY, Tag.TAG_STRING);
|
||||||
|
|
||||||
|
if (tag.size() > cursorY.get())
|
||||||
|
tag.set(cursorY.get(), StringTag.valueOf(""));
|
||||||
|
|
||||||
|
synchronized (tile) {
|
||||||
|
tile.getSourceConfig().put(TAG_KEY, tag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@LuaFunction
|
@LuaFunction
|
||||||
public void clear() {
|
public void clear() {
|
||||||
this.tile.getSourceConfig().put(TAG_KEY, new ListTag());
|
synchronized (tile) {
|
||||||
|
tile.getSourceConfig().put(TAG_KEY, new ListTag());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@LuaFunction(mainThread = true)
|
@LuaFunction(mainThread = true)
|
||||||
public void update() {
|
public void update() {
|
||||||
this.tile.tickSource();
|
tile.tickSource();
|
||||||
}
|
|
||||||
|
|
||||||
private List<String> getLinesFromArguments(IArguments arguments, int offset) throws LuaException {
|
|
||||||
List<String> lines = new ArrayList<>();
|
|
||||||
|
|
||||||
if (arguments.count() > offset + 1) {
|
|
||||||
for (int i = offset; i < arguments.count(); i++) {
|
|
||||||
lines.add(arguments.getString(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Map<?, ?> map = arguments.getTable(offset);
|
|
||||||
|
|
||||||
for (Object line : map.values()) {
|
|
||||||
lines.add(line.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return lines;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|
|
@ -7,7 +7,7 @@ import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
|
||||||
public abstract class PeripheralBase<T extends BlockEntity & ComputerControllable> implements IPeripheral {
|
public abstract class PeripheralBase<T extends BlockEntity & ComputerControllable> implements IPeripheral {
|
||||||
|
|
||||||
protected T tile;
|
protected final T tile;
|
||||||
|
|
||||||
public PeripheralBase(T tile) {
|
public PeripheralBase(T tile) {
|
||||||
this.tile = tile;
|
this.tile = tile;
|
||||||
|
|
|
@ -244,6 +244,9 @@ public class AllDisplayBehaviours {
|
||||||
DisplayBehaviour computerDisplaySource = register(Create.asResource("computer_display_source"), new ComputerDisplaySource());
|
DisplayBehaviour computerDisplaySource = register(Create.asResource("computer_display_source"), new ComputerDisplaySource());
|
||||||
|
|
||||||
assignTile(computerDisplaySource, new ResourceLocation(Mods.COMPUTERCRAFT.asId(), "wired_modem_full"));
|
assignTile(computerDisplaySource, new ResourceLocation(Mods.COMPUTERCRAFT.asId(), "wired_modem_full"));
|
||||||
|
assignTile(computerDisplaySource, new ResourceLocation(Mods.COMPUTERCRAFT.asId(), "computer_normal"));
|
||||||
|
assignTile(computerDisplaySource, new ResourceLocation(Mods.COMPUTERCRAFT.asId(), "computer_advanced"));
|
||||||
|
assignTile(computerDisplaySource, new ResourceLocation(Mods.COMPUTERCRAFT.asId(), "computer_command"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue