Merge pull request #46 from North-Western-Development/terminal-overhaul
Terminal overhaul
This commit is contained in:
1
.github/workflows/build.yml
vendored
1
.github/workflows/build.yml
vendored
@@ -1,3 +1,4 @@
|
||||
#file: noinspection UndefinedAction,UndefinedParamsPresent
|
||||
name: build
|
||||
|
||||
on:
|
||||
|
||||
1
.github/workflows/publish.yml
vendored
1
.github/workflows/publish.yml
vendored
@@ -1,3 +1,4 @@
|
||||
#file: noinspection UndefinedAction,UndefinedParamsPresent
|
||||
name: publish
|
||||
|
||||
on:
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -34,7 +34,7 @@ forge*changelog.txt
|
||||
#vscode
|
||||
.vscode
|
||||
|
||||
#libs/
|
||||
libs/*.jar
|
||||
|
||||
# Don't ignore bin from scripts
|
||||
!/src/main/scripts/bin/
|
||||
|
||||
45
build.gradle
45
build.gradle
@@ -8,14 +8,15 @@ plugins {
|
||||
}
|
||||
|
||||
apply plugin: 'org.spongepowered.mixin'
|
||||
apply from: "minecraft.gradle"
|
||||
apply plugin: "java"
|
||||
jarJar.enable()
|
||||
|
||||
allprojects {
|
||||
gradle.projectsEvaluated {
|
||||
tasks.withType(JavaCompile) {
|
||||
options.compilerArgs << "-Xmaxerrs" << "1000"
|
||||
tasks.withType(JavaCompile).tap {
|
||||
configureEach {
|
||||
options.compilerArgs << "-Xmaxerrs" << "1000"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,7 +99,6 @@ dependencies {
|
||||
minecraftLibrary "org.apache.commons:commons-collections4:4.4"
|
||||
|
||||
implementation fg.deobf("curse.maven:architectury-api-419699:5137938")
|
||||
|
||||
implementation fg.deobf("curse.maven:markdownmanual-502485:4873115")
|
||||
|
||||
compileOnly fg.deobf("mezz.jei:jei-1.20.1-common-api:15.3.0.4")
|
||||
@@ -137,16 +137,16 @@ dependencies {
|
||||
|
||||
System.setProperty("line.separator", "\n")
|
||||
|
||||
task packageScripts(type: Zip) {
|
||||
tasks.register('packageScripts', Zip) {
|
||||
archiveFileName = "scripts.zip"
|
||||
destinationDirectory = file("$buildDir/resources/main/data/oc2r/file_systems")
|
||||
destinationDirectory = file("${layout.buildDirectory.get()}/resources/main/data/oc2r/file_systems")
|
||||
from "src/main/scripts"
|
||||
filter { line -> line }
|
||||
}
|
||||
|
||||
task copyLicensesToResources(type: Copy) {
|
||||
tasks.register('copyLicensesToResources', Copy) {
|
||||
from "."
|
||||
into file("$buildDir/resources/main")
|
||||
into file("${layout.buildDirectory.get()}/resources/main")
|
||||
include "LICENSE*"
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ minecraft {
|
||||
accessTransformer = file("src/main/resources/META-INF/accesstransformer.cfg")
|
||||
|
||||
runs {
|
||||
all {
|
||||
configureEach {
|
||||
property "forge.logging.markers", "REGISTRIES"
|
||||
property "forge.logging.console.level", "debug"
|
||||
|
||||
@@ -203,7 +203,7 @@ mixin {
|
||||
// quiet
|
||||
}
|
||||
|
||||
task copyGeneratedResources(type: Copy) {
|
||||
tasks.register('copyGeneratedResources', Copy) {
|
||||
from "src/generated"
|
||||
into "src/main"
|
||||
exclude "resources/.cache"
|
||||
@@ -228,7 +228,7 @@ jar {
|
||||
}
|
||||
}
|
||||
|
||||
task apiJar(type: Jar) {
|
||||
tasks.register('apiJar', Jar) {
|
||||
archiveClassifier.set("api")
|
||||
from sourceSets.main.allSource
|
||||
from sourceSets.main.output
|
||||
@@ -239,29 +239,6 @@ artifacts {
|
||||
archives apiJar
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
groupId = project.group
|
||||
artifactId = project.name
|
||||
version = semver
|
||||
artifact jar
|
||||
artifact apiJar
|
||||
jarJar.component(it)
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
maven {
|
||||
name = "GitHubPackages"
|
||||
url = System.getenv("GITHUB_MAVEN_URL") ?: ""
|
||||
credentials {
|
||||
username = System.getenv("GITHUB_ACTOR")
|
||||
password = System.getenv("GITHUB_TOKEN")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
curseforge {
|
||||
apiKey = System.getenv("CURSEFORGE_API_KEY") ?: ""
|
||||
project {
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
org.gradle.jvmargs=-Xmx3G
|
||||
org.gradle.daemon=false
|
||||
|
||||
forge_version=47.3.0
|
||||
forge_version=47.3.38
|
||||
minecraft_version = 1.20.1
|
||||
minecraft_sdk = forge
|
||||
|
||||
semver=0.0.0
|
||||
|
||||
|
||||
2
libs/gitignore
Normal file
2
libs/gitignore
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
@@ -1,4 +0,0 @@
|
||||
ext {
|
||||
minecraft_version = '1.20.1'
|
||||
minecraft_sdk = 'forge'
|
||||
}
|
||||
@@ -5,12 +5,10 @@ pluginManagement {
|
||||
maven { url "https://repo.spongepowered.org/repository/maven-public/" }
|
||||
}
|
||||
}
|
||||
|
||||
apply from: 'minecraft.gradle'
|
||||
rootProject.name = "oc2r-${minecraft_version}-${minecraft_sdk}"
|
||||
|
||||
def substituteLocal(final directoryName, final libraryName) {
|
||||
final def path = new File("../${directoryName}");
|
||||
final def path = new File("../${directoryName}")
|
||||
if (path.exists()) {
|
||||
println("Found local [${directoryName}] project, substituting...")
|
||||
includeBuild(path) {
|
||||
|
||||
@@ -21,7 +21,7 @@ public interface DeviceType {
|
||||
/**
|
||||
* The registry name of the registry holding device types.
|
||||
*/
|
||||
ResourceKey<Registry<DeviceType>> REGISTRY = ResourceKey.createRegistryKey(new ResourceLocation(API.MOD_ID, "device_type"));
|
||||
ResourceKey<Registry<DeviceType>> REGISTRY = ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "device_type"));
|
||||
|
||||
/**
|
||||
* The tag representing this device type.
|
||||
|
||||
@@ -9,16 +9,17 @@ import net.minecraftforge.registries.RegistryObject;
|
||||
/**
|
||||
* Lists built-in device types for convenience.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public final class DeviceTypes {
|
||||
public static final DeviceType MEMORY = (DeviceType) RegistryObject.create(new ResourceLocation(API.MOD_ID, "memory"), new ResourceLocation(API.MOD_ID, "device_type"), API.MOD_ID).get();
|
||||
public static final DeviceType MEMORY = (DeviceType) RegistryObject.create(ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "memory"), ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "device_type"), API.MOD_ID).get();
|
||||
|
||||
public static final DeviceType HARD_DRIVE = (DeviceType) RegistryObject.create(new ResourceLocation(API.MOD_ID, "hard_drive"), new ResourceLocation(API.MOD_ID, "device_type"), API.MOD_ID).get();
|
||||
public static final DeviceType HARD_DRIVE = (DeviceType) RegistryObject.create(ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "hard_drive"), ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "device_type"), API.MOD_ID).get();
|
||||
|
||||
public static final DeviceType FLASH_MEMORY = (DeviceType) RegistryObject.create(new ResourceLocation(API.MOD_ID, "flash_memory"), new ResourceLocation(API.MOD_ID, "device_type"), API.MOD_ID).get();
|
||||
public static final DeviceType CARD = (DeviceType) RegistryObject.create(new ResourceLocation(API.MOD_ID, "card"), new ResourceLocation(API.MOD_ID, "device_type"), API.MOD_ID).get();
|
||||
public static final DeviceType ROBOT_MODULE = (DeviceType) RegistryObject.create(new ResourceLocation(API.MOD_ID, "robot_module"), new ResourceLocation(API.MOD_ID, "device_type"), API.MOD_ID).get();
|
||||
public static final DeviceType FLASH_MEMORY = (DeviceType) RegistryObject.create(ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "flash_memory"), ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "device_type"), API.MOD_ID).get();
|
||||
public static final DeviceType CARD = (DeviceType) RegistryObject.create(ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "card"), ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "device_type"), API.MOD_ID).get();
|
||||
public static final DeviceType ROBOT_MODULE = (DeviceType) RegistryObject.create(ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "robot_module"), ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "device_type"), API.MOD_ID).get();
|
||||
|
||||
public static final DeviceType FLOPPY = (DeviceType) RegistryObject.create(new ResourceLocation(API.MOD_ID, "floppy"), new ResourceLocation(API.MOD_ID, "device_type"), API.MOD_ID).get();
|
||||
public static final DeviceType NETWORK_TUNNEL = (DeviceType) RegistryObject.create(new ResourceLocation(API.MOD_ID, "network_tunnel"), new ResourceLocation(API.MOD_ID, "device_type"), API.MOD_ID).get();
|
||||
public static final DeviceType CPU = (DeviceType) RegistryObject.create(new ResourceLocation(API.MOD_ID, "cpu"), new ResourceLocation(API.MOD_ID, "device_type"), API.MOD_ID).get();
|
||||
public static final DeviceType FLOPPY = (DeviceType) RegistryObject.create(ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "floppy"), ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "device_type"), API.MOD_ID).get();
|
||||
public static final DeviceType NETWORK_TUNNEL = (DeviceType) RegistryObject.create(ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "network_tunnel"), ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "device_type"), API.MOD_ID).get();
|
||||
public static final DeviceType CPU = (DeviceType) RegistryObject.create(ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "cpu"), ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "device_type"), API.MOD_ID).get();
|
||||
}
|
||||
|
||||
@@ -38,6 +38,6 @@ public final class Registries {
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private static <T> ResourceKey<Registry<T>> key(final String name) {
|
||||
return ResourceKey.createRegistryKey(new ResourceLocation(API.MOD_ID, name));
|
||||
return ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(API.MOD_ID, name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,18 +16,18 @@ import li.cil.oc2.common.block.Blocks;
|
||||
import li.cil.oc2.common.blockentity.BlockEntities;
|
||||
import li.cil.oc2.common.container.Containers;
|
||||
import li.cil.oc2.common.entity.Entities;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.MenuScreens;
|
||||
import net.minecraft.client.renderer.ItemBlockRenderTypes;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
|
||||
import net.minecraftforge.client.event.EntityRenderersEvent;
|
||||
import net.minecraftforge.client.event.ModelEvent.RegisterGeometryLoaders;
|
||||
import net.minecraftforge.client.event.RegisterColorHandlersEvent;
|
||||
import net.minecraftforge.client.event.RenderGuiOverlayEvent;
|
||||
import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class ClientSetup {
|
||||
@SubscribeEvent
|
||||
public static void handleSetupEvent(final FMLClientSetupEvent event) {
|
||||
@@ -51,10 +51,6 @@ public final class ClientSetup {
|
||||
MenuScreens.register(Containers.ROBOT_TERMINAL.get(), RobotTerminalScreen::new);
|
||||
MenuScreens.register(Containers.NETWORK_TUNNEL.get(), NetworkTunnelScreen::new);
|
||||
|
||||
//noinspection deprecation
|
||||
ItemBlockRenderTypes.setRenderLayer(Blocks.BUS_CABLE.get(), renderType -> true);
|
||||
Minecraft.getInstance().getBlockColors().register(new BusCableBlockColor(), Blocks.BUS_CABLE.get());
|
||||
|
||||
// We need to register this manually, because static init throws errors when running data generation.
|
||||
MinecraftForge.EVENT_BUS.register(ProjectorDepthRenderer.class);
|
||||
});
|
||||
@@ -74,6 +70,11 @@ public final class ClientSetup {
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void handleColorHandler(final RegisterColorHandlersEvent.Block event) {
|
||||
event.register(new BusCableBlockColor(), Blocks.BUS_CABLE.get());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void handleEntityRendererRegisterEvent(final EntityRenderersEvent.RegisterRenderers event) {
|
||||
event.registerEntityRenderer(Entities.ROBOT.get(), RobotRenderer::new);
|
||||
|
||||
@@ -30,7 +30,8 @@ public abstract class AbstractMachineTerminalScreen<T extends AbstractMachineTer
|
||||
private static final int CONTROLS_TOP = 8;
|
||||
private static final int ENERGY_TOP = CONTROLS_TOP + Sprites.SIDEBAR_3.height + 4;
|
||||
|
||||
private static boolean isInputCaptureEnabled;
|
||||
|
||||
private boolean mouseClicked;
|
||||
|
||||
private final MachineTerminalWidget terminalWidget;
|
||||
|
||||
@@ -45,10 +46,6 @@ public abstract class AbstractMachineTerminalScreen<T extends AbstractMachineTer
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static boolean isInputCaptureEnabled() {
|
||||
return isInputCaptureEnabled;
|
||||
}
|
||||
|
||||
public List<Rect2i> getExtraAreas() {
|
||||
final List<Rect2i> list = new ArrayList<>();
|
||||
list.add(new Rect2i(
|
||||
@@ -81,14 +78,27 @@ public abstract class AbstractMachineTerminalScreen<T extends AbstractMachineTer
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(final double x, final double y, final int button) {
|
||||
mouseClicked = true;
|
||||
if (!terminalWidget.mouseClicked(x,y,button)) {
|
||||
return super.mouseClicked(x, y, button);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseMoved(double x, double y) {
|
||||
terminalWidget.mouseMoved(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double p_94686_, double p_94687_, double p_94688_)
|
||||
{
|
||||
return terminalWidget.mouseScrolled(p_94688_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(final double x, final double y, final int button) {
|
||||
if (!mouseClicked) return super.mouseReleased(x, y, button);
|
||||
if (!terminalWidget.mouseReleased(x,y,button)) {
|
||||
return super.mouseReleased(x, y, button);
|
||||
}
|
||||
@@ -160,12 +170,12 @@ public abstract class AbstractMachineTerminalScreen<T extends AbstractMachineTer
|
||||
@Override
|
||||
public void onPress() {
|
||||
super.onPress();
|
||||
isInputCaptureEnabled = !isInputCaptureEnabled;
|
||||
terminalWidget.isInputCaptureEnabled = !terminalWidget.isInputCaptureEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isToggled() {
|
||||
return isInputCaptureEnabled;
|
||||
return terminalWidget.isInputCaptureEnabled;
|
||||
}
|
||||
}).withTooltip(
|
||||
Component.translatable(Constants.TERMINAL_CAPTURE_INPUT_CAPTION),
|
||||
@@ -212,7 +222,7 @@ public abstract class AbstractMachineTerminalScreen<T extends AbstractMachineTer
|
||||
Sprites.ENERGY_BAR.drawFillY(graphics, x, y, menu.getEnergy() / (float) menu.getEnergyCapacity());
|
||||
}
|
||||
|
||||
terminalWidget.render(graphics, mouseX, mouseY, menu.getVirtualMachine().getError());
|
||||
terminalWidget.render(graphics, menu.getVirtualMachine().getError());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,15 +28,13 @@ public abstract class AbstractMonitorDisplayScreen<T extends AbstractMonitorCont
|
||||
private static final int CONTROLS_TOP = 8;
|
||||
private static final int ENERGY_TOP = CONTROLS_TOP + Sprites.MONITOR_SIDEBAR_1.height + 4;
|
||||
|
||||
private static boolean isInputCaptureEnabled;
|
||||
|
||||
private final MonitorDisplayWidget terminalWidget;
|
||||
private final MonitorDisplayWidget monitorDisplayWidget;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
protected AbstractMonitorDisplayScreen(final T container, final Inventory playerInventory, final Component title) {
|
||||
super(container, playerInventory, title);
|
||||
this.terminalWidget = new MonitorDisplayWidget(this);
|
||||
this.monitorDisplayWidget = new MonitorDisplayWidget(this);
|
||||
imageWidth = Sprites.MONITOR_SCREEN.width;
|
||||
imageHeight = Sprites.MONITOR_SCREEN.height;
|
||||
}
|
||||
@@ -47,12 +45,12 @@ public abstract class AbstractMonitorDisplayScreen<T extends AbstractMonitorCont
|
||||
public void containerTick() {
|
||||
super.containerTick();
|
||||
|
||||
terminalWidget.tick();
|
||||
monitorDisplayWidget.tick();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(final int keyCode, final int scanCode, final int modifiers) {
|
||||
if (terminalWidget.keyPressed(keyCode, scanCode, modifiers)) {
|
||||
if (monitorDisplayWidget.keyPressed(keyCode, scanCode, modifiers)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -68,7 +66,7 @@ public abstract class AbstractMonitorDisplayScreen<T extends AbstractMonitorCont
|
||||
|
||||
@Override
|
||||
public boolean keyReleased(final int keyCode, final int scanCode, final int modifiers) {
|
||||
if (terminalWidget.keyReleased(keyCode, scanCode, modifiers)) {
|
||||
if (monitorDisplayWidget.keyReleased(keyCode, scanCode, modifiers)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -85,7 +83,7 @@ public abstract class AbstractMonitorDisplayScreen<T extends AbstractMonitorCont
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
terminalWidget.init();
|
||||
monitorDisplayWidget.init();
|
||||
|
||||
final EditBox focusIndicatorEditBox = new EditBox(font, 0, 0, 0, 0, Component.empty());
|
||||
focusIndicatorEditBox.setFocused(true);
|
||||
@@ -131,12 +129,12 @@ public abstract class AbstractMonitorDisplayScreen<T extends AbstractMonitorCont
|
||||
@Override
|
||||
public void onPress() {
|
||||
super.onPress();
|
||||
isInputCaptureEnabled = !isInputCaptureEnabled;
|
||||
monitorDisplayWidget.isInputCaptureEnabled = !monitorDisplayWidget.isInputCaptureEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isToggled() {
|
||||
return isInputCaptureEnabled;
|
||||
return monitorDisplayWidget.isInputCaptureEnabled;
|
||||
}
|
||||
}).withTooltip(
|
||||
Component.translatable(Constants.TERMINAL_CAPTURE_INPUT_CAPTION),
|
||||
@@ -147,7 +145,7 @@ public abstract class AbstractMonitorDisplayScreen<T extends AbstractMonitorCont
|
||||
@Override
|
||||
public void onClose() {
|
||||
super.onClose();
|
||||
terminalWidget.onClose();
|
||||
monitorDisplayWidget.onClose();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -167,7 +165,7 @@ public abstract class AbstractMonitorDisplayScreen<T extends AbstractMonitorCont
|
||||
Sprites.ENERGY_BAR.drawFillY(graphics, x, y, menu.getEnergy() / (float) menu.getEnergyCapacity());
|
||||
}
|
||||
|
||||
terminalWidget.render(graphics, Component.translatable(Constants.COMPUTER_ERROR_NOT_ENOUGH_ENERGY));
|
||||
monitorDisplayWidget.render(graphics, Component.translatable(Constants.COMPUTER_ERROR_NOT_ENOUGH_ENERGY));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -181,7 +179,7 @@ public abstract class AbstractMonitorDisplayScreen<T extends AbstractMonitorCont
|
||||
Sprites.ENERGY_BASE.draw(graphics, x + 4, y + 4);
|
||||
}
|
||||
|
||||
terminalWidget.renderBackground(graphics, mouseX, mouseY);
|
||||
monitorDisplayWidget.renderBackground(graphics, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,24 +4,30 @@ package li.cil.oc2.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.Tesselator;
|
||||
import li.cil.oc2.common.vm.terminal.modes.MouseMode;
|
||||
import li.cil.oc2.common.vm.terminal.modes.PrivateMode;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import org.joml.Matrix4f;
|
||||
import li.cil.oc2.client.gui.terminal.TerminalInput;
|
||||
import li.cil.oc2.common.container.AbstractMachineTerminalContainer;
|
||||
import li.cil.oc2.common.vm.Terminal;
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import org.joml.Vector2i;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public final class MachineTerminalWidget {
|
||||
public boolean isInputCaptureEnabled;
|
||||
|
||||
private static final int TERMINAL_WIDTH = Terminal.WIDTH * Terminal.CHAR_WIDTH / 2;
|
||||
private static final int TERMINAL_HEIGHT = Terminal.HEIGHT * Terminal.CHAR_HEIGHT / 2;
|
||||
|
||||
@@ -40,6 +46,7 @@ public final class MachineTerminalWidget {
|
||||
private int leftPos, topPos;
|
||||
private boolean isMouseOverTerminal;
|
||||
private Terminal.RendererView rendererView;
|
||||
private boolean isOver;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -59,7 +66,7 @@ public final class MachineTerminalWidget {
|
||||
}
|
||||
}
|
||||
|
||||
public void render(final GuiGraphics graphics, final int mouseX, final int mouseY, @Nullable final Component error) {
|
||||
public void render(final GuiGraphics graphics, @Nullable final Component error) {
|
||||
if (container.getVirtualMachine().isRunning()) {
|
||||
final PoseStack terminalStack = new PoseStack();
|
||||
terminalStack.translate(leftPos + TERMINAL_X, topPos + TERMINAL_Y, 0);
|
||||
@@ -83,33 +90,18 @@ public final class MachineTerminalWidget {
|
||||
graphics,
|
||||
error,
|
||||
leftPos + TERMINAL_X + textOffsetX,
|
||||
topPos + TERMINAL_Y + textOffsetY,
|
||||
0xEE3322
|
||||
topPos + TERMINAL_Y + textOffsetY
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawShadow(Font font, GuiGraphics graphics, Component text, float x, float y, int color) {
|
||||
private void drawShadow(Font font, GuiGraphics graphics, Component text, float x, float y) {
|
||||
var batch = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
|
||||
font.drawInBatch(text, x, y, color, true, graphics.pose().last().pose(), batch, Font.DisplayMode.NORMAL, 0, 15728880);
|
||||
font.drawInBatch(text, x, y, 15610658, true, graphics.pose().last().pose(), batch, Font.DisplayMode.NORMAL, 0, 15728880);
|
||||
batch.endBatch();
|
||||
}
|
||||
|
||||
private static Matrix4f orthographic(float pMinX, float pMaxX, float pMinY, float pMaxY, float pMinZ, float pMaxZ) {
|
||||
Matrix4f matrix4f = new Matrix4f();
|
||||
float f = pMaxX - pMinX;
|
||||
float f1 = pMinY - pMaxY;
|
||||
float f2 = pMaxZ - pMinZ;
|
||||
matrix4f.set(
|
||||
2.0F / f, 0, 0, -(pMaxX + pMinX) / f,
|
||||
0, 2.0F / f1, 0, -(pMinY + pMaxY) / f1,
|
||||
0, 0, -2.0F / f2, -(pMaxZ + pMinZ) / f2,
|
||||
0, 0, 0, 1.0F
|
||||
);
|
||||
return matrix4f;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
final ByteBuffer input = terminal.getInput();
|
||||
if (input != null) {
|
||||
@@ -117,40 +109,140 @@ public final class MachineTerminalWidget {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean mouseClicked( double x, double y, int button) {
|
||||
int mx = (int) x;
|
||||
int my = (int) y;
|
||||
int sx = (int)((x - MachineTerminalWidget.TERMINAL_X) / MachineTerminalWidget.TERMINAL_WIDTH * Terminal.WIDTH);
|
||||
int sy = (int)((y - MachineTerminalWidget.TERMINAL_Y) / MachineTerminalWidget.TERMINAL_HEIGHT * Terminal.HEIGHT);
|
||||
boolean overTerminal = isMouseOverTerminal(mx, my);
|
||||
public boolean mouseScrolled(double dir) {
|
||||
if (terminal.currentPrivateModeState.isAltBufferEnabled()) return false;
|
||||
if (dir < 0) {
|
||||
terminal.incrementLastLineToDisplay(true);
|
||||
} else {
|
||||
terminal.decrementLastLineToDisplay();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void mouseMoved(double x, double y) {
|
||||
if (isMouseOverTerminal((int)x, (int)y)) {
|
||||
if (!isOver && terminal.currentPrivateModeState.FOCUS_IN_FOCUS_OUT) {
|
||||
isOver = true;
|
||||
terminal.putInput("\033[I");
|
||||
}
|
||||
} else {
|
||||
if(isOver && terminal.currentPrivateModeState.FOCUS_IN_FOCUS_OUT) {
|
||||
terminal.putInput("\033[O");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean mouseClicked(double x, double y, int button) {
|
||||
MouseMode currentMouseMode = terminal.currentPrivateModeState.getMouseMode();
|
||||
if (currentMouseMode.isMouseDisabled()) return false;
|
||||
Vector2i position = getMousePosition(x, y);
|
||||
boolean overTerminal = isMouseOverTerminal((int)x, (int)y);
|
||||
if (overTerminal && shouldCaptureInput()) {
|
||||
// terminal.putInput((byte) 0x1b);
|
||||
// terminal.putInput((byte) '[');
|
||||
// terminal.putInput((byte) button);
|
||||
// terminal.putInput((byte) sx);
|
||||
// terminal.putInput((byte) sy);
|
||||
return true;
|
||||
switch(currentMouseMode.PrimaryMode) {
|
||||
case PrivateMode.X11MM, PrivateMode.CELL_MOTION_MOUSE -> {
|
||||
if (currentMouseMode.isSecondaryModeEnabled(PrivateMode.SGR_MOUSE)) {
|
||||
terminal.putInput("\033[<" + button + ";" + position.x + ";" + position.y + "M");
|
||||
return true;
|
||||
}
|
||||
else if (currentMouseMode.isSecondaryModeEnabled(PrivateMode.UTF8_MOUSE))
|
||||
{
|
||||
byte[] csiMBytes = "\033[M".getBytes(StandardCharsets.UTF_8);
|
||||
byte[] buttonBytes = utf8(button + 32);
|
||||
byte[] colBytes = utf8(position.x + 32);
|
||||
byte[] rowBytes = utf8(position.y + 32);
|
||||
byte[] finalBytes = new byte[csiMBytes.length + buttonBytes.length + colBytes.length + rowBytes.length];
|
||||
|
||||
System.arraycopy(csiMBytes, 0, finalBytes, 0, csiMBytes.length);
|
||||
System.arraycopy(buttonBytes, 0, finalBytes, csiMBytes.length, buttonBytes.length);
|
||||
System.arraycopy(colBytes, 0, finalBytes, csiMBytes.length + buttonBytes.length, colBytes.length);
|
||||
System.arraycopy(rowBytes, 0, finalBytes, csiMBytes.length + buttonBytes.length + colBytes.length, rowBytes.length);
|
||||
|
||||
terminal.putInput(ByteBuffer.wrap(finalBytes));
|
||||
return true;
|
||||
}
|
||||
else if (currentMouseMode.isSecondaryModeEnabled(PrivateMode.URXVT_MOUSE))
|
||||
{
|
||||
terminal.putInput("\033[" + (button + 32) + ";" + position.x + ";" + position.y + "M");
|
||||
}
|
||||
else
|
||||
{
|
||||
terminal.putInput('\033');
|
||||
terminal.putInput('[');
|
||||
terminal.putInput('M');
|
||||
terminal.putInput((byte) (button + 32));
|
||||
terminal.putInput((byte) (position.x + 32));
|
||||
terminal.putInput((byte) (position.y + 32));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
default -> System.out.println("ERR: Unsupported primary mode");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean mouseReleased(double x, double y, int button) {
|
||||
int mx = (int) x;
|
||||
int my = (int) y;
|
||||
int sx = (int)((x - MachineTerminalWidget.TERMINAL_X) / MachineTerminalWidget.TERMINAL_WIDTH * Terminal.WIDTH);
|
||||
int sy = (int)((y - MachineTerminalWidget.TERMINAL_Y) / MachineTerminalWidget.TERMINAL_HEIGHT * Terminal.HEIGHT);
|
||||
boolean overTerminal = isMouseOverTerminal(mx, my);
|
||||
MouseMode currentMouseMode = terminal.currentPrivateModeState.getMouseMode();
|
||||
if (currentMouseMode.isMouseDisabled()) return false;
|
||||
Vector2i position = getMousePosition(x, y);
|
||||
boolean overTerminal = isMouseOverTerminal((int)x, (int)y);
|
||||
if (overTerminal && shouldCaptureInput()) {
|
||||
// terminal.putInput((byte) 0x1b);
|
||||
// terminal.putInput((byte) '[');
|
||||
// terminal.putInput((byte) 3);
|
||||
// terminal.putInput((byte) sx);
|
||||
// terminal.putInput((byte) sy);
|
||||
return true;
|
||||
switch(currentMouseMode.PrimaryMode) {
|
||||
case PrivateMode.X11MM, PrivateMode.CELL_MOTION_MOUSE -> {
|
||||
if (currentMouseMode.isSecondaryModeEnabled(PrivateMode.SGR_MOUSE)) {
|
||||
terminal.putInput("\033[<" + button + ";" + position.x + ";" + position.y + "m");
|
||||
return true;
|
||||
}
|
||||
else if (currentMouseMode.isSecondaryModeEnabled(PrivateMode.UTF8_MOUSE))
|
||||
{
|
||||
byte[] csiMBytes = "\033[M".getBytes(StandardCharsets.UTF_8);
|
||||
byte[] buttonBytes = utf8(35);
|
||||
byte[] colBytes = utf8(position.x + 32);
|
||||
byte[] rowBytes = utf8(position.y + 32);
|
||||
byte[] finalBytes = new byte[csiMBytes.length + buttonBytes.length + colBytes.length + rowBytes.length];
|
||||
|
||||
System.arraycopy(csiMBytes, 0, finalBytes, 0, csiMBytes.length);
|
||||
System.arraycopy(buttonBytes, 0, finalBytes, csiMBytes.length, buttonBytes.length);
|
||||
System.arraycopy(colBytes, 0, finalBytes, csiMBytes.length + buttonBytes.length, colBytes.length);
|
||||
System.arraycopy(rowBytes, 0, finalBytes, csiMBytes.length + buttonBytes.length + colBytes.length, rowBytes.length);
|
||||
|
||||
terminal.putInput(ByteBuffer.wrap(finalBytes));
|
||||
return true;
|
||||
}
|
||||
else if (currentMouseMode.isSecondaryModeEnabled(PrivateMode.URXVT_MOUSE))
|
||||
{
|
||||
terminal.putInput("\033[" + 35 + ";" + position.x + ";" + position.y + "M");
|
||||
}
|
||||
else
|
||||
{
|
||||
terminal.putInput('\033');
|
||||
terminal.putInput('[');
|
||||
terminal.putInput('M');
|
||||
terminal.putInput((byte) 35);
|
||||
terminal.putInput((byte) (position.x + 32));
|
||||
terminal.putInput((byte) (position.y + 32));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
default -> System.out.println("ERR: Unsupported primary mode");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private byte[] utf8(int value) {
|
||||
return new String(new int[]{value}, 0, 1).getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private Vector2i getMousePosition(double x, double y) {
|
||||
int tx = TERMINAL_WIDTH / Terminal.WIDTH;
|
||||
int ty = TERMINAL_HEIGHT / Terminal.HEIGHT;
|
||||
int sx = (int)(((x - leftPos) - MachineTerminalWidget.TERMINAL_X) / tx) + 1;
|
||||
int sy = (int)(((y - topPos) - MachineTerminalWidget.TERMINAL_Y) / ty) + 1;
|
||||
|
||||
return new Vector2i(sx, sy);
|
||||
}
|
||||
|
||||
public boolean charTyped(final char ch, final int modifier) {
|
||||
if (modifier == 0 || modifier == GLFW.GLFW_MOD_SHIFT) {
|
||||
terminal.putInput((byte) ch);
|
||||
@@ -158,6 +250,7 @@ public final class MachineTerminalWidget {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public boolean keyPressed(final int keyCode, final int scanCode, final int modifiers) {
|
||||
if (!shouldCaptureInput() && keyCode == GLFW.GLFW_KEY_ESCAPE) {
|
||||
return false;
|
||||
@@ -165,11 +258,17 @@ public final class MachineTerminalWidget {
|
||||
|
||||
if ((modifiers & GLFW.GLFW_MOD_CONTROL) != 0 && keyCode == GLFW.GLFW_KEY_V) {
|
||||
final String value = getClient().keyboardHandler.getClipboard();
|
||||
boolean bracketed = terminal.currentPrivateModeState.SET_BRACKETED_PASTE;
|
||||
if(bracketed) terminal.putInput("\033[200~");
|
||||
for (final char ch : value.toCharArray()) {
|
||||
terminal.putInput((byte) ch);
|
||||
}
|
||||
if(bracketed) terminal.putInput("\033[201~");
|
||||
} else {
|
||||
final byte[] sequence = TerminalInput.getSequence(keyCode, modifiers);
|
||||
byte[] sequence;
|
||||
if (terminal.currentPrivateModeState.DECCKM && (keyCode == GLFW.GLFW_KEY_UP || keyCode == GLFW.GLFW_KEY_DOWN || keyCode == GLFW.GLFW_KEY_LEFT || keyCode == GLFW.GLFW_KEY_RIGHT))
|
||||
sequence = TerminalInput.getDECCKMSequence(keyCode, modifiers);
|
||||
else sequence = TerminalInput.getSequence(keyCode, modifiers);
|
||||
if (sequence != null) {
|
||||
for (final byte b : sequence) {
|
||||
terminal.putInput(b);
|
||||
@@ -183,12 +282,9 @@ public final class MachineTerminalWidget {
|
||||
public void init() {
|
||||
this.leftPos = (parent.width - WIDTH) / 2;
|
||||
this.topPos = (parent.height - HEIGHT) / 2;
|
||||
|
||||
//getClient().keyboardHandler.setSendRepeatsToGui(true);
|
||||
}
|
||||
|
||||
public void onClose() {
|
||||
//getClient().keyboardHandler.setSendRepeatsToGui(false);
|
||||
if (rendererView != null) {
|
||||
terminal.releaseRenderer(rendererView);
|
||||
rendererView = null;
|
||||
@@ -202,7 +298,7 @@ public final class MachineTerminalWidget {
|
||||
}
|
||||
|
||||
private boolean shouldCaptureInput() {
|
||||
return isMouseOverTerminal && AbstractMachineTerminalScreen.isInputCaptureEnabled() &&
|
||||
return isMouseOverTerminal && isInputCaptureEnabled &&
|
||||
container.getVirtualMachine().isRunning();
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import li.cil.oc2.common.bus.device.vm.block.MonitorDevice;
|
||||
import li.cil.oc2.common.container.AbstractMonitorContainer;
|
||||
import li.cil.oc2.common.network.Network;
|
||||
import li.cil.oc2.common.network.message.MonitorInputMessage;
|
||||
import li.cil.oc2.common.vm.Terminal;
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
@@ -24,6 +24,8 @@ import javax.annotation.Nullable;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public final class MonitorDisplayWidget {
|
||||
public boolean isInputCaptureEnabled;
|
||||
|
||||
private static final int TERMINAL_WIDTH = Terminal.WIDTH * Terminal.CHAR_WIDTH / 2;
|
||||
private static final int TERMINAL_HEIGHT = Terminal.HEIGHT * Terminal.CHAR_HEIGHT / 2;
|
||||
|
||||
@@ -55,7 +57,7 @@ public final class MonitorDisplayWidget {
|
||||
Sprites.MONITOR_SCREEN.draw(graphics, leftPos, topPos);
|
||||
|
||||
if (shouldCaptureInput()) {
|
||||
Sprites.TERMINAL_FOCUSED.draw(graphics, leftPos, topPos);
|
||||
Sprites.MONITOR_FOCUSED.draw(graphics, leftPos, topPos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +144,7 @@ public final class MonitorDisplayWidget {
|
||||
}
|
||||
|
||||
private boolean shouldCaptureInput() {
|
||||
return isMouseOverTerminal && AbstractMachineTerminalScreen.isInputCaptureEnabled();
|
||||
return isMouseOverTerminal && isInputCaptureEnabled;
|
||||
}
|
||||
|
||||
private boolean isMouseOverTerminal(final int mouseX, final int mouseY) {
|
||||
|
||||
@@ -15,6 +15,7 @@ public final class Sprites {
|
||||
public static final Sprite NETWORK_INTERFACE_CARD_SCREEN = new Sprite(NETWORK_INTERFACE_CARD_SCREEN_TEXTURE);
|
||||
public static final Sprite NETWORK_TUNNEL_SCREEN = new Sprite(NETWORK_TUNNEL_SCREEN_TEXTURE);
|
||||
|
||||
public static final Sprite MONITOR_FOCUSED = new Sprite(MONITOR_FOCUSED_TEXTURE);
|
||||
public static final Sprite TERMINAL_FOCUSED = new Sprite(TERMINAL_FOCUSED_TEXTURE);
|
||||
public static final Sprite SLOT_SELECTION = new Sprite(SLOT_SELECTION_TEXTURE, 18, 18, 0, 0);
|
||||
public static final Sprite INFO_ICON = new Sprite(INFO_ICON_TEXTURE);
|
||||
|
||||
@@ -13,6 +13,7 @@ public final class Textures {
|
||||
public static final Texture NETWORK_INTERFACE_CARD_SCREEN_TEXTURE = new Texture("textures/gui/widget/network_interface_card_screen.png", 176, 130);
|
||||
public static final Texture NETWORK_TUNNEL_SCREEN_TEXTURE = new Texture("textures/gui/widget/network_tunnel_screen.png", 176, 197);
|
||||
|
||||
public static final Texture MONITOR_FOCUSED_TEXTURE = new Texture("textures/gui/overlay/monitor_focused.png", 265, 208);
|
||||
public static final Texture TERMINAL_FOCUSED_TEXTURE = new Texture("textures/gui/overlay/terminal_focused.png", 336, 208);
|
||||
public static final Texture SLOT_SELECTION_TEXTURE = new Texture("textures/gui/overlay/slot_selection.png", 18, 270);
|
||||
public static final Texture INFO_ICON_TEXTURE = new Texture("textures/gui/overlay/slot_info.png", 28, 28);
|
||||
|
||||
@@ -9,6 +9,7 @@ import javax.annotation.Nullable;
|
||||
|
||||
public final class TerminalInput {
|
||||
private static final Int2ObjectArrayMap<Int2ObjectArrayMap<byte[]>> KEYCODE_SEQUENCES = new Int2ObjectArrayMap<>();
|
||||
private static final Int2ObjectArrayMap<Int2ObjectArrayMap<byte[]>> DECCKM_KEYCODE_SEQUENCES = new Int2ObjectArrayMap<>();
|
||||
|
||||
static {
|
||||
addSequence(GLFW.GLFW_KEY_ENTER, '\r');
|
||||
@@ -71,6 +72,11 @@ public final class TerminalInput {
|
||||
addSequence(GLFW.GLFW_MOD_CONTROL | GLFW.GLFW_MOD_SHIFT, GLFW.GLFW_KEY_BACKSLASH, (byte) '\034');
|
||||
addSequence(GLFW.GLFW_MOD_CONTROL, GLFW.GLFW_KEY_RIGHT_BRACKET, (byte) '\035');
|
||||
addSequence(GLFW.GLFW_MOD_CONTROL | GLFW.GLFW_MOD_SHIFT, GLFW.GLFW_KEY_RIGHT_BRACKET, (byte) '\035');
|
||||
|
||||
addDECCKMSequence(GLFW.GLFW_KEY_UP, "\033OA");
|
||||
addDECCKMSequence(GLFW.GLFW_KEY_DOWN, "\033OB");
|
||||
addDECCKMSequence(GLFW.GLFW_KEY_RIGHT, "\033OC");
|
||||
addDECCKMSequence(GLFW.GLFW_KEY_LEFT, "\033OD");
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -91,6 +97,22 @@ public final class TerminalInput {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Nullable
|
||||
public static byte[] getDECCKMSequence(final int keyCode) {
|
||||
return getDECCKMSequence(keyCode, 0);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static byte[] getDECCKMSequence(final int keyCode, final int modifiers) {
|
||||
final Int2ObjectArrayMap<byte[]> map = DECCKM_KEYCODE_SEQUENCES.get(modifiers);
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
return map.get(keyCode);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private static void addSequence(final int keyCode, final char ch) {
|
||||
addSequence(keyCode, (byte) ch);
|
||||
}
|
||||
@@ -117,4 +139,33 @@ public final class TerminalInput {
|
||||
.computeIfAbsent(modifiers, i -> new Int2ObjectArrayMap<>())
|
||||
.put(keyCode, sequence);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private static void addDECCKMSequence(final int keyCode, final char ch) {
|
||||
addDECCKMSequence(keyCode, (byte) ch);
|
||||
}
|
||||
|
||||
private static void addDECCKMSequence(final int keyCode, final byte... sequence) {
|
||||
addDECCKMSequence(0, keyCode, sequence);
|
||||
}
|
||||
|
||||
private static void addDECCKMSequence(final int keyCode, final String sequence) {
|
||||
addDECCKMSequence(0, keyCode, sequence);
|
||||
}
|
||||
|
||||
private static void addDECCKMSequence(final int modifiers, final int keyCode, final String sequence) {
|
||||
final byte[] bytes = new byte[sequence.length()];
|
||||
final char[] chars = sequence.toCharArray();
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
bytes[i] = (byte) chars[i];
|
||||
}
|
||||
addDECCKMSequence(modifiers, keyCode, bytes);
|
||||
}
|
||||
|
||||
private static void addDECCKMSequence(final int modifiers, final int keyCode, final byte... sequence) {
|
||||
DECCKM_KEYCODE_SEQUENCES
|
||||
.computeIfAbsent(modifiers, i -> new Int2ObjectArrayMap<>())
|
||||
.put(keyCode, sequence);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ public final class Texture {
|
||||
public final int width, height;
|
||||
|
||||
public Texture(final String location, final int width, final int height) {
|
||||
this(new ResourceLocation(API.MOD_ID, location), width, height);
|
||||
this(ResourceLocation.fromNamespaceAndPath(API.MOD_ID, location), width, height);
|
||||
}
|
||||
|
||||
public Texture(final ResourceLocation location, final int width, final int height) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import net.minecraft.world.item.DyeableLeatherItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class CustomItemColors {
|
||||
public static final int BLACK = 0xFF404040;
|
||||
public static final int GREY = 0xFF555555;
|
||||
@@ -35,6 +36,7 @@ public final class CustomItemColors {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void initialize() {
|
||||
final ItemColors itemColors = Minecraft.getInstance().getItemColors();
|
||||
itemColors.register((stack, layer) -> layer == 1 ? getColor(stack) : NO_TINT,
|
||||
@@ -42,7 +44,6 @@ public final class CustomItemColors {
|
||||
Items.HARD_DRIVE_MEDIUM.get(),
|
||||
Items.HARD_DRIVE_LARGE.get(),
|
||||
Items.HARD_DRIVE_EXTRA_LARGE.get(),
|
||||
Items.HARD_DRIVE_CUSTOM.get(),
|
||||
Items.FLOPPY.get(),
|
||||
Items.FLOPPY_MODERN.get());
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import net.minecraft.client.renderer.item.ItemProperties;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public final class CustomItemModelProperties {
|
||||
public static final ResourceLocation COLOR_PROPERTY = new ResourceLocation(API.MOD_ID, "color");
|
||||
public static final ResourceLocation COLOR_PROPERTY = ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "color");
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -21,8 +21,6 @@ public final class CustomItemModelProperties {
|
||||
(stack, leve, entity, seed) -> CustomItemColors.getColor(stack));
|
||||
ItemProperties.register(Items.HARD_DRIVE_EXTRA_LARGE.get(), CustomItemModelProperties.COLOR_PROPERTY,
|
||||
(stack, leve, entity, seed) -> CustomItemColors.getColor(stack));
|
||||
ItemProperties.register(Items.HARD_DRIVE_CUSTOM.get(), CustomItemModelProperties.COLOR_PROPERTY,
|
||||
(stack, level, entity, seed) -> CustomItemColors.getColor(stack));
|
||||
ItemProperties.register(Items.FLOPPY.get(), CustomItemModelProperties.COLOR_PROPERTY,
|
||||
(stack, level, entity, seed) -> CustomItemColors.getColor(stack));
|
||||
ItemProperties.register(Items.FLOPPY_MODERN.get(), CustomItemModelProperties.COLOR_PROPERTY,
|
||||
|
||||
@@ -37,12 +37,12 @@ public final class Manuals {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void initialize() {
|
||||
MANUALS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
public static void initialize(FMLJavaModLoadingContext context) {
|
||||
MANUALS.register(context.getModEventBus());
|
||||
|
||||
PATH_PROVIDERS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
CONTENT_PROVIDERS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
TABS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
PATH_PROVIDERS.register(context.getModEventBus());
|
||||
CONTENT_PROVIDERS.register(context.getModEventBus());
|
||||
TABS.register(context.getModEventBus());
|
||||
|
||||
PATH_PROVIDERS.register("path_provider", () -> new NamespacePathProvider(API.MOD_ID));
|
||||
CONTENT_PROVIDERS.register("content_provider", () -> new NamespaceDocumentProvider(API.MOD_ID, "doc"));
|
||||
@@ -50,7 +50,7 @@ public final class Manuals {
|
||||
TABS.register("home", () -> new TextureTab(
|
||||
ManualModel.LANGUAGE_KEY + "/index.md",
|
||||
Component.translatable("manual." + API.MOD_ID + ".home"),
|
||||
new ResourceLocation(API.MOD_ID, "textures/gui/manual/home.png")));
|
||||
ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "textures/gui/manual/home.png")));
|
||||
TABS.register("blocks", () -> new ItemStackTab(
|
||||
ManualModel.LANGUAGE_KEY + "/block/index.md",
|
||||
Component.translatable("manual." + API.MOD_ID + ".blocks"),
|
||||
|
||||
@@ -15,17 +15,17 @@ public final class ModManualScreenStyle implements ManualScreenStyle {
|
||||
|
||||
@Override
|
||||
public ResourceLocation getWindowBackground() {
|
||||
return new ResourceLocation(API.MOD_ID, "textures/gui/manual/manual.png");
|
||||
return ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "textures/gui/manual/manual.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getScrollButtonTexture() {
|
||||
return new ResourceLocation(API.MOD_ID, "textures/gui/manual/scroll_button.png");
|
||||
return ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "textures/gui/manual/scroll_button.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getTabButtonTexture() {
|
||||
return new ResourceLocation(API.MOD_ID, "textures/gui/manual/tab_button.png");
|
||||
return ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "textures/gui/manual/tab_button.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,8 +15,8 @@ import java.util.function.Function;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
public final class BusCableModel implements IUnbakedGeometry<BusCableModel> {
|
||||
private static final ResourceLocation BUS_CABLE_STRAIGHT_MODEL = new ResourceLocation(API.MOD_ID, "block/cable_straight");
|
||||
private static final ResourceLocation BUS_CABLE_SUPPORT_MODEL = new ResourceLocation(API.MOD_ID, "block/cable_support");
|
||||
private static final ResourceLocation BUS_CABLE_STRAIGHT_MODEL = ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "block/cable_straight");
|
||||
private static final ResourceLocation BUS_CABLE_SUPPORT_MODEL = ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "block/cable_support");
|
||||
private final IUnbakedGeometry<?> proxy;
|
||||
|
||||
BusCableModel(final IUnbakedGeometry<?> proxy) {
|
||||
|
||||
@@ -17,11 +17,12 @@ import net.minecraftforge.fml.common.Mod;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Mod.EventBusSubscriber(value = Dist.CLIENT, modid = API.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public final class ModShaders {
|
||||
public static final int MAX_PROJECTORS = 3;
|
||||
|
||||
private static final ResourceLocation PROJECTORS_SHADER_LOCATION = new ResourceLocation(API.MOD_ID, "projectors");
|
||||
private static final ResourceLocation PROJECTORS_SHADER_LOCATION = ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "projectors");
|
||||
private static final String[] PROJECTOR_COLOR_NAMES = {"ProjectorColor0", "ProjectorColor1", "ProjectorColor2"};
|
||||
private static final String[] PROJECTOR_DEPTH_NAMES = {"ProjectorDepth0", "ProjectorDepth1", "ProjectorDepth2"};
|
||||
private static final String[] PROJECTOR_CAMERA_NAMES = {"ProjectorCamera0", "ProjectorCamera1", "ProjectorCamera2"};
|
||||
|
||||
@@ -148,7 +148,7 @@ public class MonitorGUIRenderer {
|
||||
RenderSystem.blendFunc(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE);
|
||||
|
||||
RenderSystem.colorMask(true, true, true, true);
|
||||
//RenderSystem.depthMask(false);
|
||||
RenderSystem.depthMask(false);
|
||||
|
||||
final ShaderInstance shader = GameRenderer.getPositionTexShader();
|
||||
|
||||
@@ -178,6 +178,8 @@ public class MonitorGUIRenderer {
|
||||
RenderSystem.restoreProjectionMatrix();
|
||||
RenderSystem.getModelViewStack().popPose();
|
||||
RenderSystem.applyModelViewMatrix();
|
||||
|
||||
RenderSystem.depthMask(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.inventory.InventoryMenu;
|
||||
|
||||
public final class ChargerRenderer implements BlockEntityRenderer<ChargerBlockEntity> {
|
||||
public static final ResourceLocation EFFECT_LOCATION = new ResourceLocation(API.MOD_ID, "block/charger/effect");
|
||||
public static final ResourceLocation EFFECT_LOCATION = ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "block/charger/effect");
|
||||
|
||||
private static final Material TEXTURE_EFFECT = new Material(InventoryMenu.BLOCK_ATLAS, EFFECT_LOCATION);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import li.cil.oc2.client.renderer.ModRenderType;
|
||||
import li.cil.oc2.common.block.ComputerBlock;
|
||||
import li.cil.oc2.common.blockentity.ComputerBlockEntity;
|
||||
import li.cil.oc2.common.util.ChainableVertexConsumer;
|
||||
import li.cil.oc2.common.vm.Terminal;
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
|
||||
@@ -39,11 +39,12 @@ import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Mod.EventBusSubscriber(value = Dist.CLIENT, modid = API.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)
|
||||
public final class ComputerRenderer implements BlockEntityRenderer<ComputerBlockEntity> {
|
||||
public static final ResourceLocation OVERLAY_POWER_LOCATION = new ResourceLocation(API.MOD_ID, "block/computer/computer_overlay_power");
|
||||
public static final ResourceLocation OVERLAY_STATUS_LOCATION = new ResourceLocation(API.MOD_ID, "block/computer/computer_overlay_status");
|
||||
public static final ResourceLocation OVERLAY_TERMINAL_LOCATION = new ResourceLocation(API.MOD_ID, "block/computer/computer_overlay_terminal");
|
||||
public static final ResourceLocation OVERLAY_POWER_LOCATION = ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "block/computer/computer_overlay_power");
|
||||
public static final ResourceLocation OVERLAY_STATUS_LOCATION = ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "block/computer/computer_overlay_status");
|
||||
public static final ResourceLocation OVERLAY_TERMINAL_LOCATION = ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "block/computer/computer_overlay_terminal");
|
||||
|
||||
private static final Material TEXTURE_POWER = new Material(InventoryMenu.BLOCK_ATLAS, OVERLAY_POWER_LOCATION);
|
||||
private static final Material TEXTURE_STATUS = new Material(InventoryMenu.BLOCK_ATLAS, OVERLAY_STATUS_LOCATION);
|
||||
@@ -206,25 +207,25 @@ public final class ComputerRenderer implements BlockEntityRenderer<ComputerBlock
|
||||
final List<FormattedText> wrappedText = fontRenderer.getSplitter().splitLines(text, maxWidth, Style.EMPTY);
|
||||
if (wrappedText.size() == 1) {
|
||||
final int textWidth = fontRenderer.width(text);
|
||||
draw(fontRenderer, stack, text, (maxWidth - textWidth) * 0.5f, 0, 0xEE3322);
|
||||
draw(fontRenderer, stack, text, (maxWidth - textWidth) * 0.5f);
|
||||
} else {
|
||||
for (int i = 0; i < wrappedText.size(); i++) {
|
||||
draw(fontRenderer, stack, wrappedText.get(i).getString(), 0, i * fontRenderer.lineHeight, 0xEE3322);
|
||||
draw(fontRenderer, stack, wrappedText.get(i).getString(), i * fontRenderer.lineHeight);
|
||||
}
|
||||
}
|
||||
|
||||
stack.popPose();
|
||||
}
|
||||
|
||||
private void draw(Font font, PoseStack stack, Component text, float x, float y, int color) {
|
||||
private void draw(Font font, PoseStack stack, Component text, float x) {
|
||||
var batch = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
|
||||
font.drawInBatch(text, x, y, color, false, stack.last().pose(), batch, Font.DisplayMode.NORMAL, 0, 15728880);
|
||||
font.drawInBatch(text, x, (float) 0, 15610658, false, stack.last().pose(), batch, Font.DisplayMode.NORMAL, 0, 15728880);
|
||||
batch.endBatch();
|
||||
}
|
||||
|
||||
private void draw(Font font, PoseStack stack, String text, float x, float y, int color) {
|
||||
private void draw(Font font, PoseStack stack, String text, float y) {
|
||||
var batch = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
|
||||
font.drawInBatch(text, x, y, color, false, stack.last().pose(), batch, Font.DisplayMode.NORMAL, 0, 15728880, false);
|
||||
font.drawInBatch(text, (float) 0, y, 15610658, false, stack.last().pose(), batch, Font.DisplayMode.NORMAL, 0, 15728880, false);
|
||||
batch.endBatch();
|
||||
}
|
||||
|
||||
|
||||
@@ -41,10 +41,11 @@ import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Mod.EventBusSubscriber(value = Dist.CLIENT, modid = API.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)
|
||||
public final class MonitorRenderer implements BlockEntityRenderer<MonitorBlockEntity> {
|
||||
public static final ResourceLocation OVERLAY_POWER_LOCATION = new ResourceLocation(API.MOD_ID, "block/monitor/monitor_overlay_power");
|
||||
public static final ResourceLocation OVERLAY_TERMINAL_LOCATION = new ResourceLocation(API.MOD_ID, "block/computer/computer_overlay_terminal");
|
||||
public static final ResourceLocation OVERLAY_POWER_LOCATION = ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "block/monitor/monitor_overlay_power");
|
||||
public static final ResourceLocation OVERLAY_TERMINAL_LOCATION = ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "block/computer/computer_overlay_terminal");
|
||||
|
||||
private static final Material TEXTURE_POWER = new Material(InventoryMenu.BLOCK_ATLAS, OVERLAY_POWER_LOCATION);
|
||||
private static final Material TEXTURE_TERMINAL = new Material(InventoryMenu.BLOCK_ATLAS, OVERLAY_TERMINAL_LOCATION);
|
||||
@@ -180,25 +181,25 @@ public final class MonitorRenderer implements BlockEntityRenderer<MonitorBlockEn
|
||||
final List<FormattedText> wrappedText = fontRenderer.getSplitter().splitLines(text, maxWidth, Style.EMPTY);
|
||||
if (wrappedText.size() == 1) {
|
||||
final int textWidth = fontRenderer.width(text);
|
||||
draw(fontRenderer, stack, text, (maxWidth - textWidth) * 0.5f, 0, 0xEE3322);
|
||||
draw(fontRenderer, stack, text, (maxWidth - textWidth) * 0.5f);
|
||||
} else {
|
||||
for (int i = 0; i < wrappedText.size(); i++) {
|
||||
draw(fontRenderer, stack, wrappedText.get(i).getString(), 0, i * fontRenderer.lineHeight, 0xEE3322);
|
||||
draw(fontRenderer, stack, wrappedText.get(i).getString(), i * fontRenderer.lineHeight);
|
||||
}
|
||||
}
|
||||
|
||||
stack.popPose();
|
||||
}
|
||||
|
||||
private void draw(Font font, PoseStack stack, Component text, float x, float y, int color) {
|
||||
private void draw(Font font, PoseStack stack, Component text, float x) {
|
||||
var batch = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
|
||||
font.drawInBatch(text, x, y, color, false, stack.last().pose(), batch, Font.DisplayMode.NORMAL, 0, 15728880);
|
||||
font.drawInBatch(text, x, (float) 0, 15610658, false, stack.last().pose(), batch, Font.DisplayMode.NORMAL, 0, 15728880);
|
||||
batch.endBatch();
|
||||
}
|
||||
|
||||
private void draw(Font font, PoseStack stack, String text, float x, float y, int color) {
|
||||
private void draw(Font font, PoseStack stack, String text, float y) {
|
||||
var batch = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
|
||||
font.drawInBatch(text, x, y, color, false, stack.last().pose(), batch, Font.DisplayMode.NORMAL, 0, 15728880, false);
|
||||
font.drawInBatch(text, (float) 0, y, 15610658, false, stack.last().pose(), batch, Font.DisplayMode.NORMAL, 0, 15728880, false);
|
||||
batch.endBatch();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.common.util.TransformationHelper;
|
||||
|
||||
public final class RobotModel extends EntityModel<Robot> {
|
||||
public static final ModelLayerLocation ROBOT_MODEL_LAYER = new ModelLayerLocation(new ResourceLocation(API.MOD_ID, "robot"), "main");
|
||||
public static final ResourceLocation ROBOT_ENTITY_TEXTURE = new ResourceLocation(API.MOD_ID, "textures/entity/robot/robot.png");
|
||||
public static final ModelLayerLocation ROBOT_MODEL_LAYER = new ModelLayerLocation(ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "robot"), "main");
|
||||
public static final ResourceLocation ROBOT_ENTITY_TEXTURE = ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "textures/entity/robot/robot.png");
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import net.minecraft.resources.ResourceLocation;
|
||||
public final class MonospaceFontRenderer extends BitmapFontRenderer {
|
||||
public static final FontRenderer INSTANCE = new MonospaceFontRenderer();
|
||||
|
||||
private static final ResourceLocation LOCATION_FONT_TEXTURE = new ResourceLocation(API.MOD_ID, "textures/font/monospace.png");
|
||||
private static final ResourceLocation LOCATION_FONT_TEXTURE = ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "textures/font/monospace.png");
|
||||
private static final String CHARS = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,11 +6,11 @@ import li.cil.oc2.api.API;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.config.IConfigSpec;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
import net.minecraftforge.fml.event.config.ModConfigEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -28,6 +28,7 @@ import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Mod.EventBusSubscriber(modid = API.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public final class ConfigManager {
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@@ -68,7 +69,6 @@ public final class ConfigManager {
|
||||
PARSERS.put(short.class, ConfigManager::parseShortField);
|
||||
PARSERS.put(long.class, ConfigManager::parseLongField);
|
||||
PARSERS.put(double.class, ConfigManager::parseDoubleField);
|
||||
PARSERS.put(boolean.class, ConfigManager::parseBooleanField);
|
||||
PARSERS.put(String.class, ConfigManager::parseStringField);
|
||||
PARSERS.put(UUID.class, ConfigManager::parseUUIDField);
|
||||
PARSERS.put(ResourceLocation.class, ConfigManager::parseResourceLocationField);
|
||||
@@ -87,11 +87,11 @@ public final class ConfigManager {
|
||||
CONFIGS.put(config.getValue(), new ConfigDefinition(config.getKey(), values));
|
||||
}
|
||||
|
||||
public static void initialize() {
|
||||
public static void initialize(FMLJavaModLoadingContext context) {
|
||||
CONFIGS.forEach((spec, config) -> {
|
||||
final Type typeAnnotation = config.instance.getClass().getAnnotation(Type.class);
|
||||
final ModConfig.Type configType = typeAnnotation != null ? typeAnnotation.value() : ModConfig.Type.COMMON;
|
||||
ModLoadingContext.get().registerConfig(configType, spec);
|
||||
context.registerConfig(configType, spec);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ public final class ConfigManager {
|
||||
|
||||
final ForgeConfigSpec.ConfigValue<String> configValue = builder.define(path, defaultValue.toString());
|
||||
|
||||
return new ConfigFieldPair<>(field, configValue, ResourceLocation::new);
|
||||
return new ConfigFieldPair<>(field, configValue, ResourceLocation::parse);
|
||||
}
|
||||
|
||||
private static String getPath(@Nullable final String prefix, final Field field) {
|
||||
|
||||
@@ -32,41 +32,41 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
@Mod(API.MOD_ID)
|
||||
public final class Main {
|
||||
public Main() {
|
||||
EventBuses.registerModEventBus(API.MOD_ID, FMLJavaModLoadingContext.get().getModEventBus());
|
||||
public Main(FMLJavaModLoadingContext context) {
|
||||
EventBuses.registerModEventBus(API.MOD_ID, context.getModEventBus());
|
||||
Ceres.initialize();
|
||||
Sedna.initialize();
|
||||
DeviceTreeProviders.initialize();
|
||||
Serializers.initialize();
|
||||
|
||||
ConfigManager.add(Config::new);
|
||||
ConfigManager.initialize();
|
||||
ConfigManager.initialize(context);
|
||||
|
||||
RegistryUtils.begin();
|
||||
|
||||
ItemTags.initialize();
|
||||
BlockTags.initialize();
|
||||
Blocks.initialize();
|
||||
Items.initialize();
|
||||
BlockEntities.initialize();
|
||||
Entities.initialize();
|
||||
Containers.initialize();
|
||||
RecipeSerializers.initialize();
|
||||
SoundEvents.initialize();
|
||||
Blocks.initialize(context);
|
||||
Items.initialize(context);
|
||||
BlockEntities.initialize(context);
|
||||
Entities.initialize(context);
|
||||
Containers.initialize(context);
|
||||
RecipeSerializers.initialize(context);
|
||||
SoundEvents.initialize(context);
|
||||
|
||||
ProviderRegistry.initialize();
|
||||
DeviceTypes.initialize();
|
||||
ProviderRegistry.initialize(context);
|
||||
DeviceTypes.initialize(context);
|
||||
|
||||
BlockDeviceDataRegistry.initialize();
|
||||
FirmwareRegistry.initialize();
|
||||
BlockDeviceDataRegistry.initialize(context);
|
||||
FirmwareRegistry.initialize(context);
|
||||
|
||||
RegistryUtils.finish();
|
||||
RegistryUtils.finish(context);
|
||||
|
||||
FMLJavaModLoadingContext.get().getModEventBus().register(CommonSetup.class);
|
||||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> Manuals::initialize);
|
||||
context.getModEventBus().register(CommonSetup.class);
|
||||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> Manuals.initialize(context));
|
||||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () ->
|
||||
FMLJavaModLoadingContext.get().getModEventBus().register(ClientSetup.class));
|
||||
context.getModEventBus().register(ClientSetup.class));
|
||||
|
||||
ItemGroup.TAB_REGISTER.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
ItemGroup.TAB_REGISTER.register(context.getModEventBus());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public final class Blocks {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void initialize() {
|
||||
BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
public static void initialize(FMLJavaModLoadingContext context) {
|
||||
BLOCKS.register(context.getModEventBus());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,19 @@ public final class DiskDriveBlock extends HorizontalDirectionalBlock implements
|
||||
return super.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerWillDestroy(final Level level, final BlockPos pos, final BlockState state, final Player player) {
|
||||
final BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||
if (!level.isClientSide() && blockEntity instanceof final DiskDriveBlockEntity diskDrive) {
|
||||
if (!diskDrive.getDiskItemStack().isEmpty()) {
|
||||
final ItemStack stack = diskDrive.getDiskItemStack();
|
||||
popResource(level, pos, stack);
|
||||
}
|
||||
}
|
||||
|
||||
super.playerWillDestroy(level, pos, state, player);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public InteractionResult use(final BlockState state, final Level level, final BlockPos pos, final Player player, final InteractionHand hand, final BlockHitResult hit) {
|
||||
|
||||
@@ -69,6 +69,19 @@ public final class FlashMemoryFlasherBlock extends HorizontalDirectionalBlock im
|
||||
return super.use(state, level, pos, player, hand, hit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerWillDestroy(final Level level, final BlockPos pos, final BlockState state, final Player player) {
|
||||
final BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||
if (!level.isClientSide() && blockEntity instanceof final FlashMemoryFlasherBlockEntity flashFlasher) {
|
||||
if (!flashFlasher.getDiskItemStack().isEmpty()) {
|
||||
final ItemStack stack = flashFlasher.getDiskItemStack();
|
||||
popResource(level, pos, stack);
|
||||
}
|
||||
}
|
||||
|
||||
super.playerWillDestroy(level, pos, state, player);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// EntityBlock
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ public final class RedstoneInterfaceBlock extends HorizontalDirectionalBlock imp
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"deprecation", "DataFlowIssue"})
|
||||
public void neighborChanged(BlockState state, Level worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) {
|
||||
RedstoneInterfaceBlockEntity ribe = (RedstoneInterfaceBlockEntity) worldIn.getBlockEntity(pos);
|
||||
ribe.neighborChanged(fromPos);
|
||||
|
||||
@@ -37,8 +37,8 @@ public final class BlockEntities {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void initialize() {
|
||||
BLOCK_ENTITIES.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
public static void initialize(FMLJavaModLoadingContext context) {
|
||||
BLOCK_ENTITIES.register(context.getModEventBus());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -26,6 +26,7 @@ import li.cil.oc2.common.network.message.ComputerTerminalOutputMessage;
|
||||
import li.cil.oc2.common.serialization.NBTSerialization;
|
||||
import li.cil.oc2.common.util.*;
|
||||
import li.cil.oc2.common.vm.*;
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
@@ -15,7 +15,6 @@ import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import java.util.Collection;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import java.util.*;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -24,6 +23,7 @@ import com.google.gson.JsonObject;
|
||||
import li.cil.oc2.api.bus.device.rpc.*;
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class RedstoneInterfaceBlockEntity extends ModBlockEntity implements NamedDevice, DocumentedDevice, RPCEventSource {
|
||||
private static final String OUTPUT_TAG_NAME = "output";
|
||||
private static final String BUNDLED_TAG_NAME = "bundled";
|
||||
@@ -40,7 +40,7 @@ public final class RedstoneInterfaceBlockEntity extends ModBlockEntity implement
|
||||
private static final String VALUES = "values";
|
||||
private static final String COLOUR = "colour";
|
||||
|
||||
private final HashMap<IEventSink, UUID> subscribers = new HashMap();
|
||||
private final HashMap<IEventSink, UUID> subscribers = new HashMap<>();
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -298,7 +298,7 @@ public final class RedstoneInterfaceBlockEntity extends ModBlockEntity implement
|
||||
}
|
||||
|
||||
public void neighborChanged(BlockPos fromPos) {
|
||||
int sl = 0;
|
||||
int sl;
|
||||
if (level == null) {
|
||||
return;
|
||||
}
|
||||
@@ -310,9 +310,10 @@ public final class RedstoneInterfaceBlockEntity extends ModBlockEntity implement
|
||||
final ChunkPos chunkPos = new ChunkPos(fromPos);
|
||||
if (!level.hasChunk(chunkPos.x, chunkPos.z)) {
|
||||
sl = 0;
|
||||
} else {
|
||||
sl = level.getSignal(fromPos, direction);
|
||||
}
|
||||
|
||||
sl = level.getSignal(fromPos, direction);
|
||||
JsonObject msg = new JsonObject();
|
||||
msg.addProperty("event", "redstone");
|
||||
msg.addProperty("side", ""+direction);
|
||||
|
||||
@@ -163,7 +163,7 @@ public abstract class AbstractBlockDeviceBusElement extends AbstractGroupingDevi
|
||||
super.onEntryRemoved(dataKey, tag, query);
|
||||
assert query != null : "Passed null query for block device bus element.";
|
||||
final IForgeRegistry<BlockDeviceProvider> registry = Providers.blockDeviceProviderRegistry();
|
||||
final BlockDeviceProvider provider = registry.getValue(new ResourceLocation(dataKey));
|
||||
final BlockDeviceProvider provider = registry.getValue(ResourceLocation.parse(dataKey));
|
||||
if (provider != null) {
|
||||
provider.unmount(query, tag);
|
||||
}
|
||||
|
||||
@@ -85,6 +85,7 @@ public abstract class AbstractItemDeviceBusElement extends AbstractGroupingDevic
|
||||
return new ItemQueryResult(query, entries);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantValue")
|
||||
protected void collectSyntheticDevices(final ItemDeviceQuery query, final HashSet<ItemEntry> entries) {
|
||||
if (entries.isEmpty()) {
|
||||
return;
|
||||
@@ -99,7 +100,7 @@ public abstract class AbstractItemDeviceBusElement extends AbstractGroupingDevic
|
||||
protected void onEntryRemoved(final String dataKey, final CompoundTag tag, @Nullable final ItemDeviceQuery query) {
|
||||
super.onEntryRemoved(dataKey, tag, query);
|
||||
final IForgeRegistry<ItemDeviceProvider> registry = Providers.itemDeviceProviderRegistry();
|
||||
final ItemDeviceProvider provider = registry.getValue(new ResourceLocation(dataKey));
|
||||
final ItemDeviceProvider provider = registry.getValue(ResourceLocation.parse(dataKey));
|
||||
if (provider != null) {
|
||||
provider.unmount(query, tag);
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ public final class DeviceTypes {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void initialize() {
|
||||
DEVICE_TYPES.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
public static void initialize(FMLJavaModLoadingContext context) {
|
||||
DEVICE_TYPES.register(context.getModEventBus());
|
||||
|
||||
register(ItemTags.DEVICES_MEMORY);
|
||||
register(ItemTags.DEVICES_HARD_DRIVE);
|
||||
@@ -47,7 +47,7 @@ public final class DeviceTypes {
|
||||
final String id = tag.location().getPath().replaceFirst("^devices/", "");
|
||||
DEVICE_TYPES.register(id, () -> new DeviceTypeImpl(
|
||||
tag,
|
||||
new ResourceLocation(API.MOD_ID, "item/" + id + "_slot"),
|
||||
ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "item/" + id + "_slot"),
|
||||
text("gui.{mod}.device_type." + id)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import javax.annotation.Nullable;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class BlockDeviceDataRegistry {
|
||||
private static final DeferredRegister<BlockDeviceData> INITIALIZER = DeferredRegister.create(Registries.BLOCK_DEVICE_DATA, API.MOD_ID);
|
||||
|
||||
@@ -29,8 +30,8 @@ public final class BlockDeviceDataRegistry {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void initialize() {
|
||||
INITIALIZER.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
public static void initialize(FMLJavaModLoadingContext context) {
|
||||
INITIALIZER.register(context.getModEventBus());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -23,6 +23,7 @@ import net.minecraftforge.fml.common.Mod;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.*;
|
||||
@@ -31,6 +32,7 @@ import java.util.concurrent.Executor;
|
||||
|
||||
import static li.cil.oc2.common.util.TextFormatUtils.formatSize;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Mod.EventBusSubscriber(modid = API.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)
|
||||
public final class FileSystems {
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
@@ -50,6 +52,7 @@ public final class FileSystems {
|
||||
return blocksByName.get(name);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ResourceLocation getKeyByValue(BlockDeviceData value) {
|
||||
for (Map.Entry<ResourceLocation, BlockDeviceData> entry : BLOCK_DEVICE_DATA.entrySet()) {
|
||||
if (Objects.equals(value, entry.getValue())) {
|
||||
@@ -109,7 +112,7 @@ public final class FileSystems {
|
||||
final String type = json.getAsJsonPrimitive("type").getAsString();
|
||||
switch (type) {
|
||||
case "layer" -> {
|
||||
final ResourceLocation location = new ResourceLocation(json.getAsJsonPrimitive("location").getAsString());
|
||||
final ResourceLocation location = ResourceLocation.parse(json.getAsJsonPrimitive("location").getAsString());
|
||||
|
||||
final ZipStreamFileSystem fileSystem;
|
||||
try (final InputStream stream = resourceManager.getResource(location).get().open()) {
|
||||
@@ -132,7 +135,7 @@ public final class FileSystems {
|
||||
}
|
||||
}
|
||||
case "block" -> {
|
||||
final ResourceLocation location = new ResourceLocation(json.getAsJsonPrimitive("location").getAsString());
|
||||
final ResourceLocation location = ResourceLocation.parse(json.getAsJsonPrimitive("location").getAsString());
|
||||
if (BlockDeviceDataRegistry.getValue(location) != null) {
|
||||
LOGGER.error("Block device from datapack collides with already registered location [{}].", location);
|
||||
continue;
|
||||
|
||||
@@ -29,11 +29,11 @@ public final class FirmwareRegistry {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void initialize() {
|
||||
INITIALIZER.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
public static void initialize(FMLJavaModLoadingContext context) {
|
||||
INITIALIZER.register(context.getModEventBus());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@SuppressWarnings("unused")
|
||||
public static ResourceLocation getKey(final Firmware firmware) {
|
||||
return INITIALIZER.getRegistryName();
|
||||
}
|
||||
|
||||
@@ -27,9 +27,9 @@ public final class ProviderRegistry {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void initialize() {
|
||||
ITEM_DEVICE_PROVIDERS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
BLOCK_DEVICE_PROVIDERS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
public static void initialize(FMLJavaModLoadingContext context) {
|
||||
ITEM_DEVICE_PROVIDERS.register(context.getModEventBus());
|
||||
BLOCK_DEVICE_PROVIDERS.register(context.getModEventBus());
|
||||
|
||||
ITEM_DEVICE_PROVIDERS.register("memory", MemoryItemDeviceProvider::new);
|
||||
ITEM_DEVICE_PROVIDERS.register("hard_drive", HardDriveItemDeviceProvider::new);
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class SoundCardItemDevice extends AbstractItemRPCDevice {
|
||||
private final int COOLDOWN_IN_TICKS = TickUtils.toTicks(Duration.ofSeconds(Config.soundCardCoolDownSeconds));
|
||||
private static final int MAX_FIND_RESULTS = 25;
|
||||
@@ -68,7 +69,7 @@ public final class SoundCardItemDevice extends AbstractItemRPCDevice {
|
||||
|
||||
gameTimeCooldownExpiresAt = gameTime + COOLDOWN_IN_TICKS;
|
||||
|
||||
final SoundEvent soundEvent = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(name));
|
||||
final SoundEvent soundEvent = ForgeRegistries.SOUND_EVENTS.getValue(ResourceLocation.parse(name));
|
||||
if (soundEvent == null) throw new IllegalArgumentException("Sound not found.");
|
||||
level.playSound(null, location.blockPos(), soundEvent, SoundSource.BLOCKS, volume, pitch);
|
||||
}));
|
||||
@@ -76,7 +77,7 @@ public final class SoundCardItemDevice extends AbstractItemRPCDevice {
|
||||
|
||||
@Callback
|
||||
public List<String> findSound(@Nullable @Parameter("name") final String name) {
|
||||
if (name == null || name.length() == 0) throw new IllegalArgumentException();
|
||||
if (name == null || name.isEmpty()) throw new IllegalArgumentException();
|
||||
|
||||
final ArrayList<String> matches = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import li.cil.oc2.common.network.message.ComputerPowerMessage;
|
||||
import li.cil.oc2.common.network.message.ComputerTerminalInputMessage;
|
||||
import li.cil.oc2.common.network.message.OpenComputerInventoryMessage;
|
||||
import li.cil.oc2.common.network.message.OpenComputerTerminalMessage;
|
||||
import li.cil.oc2.common.vm.Terminal;
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
import li.cil.oc2.common.vm.VirtualMachine;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.ContainerLevelAccess;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
package li.cil.oc2.common.container;
|
||||
|
||||
import li.cil.oc2.common.vm.Terminal;
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@@ -10,7 +10,7 @@ import li.cil.oc2.common.network.message.OpenRobotInventoryMessage;
|
||||
import li.cil.oc2.common.network.message.OpenRobotTerminalMessage;
|
||||
import li.cil.oc2.common.network.message.RobotPowerMessage;
|
||||
import li.cil.oc2.common.network.message.RobotTerminalInputMessage;
|
||||
import li.cil.oc2.common.vm.Terminal;
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
import li.cil.oc2.common.vm.VirtualMachine;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
|
||||
@@ -24,7 +24,7 @@ public final class Containers {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void initialize() {
|
||||
CONTAINERS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
public static void initialize(FMLJavaModLoadingContext context) {
|
||||
CONTAINERS.register(context.getModEventBus());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,12 +22,13 @@ public final class Entities {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void initialize() {
|
||||
ENTITIES.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
public static void initialize(FMLJavaModLoadingContext context) {
|
||||
ENTITIES.register(context.getModEventBus());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private static <T extends Entity> RegistryObject<EntityType<T>> register(final String name, final EntityType.EntityFactory<T> factory, final MobCategory classification, final Function<EntityType.Builder<T>, EntityType.Builder<T>> customizer) {
|
||||
return ENTITIES.register(name, () -> customizer.apply(EntityType.Builder.of(factory, classification)).build(name));
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import li.cil.oc2.common.util.NBTTagIds;
|
||||
import li.cil.oc2.common.util.NBTUtils;
|
||||
import li.cil.oc2.common.util.TerminalUtils;
|
||||
import li.cil.oc2.common.vm.*;
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Cursor3D;
|
||||
import net.minecraft.core.Direction;
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
package li.cil.oc2.common.integration;
|
||||
|
||||
import dev.architectury.platform.forge.EventBuses;
|
||||
import li.cil.oc2.api.API;
|
||||
import li.cil.oc2.api.imc.RPCMethodParameterTypeAdapter;
|
||||
import li.cil.oc2.common.bus.device.rpc.RPCMethodParameterTypeAdapters;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraftforge.fml.InterModComms;
|
||||
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -30,7 +30,7 @@ public final class IMC {
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void initialize() {
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(IMC::handleIMCMessages);
|
||||
EventBuses.getModEventBus(API.MOD_ID).get().addListener(IMC::handleIMCMessages);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -56,7 +56,7 @@ public final class IMC {
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({"unchecked", "SameParameterValue"})
|
||||
private static <T> Optional<T> getMessageParameter(final InterModComms.IMCMessage message, final Class<T> type) {
|
||||
final Object value = message.messageSupplier().get();
|
||||
if (type.isInstance(value)) {
|
||||
|
||||
@@ -20,10 +20,11 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
@JeiPlugin
|
||||
@SuppressWarnings("unused")
|
||||
public class ExtraGuiAreasJEIPlugin implements IModPlugin {
|
||||
@Override
|
||||
public ResourceLocation getPluginUid() {
|
||||
return new ResourceLocation(API.MOD_ID, "extra_gui_areas");
|
||||
return ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "extra_gui_areas");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,17 +27,17 @@ import static li.cil.oc2.common.Constants.BLOCK_ENTITY_TAG_NAME_IN_ITEM;
|
||||
import static li.cil.oc2.common.Constants.ITEMS_TAG_NAME;
|
||||
|
||||
@JeiPlugin
|
||||
@SuppressWarnings("unused")
|
||||
public class ExtraItemsJEIPlugin implements IModPlugin {
|
||||
@Override
|
||||
public ResourceLocation getPluginUid() {
|
||||
return new ResourceLocation(API.MOD_ID, "extra_items");
|
||||
return ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "extra_items");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerItemSubtypes(final ISubtypeRegistration registration) {
|
||||
registration.registerSubtypeInterpreter(VanillaTypes.ITEM_STACK, Items.COMPUTER.get(), new ComputerSubtypeInterpreter());
|
||||
registration.registerSubtypeInterpreter(VanillaTypes.ITEM_STACK, Items.ROBOT.get(), new RobotSubtypeInterpreter());
|
||||
registration.registerSubtypeInterpreter(VanillaTypes.ITEM_STACK, Items.HARD_DRIVE_CUSTOM.get(), new BlockDeviceSubtypeInterpreter());
|
||||
registration.registerSubtypeInterpreter(VanillaTypes.ITEM_STACK, Items.FLASH_MEMORY_CUSTOM.get(), new BlockDeviceSubtypeInterpreter());
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public abstract class AbstractBlockDeviceItem extends ModItem {
|
||||
ResourceLocation location = defaultData;
|
||||
if (!StringUtil.isNullOrEmpty(registryName)) {
|
||||
try {
|
||||
location = new ResourceLocation(registryName);
|
||||
location = ResourceLocation.parse(registryName);
|
||||
} catch (final ResourceLocationException ignored) {
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,7 @@ public abstract class AbstractBlockDeviceItem extends ModItem {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public ItemStack withData(final BlockDeviceData data) {
|
||||
return withData(new ItemStack(this), data);
|
||||
}
|
||||
@@ -87,6 +88,7 @@ public abstract class AbstractBlockDeviceItem extends ModItem {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected ResourceLocation getDefaultData() {
|
||||
return defaultData;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public final class FlashMemoryWithExternalDataItem extends ModItem {
|
||||
ResourceLocation location = defaultData;
|
||||
if (!StringUtil.isNullOrEmpty(registryName)) {
|
||||
try {
|
||||
location = new ResourceLocation(registryName);
|
||||
location = ResourceLocation.parse(registryName);
|
||||
} catch (final ResourceLocationException ignored) {
|
||||
}
|
||||
}
|
||||
@@ -56,15 +56,13 @@ public final class FlashMemoryWithExternalDataItem extends ModItem {
|
||||
}
|
||||
|
||||
final ResourceLocation key = FirmwareRegistry.getKey(firmware);
|
||||
if (key == null) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
ItemStackUtils.getOrCreateModDataTag(stack).putString(FIRMWARE_TAG_NAME, key.toString());
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public ItemStack withFirmware(final Firmware firmware) {
|
||||
return withFirmware(new ItemStack(this), firmware);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public final class HardDriveItem extends AbstractStorageItem implements DyeableL
|
||||
@Override
|
||||
protected String getOrCreateDescriptionId() {
|
||||
if (descriptionId == null) {
|
||||
descriptionId = Util.makeDescriptionId("item", new ResourceLocation(API.MOD_ID, "hard_drive"));
|
||||
descriptionId = Util.makeDescriptionId("item", ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "hard_drive"));
|
||||
}
|
||||
return descriptionId;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public final class HardDriveWithExternalDataItem extends AbstractBlockDeviceItem
|
||||
@Override
|
||||
protected String getOrCreateDescriptionId() {
|
||||
if (descriptionId == null) {
|
||||
descriptionId = Util.makeDescriptionId("item", new ResourceLocation(API.MOD_ID, "hard_drive"));
|
||||
descriptionId = Util.makeDescriptionId("item", ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "hard_drive"));
|
||||
}
|
||||
return descriptionId;
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ public final class ItemGroup {
|
||||
output.accept(Items.CPU_TIER_2.get());
|
||||
output.accept(Items.CPU_TIER_3.get());
|
||||
output.accept(Items.CPU_TIER_4.get());
|
||||
output.accept(Items.CPU_TIER_INF.get());
|
||||
output.accept(Items.FLASH_MEMORY.get());
|
||||
output.accept(Items.FLASH_MEMORY_CUSTOM.get());
|
||||
output.accept(Items.FLOPPY.get());
|
||||
|
||||
@@ -13,11 +13,11 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class ItemRenameHandler {
|
||||
private static final Map<String, Supplier<Item>> RENAMES = Util.make(() -> {
|
||||
final Map<String, Supplier<Item>> map = new HashMap<>();
|
||||
|
||||
map.put("hard_drive_buildroot", Items.HARD_DRIVE_CUSTOM::get);
|
||||
map.put("flash_memory_buildroot", Items.FLASH_MEMORY_CUSTOM::get);
|
||||
|
||||
return map;
|
||||
@@ -28,6 +28,7 @@ public final class ItemRenameHandler {
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@SubscribeEvent
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
private static void handleMissingMappings(final MissingMappingsEvent event) {
|
||||
|
||||
for (final MissingMappingsEvent.Mapping mapping : event.getAllMappings(ResourceKey.createRegistryKey(event.getKey().location()))) {
|
||||
|
||||
@@ -14,11 +14,11 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import li.cil.oc2.common.bus.device.data.FileSystems;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Items {
|
||||
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, API.MOD_ID);
|
||||
|
||||
@@ -67,9 +67,6 @@ public final class Items {
|
||||
new HardDriveItem(4 * Config.diskSizeFactor, DyeColor.CYAN));
|
||||
public static final RegistryObject<HardDriveItem> HARD_DRIVE_EXTRA_LARGE = register("hard_drive_extra_large", () ->
|
||||
new HardDriveItem(16 * Config.diskSizeFactor, DyeColor.YELLOW));
|
||||
public static final RegistryObject<HardDriveWithExternalDataItem> HARD_DRIVE_CUSTOM = register
|
||||
("hard_drive_custom", () ->
|
||||
new HardDriveWithExternalDataItem(FileSystems.getKeyByValue(FileSystems.getBlockByName("rootfs")), DyeColor.BROWN));
|
||||
|
||||
public static final RegistryObject<CPUItem> CPU_TIER_1 = register("cpu_tier_1", () ->
|
||||
new CPUItem(25_000_000));
|
||||
@@ -79,6 +76,8 @@ public final class Items {
|
||||
new CPUItem(100_000_000));
|
||||
public static final RegistryObject<CPUItem> CPU_TIER_4 = register("cpu_tier_4", () ->
|
||||
new CPUItem(200_000_000));
|
||||
public static final RegistryObject<CPUItem> CPU_TIER_INF = register("cpu_tier_inf", () ->
|
||||
new CPUItem(1_000_000_000));
|
||||
public static final RegistryObject<FlashMemoryItem> FLASH_MEMORY = register("flash_memory", () ->
|
||||
new FlashMemoryItem(12 * Constants.MEGABYTE));
|
||||
public static final RegistryObject<FlashMemoryWithExternalDataItem> FLASH_MEMORY_CUSTOM = register("flash_memory_custom", () ->
|
||||
@@ -109,8 +108,8 @@ public final class Items {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void initialize() {
|
||||
ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
public static void initialize(FMLJavaModLoadingContext context) {
|
||||
ITEMS.register(context.getModEventBus());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -22,7 +22,7 @@ public final class MemoryItem extends AbstractStorageItem {
|
||||
@Override
|
||||
protected String getOrCreateDescriptionId() {
|
||||
if (descriptionId == null) {
|
||||
descriptionId = Util.makeDescriptionId("item", new ResourceLocation(API.MOD_ID, "memory"));
|
||||
descriptionId = Util.makeDescriptionId("item", ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "memory"));
|
||||
}
|
||||
return descriptionId;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public final class RecipeSerializers {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void initialize() {
|
||||
RECIPE_SERIALIZERS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
public static void initialize(FMLJavaModLoadingContext context) {
|
||||
RECIPE_SERIALIZERS.register(context.getModEventBus());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public final class Network {
|
||||
private static final String PROTOCOL_VERSION = "1";
|
||||
|
||||
public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(
|
||||
new ResourceLocation(API.MOD_ID, "main"),
|
||||
ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "main"),
|
||||
() -> PROTOCOL_VERSION,
|
||||
PROTOCOL_VERSION::equals,
|
||||
PROTOCOL_VERSION::equals
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package li.cil.oc2.common.serialization.ceres;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import li.cil.ceres.api.DeserializationVisitor;
|
||||
import li.cil.ceres.api.SerializationException;
|
||||
import li.cil.ceres.api.SerializationVisitor;
|
||||
import li.cil.ceres.api.Serializer;
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ColorDataSerializer implements Serializer<Terminal.ColorData> {
|
||||
@Override
|
||||
public void serialize(final SerializationVisitor serializationVisitor, final Class<Terminal.ColorData> aClass, final Object o) throws SerializationException {
|
||||
final String json = new Gson().toJson(o);
|
||||
serializationVisitor.putObject("value", String.class, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal.ColorData deserialize(final DeserializationVisitor deserializationVisitor, final Class<Terminal.ColorData> aClass, @Nullable final Object o) throws SerializationException {
|
||||
if (!deserializationVisitor.exists("value")) {
|
||||
return new Terminal.ColorData();
|
||||
}
|
||||
|
||||
final String json = (String) deserializationVisitor.getObject("value", String.class, null);
|
||||
if (json == null) {
|
||||
return new Terminal.ColorData();
|
||||
}
|
||||
|
||||
return new Gson().fromJson(json, Terminal.ColorData.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package li.cil.oc2.common.serialization.ceres;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import li.cil.ceres.api.DeserializationVisitor;
|
||||
import li.cil.ceres.api.SerializationException;
|
||||
import li.cil.ceres.api.SerializationVisitor;
|
||||
import li.cil.ceres.api.Serializer;
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ColorModeSerializer implements Serializer<Terminal.ColorMode> {
|
||||
|
||||
@Override
|
||||
public void serialize(final SerializationVisitor serializationVisitor, final Class<Terminal.ColorMode> aClass, final Object o) throws SerializationException {
|
||||
final String json = new Gson().toJson(o);
|
||||
serializationVisitor.putObject("value", String.class, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal.ColorMode deserialize(final DeserializationVisitor deserializationVisitor, final Class<Terminal.ColorMode> aClass, @Nullable final Object value) throws SerializationException {
|
||||
if (!deserializationVisitor.exists("value")) {
|
||||
return Terminal.ColorMode.SIXTEEN_COLOR;
|
||||
}
|
||||
|
||||
final String json = (String) deserializationVisitor.getObject("value", String.class, null);
|
||||
if (json == null) {
|
||||
return Terminal.ColorMode.SIXTEEN_COLOR;
|
||||
}
|
||||
|
||||
return new Gson().fromJson(json, Terminal.ColorMode.class);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ package li.cil.oc2.common.serialization.ceres;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import li.cil.ceres.Ceres;
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
import li.cil.oc2.common.vm.context.global.MemoryRangeList;
|
||||
import li.cil.sedna.api.memory.MemoryRange;
|
||||
import net.minecraft.network.chat.Component;
|
||||
@@ -26,5 +27,7 @@ public final class Serializers {
|
||||
Ceres.putSerializer(Component.class, new TextComponentSerializer());
|
||||
Ceres.putSerializer(MemoryRange.class, new MemoryRangeSerializer());
|
||||
Ceres.putSerializer(MemoryRangeList.class, new MemoryRangeListSerializer());
|
||||
Ceres.putSerializer(Terminal.ColorMode.class, new ColorModeSerializer());
|
||||
Ceres.putSerializer(Terminal.ColorData.class, new ColorDataSerializer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,6 @@ public final class BlockTags {
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private static TagKey<Block> tag(final String name) {
|
||||
return TagKey.create(Registries.BLOCK, new ResourceLocation(API.MOD_ID, name));
|
||||
return TagKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath(API.MOD_ID, name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,6 @@ public final class ItemTags {
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private static TagKey<Item> tag(final String name) {
|
||||
return TagKey.create(Registries.ITEM, new ResourceLocation(API.MOD_ID, name));
|
||||
return TagKey.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(API.MOD_ID, name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,13 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public abstract class RegistryUtils {
|
||||
private enum Phase {
|
||||
PRE_INIT,
|
||||
@@ -49,12 +51,12 @@ public abstract class RegistryUtils {
|
||||
phase = Phase.INIT;
|
||||
}
|
||||
|
||||
public static void finish() {
|
||||
public static void finish(FMLJavaModLoadingContext context) {
|
||||
if (phase != Phase.INIT) throw new IllegalStateException();
|
||||
phase = Phase.POST_INIT;
|
||||
|
||||
for (final DeferredRegister<?> register : ENTRIES) {
|
||||
register.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
register.register(context.getModEventBus());
|
||||
}
|
||||
|
||||
ENTRIES.clear();
|
||||
@@ -64,7 +66,7 @@ public abstract class RegistryUtils {
|
||||
return Objects.requireNonNull(registryEntry.getName()).toString();
|
||||
}
|
||||
|
||||
public static <T> Optional<String> optionalKey(final T registryEntry) {
|
||||
public static <T> Optional<String> optionalKey(@Nullable final T registryEntry) {
|
||||
if(registryEntry == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -23,13 +23,13 @@ public final class SoundEvents {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void initialize() {
|
||||
SOUNDS.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
public static void initialize(FMLJavaModLoadingContext context) {
|
||||
SOUNDS.register(context.getModEventBus());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private static RegistryObject<SoundEvent> register(final String name) {
|
||||
return SOUNDS.register(name, () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(API.MOD_ID, name)));
|
||||
return SOUNDS.register(name, () -> SoundEvent.createVariableRangeEvent(ResourceLocation.fromNamespaceAndPath(API.MOD_ID, name)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
package li.cil.oc2.common.util;
|
||||
|
||||
import li.cil.oc2.common.vm.Terminal;
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
package li.cil.oc2.common.vm;
|
||||
|
||||
import it.unimi.dsi.fastutil.bytes.ByteArrayFIFOQueue;
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
import li.cil.sedna.device.serial.UART16550A;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
package li.cil.oc2.common.vm;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.*;
|
||||
import org.joml.Matrix4f;
|
||||
@@ -26,11 +27,15 @@ import java.util.WeakHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
// VT100 emulation: https://vt100.net/docs/vt100-ug/chapter3.html
|
||||
// Still around in case of needing to look back when new bugs surface
|
||||
@Serialized
|
||||
public final class Terminal {
|
||||
@SuppressWarnings("all")
|
||||
public final class OldTerminal {
|
||||
public static final int WIDTH = 80, HEIGHT = 24;
|
||||
public static final int CHAR_WIDTH = 8;
|
||||
public static final int CHAR_HEIGHT = 16;
|
||||
public MouseMode CurrentMouseMode = MouseMode.None;
|
||||
public boolean Use1006 = false;
|
||||
|
||||
private static final int TAB_WIDTH = 4;
|
||||
|
||||
@@ -74,7 +79,10 @@ public final class Terminal {
|
||||
private static final byte DEFAULT_COLORS = Color.WHITE << COLOR_FOREGROUND_SHIFT;
|
||||
private static final byte DEFAULT_STYLE = 0;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
private static final ColorData DEFAULT_TRUE_COLOR_FOREGROUND = new ColorData(238, 238, 238);
|
||||
private static final ColorData DEFAULT_TRUE_COLOR_BACKGROUND = new ColorData(0, 0, 0);
|
||||
|
||||
/// ////////////////////////////////////////////////////////////////
|
||||
|
||||
public enum State { // Must be public for serialization.
|
||||
NORMAL, // Reading characters normally.
|
||||
@@ -82,22 +90,72 @@ public final class Terminal {
|
||||
SHIFT_IN_CHARACTER_SET, // Shift in character set.
|
||||
SHIFT_OUT_CHARACTER_SET, // Shift out character set.
|
||||
HASH, // Escape sequence with # intermediate.
|
||||
DCS,
|
||||
OSC,
|
||||
CONTROL_SEQUENCE, // Know what sequence we have, now parsing it.
|
||||
}
|
||||
|
||||
public static class ColorData {
|
||||
public int R;
|
||||
public int G;
|
||||
public int B;
|
||||
|
||||
public ColorData() {
|
||||
R = 0;
|
||||
G = 0;
|
||||
B = 0;
|
||||
}
|
||||
|
||||
public ColorData(final int r, final int g, final int b) {
|
||||
R = r;
|
||||
G = g;
|
||||
B = b;
|
||||
}
|
||||
|
||||
public int asInt() {
|
||||
return (((R & 0b11111111) << 16) | ((G & 0b11111111) << 8) | (B & 0b11111111));
|
||||
}
|
||||
}
|
||||
|
||||
public ColorData fromByte(byte color) {
|
||||
return new ColorData(color, 0, 0);
|
||||
}
|
||||
|
||||
public enum ColorMode {
|
||||
@SerializedName("0")
|
||||
SIXTEEN_COLOR,
|
||||
@SerializedName("1")
|
||||
TWO_FIFTY_SIX_COLOR,
|
||||
@SerializedName("2")
|
||||
TWENTY_FOUR_BIT_COLOR
|
||||
}
|
||||
|
||||
public enum MouseMode {
|
||||
@SerializedName("0")
|
||||
None,
|
||||
@SerializedName("1")
|
||||
X10Compat,
|
||||
@SerializedName("2")
|
||||
Normal,
|
||||
@SerializedName("3")
|
||||
MouseHilite
|
||||
}
|
||||
|
||||
public interface RendererView {
|
||||
void render(final PoseStack stack, final Matrix4f projectionMatrix);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
/// ////////////////////////////////////////////////////////////////
|
||||
|
||||
private final ByteArrayFIFOQueue input = new ByteArrayFIFOQueue(32);
|
||||
private final byte[] buffer = new byte[WIDTH * HEIGHT];
|
||||
private final byte[] colors = new byte[WIDTH * HEIGHT];
|
||||
private final ColorMode[] colorModes = new ColorMode[WIDTH * HEIGHT];
|
||||
private final ColorData[] colors = new ColorData[WIDTH * HEIGHT];
|
||||
private final ColorData[] colorsBackground = new ColorData[WIDTH * HEIGHT]; // only used for TrueColor
|
||||
private final byte[] styles = new byte[WIDTH * HEIGHT];
|
||||
private final boolean[] tabs = new boolean[WIDTH];
|
||||
private State state = State.NORMAL;
|
||||
private final int[] args = new int[4];
|
||||
private final int[] args = new int[5];
|
||||
private int argCount = 0;
|
||||
private int modes;
|
||||
private int scrollFirst = 0, scrollLast = HEIGHT - 1;
|
||||
@@ -107,7 +165,15 @@ public final class Terminal {
|
||||
// Color info packed into one byte for compact storage
|
||||
// 0-2: background color (index)
|
||||
// 3-5: foreground color (index)
|
||||
private byte color;
|
||||
private ColorData color;
|
||||
// 256 color
|
||||
private boolean enable256;
|
||||
private byte foregroundColor256;
|
||||
private byte backgroundColor256;
|
||||
// true color
|
||||
private boolean trueColor;
|
||||
private ColorData backgroundColor;
|
||||
private ColorData foregroundColor;
|
||||
// Style info packed into one byte for compact storage
|
||||
private byte style;
|
||||
|
||||
@@ -115,14 +181,15 @@ public final class Terminal {
|
||||
private final transient Set<RendererModel> renderers = Collections.synchronizedSet(Collections.newSetFromMap(new WeakHashMap<>()));
|
||||
private transient boolean displayOnly; // Set on client to not send responses to status requests.
|
||||
private transient boolean hasPendingBell;
|
||||
private char lastChar;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
/// ////////////////////////////////////////////////////////////////
|
||||
|
||||
public Terminal() {
|
||||
public OldTerminal() {
|
||||
RIS();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
/// ////////////////////////////////////////////////////////////////
|
||||
|
||||
public int getWidth() {
|
||||
return WIDTH * CHAR_WIDTH;
|
||||
@@ -183,6 +250,10 @@ public final class Terminal {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void putInput(final String value) {
|
||||
putInput(ByteBuffer.wrap(value.getBytes()));
|
||||
}
|
||||
|
||||
public synchronized void putInput(final ByteBuffer values) {
|
||||
while (values.hasRemaining()) {
|
||||
input.enqueue(values.get());
|
||||
@@ -195,6 +266,8 @@ public final class Terminal {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void putInput(final char value) { putInput((byte) value); }
|
||||
|
||||
public synchronized void putInput(final byte value) {
|
||||
input.enqueue(value);
|
||||
}
|
||||
@@ -206,8 +279,10 @@ public final class Terminal {
|
||||
switch (value) {
|
||||
case '\007' -> hasPendingBell = true;
|
||||
case '\033' -> state = State.ESCAPE;
|
||||
case '\016' -> { } // SO
|
||||
case '\017' -> { } // SI
|
||||
case '\016' -> {
|
||||
} // SO
|
||||
case '\017' -> {
|
||||
} // SI
|
||||
|
||||
case (byte) '\r' /* 015 */ -> setCursorPos(0, y);
|
||||
case (byte) '\n' /* 012 */, '\013', '\014' -> {
|
||||
@@ -240,6 +315,10 @@ public final class Terminal {
|
||||
state = State.SHIFT_OUT_CHARACTER_SET;
|
||||
} else if (ch == '#') { // # Intermediate
|
||||
state = State.HASH;
|
||||
} else if (ch == 'P') {
|
||||
state = State.DCS;
|
||||
} else if (ch == ']') {
|
||||
state = State.OSC;
|
||||
} else {
|
||||
state = State.NORMAL;
|
||||
switch (ch) {
|
||||
@@ -250,8 +329,11 @@ public final class Terminal {
|
||||
case '8' -> DECRC(); // DECRC – Restore Cursor (DEC Private)
|
||||
case 'H' -> HTS(); // HTS – Horizontal Tabulation Set
|
||||
case 'c' -> RIS(); // RIS – Reset To Initial State
|
||||
case '=' -> { } // DECKPAM – Keypad Application Mode (DEC Private)
|
||||
case '>' -> { } // DECKPNM – Keypad Numeric Mode (DEC Private)
|
||||
case '=' -> {
|
||||
} // DECKPAM – Keypad Application Mode (DEC Private)
|
||||
case '>' -> {
|
||||
} // DECKPNM – Keypad Numeric Mode (DEC Private)
|
||||
default -> System.out.println("Invalid escape: " + ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -295,32 +377,87 @@ public final class Terminal {
|
||||
case 'l' -> RM(); // RM – Reset Mode
|
||||
case 'n' -> DSR(); // DSR – Device Status Report
|
||||
case 'c' -> DA(); // DA – Device Attributes
|
||||
case 'd' -> {
|
||||
setClampedCursorPos(x, args[0] - 1);
|
||||
}
|
||||
case 'G' -> {
|
||||
setClampedCursorPos(args[0] - 1, y);
|
||||
}
|
||||
case 't' -> {
|
||||
if (args[0] == 14) {
|
||||
putInput("\033[4;80;24t");
|
||||
}
|
||||
}
|
||||
case 'L' -> IL();
|
||||
case 'M' -> DL();
|
||||
case '>' -> {
|
||||
if (args[0] == 6) {
|
||||
putInput("\033[" + (y + 1) + ";" + (x + 1) + "R");
|
||||
return;
|
||||
} else if (args[0] == 0) {
|
||||
//putInput("\033[0>"); // Don't respond?
|
||||
return;
|
||||
}
|
||||
System.out.println("Invalid parameter: " + args[0]);
|
||||
}
|
||||
case '%' -> {
|
||||
System.out.println("%: " + argCount);
|
||||
|
||||
for(int i = 0; i < argCount; i++) System.out.println(args[i]);
|
||||
}
|
||||
default -> {
|
||||
System.out.println("Control sequence: " + ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case SHIFT_IN_CHARACTER_SET, SHIFT_OUT_CHARACTER_SET -> {
|
||||
state = State.NORMAL;
|
||||
switch (ch) {
|
||||
case 'A' -> { } // United Kingdom Set
|
||||
case 'B' -> { } // ASCII Set
|
||||
case '0' -> { } // Special Graphics
|
||||
case '1' -> { } // Alternate Character ROM Standard Character Set
|
||||
case '2' -> { } // Alternate Character ROM Special Graphics
|
||||
case 'A' -> {
|
||||
} // United Kingdom Set
|
||||
case 'B' -> {
|
||||
} // ASCII Set
|
||||
case '0' -> {
|
||||
} // Special Graphics
|
||||
case '1' -> {
|
||||
} // Alternate Character ROM Standard Character Set
|
||||
case '2' -> {
|
||||
} // Alternate Character ROM Special Graphics
|
||||
}
|
||||
}
|
||||
case HASH -> {
|
||||
state = State.NORMAL;
|
||||
switch (ch) {
|
||||
case '3' -> { } // Change this line to double-height top half (DECDHL)
|
||||
case '4' -> { } // Change this line to double-height bottom half (DECDHL)
|
||||
case '5' -> { } // Change this line to single-width single-height (DECSWL)
|
||||
case '6' -> { } // Change this line to double-width single-height (DECDWL)
|
||||
case '3' -> {
|
||||
} // Change this line to double-height top half (DECDHL)
|
||||
case '4' -> {
|
||||
} // Change this line to double-height bottom half (DECDHL)
|
||||
case '5' -> {
|
||||
} // Change this line to single-width single-height (DECSWL)
|
||||
case '6' -> {
|
||||
} // Change this line to double-width single-height (DECDWL)
|
||||
case '8' -> { // Fill Screen with Es (DECALN)
|
||||
Arrays.fill(buffer, (byte) 'E');
|
||||
renderers.forEach(model -> model.getDirtyMask().set(-1));
|
||||
}
|
||||
}
|
||||
}
|
||||
case DCS -> {
|
||||
if (lastChar == '\033' && ch == '\\') {
|
||||
state = State.NORMAL;
|
||||
} else {
|
||||
lastChar = ch;
|
||||
}
|
||||
// Used for mapping Function keys and possibly other things
|
||||
}
|
||||
case OSC -> {
|
||||
if (lastChar == '\033' && ch == '\\' || ch == '\007') {
|
||||
state = State.NORMAL;
|
||||
} else {
|
||||
lastChar = ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,6 +496,24 @@ public final class Terminal {
|
||||
y = savedY;
|
||||
}
|
||||
|
||||
private void IL() {
|
||||
int lines = args[0];
|
||||
|
||||
shiftLines(y, scrollLast-1, (Math.max(1, lines)));
|
||||
}
|
||||
|
||||
private void DL() {
|
||||
int lines = args[0];
|
||||
|
||||
setCursorPos(0, y);
|
||||
|
||||
for (int i = 0; i < Math.max(1, lines); i++) {
|
||||
clearLine(y + i);
|
||||
}
|
||||
|
||||
shiftLines(y + (Math.max(1, lines)), scrollLast, -(Math.max(1, lines)));
|
||||
}
|
||||
|
||||
private void HTS() {
|
||||
if (x >= 0 && x < WIDTH) {
|
||||
tabs[x] = true;
|
||||
@@ -366,8 +521,14 @@ public final class Terminal {
|
||||
}
|
||||
|
||||
private void RIS() {
|
||||
color = DEFAULT_COLORS;
|
||||
enable256 = false;
|
||||
trueColor = false;
|
||||
Use1006 = false;
|
||||
color = fromByte(DEFAULT_COLORS);
|
||||
backgroundColor = null;
|
||||
foregroundColor = null;
|
||||
style = DEFAULT_STYLE;
|
||||
CurrentMouseMode = MouseMode.None;
|
||||
clear();
|
||||
Arrays.fill(tabs, false);
|
||||
for (int i = 1; i < WIDTH; i++) {
|
||||
@@ -402,6 +563,35 @@ public final class Terminal {
|
||||
}
|
||||
|
||||
private void SGR() {
|
||||
if (args[0] == 38 || args[0] == 48) {
|
||||
if (args[0] == 38) {
|
||||
if (args[1] == 5) {
|
||||
// 256
|
||||
enable256 = true;
|
||||
trueColor = false;
|
||||
foregroundColor256 = (byte) args[2];
|
||||
} else if (args[1] == 2) {
|
||||
// true color
|
||||
enable256 = false;
|
||||
trueColor = true;
|
||||
foregroundColor = new ColorData(args[2], args[3], args[4]);
|
||||
}
|
||||
} else {
|
||||
if (args[1] == 5) {
|
||||
// 256
|
||||
enable256 = true;
|
||||
trueColor = false;
|
||||
backgroundColor256 = (byte) args[2];
|
||||
} else if (args[1] == 2) {
|
||||
// true color
|
||||
enable256 = false;
|
||||
trueColor = true;
|
||||
backgroundColor = new ColorData(args[2], args[3], args[4]);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < argCount; i++) {
|
||||
selectStyle(args[i]);
|
||||
}
|
||||
@@ -469,6 +659,31 @@ public final class Terminal {
|
||||
private void SM() {
|
||||
for (int i = 0; i < argCount; i++) {
|
||||
final int mode = args[i];
|
||||
if (mode == 1000) {
|
||||
CurrentMouseMode = MouseMode.Normal;
|
||||
System.out.println("Current mouse mode: " + CurrentMouseMode);
|
||||
continue;
|
||||
} else if (mode == 1001) {
|
||||
CurrentMouseMode = MouseMode.MouseHilite;
|
||||
System.out.println("Current mouse mode: " + CurrentMouseMode);
|
||||
continue;
|
||||
} else if (mode == 9) {
|
||||
CurrentMouseMode = MouseMode.X10Compat;
|
||||
System.out.println("Current mouse mode: " + CurrentMouseMode);
|
||||
continue;
|
||||
} else if (mode == 1005) {
|
||||
System.out.println("bad1");
|
||||
} else if (mode == 1006) {
|
||||
Use1006 = true;
|
||||
continue;
|
||||
} else if (mode == 1015) {
|
||||
System.out.println("bad3");
|
||||
continue;
|
||||
} else if (mode == 1016) {
|
||||
System.out.println("bad4");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mode != 0) {
|
||||
setMode(mode);
|
||||
}
|
||||
@@ -481,6 +696,14 @@ public final class Terminal {
|
||||
private void RM() {
|
||||
for (int i = 0; i < argCount; i++) {
|
||||
final int mode = args[i];
|
||||
if (mode == 9 || mode == 1000 || mode == 1001) {
|
||||
CurrentMouseMode = MouseMode.None;
|
||||
System.out.println("Current mouse mode: " + CurrentMouseMode);
|
||||
continue;
|
||||
} else if (mode == 1006) {
|
||||
Use1006 = false;
|
||||
continue;
|
||||
}
|
||||
if (mode != 0) {
|
||||
resetMode(mode);
|
||||
}
|
||||
@@ -536,8 +759,14 @@ public final class Terminal {
|
||||
private void selectStyle(final int sgr) {
|
||||
switch (sgr) {
|
||||
case 0 -> { // Reset / Normal
|
||||
color = DEFAULT_COLORS;
|
||||
color = fromByte(DEFAULT_COLORS);
|
||||
style = DEFAULT_STYLE;
|
||||
enable256 = false;
|
||||
trueColor = false;
|
||||
foregroundColor256 = 0;
|
||||
backgroundColor256 = 0;
|
||||
foregroundColor = null;
|
||||
backgroundColor = null;
|
||||
}
|
||||
case 1 -> // Bold or increased intensity
|
||||
style |= STYLE_BOLD_MASK;
|
||||
@@ -550,7 +779,9 @@ public final class Terminal {
|
||||
case 7 -> // Negative (reverse) image
|
||||
style |= STYLE_INVERT_MASK;
|
||||
case 8 -> // Conceal aka Hide
|
||||
{
|
||||
style |= STYLE_HIDDEN_MASK;
|
||||
}
|
||||
case 22 -> // Normal color or intensity
|
||||
style &= ~(STYLE_BOLD_MASK | STYLE_DIM_MASK);
|
||||
case 24 -> // Underline off
|
||||
@@ -560,14 +791,21 @@ public final class Terminal {
|
||||
case 27 -> // Reverse/invert off
|
||||
style &= ~STYLE_INVERT_MASK;
|
||||
case 28 -> // Reveal conceal off
|
||||
{
|
||||
style &= ~STYLE_HIDDEN_MASK;
|
||||
}
|
||||
case 30, 31, 32, 33, 34, 35, 36, 37 -> { // Set foreground color
|
||||
enable256 = false;
|
||||
trueColor = false;
|
||||
final int color = sgr - 30;
|
||||
this.color = (byte) ((this.color & ~(COLOR_MASK << COLOR_FOREGROUND_SHIFT)) | (color << COLOR_FOREGROUND_SHIFT));
|
||||
System.out.println(color);
|
||||
this.color = fromByte((byte) ((this.color.R & ~(COLOR_MASK << COLOR_FOREGROUND_SHIFT)) | (color << COLOR_FOREGROUND_SHIFT)));
|
||||
}
|
||||
case 40, 41, 42, 43, 44, 45, 46, 47 -> { //–47 Set background color
|
||||
enable256 = false;
|
||||
trueColor = false;
|
||||
final int color = sgr - 40;
|
||||
this.color = (byte) ((this.color & ~COLOR_MASK) | color);
|
||||
this.color = fromByte((byte) ((this.color.R & ~COLOR_MASK) | color));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -607,23 +845,31 @@ public final class Terminal {
|
||||
|
||||
private void setChar(final int x, final int y, final char ch) {
|
||||
final int index = x + y * WIDTH;
|
||||
if (buffer[index] == ch &&
|
||||
colors[index] == color &&
|
||||
styles[index] == style) {
|
||||
return;
|
||||
}
|
||||
|
||||
buffer[index] = (byte) ch;
|
||||
colors[index] = color;
|
||||
if (!enable256 && !trueColor) {
|
||||
colorModes[index] = ColorMode.SIXTEEN_COLOR;
|
||||
colors[index] = color;
|
||||
} else if (enable256) {
|
||||
colorModes[index] = ColorMode.TWO_FIFTY_SIX_COLOR;
|
||||
colors[index] = new ColorData((backgroundColor256 & ~(0b11111111 << 8)) | (foregroundColor256 << 8), 0, 0);
|
||||
} else {
|
||||
colorModes[index] = ColorMode.TWENTY_FOUR_BIT_COLOR;
|
||||
colors[index] = (foregroundColor != null) ? foregroundColor : DEFAULT_TRUE_COLOR_FOREGROUND;
|
||||
colorsBackground[index] = (backgroundColor != null) ? backgroundColor : DEFAULT_TRUE_COLOR_BACKGROUND;
|
||||
}
|
||||
|
||||
styles[index] = style;
|
||||
renderers.forEach(model -> model.getDirtyMask().accumulateAndGet(1 << y, (prev, next) -> prev | next));
|
||||
}
|
||||
|
||||
private void clear() {
|
||||
Arrays.fill(buffer, (byte) ' ');
|
||||
Arrays.fill(colors, DEFAULT_COLORS);
|
||||
Arrays.fill(colorModes, ColorMode.SIXTEEN_COLOR);
|
||||
Arrays.fill(colors, fromByte(DEFAULT_COLORS));
|
||||
Arrays.fill(colorsBackground, fromByte(DEFAULT_COLORS));
|
||||
Arrays.fill(styles, DEFAULT_STYLE);
|
||||
setCursorPos(0,0);
|
||||
setCursorPos(0, 0);
|
||||
renderers.forEach(model -> model.getDirtyMask().set(-1));
|
||||
}
|
||||
|
||||
@@ -632,8 +878,12 @@ public final class Terminal {
|
||||
}
|
||||
|
||||
private void clearLine(final int y, final int fromIndex, final int toIndex) {
|
||||
enable256 = false;
|
||||
trueColor = false;
|
||||
Arrays.fill(buffer, y * WIDTH + fromIndex, y * WIDTH + toIndex, (byte) ' ');
|
||||
Arrays.fill(colors, y * WIDTH + fromIndex, y * WIDTH + toIndex, DEFAULT_COLORS);
|
||||
Arrays.fill(colorModes, y * WIDTH + fromIndex, y * WIDTH + toIndex, ColorMode.SIXTEEN_COLOR);
|
||||
Arrays.fill(colors, y * WIDTH + fromIndex, y * WIDTH + toIndex, fromByte(DEFAULT_COLORS));
|
||||
Arrays.fill(colorsBackground, y * WIDTH + fromIndex, y * WIDTH + toIndex, fromByte(DEFAULT_COLORS));
|
||||
Arrays.fill(styles, y * WIDTH + fromIndex, y * WIDTH + toIndex, DEFAULT_STYLE);
|
||||
renderers.forEach(model -> model.getDirtyMask().accumulateAndGet(1 << y, (prev, next) -> prev | next));
|
||||
}
|
||||
@@ -655,7 +905,9 @@ public final class Terminal {
|
||||
final int dstIndex = srcIndex + count * WIDTH;
|
||||
|
||||
System.arraycopy(buffer, srcIndex, buffer, dstIndex, charCount);
|
||||
System.arraycopy(colorModes, srcIndex, colorModes, dstIndex, charCount);
|
||||
System.arraycopy(colors, srcIndex, colors, dstIndex, charCount);
|
||||
System.arraycopy(colorsBackground, srcIndex, colorsBackground, dstIndex, charCount);
|
||||
System.arraycopy(styles, srcIndex, styles, dstIndex, charCount);
|
||||
|
||||
final int clearIndex = count > 0 ? srcIndex : (dstIndex + charCount);
|
||||
@@ -663,7 +915,9 @@ public final class Terminal {
|
||||
Arrays.fill(buffer, clearIndex, clearIndex + clearCount, (byte) ' ');
|
||||
// TODO Copy color and style from last line.
|
||||
// TODO Copy color and style from last line.
|
||||
Arrays.fill(colors, clearIndex, clearIndex + clearCount, DEFAULT_COLORS);
|
||||
Arrays.fill(colorModes, clearIndex, clearIndex + clearCount, ColorMode.SIXTEEN_COLOR);
|
||||
Arrays.fill(colors, clearIndex, clearIndex + clearCount, fromByte(DEFAULT_COLORS));
|
||||
Arrays.fill(colorsBackground, clearIndex, clearIndex + clearCount, fromByte(DEFAULT_COLORS));
|
||||
Arrays.fill(styles, clearIndex, clearIndex + clearCount, DEFAULT_STYLE);
|
||||
|
||||
int dirtyLinesMask = 0;
|
||||
@@ -674,9 +928,12 @@ public final class Terminal {
|
||||
}
|
||||
final int finalDirtyLinesMask = dirtyLinesMask;
|
||||
renderers.forEach(model -> model.getDirtyMask().accumulateAndGet(finalDirtyLinesMask, (left, right) -> left | right));
|
||||
|
||||
enable256 = false;
|
||||
trueColor = false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
/// ////////////////////////////////////////////////////////////////
|
||||
|
||||
private interface RendererModel {
|
||||
AtomicInteger getDirtyMask();
|
||||
@@ -686,14 +943,14 @@ public final class Terminal {
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private static final class Renderer implements RendererModel, RendererView {
|
||||
private static final ResourceLocation LOCATION_FONT_TEXTURE = new ResourceLocation(API.MOD_ID, "textures/font/terminus.png");
|
||||
private static final ResourceLocation LOCATION_FONT_TEXTURE = ResourceLocation.fromNamespaceAndPath(API.MOD_ID, "textures/font/terminus.png");
|
||||
private static final int TEXTURE_RESOLUTION = 256;
|
||||
private static final float ONE_OVER_TEXTURE_RESOLUTION = 1.0f / (float) TEXTURE_RESOLUTION;
|
||||
private static final int TEXTURE_COLUMNS = 16;
|
||||
private static final int TEXTURE_BOLD_SHIFT = TEXTURE_COLUMNS; // Bold chars are in right half of texture.
|
||||
|
||||
private static final int[] COLORS = {
|
||||
0x010101, // Black
|
||||
0x555555, // Black
|
||||
0xEE3322, // Red
|
||||
0x33DD44, // Green
|
||||
0xFFCC11, // Yellow
|
||||
@@ -714,20 +971,49 @@ public final class Terminal {
|
||||
0x777777, // White
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
private static final int[] COLORS_256 = {
|
||||
0x000000, 0x800000, 0x008000, 0x808000, 0x000080, 0x800080, 0x008080, 0xc0c0c0, 0x808080, 0xff0000,
|
||||
0x00ff00, 0xffff00, 0x0000ff, 0xff00ff, 0x00ffff, 0xffffff, 0x000000, 0x00005f, 0x000087, 0x0000af,
|
||||
0x0000d7, 0x0000ff, 0x005f00, 0x005f5f, 0x005f87, 0x005faf, 0x005fd7, 0x005fff, 0x008700, 0x00875f,
|
||||
0x008787, 0x0087af, 0x0087d7, 0x0087ff, 0x00af00, 0x00af5f, 0x00af87, 0x00afaf, 0x00afd7, 0x00afff,
|
||||
0x00d700, 0x00d75f, 0x00d787, 0x00d7af, 0x00d7d7, 0x00d7ff, 0x00ff00, 0x00ff5f, 0x00ff87, 0x00ffaf,
|
||||
0x00ffd7, 0x00ffff, 0x5f0000, 0x5f005f, 0x5f0087, 0x5f00af, 0x5f00d7, 0x5f00ff, 0x5f5f00, 0x5f5f5f,
|
||||
0x5f5f87, 0x5f5faf, 0x5f5fd7, 0x5f5fff, 0x5f8700, 0x5f875f, 0x5f8787, 0x5f87af, 0x5f87d7, 0x5f87ff,
|
||||
0x5faf00, 0x5faf5f, 0x5faf87, 0x5fafaf, 0x5fafd7, 0x5fafff, 0x5fd700, 0x5fd75f, 0x5fd787, 0x5fd7af,
|
||||
0x5fd7d7, 0x5fd7ff, 0x5fff00, 0x5fff5f, 0x5fff87, 0x5fffaf, 0x5fffd7, 0x5fffff, 0x870000, 0x87005f,
|
||||
0x870087, 0x8700af, 0x8700d7, 0x8700ff, 0x875f00, 0x875f5f, 0x875f87, 0x875faf, 0x875fd7, 0x875fff,
|
||||
0x878700, 0x87875f, 0x878787, 0x8787af, 0x8787d7, 0x8787ff, 0x87af00, 0x87af5f, 0x87af87, 0x87afaf,
|
||||
0x87afd7, 0x87afff, 0x87d700, 0x87d75f, 0x87d787, 0x87d7af, 0x87d7d7, 0x87d7ff, 0x87ff00, 0x87ff5f,
|
||||
0x87ff87, 0x87ffaf, 0x87ffd7, 0x87ffff, 0xaf0000, 0xaf005f, 0xaf0087, 0xaf00af, 0xaf00d7, 0xaf00ff,
|
||||
0xaf5f00, 0xaf5f5f, 0xaf5f87, 0xaf5faf, 0xaf5fd7, 0xaf5fff, 0xaf8700, 0xaf875f, 0xaf8787, 0xaf87af,
|
||||
0xaf87d7, 0xaf87ff, 0xafaf00, 0xafaf5f, 0xafaf87, 0xafafaf, 0xafafd7, 0xafafff, 0xafd700, 0xafd75f,
|
||||
0xafd787, 0xafd7af, 0xafd7d7, 0xafd7ff, 0xafff00, 0xafff5f, 0xafff87, 0xafffaf, 0xafffd7, 0xafffff,
|
||||
0xd70000, 0xd7005f, 0xd70087, 0xd700af, 0xd700d7, 0xd700ff, 0xd75f00, 0xd75f5f, 0xd75f87, 0xd75faf,
|
||||
0xd75fd7, 0xd75fff, 0xd78700, 0xd7875f, 0xd78787, 0xd787af, 0xd787d7, 0xd787ff, 0xdfaf00, 0xdfaf5f,
|
||||
0xdfaf87, 0xdfafaf, 0xdfafdf, 0xdfafff, 0xdfdf00, 0xdfdf5f, 0xdfdf87, 0xdfdfaf, 0xdfdfdf, 0xdfdfff,
|
||||
0xdfff00, 0xdfff5f, 0xdfff87, 0xdfffaf, 0xdfffdf, 0xdfffff, 0xff0000, 0xff005f, 0xff0087, 0xff00af,
|
||||
0xff00df, 0xff00ff, 0xff5f00, 0xff5f5f, 0xff5f87, 0xff5faf, 0xff5fdf, 0xff5fff, 0xff8700, 0xff875f,
|
||||
0xff8787, 0xff87af, 0xff87df, 0xff87ff, 0xffaf00, 0xffaf5f, 0xffaf87, 0xffafaf, 0xffafdf, 0xffafff,
|
||||
0xffdf00, 0xffdf5f, 0xffdf87, 0xffdfaf, 0xffdfdf, 0xffdfff, 0xffff00, 0xffff5f, 0xffff87, 0xffffaf,
|
||||
0xffffdf, 0xffffff, 0x080808, 0x121212, 0x1c1c1c, 0x262626, 0x303030, 0x3a3a3a, 0x444444, 0x4e4e4e,
|
||||
0x585858, 0x626262, 0x6c6c6c, 0x767676, 0x808080, 0x8a8a8a, 0x949494, 0x9e9e9e, 0xa8a8a8, 0xb2b2b2,
|
||||
0xbcbcbc, 0xc6c6c6, 0xd0d0d0, 0xdadada, 0xe4e4e4, 0xeeeeee
|
||||
};
|
||||
|
||||
private final Terminal terminal;
|
||||
/// ////////////////////////////////////////////////////////////
|
||||
|
||||
private final OldTerminal terminal;
|
||||
private final VertexBuffer[] lines = new VertexBuffer[HEIGHT];
|
||||
|
||||
private final AtomicInteger dirty = new AtomicInteger(-1);
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
/// ////////////////////////////////////////////////////////////
|
||||
|
||||
public Renderer(final Terminal terminal) {
|
||||
public Renderer(final OldTerminal terminal) {
|
||||
this.terminal = terminal;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
/// ////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void render(final PoseStack stack, final Matrix4f projectionMatrix) {
|
||||
@@ -755,7 +1041,7 @@ public final class Terminal {
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
/// ////////////////////////////////////////////////////////////
|
||||
|
||||
private int findLineIndex(VertexBuffer[] vba, VertexBuffer vb) {
|
||||
int i = 0;
|
||||
@@ -799,7 +1085,6 @@ public final class Terminal {
|
||||
}
|
||||
|
||||
|
||||
|
||||
final int mask = dirty.getAndSet(0);
|
||||
for (int row = 0; row < lines.length; row++) {
|
||||
if ((mask & (1 << row)) == 0) {
|
||||
@@ -818,12 +1103,12 @@ public final class Terminal {
|
||||
|
||||
if (lines[row] == null) {
|
||||
lines[row] = new VertexBuffer(VertexBuffer.Usage.DYNAMIC);
|
||||
}else if (lines[row] != null) {
|
||||
} else if (lines[row] != null) {
|
||||
lines[row].close();
|
||||
lines[row] = new VertexBuffer(VertexBuffer.Usage.DYNAMIC);
|
||||
}
|
||||
|
||||
if (!lines[row].isInvalid()){
|
||||
if (!lines[row].isInvalid()) {
|
||||
lines[row].bind();
|
||||
lines[row].upload(rb);
|
||||
VertexBuffer.unbind();
|
||||
@@ -838,16 +1123,34 @@ public final class Terminal {
|
||||
|
||||
float tx = 0f;
|
||||
for (int col = 0, index = row * WIDTH; col < WIDTH; col++, index++) {
|
||||
final byte colors = terminal.colors[index];
|
||||
final ColorMode colorMode = terminal.colorModes[index];
|
||||
final ColorData colors = terminal.colors[index];
|
||||
final byte style = terminal.styles[index];
|
||||
|
||||
if ((style & STYLE_HIDDEN_MASK) != 0) continue;
|
||||
|
||||
final int[] palette = (style & STYLE_DIM_MASK) != 0 ? DIM_COLORS : COLORS;
|
||||
|
||||
final int foregroundIndex = (colors >> COLOR_FOREGROUND_SHIFT) & COLOR_MASK;
|
||||
final int backgroundIndex = colors & COLOR_MASK;
|
||||
final int background = palette[(style & STYLE_INVERT_MASK) == 0 ? backgroundIndex : foregroundIndex];
|
||||
int background;
|
||||
int foregroundIndex;
|
||||
int backgroundIndex;
|
||||
switch (colorMode) {
|
||||
case SIXTEEN_COLOR:
|
||||
foregroundIndex = (colors.R >> COLOR_FOREGROUND_SHIFT) & COLOR_MASK;
|
||||
backgroundIndex = colors.R & COLOR_MASK;
|
||||
background = palette[(style & STYLE_INVERT_MASK) == 0 ? backgroundIndex : foregroundIndex];
|
||||
break;
|
||||
case TWO_FIFTY_SIX_COLOR:
|
||||
foregroundIndex = (char)((colors.R >> 8) & 0b11111111);
|
||||
backgroundIndex = (char)(colors.R & 0b11111111);
|
||||
background = COLORS_256[(style & STYLE_INVERT_MASK) == 0 ? backgroundIndex : foregroundIndex];
|
||||
break;
|
||||
case TWENTY_FOUR_BIT_COLOR:
|
||||
background = terminal.colorsBackground[index].asInt();
|
||||
break;
|
||||
default:
|
||||
background = colors.R & COLOR_MASK;
|
||||
break;
|
||||
}
|
||||
|
||||
final boolean hadBackground = backgroundStartX >= 0;
|
||||
final boolean hasBackground = background != palette[0];
|
||||
@@ -890,16 +1193,34 @@ public final class Terminal {
|
||||
private void renderForeground(final Matrix4f matrix, final BufferBuilder buffer, final int row) {
|
||||
float tx = 0f;
|
||||
for (int col = 0, index = row * WIDTH; col < WIDTH; col++, index++) {
|
||||
final byte colors = terminal.colors[index];
|
||||
final ColorMode colorMode = terminal.colorModes[index];
|
||||
final ColorData color = terminal.colors[index];
|
||||
final byte style = terminal.styles[index];
|
||||
|
||||
if ((style & STYLE_HIDDEN_MASK) != 0) continue;
|
||||
|
||||
final int[] palette = (style & STYLE_DIM_MASK) != 0 ? DIM_COLORS : COLORS;
|
||||
|
||||
final int foregroundIndex = (colors >> COLOR_FOREGROUND_SHIFT) & COLOR_MASK;
|
||||
final int backgroundIndex = colors & COLOR_MASK;
|
||||
final int foreground = palette[(style & STYLE_INVERT_MASK) == 0 ? foregroundIndex : backgroundIndex];
|
||||
int foreground;
|
||||
int foregroundIndex;
|
||||
int backgroundIndex;
|
||||
switch (colorMode) {
|
||||
case SIXTEEN_COLOR:
|
||||
final int[] palette = (style & STYLE_DIM_MASK) != 0 ? DIM_COLORS : COLORS;
|
||||
foregroundIndex = (color.R >> COLOR_FOREGROUND_SHIFT) & COLOR_MASK;
|
||||
backgroundIndex = color.R & COLOR_MASK;
|
||||
foreground = palette[(style & STYLE_INVERT_MASK) == 0 ? foregroundIndex : backgroundIndex];
|
||||
break;
|
||||
case TWO_FIFTY_SIX_COLOR:
|
||||
foregroundIndex = (char)((color.R >> 8) & 0b11111111);
|
||||
backgroundIndex = (char)(color.R & 0b11111111);
|
||||
foreground = COLORS_256[(style & STYLE_INVERT_MASK) == 0 ? foregroundIndex : backgroundIndex];
|
||||
break;
|
||||
case TWENTY_FOUR_BIT_COLOR:
|
||||
foreground = terminal.colors[index].asInt();
|
||||
break;
|
||||
default:
|
||||
foreground = color.R & COLOR_MASK;
|
||||
break;
|
||||
}
|
||||
|
||||
final int character = terminal.buffer[index] & 0xFF;
|
||||
|
||||
@@ -980,3 +1301,5 @@ public final class Terminal {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1128
src/main/java/li/cil/oc2/common/vm/terminal/Terminal.java
Normal file
1128
src/main/java/li/cil/oc2/common/vm/terminal/Terminal.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,15 @@
|
||||
package li.cil.oc2.common.vm.terminal.escapes;
|
||||
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
|
||||
public class DECRC {
|
||||
public static void execute(Terminal terminal) {
|
||||
if (terminal.currentPrivateModeState.isAltBufferEnabled()) {
|
||||
terminal.x = terminal.altSavedX;
|
||||
terminal.y = terminal.altSavedY;
|
||||
} else {
|
||||
terminal.x = terminal.savedX;
|
||||
terminal.y = terminal.savedY;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package li.cil.oc2.common.vm.terminal.escapes;
|
||||
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
|
||||
public class DECSC {
|
||||
public static void execute(Terminal terminal) {
|
||||
if (terminal.currentPrivateModeState.isAltBufferEnabled()) {
|
||||
terminal.altSavedX = terminal.x;
|
||||
terminal.altSavedY = terminal.y;
|
||||
} else {
|
||||
terminal.savedX = terminal.x;
|
||||
terminal.savedY = terminal.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package li.cil.oc2.common.vm.terminal.escapes;
|
||||
|
||||
public class EscapeUtilities {
|
||||
public static int parseArgument(final char ch, int currentValue) {
|
||||
final int digit = ch - '0';
|
||||
if (currentValue < (Integer.MAX_VALUE - digit) / 10) {
|
||||
currentValue = currentValue * 10 + digit;
|
||||
} else {
|
||||
currentValue = Integer.MAX_VALUE;
|
||||
}
|
||||
return currentValue;
|
||||
}
|
||||
}
|
||||
14
src/main/java/li/cil/oc2/common/vm/terminal/escapes/HTS.java
Normal file
14
src/main/java/li/cil/oc2/common/vm/terminal/escapes/HTS.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package li.cil.oc2.common.vm.terminal.escapes;
|
||||
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
|
||||
public class HTS {
|
||||
public static void execute(Terminal terminal) {
|
||||
if (terminal.x >= 0 && terminal.x < Terminal.WIDTH) {
|
||||
if(terminal.currentPrivateModeState.isAltBufferEnabled())
|
||||
terminal.altTabs[terminal.x] = true;
|
||||
else
|
||||
terminal.tabs[terminal.x] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
src/main/java/li/cil/oc2/common/vm/terminal/escapes/IND.java
Normal file
14
src/main/java/li/cil/oc2/common/vm/terminal/escapes/IND.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package li.cil.oc2.common.vm.terminal.escapes;
|
||||
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
|
||||
public class IND {
|
||||
public static void execute(Terminal terminal) {
|
||||
if (terminal.y >= terminal.scrollLast) {
|
||||
terminal.shiftUpOne();
|
||||
if (!terminal.currentPrivateModeState.isAltBufferEnabled()) terminal.incrementLastLineToDisplay();
|
||||
} else {
|
||||
terminal.setCursorPos(terminal.x, terminal.y + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
15
src/main/java/li/cil/oc2/common/vm/terminal/escapes/NEL.java
Normal file
15
src/main/java/li/cil/oc2/common/vm/terminal/escapes/NEL.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package li.cil.oc2.common.vm.terminal.escapes;
|
||||
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
|
||||
public class NEL {
|
||||
public static void execute(Terminal terminal) {
|
||||
if (terminal.y >= terminal.scrollLast) {
|
||||
terminal.shiftUpOne();
|
||||
if (!terminal.currentPrivateModeState.isAltBufferEnabled()) terminal.incrementLastLineToDisplay();
|
||||
terminal.setCursorPos(0, terminal.y);
|
||||
} else {
|
||||
terminal.setCursorPos(0, terminal.y + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
src/main/java/li/cil/oc2/common/vm/terminal/escapes/RI.java
Normal file
13
src/main/java/li/cil/oc2/common/vm/terminal/escapes/RI.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package li.cil.oc2.common.vm.terminal.escapes;
|
||||
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
|
||||
public class RI {
|
||||
public static void execute(Terminal terminal) {
|
||||
if (terminal.y <= terminal.scrollFirst) {
|
||||
terminal.shiftDownOne();
|
||||
} else {
|
||||
terminal.setCursorPos(0, terminal.y - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/main/java/li/cil/oc2/common/vm/terminal/escapes/RIS.java
Normal file
37
src/main/java/li/cil/oc2/common/vm/terminal/escapes/RIS.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package li.cil.oc2.common.vm.terminal.escapes;
|
||||
|
||||
import li.cil.oc2.common.vm.terminal.modes.ModeState;
|
||||
import li.cil.oc2.common.vm.terminal.modes.PrivateModeState;
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class RIS {
|
||||
public static void execute(Terminal terminal) {
|
||||
terminal.currentForegroundColorMode = Terminal.ColorMode.SIXTEEN_COLOR;
|
||||
terminal.currentBackgroundColorMode = Terminal.ColorMode.SIXTEEN_COLOR;
|
||||
terminal.Use1006 = false;
|
||||
terminal.sixteenColor = Terminal.DEFAULT_COLORS.Copy();
|
||||
terminal.backgroundColor = Terminal.DEFAULT_TRUE_COLOR_BACKGROUND.Copy();
|
||||
terminal.foregroundColor = Terminal.DEFAULT_TRUE_COLOR_FOREGROUND.Copy();
|
||||
terminal.twoFiftySixColor = Terminal.DEFAULT_256_COLORS.Copy();
|
||||
terminal.style = Terminal.DEFAULT_STYLE;
|
||||
terminal.currentModeState = new ModeState();
|
||||
terminal.currentPrivateModeState = new PrivateModeState();
|
||||
terminal.lastRowToDisplay = 24;
|
||||
terminal.lastRowToDisplayMax = 24;
|
||||
terminal.drawingModeG0 = Terminal.DrawingMode.ASCII;
|
||||
terminal.drawingModeG1 = Terminal.DrawingMode.ASCII;
|
||||
terminal.useG0 = true;
|
||||
terminal.clear();
|
||||
terminal.clearAlt();
|
||||
Arrays.fill(terminal.tabs, false);
|
||||
Arrays.fill(terminal.altTabs, false);
|
||||
for (int i = 1; i < Terminal.WIDTH; i++) {
|
||||
if (i % Terminal.TAB_WIDTH == 0) {
|
||||
terminal.tabs[i] = true;
|
||||
terminal.altTabs[i] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package li.cil.oc2.common.vm.terminal.escapes.apc;
|
||||
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
|
||||
public class APCManager {
|
||||
private final Terminal terminal;
|
||||
private int lastChar = '\0';
|
||||
|
||||
public APCManager(Terminal terminal) {
|
||||
this.terminal = terminal;
|
||||
}
|
||||
|
||||
public void handle(int ch) {
|
||||
if ((lastChar == '\033' && ch == '\\')) {
|
||||
terminal.state = Terminal.State.NORMAL;
|
||||
} else {
|
||||
lastChar = ch;
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
lastChar = '\0';
|
||||
}
|
||||
}
|
||||
112
src/main/java/li/cil/oc2/common/vm/terminal/escapes/csi/CH1.java
Normal file
112
src/main/java/li/cil/oc2/common/vm/terminal/escapes/csi/CH1.java
Normal file
@@ -0,0 +1,112 @@
|
||||
package li.cil.oc2.common.vm.terminal.escapes.csi;
|
||||
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
|
||||
public class CH1 extends CSISequenceHandler { // Combined Handler 1 (DECSTBM & XTRESTORE)
|
||||
public CH1(final Terminal terminal) {
|
||||
super(terminal);
|
||||
}
|
||||
|
||||
public void execute(int[] args, int argCount, CSIState state) {
|
||||
if (state.questionMark) {
|
||||
handleXTRESTORE(args[0]);
|
||||
}
|
||||
else if (argCount == 2) {
|
||||
handleDECSTBM(args, argCount);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleXTRESTORE(int mode) {
|
||||
switch (mode) {
|
||||
case 1 -> terminal.currentPrivateModeState.DECCKM = terminal.savePrivateModeState.DECCKM;
|
||||
case 2 -> terminal.currentPrivateModeState.DECANM = terminal.savePrivateModeState.DECANM;
|
||||
case 3 -> terminal.currentPrivateModeState.DECCOLM = terminal.savePrivateModeState.DECCOLM;
|
||||
case 4 -> terminal.currentPrivateModeState.DECSCLM = terminal.savePrivateModeState.DECSCLM;
|
||||
case 5 -> terminal.currentPrivateModeState.DECSCNM = terminal.savePrivateModeState.DECSCNM;
|
||||
case 6 -> terminal.currentPrivateModeState.DECOM = terminal.savePrivateModeState.DECOM;
|
||||
case 7 -> terminal.currentPrivateModeState.DECAWM = terminal.savePrivateModeState.DECAWM;
|
||||
case 8 -> terminal.currentPrivateModeState.DECARM = terminal.savePrivateModeState.DECARM;
|
||||
case 9 -> terminal.currentPrivateModeState.X10MM = terminal.savePrivateModeState.X10MM;
|
||||
case 10 -> terminal.currentPrivateModeState.TOOLBAR = terminal.savePrivateModeState.TOOLBAR;
|
||||
case 12 -> terminal.currentPrivateModeState.START_BLINKING_CURSOR = terminal.savePrivateModeState.START_BLINKING_CURSOR;
|
||||
case 13 -> terminal.currentPrivateModeState.START_BLINKING_CURSOR2 = terminal.savePrivateModeState.START_BLINKING_CURSOR2;
|
||||
case 14 -> terminal.currentPrivateModeState.XORBLINK = terminal.savePrivateModeState.XORBLINK;
|
||||
case 18 -> terminal.currentPrivateModeState.DECPFF = terminal.savePrivateModeState.DECPFF;
|
||||
case 19 -> terminal.currentPrivateModeState.DECPEX = terminal.savePrivateModeState.DECPEX;
|
||||
case 25 -> terminal.currentPrivateModeState.DECTCEM = terminal.savePrivateModeState.DECTCEM;
|
||||
case 30 -> terminal.currentPrivateModeState.SHOW_SCROLL = terminal.savePrivateModeState.SHOW_SCROLL;
|
||||
case 35 -> terminal.currentPrivateModeState.FONT_SHIFT = terminal.savePrivateModeState.FONT_SHIFT;
|
||||
case 38 -> terminal.currentPrivateModeState.TEKTRONIX = terminal.savePrivateModeState.TEKTRONIX;
|
||||
case 40 -> terminal.currentPrivateModeState.ENABLE_80_132 = terminal.savePrivateModeState.ENABLE_80_132;
|
||||
case 41 -> terminal.currentPrivateModeState.MORE_FIX = terminal.savePrivateModeState.MORE_FIX;
|
||||
case 42 -> terminal.currentPrivateModeState.DECNRCM = terminal.savePrivateModeState.DECNRCM;
|
||||
case 43 -> terminal.currentPrivateModeState.DECGEPM = terminal.savePrivateModeState.DECGEPM;
|
||||
case 44 -> terminal.currentPrivateModeState.MARG_BELL = terminal.savePrivateModeState.MARG_BELL;
|
||||
case 45 -> terminal.currentPrivateModeState.XTREVWRAP = terminal.savePrivateModeState.XTREVWRAP;
|
||||
case 46 -> terminal.currentPrivateModeState.XTLOGGING = terminal.savePrivateModeState.XTLOGGING;
|
||||
case 47 -> terminal.currentPrivateModeState.ALT_BUFFER = terminal.savePrivateModeState.ALT_BUFFER;
|
||||
case 66 -> terminal.currentPrivateModeState.DECNKM = terminal.savePrivateModeState.DECNKM;
|
||||
case 67 -> terminal.currentPrivateModeState.DECBKM = terminal.savePrivateModeState.DECBKM;
|
||||
case 69 -> terminal.currentPrivateModeState.DECLRMM = terminal.savePrivateModeState.DECLRMM;
|
||||
case 80 -> terminal.currentPrivateModeState.DECSDM = terminal.savePrivateModeState.DECSDM;
|
||||
case 96 -> terminal.currentPrivateModeState.DECNCSM = terminal.savePrivateModeState.DECNCSM;
|
||||
case 1000 -> terminal.currentPrivateModeState.X11MM = terminal.savePrivateModeState.X11MM;
|
||||
case 1001 -> terminal.currentPrivateModeState.HILITE_MOUSE = terminal.savePrivateModeState.HILITE_MOUSE;
|
||||
case 1002 -> terminal.currentPrivateModeState.CELL_MOTION_MOUSE = terminal.savePrivateModeState.CELL_MOTION_MOUSE;
|
||||
case 1003 -> terminal.currentPrivateModeState.ALL_MOTION_MOUSE_TRACKING = terminal.savePrivateModeState.ALL_MOTION_MOUSE_TRACKING;
|
||||
case 1004 -> terminal.currentPrivateModeState.FOCUS_IN_FOCUS_OUT = terminal.savePrivateModeState.FOCUS_IN_FOCUS_OUT;
|
||||
case 1005 -> terminal.currentPrivateModeState.UTF8_MOUSE = terminal.savePrivateModeState.UTF8_MOUSE;
|
||||
case 1006 -> terminal.currentPrivateModeState.SGR_MOUSE = terminal.savePrivateModeState.SGR_MOUSE;
|
||||
case 1007 -> terminal.currentPrivateModeState.ALTERNATE_SCROLL_MODE = terminal.savePrivateModeState.ALTERNATE_SCROLL_MODE;
|
||||
case 1010 -> terminal.currentPrivateModeState.SCROLL_BOTTOM_ON_OUTPUT = terminal.savePrivateModeState.SCROLL_BOTTOM_ON_OUTPUT;
|
||||
case 1011 -> terminal.currentPrivateModeState.SCROLL_BOTTOM_ON_KEY_PRESS = terminal.savePrivateModeState.SCROLL_BOTTOM_ON_KEY_PRESS;
|
||||
case 1014 -> terminal.currentPrivateModeState.FAST_SCROLL = terminal.savePrivateModeState.FAST_SCROLL;
|
||||
case 1015 -> terminal.currentPrivateModeState.URXVT_MOUSE = terminal.savePrivateModeState.URXVT_MOUSE;
|
||||
case 1016 -> terminal.currentPrivateModeState.SGR_MOUSE_PIXEL = terminal.savePrivateModeState.SGR_MOUSE_PIXEL;
|
||||
case 1034 -> terminal.currentPrivateModeState.META_KEY = terminal.savePrivateModeState.META_KEY;
|
||||
case 1035 -> terminal.currentPrivateModeState.SPECIAL_MODIFIERS = terminal.savePrivateModeState.SPECIAL_MODIFIERS;
|
||||
case 1036 -> terminal.currentPrivateModeState.META_SENDS_ESCAPE = terminal.savePrivateModeState.META_SENDS_ESCAPE;
|
||||
case 1037 -> terminal.currentPrivateModeState.DEL_EDIT_KEYPAD_DEL = terminal.savePrivateModeState.DEL_EDIT_KEYPAD_DEL;
|
||||
case 1039 -> terminal.currentPrivateModeState.ALT_SENDS_ESC = terminal.savePrivateModeState.ALT_SENDS_ESC;
|
||||
case 1040 -> terminal.currentPrivateModeState.KEEP_SELECTION = terminal.savePrivateModeState.KEEP_SELECTION;
|
||||
case 1041 -> terminal.currentPrivateModeState.USE_CLIP = terminal.savePrivateModeState.USE_CLIP;
|
||||
case 1042 -> terminal.currentPrivateModeState.ENABLE_URGENCY = terminal.savePrivateModeState.ENABLE_URGENCY;
|
||||
case 1043 -> terminal.currentPrivateModeState.RAISE_ON_CTRL_G = terminal.savePrivateModeState.RAISE_ON_CTRL_G;
|
||||
case 1044 -> terminal.currentPrivateModeState.KEEP_CLIP = terminal.savePrivateModeState.KEEP_CLIP;
|
||||
case 1045 -> terminal.currentPrivateModeState.EXT_REV_WRAP = terminal.savePrivateModeState.EXT_REV_WRAP;
|
||||
case 1046 -> terminal.currentPrivateModeState.ALLOW_ALT_BUFFER = terminal.savePrivateModeState.ALLOW_ALT_BUFFER;
|
||||
case 1047 -> terminal.currentPrivateModeState.SWITCH_ALT_BUFFER = terminal.savePrivateModeState.SWITCH_ALT_BUFFER;
|
||||
case 1048 -> terminal.currentPrivateModeState.SAVE_CURSOR = terminal.savePrivateModeState.SAVE_CURSOR;
|
||||
case 1049 -> terminal.currentPrivateModeState.SAVE_CLEAR_AND_SWITCH = terminal.savePrivateModeState.SAVE_CLEAR_AND_SWITCH;
|
||||
case 1050 -> terminal.currentPrivateModeState.SET_TERMINFO_FUNC_KEY_MODE = terminal.savePrivateModeState.SET_TERMINFO_FUNC_KEY_MODE;
|
||||
case 1051 -> terminal.currentPrivateModeState.SET_SUN_KEY_MODE = terminal.savePrivateModeState.SET_SUN_KEY_MODE;
|
||||
case 1052 -> terminal.currentPrivateModeState.SET_HP_K0EY_MODE = terminal.savePrivateModeState.SET_HP_K0EY_MODE;
|
||||
case 1053 -> terminal.currentPrivateModeState.SET_SCO_KEY_MODE = terminal.savePrivateModeState.SET_SCO_KEY_MODE;
|
||||
case 1060 -> terminal.currentPrivateModeState.SET_LEGACY_KEYBOARD = terminal.savePrivateModeState.SET_LEGACY_KEYBOARD;
|
||||
case 1061 -> terminal.currentPrivateModeState.SET_VT220_KEYBOARD = terminal.savePrivateModeState.SET_VT220_KEYBOARD;
|
||||
case 2001 -> terminal.currentPrivateModeState.ENABLE_READLINE_MOUSE_1 = terminal.savePrivateModeState.ENABLE_READLINE_MOUSE_1;
|
||||
case 2002 -> terminal.currentPrivateModeState.ENABLE_READLINE_MOUSE_2 = terminal.savePrivateModeState.ENABLE_READLINE_MOUSE_2;
|
||||
case 2003 -> terminal.currentPrivateModeState.ENABLE_READLINE_MOUSE_3 = terminal.savePrivateModeState.ENABLE_READLINE_MOUSE_3;
|
||||
case 2004 -> terminal.currentPrivateModeState.SET_BRACKETED_PASTE = terminal.savePrivateModeState.SET_BRACKETED_PASTE;
|
||||
case 2005 -> terminal.currentPrivateModeState.ENABLE_READLINE_CHAR_QUOTE = terminal.savePrivateModeState.ENABLE_READLINE_CHAR_QUOTE;
|
||||
case 2006 -> terminal.currentPrivateModeState.ENABLE_READLINE_NEWLINE_PASTE = terminal.savePrivateModeState.ENABLE_READLINE_NEWLINE_PASTE;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDECSTBM(int[] args, int argCount) {
|
||||
final int first, last;
|
||||
if (argCount == 2) {
|
||||
first = args[0] - 1;
|
||||
last = args[1] - 1;
|
||||
} else {
|
||||
first = 0;
|
||||
last = Terminal.HEIGHT - 1;
|
||||
}
|
||||
if (first < 0 || last > Terminal.HEIGHT - 1 || last - first <= 0) {
|
||||
return;
|
||||
}
|
||||
terminal.scrollFirst = first; // to index
|
||||
terminal.scrollLast = last; // to index
|
||||
terminal.setRelativeCursorPos(0, 0); // send cursor home
|
||||
}
|
||||
}
|
||||
207
src/main/java/li/cil/oc2/common/vm/terminal/escapes/csi/CH2.java
Normal file
207
src/main/java/li/cil/oc2/common/vm/terminal/escapes/csi/CH2.java
Normal file
@@ -0,0 +1,207 @@
|
||||
package li.cil.oc2.common.vm.terminal.escapes.csi;
|
||||
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
import li.cil.oc2.common.vm.terminal.modes.ImplementedPrivateModes;
|
||||
|
||||
public class CH2 extends CSISequenceHandler { // Combined Handler 2 (SM & DECSET)
|
||||
public CH2(final Terminal terminal) {
|
||||
super(terminal);
|
||||
}
|
||||
|
||||
public void execute(int[] args, int argCount, CSIState state) {
|
||||
if (state.questionMark) {
|
||||
handleDECSET(args, argCount);
|
||||
} else {
|
||||
handleSM(args, argCount);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDECSET(int[] args, int argCount) {
|
||||
for (int i = 0; i < argCount; i++) {
|
||||
switch (args[i]) {
|
||||
case 1 -> terminal.currentPrivateModeState.DECCKM = true;
|
||||
case 2 -> terminal.currentPrivateModeState.DECANM = true;
|
||||
case 3 -> terminal.currentPrivateModeState.DECCOLM = true;
|
||||
case 4 -> terminal.currentPrivateModeState.DECSCLM = true;
|
||||
case 5 -> terminal.currentPrivateModeState.DECSCNM = true;
|
||||
case 6 -> {
|
||||
terminal.currentPrivateModeState.DECOM = true;
|
||||
terminal.setRelativeCursorPos(0, 0);
|
||||
}
|
||||
case 7 -> terminal.currentPrivateModeState.DECAWM = true;
|
||||
case 8 -> terminal.currentPrivateModeState.DECARM = true;
|
||||
case 9 -> {
|
||||
terminal.currentPrivateModeState.X11MM = false;
|
||||
terminal.currentPrivateModeState.CELL_MOTION_MOUSE = false;
|
||||
terminal.currentPrivateModeState.ALL_MOTION_MOUSE_TRACKING = false;
|
||||
terminal.currentPrivateModeState.X10MM = true;
|
||||
}
|
||||
case 10 -> terminal.currentPrivateModeState.TOOLBAR = true;
|
||||
case 12 -> {
|
||||
terminal.cursorMode = switch (terminal.cursorMode) {
|
||||
case 2 -> 1;
|
||||
case 4 -> 3;
|
||||
case 6 -> 5;
|
||||
default -> terminal.cursorMode;
|
||||
};
|
||||
terminal.currentPrivateModeState.START_BLINKING_CURSOR = true;
|
||||
}
|
||||
case 13 -> terminal.currentPrivateModeState.START_BLINKING_CURSOR2 = true;
|
||||
case 14 -> terminal.currentPrivateModeState.XORBLINK = true;
|
||||
case 18 -> terminal.currentPrivateModeState.DECPFF = true;
|
||||
case 19 -> terminal.currentPrivateModeState.DECPEX = true;
|
||||
case 25 -> terminal.currentPrivateModeState.DECTCEM = true;
|
||||
case 30 -> terminal.currentPrivateModeState.SHOW_SCROLL = true;
|
||||
case 35 -> terminal.currentPrivateModeState.FONT_SHIFT = true;
|
||||
case 38 -> terminal.currentPrivateModeState.TEKTRONIX = true;
|
||||
case 40 -> terminal.currentPrivateModeState.ENABLE_80_132 = true;
|
||||
case 41 -> terminal.currentPrivateModeState.MORE_FIX = true;
|
||||
case 42 -> terminal.currentPrivateModeState.DECNRCM = true;
|
||||
case 43 -> terminal.currentPrivateModeState.DECGEPM = true;
|
||||
case 44 -> terminal.currentPrivateModeState.MARG_BELL = true;
|
||||
case 45 -> terminal.currentPrivateModeState.XTREVWRAP = true;
|
||||
case 46 -> terminal.currentPrivateModeState.XTLOGGING = true;
|
||||
case 47 -> {
|
||||
terminal.clearAlt();
|
||||
terminal.setCursorPos(0, 0);
|
||||
terminal.currentPrivateModeState.ALT_BUFFER = true;
|
||||
int dirtyLinesMask = 0;
|
||||
for (int j = 0; j <= 23; j++) {
|
||||
dirtyLinesMask |= 1 << j;
|
||||
}
|
||||
final int finalDirtyLinesMask = dirtyLinesMask;
|
||||
terminal.renderers.forEach(model -> model.getDirtyMask().accumulateAndGet(finalDirtyLinesMask, (left, right) -> left | right));
|
||||
}
|
||||
case 66 -> terminal.currentPrivateModeState.DECNKM = true;
|
||||
case 67 -> terminal.currentPrivateModeState.DECBKM = true;
|
||||
case 69 -> terminal.currentPrivateModeState.DECLRMM = true;
|
||||
case 80 -> terminal.currentPrivateModeState.DECSDM = true;
|
||||
case 96 -> terminal.currentPrivateModeState.DECNCSM = true;
|
||||
case 1000 -> {
|
||||
terminal.currentPrivateModeState.CELL_MOTION_MOUSE = false;
|
||||
terminal.currentPrivateModeState.ALL_MOTION_MOUSE_TRACKING = false;
|
||||
terminal.currentPrivateModeState.X10MM = false;
|
||||
terminal.currentPrivateModeState.X11MM = true;
|
||||
}
|
||||
case 1001 -> terminal.currentPrivateModeState.HILITE_MOUSE = true;
|
||||
case 1002 -> {
|
||||
terminal.currentPrivateModeState.ALL_MOTION_MOUSE_TRACKING = false;
|
||||
terminal.currentPrivateModeState.X10MM = false;
|
||||
terminal.currentPrivateModeState.X11MM = false;
|
||||
terminal.currentPrivateModeState.CELL_MOTION_MOUSE = true;
|
||||
}
|
||||
case 1003 -> {
|
||||
terminal.currentPrivateModeState.CELL_MOTION_MOUSE = false;
|
||||
terminal.currentPrivateModeState.X10MM = false;
|
||||
terminal.currentPrivateModeState.X11MM = false;
|
||||
terminal.currentPrivateModeState.ALL_MOTION_MOUSE_TRACKING = true;
|
||||
}
|
||||
case 1004 -> terminal.currentPrivateModeState.FOCUS_IN_FOCUS_OUT = true;
|
||||
case 1005 -> {
|
||||
terminal.currentPrivateModeState.SGR_MOUSE = false;
|
||||
terminal.currentPrivateModeState.URXVT_MOUSE = false;
|
||||
terminal.currentPrivateModeState.SGR_MOUSE_PIXEL = false;
|
||||
terminal.currentPrivateModeState.UTF8_MOUSE = true;
|
||||
}
|
||||
case 1006 -> {
|
||||
terminal.currentPrivateModeState.UTF8_MOUSE = false;
|
||||
terminal.currentPrivateModeState.URXVT_MOUSE = false;
|
||||
terminal.currentPrivateModeState.SGR_MOUSE_PIXEL = false;
|
||||
terminal.currentPrivateModeState.SGR_MOUSE = true;
|
||||
}
|
||||
case 1007 -> terminal.currentPrivateModeState.ALTERNATE_SCROLL_MODE = true;
|
||||
case 1010 -> terminal.currentPrivateModeState.SCROLL_BOTTOM_ON_OUTPUT = true;
|
||||
case 1011 -> terminal.currentPrivateModeState.SCROLL_BOTTOM_ON_KEY_PRESS = true;
|
||||
case 1014 -> terminal.currentPrivateModeState.FAST_SCROLL = true;
|
||||
case 1015 -> {
|
||||
terminal.currentPrivateModeState.UTF8_MOUSE = false;
|
||||
terminal.currentPrivateModeState.SGR_MOUSE = false;
|
||||
terminal.currentPrivateModeState.SGR_MOUSE_PIXEL = false;
|
||||
terminal.currentPrivateModeState.URXVT_MOUSE = true;
|
||||
}
|
||||
case 1016 -> {
|
||||
terminal.currentPrivateModeState.UTF8_MOUSE = false;
|
||||
terminal.currentPrivateModeState.SGR_MOUSE = false;
|
||||
terminal.currentPrivateModeState.URXVT_MOUSE = false;
|
||||
terminal.currentPrivateModeState.SGR_MOUSE_PIXEL = true;
|
||||
}
|
||||
case 1034 -> terminal.currentPrivateModeState.META_KEY = true;
|
||||
case 1035 -> terminal.currentPrivateModeState.SPECIAL_MODIFIERS = true;
|
||||
case 1036 -> terminal.currentPrivateModeState.META_SENDS_ESCAPE = true;
|
||||
case 1037 -> terminal.currentPrivateModeState.DEL_EDIT_KEYPAD_DEL = true;
|
||||
case 1039 -> terminal.currentPrivateModeState.ALT_SENDS_ESC = true;
|
||||
case 1040 -> terminal.currentPrivateModeState.KEEP_SELECTION = true;
|
||||
case 1041 -> terminal.currentPrivateModeState.USE_CLIP = true;
|
||||
case 1042 -> terminal.currentPrivateModeState.ENABLE_URGENCY = true;
|
||||
case 1043 -> terminal.currentPrivateModeState.RAISE_ON_CTRL_G = true;
|
||||
case 1044 -> terminal.currentPrivateModeState.KEEP_CLIP = true;
|
||||
case 1045 -> terminal.currentPrivateModeState.EXT_REV_WRAP = true;
|
||||
case 1046 -> terminal.currentPrivateModeState.ALLOW_ALT_BUFFER = true;
|
||||
case 1047 -> {
|
||||
terminal.clearAlt();
|
||||
terminal.setCursorPos(0, 0);
|
||||
terminal.currentPrivateModeState.SWITCH_ALT_BUFFER = true;
|
||||
int dirtyLinesMask = 0;
|
||||
for (int j = 0; j <= 23; j++) {
|
||||
dirtyLinesMask |= 1 << j;
|
||||
}
|
||||
final int finalDirtyLinesMask = dirtyLinesMask;
|
||||
terminal.renderers.forEach(model -> model.getDirtyMask().accumulateAndGet(finalDirtyLinesMask, (left, right) -> left | right));
|
||||
}
|
||||
case 1048 -> {
|
||||
if (terminal.currentPrivateModeState.isAltBufferEnabled()) {
|
||||
terminal.altSavedX = terminal.x;
|
||||
terminal.altSavedY = terminal.y;
|
||||
} else {
|
||||
terminal.savedX = terminal.x;
|
||||
terminal.savedY = terminal.y;
|
||||
}
|
||||
terminal.currentPrivateModeState.SAVE_CURSOR = true;
|
||||
}
|
||||
case 1049 -> {
|
||||
if (terminal.currentPrivateModeState.isAltBufferEnabled()) {
|
||||
terminal.altSavedX = terminal.x;
|
||||
terminal.altSavedY = terminal.y;
|
||||
} else {
|
||||
terminal.savedX = terminal.x;
|
||||
terminal.savedY = terminal.y;
|
||||
}
|
||||
terminal.clearAlt();
|
||||
terminal.setCursorPos(0, 0);
|
||||
terminal.currentPrivateModeState.SAVE_CLEAR_AND_SWITCH = true;
|
||||
int dirtyLinesMask = 0;
|
||||
for (int j = 0; j <= 23; j++) {
|
||||
dirtyLinesMask |= 1 << j;
|
||||
}
|
||||
final int finalDirtyLinesMask = dirtyLinesMask;
|
||||
terminal.renderers.forEach(model -> model.getDirtyMask().accumulateAndGet(finalDirtyLinesMask, (left, right) -> left | right));
|
||||
}
|
||||
case 1050 -> terminal.currentPrivateModeState.SET_TERMINFO_FUNC_KEY_MODE = true;
|
||||
case 1051 -> terminal.currentPrivateModeState.SET_SUN_KEY_MODE = true;
|
||||
case 1052 -> terminal.currentPrivateModeState.SET_HP_K0EY_MODE = true;
|
||||
case 1053 -> terminal.currentPrivateModeState.SET_SCO_KEY_MODE = true;
|
||||
case 1060 -> terminal.currentPrivateModeState.SET_LEGACY_KEYBOARD = true;
|
||||
case 1061 -> terminal.currentPrivateModeState.SET_VT220_KEYBOARD = true;
|
||||
case 2001 -> terminal.currentPrivateModeState.ENABLE_READLINE_MOUSE_1 = true;
|
||||
case 2002 -> terminal.currentPrivateModeState.ENABLE_READLINE_MOUSE_2 = true;
|
||||
case 2003 -> terminal.currentPrivateModeState.ENABLE_READLINE_MOUSE_3 = true;
|
||||
case 2004 -> terminal.currentPrivateModeState.SET_BRACKETED_PASTE = true;
|
||||
case 2005 -> terminal.currentPrivateModeState.ENABLE_READLINE_CHAR_QUOTE = true;
|
||||
case 2006 -> terminal.currentPrivateModeState.ENABLE_READLINE_NEWLINE_PASTE = true;
|
||||
}
|
||||
|
||||
ImplementedPrivateModes.instance.modeUsed(args[i], true);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleSM(int[] args, int argCount) {
|
||||
for (int i = 0; i < argCount; i++) {
|
||||
switch (args[i]) {
|
||||
case 2 -> terminal.currentModeState.KAM = true;
|
||||
case 4 -> terminal.currentModeState.IRM = true;
|
||||
case 12 -> terminal.currentModeState.SRM = true;
|
||||
case 20 -> terminal.currentModeState.LNM = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
156
src/main/java/li/cil/oc2/common/vm/terminal/escapes/csi/CH3.java
Normal file
156
src/main/java/li/cil/oc2/common/vm/terminal/escapes/csi/CH3.java
Normal file
@@ -0,0 +1,156 @@
|
||||
package li.cil.oc2.common.vm.terminal.escapes.csi;
|
||||
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
import li.cil.oc2.common.vm.terminal.modes.ImplementedPrivateModes;
|
||||
|
||||
public class CH3 extends CSISequenceHandler { // Combined Handler 3 (RM & DECRST)
|
||||
public CH3(final Terminal terminal) {
|
||||
super(terminal);
|
||||
}
|
||||
|
||||
public void execute(int[] args, int argCount, CSIState state) {
|
||||
if (state.questionMark) {
|
||||
handleDECRST(args, argCount);
|
||||
}
|
||||
else if (argCount == 2) {
|
||||
handleRM(args, argCount);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDECRST(int[] args, int argCount) {
|
||||
for (int i = 0; i < argCount; i++) {
|
||||
switch (args[i]) {
|
||||
case 1 -> terminal.currentPrivateModeState.DECCKM = false;
|
||||
case 2 -> terminal.currentPrivateModeState.DECANM = false;
|
||||
case 3 -> terminal.currentPrivateModeState.DECCOLM = false;
|
||||
case 4 -> terminal.currentPrivateModeState.DECSCLM = false;
|
||||
case 5 -> terminal.currentPrivateModeState.DECSCNM = false;
|
||||
case 6 -> {
|
||||
terminal.currentPrivateModeState.DECOM = false;
|
||||
terminal.setRelativeCursorPos(0, 0);
|
||||
terminal.clear();
|
||||
}
|
||||
case 7 -> terminal.currentPrivateModeState.DECAWM = false;
|
||||
case 8 -> terminal.currentPrivateModeState.DECARM = false;
|
||||
case 9 -> terminal.currentPrivateModeState.X10MM = false;
|
||||
case 10 -> terminal.currentPrivateModeState.TOOLBAR = false;
|
||||
case 12 -> terminal.currentPrivateModeState.START_BLINKING_CURSOR = false;
|
||||
case 13 -> terminal.currentPrivateModeState.START_BLINKING_CURSOR2 = false;
|
||||
case 14 -> terminal.currentPrivateModeState.XORBLINK = false;
|
||||
case 18 -> terminal.currentPrivateModeState.DECPFF = false;
|
||||
case 19 -> terminal.currentPrivateModeState.DECPEX = false;
|
||||
case 25 -> terminal.currentPrivateModeState.DECTCEM = false;
|
||||
case 30 -> terminal.currentPrivateModeState.SHOW_SCROLL = false;
|
||||
case 35 -> terminal.currentPrivateModeState.FONT_SHIFT = false;
|
||||
case 38 -> terminal.currentPrivateModeState.TEKTRONIX = false;
|
||||
case 40 -> terminal.currentPrivateModeState.ENABLE_80_132 = false;
|
||||
case 41 -> terminal.currentPrivateModeState.MORE_FIX = false;
|
||||
case 42 -> terminal.currentPrivateModeState.DECNRCM = false;
|
||||
case 43 -> terminal.currentPrivateModeState.DECGEPM = false;
|
||||
case 44 -> terminal.currentPrivateModeState.MARG_BELL = false;
|
||||
case 45 -> terminal.currentPrivateModeState.XTREVWRAP = false;
|
||||
case 46 -> terminal.currentPrivateModeState.XTLOGGING = false;
|
||||
case 47 -> {
|
||||
terminal.currentPrivateModeState.ALT_BUFFER = false;
|
||||
int dirtyLinesMask = 0;
|
||||
for (int j = 0; j <= 23; j++) {
|
||||
dirtyLinesMask |= 1 << j;
|
||||
}
|
||||
final int finalDirtyLinesMask = dirtyLinesMask;
|
||||
terminal.renderers.forEach(model -> model.getDirtyMask().accumulateAndGet(finalDirtyLinesMask, (left, right) -> left | right));
|
||||
}
|
||||
case 66 -> terminal.currentPrivateModeState.DECNKM = false;
|
||||
case 67 -> terminal.currentPrivateModeState.DECBKM = false;
|
||||
case 69 -> terminal.currentPrivateModeState.DECLRMM = false;
|
||||
case 80 -> terminal.currentPrivateModeState.DECSDM = false;
|
||||
case 96 -> terminal.currentPrivateModeState.DECNCSM = false;
|
||||
case 1000 -> terminal.currentPrivateModeState.X11MM = false;
|
||||
case 1001 -> terminal.currentPrivateModeState.HILITE_MOUSE = false;
|
||||
case 1002 -> terminal.currentPrivateModeState.CELL_MOTION_MOUSE = false;
|
||||
case 1003 -> terminal.currentPrivateModeState.ALL_MOTION_MOUSE_TRACKING = false;
|
||||
case 1004 -> terminal.currentPrivateModeState.FOCUS_IN_FOCUS_OUT = false;
|
||||
case 1005 -> terminal.currentPrivateModeState.UTF8_MOUSE = false;
|
||||
case 1006 -> terminal.currentPrivateModeState.SGR_MOUSE = false;
|
||||
case 1007 -> terminal.currentPrivateModeState.ALTERNATE_SCROLL_MODE = false;
|
||||
case 1010 -> terminal.currentPrivateModeState.SCROLL_BOTTOM_ON_OUTPUT = false;
|
||||
case 1011 -> terminal.currentPrivateModeState.SCROLL_BOTTOM_ON_KEY_PRESS = false;
|
||||
case 1014 -> terminal.currentPrivateModeState.FAST_SCROLL = false;
|
||||
case 1015 -> terminal.currentPrivateModeState.URXVT_MOUSE = false;
|
||||
case 1016 -> terminal.currentPrivateModeState.SGR_MOUSE_PIXEL = false;
|
||||
case 1034 -> terminal.currentPrivateModeState.META_KEY = false;
|
||||
case 1035 -> terminal.currentPrivateModeState.SPECIAL_MODIFIERS = false;
|
||||
case 1036 -> terminal.currentPrivateModeState.META_SENDS_ESCAPE = false;
|
||||
case 1037 -> terminal.currentPrivateModeState.DEL_EDIT_KEYPAD_DEL = false;
|
||||
case 1039 -> terminal.currentPrivateModeState.ALT_SENDS_ESC = false;
|
||||
case 1040 -> terminal.currentPrivateModeState.KEEP_SELECTION = false;
|
||||
case 1041 -> terminal.currentPrivateModeState.USE_CLIP = false;
|
||||
case 1042 -> terminal.currentPrivateModeState.ENABLE_URGENCY = false;
|
||||
case 1043 -> terminal.currentPrivateModeState.RAISE_ON_CTRL_G = false;
|
||||
case 1044 -> terminal.currentPrivateModeState.KEEP_CLIP = false;
|
||||
case 1045 -> terminal.currentPrivateModeState.EXT_REV_WRAP = false;
|
||||
case 1046 -> terminal.currentPrivateModeState.ALLOW_ALT_BUFFER = false;
|
||||
case 1047 -> {
|
||||
terminal.currentPrivateModeState.SWITCH_ALT_BUFFER = false;
|
||||
int dirtyLinesMask = 0;
|
||||
for (int j = 0; j <= 23; j++) {
|
||||
dirtyLinesMask |= 1 << j;
|
||||
}
|
||||
final int finalDirtyLinesMask = dirtyLinesMask;
|
||||
terminal.renderers.forEach(model -> model.getDirtyMask().accumulateAndGet(finalDirtyLinesMask, (left, right) -> left | right));
|
||||
}
|
||||
case 1048 -> {
|
||||
terminal.currentPrivateModeState.SAVE_CURSOR = false;
|
||||
if (terminal.currentPrivateModeState.isAltBufferEnabled()) {
|
||||
terminal.x = terminal.altSavedX;
|
||||
terminal.y = terminal.altSavedY;
|
||||
} else {
|
||||
terminal.x = terminal.savedX;
|
||||
terminal.y = terminal.savedY;
|
||||
}
|
||||
}
|
||||
case 1049 -> {
|
||||
terminal.currentPrivateModeState.SAVE_CLEAR_AND_SWITCH = false;
|
||||
if (terminal.currentPrivateModeState.isAltBufferEnabled()) {
|
||||
terminal.x = terminal.altSavedX;
|
||||
terminal.y = terminal.altSavedY;
|
||||
} else {
|
||||
terminal.x = terminal.savedX;
|
||||
terminal.y = terminal.savedY;
|
||||
}
|
||||
int dirtyLinesMask = 0;
|
||||
for (int j = 0; j <= 23; j++) {
|
||||
dirtyLinesMask |= 1 << j;
|
||||
}
|
||||
final int finalDirtyLinesMask = dirtyLinesMask;
|
||||
terminal.renderers.forEach(model -> model.getDirtyMask().accumulateAndGet(finalDirtyLinesMask, (left, right) -> left | right));
|
||||
}
|
||||
case 1050 -> terminal.currentPrivateModeState.SET_TERMINFO_FUNC_KEY_MODE = false;
|
||||
case 1051 -> terminal.currentPrivateModeState.SET_SUN_KEY_MODE = false;
|
||||
case 1052 -> terminal.currentPrivateModeState.SET_HP_K0EY_MODE = false;
|
||||
case 1053 -> terminal.currentPrivateModeState.SET_SCO_KEY_MODE = false;
|
||||
case 1060 -> terminal.currentPrivateModeState.SET_LEGACY_KEYBOARD = false;
|
||||
case 1061 -> terminal.currentPrivateModeState.SET_VT220_KEYBOARD = false;
|
||||
case 2001 -> terminal.currentPrivateModeState.ENABLE_READLINE_MOUSE_1 = false;
|
||||
case 2002 -> terminal.currentPrivateModeState.ENABLE_READLINE_MOUSE_2 = false;
|
||||
case 2003 -> terminal.currentPrivateModeState.ENABLE_READLINE_MOUSE_3 = false;
|
||||
case 2004 -> terminal.currentPrivateModeState.SET_BRACKETED_PASTE = false;
|
||||
case 2005 -> terminal.currentPrivateModeState.ENABLE_READLINE_CHAR_QUOTE = false;
|
||||
case 2006 -> terminal.currentPrivateModeState.ENABLE_READLINE_NEWLINE_PASTE = false;
|
||||
case 2026 -> terminal.currentPrivateModeState.APPLICATION_SYNC = false;
|
||||
}
|
||||
|
||||
ImplementedPrivateModes.instance.modeUsed(args[i], false);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleRM(int[] args, int argCount) {
|
||||
for (int i = 0; i < argCount; i++) {
|
||||
switch (args[i]) {
|
||||
case 2 -> terminal.currentModeState.KAM = false;
|
||||
case 4 -> terminal.currentModeState.IRM = false;
|
||||
case 12 -> terminal.currentModeState.SRM = false;
|
||||
case 20 -> terminal.currentModeState.LNM = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package li.cil.oc2.common.vm.terminal.escapes.csi;
|
||||
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
|
||||
public class CH4 extends CSISequenceHandler { // Combined Handler 4 (XTWINOPS, XTSMTITLE, DECSWBV, and DECRARA)
|
||||
public CH4(final Terminal terminal) {
|
||||
super(terminal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final int[] args, final int argsCount, final CSIState state) {
|
||||
if (state.greaterThan) { // XTSMTITLE
|
||||
System.out.println("XTSMTITLE is not implemented");
|
||||
} else if (state.space) { // DECSWBV
|
||||
System.out.println("DECSWBV is not implemented yet");
|
||||
} else if (state.dollarSign) { //DECRARA
|
||||
System.out.println("DECRARA is not implemented");
|
||||
} else { // XTWINOPS
|
||||
switch (args[0]) {
|
||||
case 14 -> terminal.putResponse("\033[4;" + Terminal.HEIGHT + ";" + Terminal.WIDTH); //terminal.putResponse("\033[4;" + (Terminal.HEIGHT * Terminal.CHAR_HEIGHT) + ";" + (Terminal.WIDTH * Terminal.CHAR_WIDTH));
|
||||
case 15 -> terminal.putResponse("\033[5;" + (Terminal.HEIGHT * Terminal.CHAR_HEIGHT) + ";" + (Terminal.WIDTH * Terminal.CHAR_WIDTH));
|
||||
case 16 -> terminal.putResponse("\033[6;" + Terminal.CHAR_HEIGHT + ";" + Terminal.CHAR_WIDTH);
|
||||
case 18 -> terminal.putResponse("\033[8;" + Terminal.HEIGHT + ";" + Terminal.WIDTH);
|
||||
case 19 -> terminal.putResponse("\033[9;" + Terminal.HEIGHT + ";" + Terminal.WIDTH);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package li.cil.oc2.common.vm.terminal.escapes.csi;
|
||||
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
|
||||
public class CH5 extends CSISequenceHandler { // Combined Handler 5 (XTSMPOINTER, DECSTR, DECSCL, and DECRARA)
|
||||
public CH5(final Terminal terminal) {
|
||||
super(terminal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final int[] args, final int argsCount, final CSIState state) {
|
||||
if (state.greaterThan) { // XTSMPOINTER
|
||||
System.out.println("XTSMPOINTER not implemented");
|
||||
} else if (state.exclamation) { // DECSTR
|
||||
System.out.println("DECSTR not implemented");
|
||||
} else if (state.quote) { // DECSCL
|
||||
System.out.println("DECSCL not implemented");
|
||||
} else if (state.dollarSign) { // DECRQM
|
||||
int mode = args[0];
|
||||
if (state.questionMark) { // DECSET/DECRST
|
||||
terminal.putResponse("\033[?" + mode + ";" + (terminal.currentPrivateModeState.getMode(mode) ? 1 : 0) + "$y");
|
||||
}
|
||||
else { // SM/RM
|
||||
terminal.putResponse("\033[" + mode + ";" + (terminal.currentModeState.getMode(mode) ? 1 : 0) + "$y");
|
||||
}
|
||||
} else { // XTPUSHSGR
|
||||
System.out.println("XTPUSHSGR not implemented");
|
||||
}
|
||||
}
|
||||
}
|
||||
104
src/main/java/li/cil/oc2/common/vm/terminal/escapes/csi/CH6.java
Normal file
104
src/main/java/li/cil/oc2/common/vm/terminal/escapes/csi/CH6.java
Normal file
@@ -0,0 +1,104 @@
|
||||
package li.cil.oc2.common.vm.terminal.escapes.csi;
|
||||
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
|
||||
public class CH6 extends CSISequenceHandler { // Combined Handler 6 (XTSAVE, XTSHIFTESCAPE, DECSLRM, and SCOSC)
|
||||
public CH6(final Terminal terminal) {
|
||||
super(terminal);
|
||||
}
|
||||
|
||||
public void execute(final int[] args, final int argsCount, final CSIState state) {
|
||||
if (state.questionMark) { // XTSAVE
|
||||
handleXTSAVE(args[0]);
|
||||
}
|
||||
else if (state.greaterThan) { // XTSHIFTESCAPE
|
||||
System.out.println("XTSHIFTESCAPE not implemented");
|
||||
}
|
||||
else if (argsCount == 2) { // DECSLRM
|
||||
System.out.println("DECSLRM not implemented");
|
||||
}
|
||||
else if (argsCount == 0) { // SCOSC
|
||||
if (!terminal.currentPrivateModeState.DECLRMM) {
|
||||
terminal.savedX = terminal.x;
|
||||
terminal.savedY = terminal.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleXTSAVE(final int mode) {
|
||||
switch (mode) {
|
||||
case 1 -> terminal.savePrivateModeState.DECCKM = terminal.currentPrivateModeState.DECCKM;
|
||||
case 2 -> terminal.savePrivateModeState.DECANM = terminal.currentPrivateModeState.DECANM;
|
||||
case 3 -> terminal.savePrivateModeState.DECCOLM = terminal.currentPrivateModeState.DECCOLM;
|
||||
case 4 -> terminal.savePrivateModeState.DECSCLM = terminal.currentPrivateModeState.DECSCLM;
|
||||
case 5 -> terminal.savePrivateModeState.DECSCNM = terminal.currentPrivateModeState.DECSCNM;
|
||||
case 6 -> terminal.savePrivateModeState.DECOM = terminal.currentPrivateModeState.DECOM;
|
||||
case 7 -> terminal.savePrivateModeState.DECAWM = terminal.currentPrivateModeState.DECAWM;
|
||||
case 8 -> terminal.savePrivateModeState.DECARM = terminal.currentPrivateModeState.DECARM;
|
||||
case 9 -> terminal.savePrivateModeState.X10MM = terminal.currentPrivateModeState.X10MM;
|
||||
case 10 -> terminal.savePrivateModeState.TOOLBAR = terminal.currentPrivateModeState.TOOLBAR;
|
||||
case 12 -> terminal.savePrivateModeState.START_BLINKING_CURSOR = terminal.currentPrivateModeState.START_BLINKING_CURSOR;
|
||||
case 13 -> terminal.savePrivateModeState.START_BLINKING_CURSOR2 = terminal.currentPrivateModeState.START_BLINKING_CURSOR2;
|
||||
case 14 -> terminal.savePrivateModeState.XORBLINK = terminal.currentPrivateModeState.XORBLINK;
|
||||
case 18 -> terminal.savePrivateModeState.DECPFF = terminal.currentPrivateModeState.DECPFF;
|
||||
case 19 -> terminal.savePrivateModeState.DECPEX = terminal.currentPrivateModeState.DECPEX;
|
||||
case 25 -> terminal.savePrivateModeState.DECTCEM = terminal.currentPrivateModeState.DECTCEM;
|
||||
case 30 -> terminal.savePrivateModeState.SHOW_SCROLL = terminal.currentPrivateModeState.SHOW_SCROLL;
|
||||
case 35 -> terminal.savePrivateModeState.FONT_SHIFT = terminal.currentPrivateModeState.FONT_SHIFT;
|
||||
case 38 -> terminal.savePrivateModeState.TEKTRONIX = terminal.currentPrivateModeState.TEKTRONIX;
|
||||
case 40 -> terminal.savePrivateModeState.ENABLE_80_132 = terminal.currentPrivateModeState.ENABLE_80_132;
|
||||
case 41 -> terminal.savePrivateModeState.MORE_FIX = terminal.currentPrivateModeState.MORE_FIX;
|
||||
case 42 -> terminal.savePrivateModeState.DECNRCM = terminal.currentPrivateModeState.DECNRCM;
|
||||
case 43 -> terminal.savePrivateModeState.DECGEPM = terminal.currentPrivateModeState.DECGEPM;
|
||||
case 44 -> terminal.savePrivateModeState.MARG_BELL = terminal.currentPrivateModeState.MARG_BELL;
|
||||
case 45 -> terminal.savePrivateModeState.XTREVWRAP = terminal.currentPrivateModeState.XTREVWRAP;
|
||||
case 46 -> terminal.savePrivateModeState.XTLOGGING = terminal.currentPrivateModeState.XTLOGGING;
|
||||
case 47 -> terminal.savePrivateModeState.ALT_BUFFER = terminal.currentPrivateModeState.ALT_BUFFER;
|
||||
case 66 -> terminal.savePrivateModeState.DECNKM = terminal.currentPrivateModeState.DECNKM;
|
||||
case 67 -> terminal.savePrivateModeState.DECBKM = terminal.currentPrivateModeState.DECBKM;
|
||||
case 69 -> terminal.savePrivateModeState.DECLRMM = terminal.currentPrivateModeState.DECLRMM;
|
||||
case 80 -> terminal.savePrivateModeState.DECSDM = terminal.currentPrivateModeState.DECSDM;
|
||||
case 96 -> terminal.savePrivateModeState.DECNCSM = terminal.currentPrivateModeState.DECNCSM;
|
||||
case 1000 -> terminal.savePrivateModeState.X11MM = terminal.currentPrivateModeState.X11MM;
|
||||
case 1001 -> terminal.savePrivateModeState.HILITE_MOUSE = terminal.currentPrivateModeState.HILITE_MOUSE;
|
||||
case 1002 -> terminal.savePrivateModeState.CELL_MOTION_MOUSE = terminal.currentPrivateModeState.CELL_MOTION_MOUSE;
|
||||
case 1003 -> terminal.savePrivateModeState.ALL_MOTION_MOUSE_TRACKING = terminal.currentPrivateModeState.ALL_MOTION_MOUSE_TRACKING;
|
||||
case 1004 -> terminal.savePrivateModeState.FOCUS_IN_FOCUS_OUT = terminal.currentPrivateModeState.FOCUS_IN_FOCUS_OUT;
|
||||
case 1005 -> terminal.savePrivateModeState.UTF8_MOUSE = terminal.currentPrivateModeState.UTF8_MOUSE;
|
||||
case 1006 -> terminal.savePrivateModeState.SGR_MOUSE = terminal.currentPrivateModeState.SGR_MOUSE;
|
||||
case 1007 -> terminal.savePrivateModeState.ALTERNATE_SCROLL_MODE = terminal.currentPrivateModeState.ALTERNATE_SCROLL_MODE;
|
||||
case 1010 -> terminal.savePrivateModeState.SCROLL_BOTTOM_ON_OUTPUT = terminal.currentPrivateModeState.SCROLL_BOTTOM_ON_OUTPUT;
|
||||
case 1011 -> terminal.savePrivateModeState.SCROLL_BOTTOM_ON_KEY_PRESS = terminal.currentPrivateModeState.SCROLL_BOTTOM_ON_KEY_PRESS;
|
||||
case 1014 -> terminal.savePrivateModeState.FAST_SCROLL = terminal.currentPrivateModeState.FAST_SCROLL;
|
||||
case 1015 -> terminal.savePrivateModeState.URXVT_MOUSE = terminal.currentPrivateModeState.URXVT_MOUSE;
|
||||
case 1016 -> terminal.savePrivateModeState.SGR_MOUSE_PIXEL = terminal.currentPrivateModeState.SGR_MOUSE_PIXEL;
|
||||
case 1034 -> terminal.savePrivateModeState.META_KEY = terminal.currentPrivateModeState.META_KEY;
|
||||
case 1035 -> terminal.savePrivateModeState.SPECIAL_MODIFIERS = terminal.currentPrivateModeState.SPECIAL_MODIFIERS;
|
||||
case 1036 -> terminal.savePrivateModeState.META_SENDS_ESCAPE = terminal.currentPrivateModeState.META_SENDS_ESCAPE;
|
||||
case 1037 -> terminal.savePrivateModeState.DEL_EDIT_KEYPAD_DEL = terminal.currentPrivateModeState.DEL_EDIT_KEYPAD_DEL;
|
||||
case 1039 -> terminal.savePrivateModeState.ALT_SENDS_ESC = terminal.currentPrivateModeState.ALT_SENDS_ESC;
|
||||
case 1040 -> terminal.savePrivateModeState.KEEP_SELECTION = terminal.currentPrivateModeState.KEEP_SELECTION;
|
||||
case 1041 -> terminal.savePrivateModeState.USE_CLIP = terminal.currentPrivateModeState.USE_CLIP;
|
||||
case 1042 -> terminal.savePrivateModeState.ENABLE_URGENCY = terminal.currentPrivateModeState.ENABLE_URGENCY;
|
||||
case 1043 -> terminal.savePrivateModeState.RAISE_ON_CTRL_G = terminal.currentPrivateModeState.RAISE_ON_CTRL_G;
|
||||
case 1044 -> terminal.savePrivateModeState.KEEP_CLIP = terminal.currentPrivateModeState.KEEP_CLIP;
|
||||
case 1045 -> terminal.savePrivateModeState.EXT_REV_WRAP = terminal.currentPrivateModeState.EXT_REV_WRAP;
|
||||
case 1046 -> terminal.savePrivateModeState.ALLOW_ALT_BUFFER = terminal.currentPrivateModeState.ALLOW_ALT_BUFFER;
|
||||
case 1047 -> terminal.savePrivateModeState.SWITCH_ALT_BUFFER = terminal.currentPrivateModeState.SWITCH_ALT_BUFFER;
|
||||
case 1048 -> terminal.savePrivateModeState.SAVE_CURSOR = terminal.currentPrivateModeState.SAVE_CURSOR;
|
||||
case 1049 -> terminal.savePrivateModeState.SAVE_CLEAR_AND_SWITCH = terminal.currentPrivateModeState.SAVE_CLEAR_AND_SWITCH;
|
||||
case 1050 -> terminal.savePrivateModeState.SET_TERMINFO_FUNC_KEY_MODE = terminal.currentPrivateModeState.SET_TERMINFO_FUNC_KEY_MODE;
|
||||
case 1051 -> terminal.savePrivateModeState.SET_SUN_KEY_MODE = terminal.currentPrivateModeState.SET_SUN_KEY_MODE;
|
||||
case 1052 -> terminal.savePrivateModeState.SET_HP_K0EY_MODE = terminal.currentPrivateModeState.SET_HP_K0EY_MODE;
|
||||
case 1053 -> terminal.savePrivateModeState.SET_SCO_KEY_MODE = terminal.currentPrivateModeState.SET_SCO_KEY_MODE;
|
||||
case 1060 -> terminal.savePrivateModeState.SET_LEGACY_KEYBOARD = terminal.currentPrivateModeState.SET_LEGACY_KEYBOARD;
|
||||
case 1061 -> terminal.savePrivateModeState.SET_VT220_KEYBOARD = terminal.currentPrivateModeState.SET_VT220_KEYBOARD;
|
||||
case 2001 -> terminal.savePrivateModeState.ENABLE_READLINE_MOUSE_1 = terminal.currentPrivateModeState.ENABLE_READLINE_MOUSE_1;
|
||||
case 2002 -> terminal.savePrivateModeState.ENABLE_READLINE_MOUSE_2 = terminal.currentPrivateModeState.ENABLE_READLINE_MOUSE_2;
|
||||
case 2003 -> terminal.savePrivateModeState.ENABLE_READLINE_MOUSE_3 = terminal.currentPrivateModeState.ENABLE_READLINE_MOUSE_3;
|
||||
case 2004 -> terminal.savePrivateModeState.SET_BRACKETED_PASTE = terminal.currentPrivateModeState.SET_BRACKETED_PASTE;
|
||||
case 2005 -> terminal.savePrivateModeState.ENABLE_READLINE_CHAR_QUOTE = terminal.currentPrivateModeState.ENABLE_READLINE_CHAR_QUOTE;
|
||||
case 2006 -> terminal.savePrivateModeState.ENABLE_READLINE_NEWLINE_PASTE = terminal.currentPrivateModeState.ENABLE_READLINE_NEWLINE_PASTE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package li.cil.oc2.common.vm.terminal.escapes.csi;
|
||||
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
|
||||
public class CH7 extends CSISequenceHandler { // Combined Handler 7 (XTVERSION, DECLL, DECSCUSR, DECSCA, and XTPOPSGR)
|
||||
public CH7(final Terminal terminal) {
|
||||
super(terminal);
|
||||
}
|
||||
|
||||
public void execute(final int[] args, final int argsCount, final CSIState state) {
|
||||
if (state.greaterThan) { // XTVERSION
|
||||
System.out.println("XTVERSION not implemented");
|
||||
} else if (state.space) { // DECSCUSR
|
||||
int cursorStyle = args[0];
|
||||
if (cursorStyle < 0 || cursorStyle > 6) {
|
||||
terminal.cursorMode = Terminal.CursorMode.DEFAULT;
|
||||
return;
|
||||
}
|
||||
terminal.cursorMode = cursorStyle;
|
||||
} else if (state.quote) { // DECSCA
|
||||
System.out.println("DECSCA not implemented");
|
||||
} else if (state.hash) { // XTPOPSGR
|
||||
System.out.println("XTPOPSGR not implemented");
|
||||
} else { // DECLL
|
||||
System.out.println("DECLL not implemented");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package li.cil.oc2.common.vm.terminal.escapes.csi;
|
||||
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
|
||||
public class CH8 extends CSISequenceHandler { // Combined Handler 8 (SU, XTTITLEPOS, and XTSMGRAPHICS)
|
||||
public CH8(final Terminal terminal) {
|
||||
super(terminal);
|
||||
}
|
||||
|
||||
public void execute(final int[] args, final int argsCount, final CSIState state) {
|
||||
if (state.questionMark) { // XTSMGRAPHICS
|
||||
System.out.println("XTSMGRAPHICS not implemented");
|
||||
} else if (state.hash) { // XTTITLEPOS
|
||||
System.out.println("XTTITLEPOS not implemented");
|
||||
} else { // SU
|
||||
for (int i = 0; i < args[0]; i++) {
|
||||
terminal.shiftUpOne();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package li.cil.oc2.common.vm.terminal.escapes.csi;
|
||||
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
|
||||
public class CH9 extends CSISequenceHandler { // Combined Handler 9 (SD, XTHIMOUSE, and XTRMTITLE)
|
||||
public CH9(final Terminal terminal) {
|
||||
super(terminal);
|
||||
}
|
||||
|
||||
public void execute(final int[] args, final int argsCount, final CSIState state) {
|
||||
if (state.greaterThan) { // XTRMTITLE
|
||||
System.out.println("XTRMTITLE not implemented");
|
||||
} else if (argsCount == 5) { // XTHIMOUSE
|
||||
System.out.println("XTHIMOUSE not implemented");
|
||||
} else { // SD
|
||||
for (int i = 0; i < args[0]; i++) {
|
||||
terminal.shiftDownOne();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package li.cil.oc2.common.vm.terminal.escapes.csi;
|
||||
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
|
||||
public class CHA extends CSISequenceHandler {
|
||||
public CHA(final Terminal terminal) {
|
||||
super(terminal);
|
||||
}
|
||||
|
||||
public void execute(final int[] args, final int argsCount, final CSIState state) {
|
||||
terminal.setClampedCursorPos(args[0] - 1, terminal.y);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package li.cil.oc2.common.vm.terminal.escapes.csi;
|
||||
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
import li.cil.oc2.common.vm.terminal.escapes.EscapeUtilities;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class CSIManager {
|
||||
private final int[] args = new int[10];
|
||||
private int argCount = 0;
|
||||
private boolean questionMark = false;
|
||||
private boolean greaterThan = false;
|
||||
private boolean dollarSign = false;
|
||||
private boolean hash = false;
|
||||
private boolean quote = false;
|
||||
private boolean singleQuote = false;
|
||||
private boolean space = false;
|
||||
private boolean exclamation = false;
|
||||
|
||||
private final Terminal terminal;
|
||||
private final HashMap<Character, CSISequenceHandler> sequences = new HashMap<>();
|
||||
|
||||
public CSIManager(Terminal terminal) {
|
||||
this.terminal = terminal;
|
||||
|
||||
sequences.put('A', new CUU(terminal));
|
||||
sequences.put('B', new CUD(terminal));
|
||||
sequences.put('C', new CUF(terminal));
|
||||
sequences.put('D', new CUB(terminal));
|
||||
sequences.put('H', new CUP(terminal));
|
||||
sequences.put('f', new HVP(terminal));
|
||||
sequences.put('m', new SGR(terminal));
|
||||
sequences.put('K', new EL(terminal));
|
||||
sequences.put('J', new ED(terminal));
|
||||
sequences.put('r', new CH1(terminal));
|
||||
sequences.put('g', new TBC(terminal));
|
||||
sequences.put('h', new CH2(terminal));
|
||||
sequences.put('l', new CH3(terminal));
|
||||
sequences.put('n', new DSR(terminal));
|
||||
sequences.put('c', new DA(terminal));
|
||||
sequences.put('d', new VPA(terminal));
|
||||
sequences.put('G', new CHA(terminal));
|
||||
sequences.put('t', new CH4(terminal));
|
||||
sequences.put('p', new CH5(terminal));
|
||||
sequences.put('s', new CH6(terminal));
|
||||
sequences.put('X', new ECH(terminal));
|
||||
sequences.put('q', new CH7(terminal));
|
||||
sequences.put('L', new IL(terminal));
|
||||
sequences.put('M', new DL(terminal));
|
||||
sequences.put('S', new CH8(terminal));
|
||||
sequences.put('T', new CH9(terminal));
|
||||
}
|
||||
|
||||
public void handle(final char ch) {
|
||||
if (ch >= '0' && ch <= '9') {
|
||||
if (argCount < args.length) {
|
||||
args[argCount] = EscapeUtilities.parseArgument(ch, args[argCount]);
|
||||
}
|
||||
} else {
|
||||
switch (ch) {
|
||||
case ' ' -> {
|
||||
space = true;
|
||||
return;
|
||||
}
|
||||
case '?' -> {
|
||||
questionMark = true;
|
||||
return;
|
||||
}
|
||||
case '>' -> {
|
||||
greaterThan = true;
|
||||
return;
|
||||
}
|
||||
case '$' -> {
|
||||
dollarSign = true;
|
||||
return;
|
||||
}
|
||||
case '#' -> {
|
||||
hash = true;
|
||||
return;
|
||||
}
|
||||
case '"' -> {
|
||||
quote = true;
|
||||
return;
|
||||
}
|
||||
case '\'' -> {
|
||||
singleQuote = true;
|
||||
return;
|
||||
}
|
||||
case '!' -> {
|
||||
exclamation = true;
|
||||
return;
|
||||
}
|
||||
case ';' -> {
|
||||
argCount++;
|
||||
return; // Keep going, we have another argument.
|
||||
}
|
||||
default -> argCount++;
|
||||
}
|
||||
|
||||
terminal.state = Terminal.State.NORMAL;
|
||||
|
||||
CSISequenceHandler handler = sequences.get(ch);
|
||||
CSIState state = new CSIState(questionMark, greaterThan, dollarSign, hash, quote, singleQuote, space, exclamation);
|
||||
|
||||
if (handler != null) {
|
||||
handler.execute(args, argCount, state);
|
||||
}
|
||||
else {
|
||||
System.out.println("Control sequence: " + ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
questionMark = false;
|
||||
greaterThan = false;
|
||||
dollarSign = false;
|
||||
hash = false;
|
||||
quote = false;
|
||||
singleQuote = false;
|
||||
space = false;
|
||||
argCount = 0;
|
||||
Arrays.fill(args, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package li.cil.oc2.common.vm.terminal.escapes.csi;
|
||||
|
||||
import li.cil.oc2.common.vm.terminal.Terminal;
|
||||
|
||||
public abstract class CSISequenceHandler {
|
||||
protected Terminal terminal;
|
||||
|
||||
public CSISequenceHandler(Terminal terminal) {
|
||||
this.terminal = terminal;
|
||||
}
|
||||
|
||||
public abstract void execute(int[] args, int argsCount, CSIState state);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user