Forge upgrade/fix and CSI cleanup. Also fixes scrollback. Also clears *all* warnings from the build.

This commit is contained in:
JacksonAbney
2025-04-15 20:58:28 -08:00
parent 870cce43da
commit e64ee88f14
124 changed files with 1106 additions and 870 deletions

View File

@@ -1,3 +1,4 @@
#file: noinspection UndefinedAction,UndefinedParamsPresent
name: build
on:

View File

@@ -1,3 +1,4 @@
#file: noinspection UndefinedAction,UndefinedParamsPresent
name: publish
on:

View File

@@ -7,14 +7,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"
}
}
}
}
@@ -135,16 +136,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*"
}
@@ -160,7 +161,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"
@@ -201,7 +202,7 @@ mixin {
// quiet
}
task copyGeneratedResources(type: Copy) {
tasks.register('copyGeneratedResources', Copy) {
from "src/generated"
into "src/main"
exclude "resources/.cache"
@@ -226,7 +227,7 @@ jar {
}
}
task apiJar(type: Jar) {
tasks.register('apiJar', Jar) {
archiveClassifier.set("api")
from sourceSets.main.allSource
from sourceSets.main.output
@@ -237,29 +238,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 {

View File

@@ -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

View File

@@ -1,4 +0,0 @@
ext {
minecraft_version = '1.20.1'
minecraft_sdk = 'forge'
}

View File

@@ -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) {

View File

@@ -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.

View File

@@ -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();
}

View File

@@ -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));
}
}

View File

@@ -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);

View File

@@ -222,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

View File

@@ -28,13 +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 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;
}
@@ -45,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;
}
@@ -66,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;
}
@@ -83,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);
@@ -129,12 +129,12 @@ public abstract class AbstractMonitorDisplayScreen<T extends AbstractMonitorCont
@Override
public void onPress() {
super.onPress();
terminalWidget.isInputCaptureEnabled = !terminalWidget.isInputCaptureEnabled;
monitorDisplayWidget.isInputCaptureEnabled = !monitorDisplayWidget.isInputCaptureEnabled;
}
@Override
public boolean isToggled() {
return terminalWidget.isInputCaptureEnabled;
return monitorDisplayWidget.isInputCaptureEnabled;
}
}).withTooltip(
Component.translatable(Constants.TERMINAL_CAPTURE_INPUT_CAPTION),
@@ -145,7 +145,7 @@ public abstract class AbstractMonitorDisplayScreen<T extends AbstractMonitorCont
@Override
public void onClose() {
super.onClose();
terminalWidget.onClose();
monitorDisplayWidget.onClose();
}
///////////////////////////////////////////////////////////////////
@@ -165,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
@@ -179,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

View File

@@ -4,8 +4,8 @@ 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.MouseMode;
import li.cil.oc2.common.vm.terminal.PrivateMode;
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;
@@ -66,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);
@@ -90,16 +90,15 @@ 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();
}
@@ -135,7 +134,7 @@ public final class MachineTerminalWidget {
public boolean mouseClicked(double x, double y, int button) {
MouseMode currentMouseMode = terminal.currentPrivateModeState.getMouseMode();
if (!currentMouseMode.isMouseEnabled()) return false;
if (currentMouseMode.isMouseDisabled()) return false;
Vector2i position = getMousePosition(x, y);
boolean overTerminal = isMouseOverTerminal((int)x, (int)y);
if (overTerminal && shouldCaptureInput()) {
@@ -184,7 +183,7 @@ public final class MachineTerminalWidget {
public boolean mouseReleased(double x, double y, int button) {
MouseMode currentMouseMode = terminal.currentPrivateModeState.getMouseMode();
if (!currentMouseMode.isMouseEnabled()) return false;
if (currentMouseMode.isMouseDisabled()) return false;
Vector2i position = getMousePosition(x, y);
boolean overTerminal = isMouseOverTerminal((int)x, (int)y);
if (overTerminal && shouldCaptureInput()) {
@@ -251,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;

View File

@@ -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) {

View File

@@ -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");
///////////////////////////////////////////////////////////////////

View File

@@ -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"),

View File

@@ -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

View File

@@ -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) {

View File

@@ -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"};

View File

@@ -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);

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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");
///////////////////////////////////////////////////////////////////

View File

@@ -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

View File

@@ -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) {

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -3,9 +3,7 @@
package li.cil.oc2.common.block;
import li.cil.oc2.common.blockentity.BlockEntities;
import li.cil.oc2.common.blockentity.ComputerBlockEntity;
import li.cil.oc2.common.blockentity.DiskDriveBlockEntity;
import li.cil.oc2.common.item.Items;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionHand;

View File

@@ -3,7 +3,6 @@
package li.cil.oc2.common.block;
import li.cil.oc2.common.blockentity.BlockEntities;
import li.cil.oc2.common.blockentity.DiskDriveBlockEntity;
import li.cil.oc2.common.blockentity.FlashMemoryFlasherBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;

View File

@@ -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());
}
///////////////////////////////////////////////////////////////////

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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)
));
}

View File

@@ -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

View File

@@ -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;

View File

@@ -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();
}

View File

@@ -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);

View File

@@ -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<>();

View File

@@ -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());
}
}

View File

@@ -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));
}

View File

@@ -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)) {

View File

@@ -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

View File

@@ -27,10 +27,11 @@ 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

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -16,9 +16,11 @@ import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import li.cil.oc2.common.bus.device.data.FileSystems;
import java.util.Objects;
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);
@@ -69,7 +71,7 @@ public final class Items {
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));
new HardDriveWithExternalDataItem(Objects.requireNonNull(FileSystems.getKeyByValue(FileSystems.getBlockByName("rootfs"))), DyeColor.BROWN));
public static final RegistryObject<CPUItem> CPU_TIER_1 = register("cpu_tier_1", () ->
new CPUItem(25_000_000));
@@ -111,8 +113,8 @@ public final class Items {
///////////////////////////////////////////////////////////////////
public static void initialize() {
ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
public static void initialize(FMLJavaModLoadingContext context) {
ITEMS.register(context.getModEventBus());
}
///////////////////////////////////////////////////////////////////

View File

@@ -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;
}

View File

@@ -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());
}
}

View File

@@ -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

View File

@@ -1,15 +1,11 @@
package li.cil.oc2.common.serialization.ceres;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.SerializedName;
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 net.minecraft.network.chat.MutableComponent;
import net.minecraft.util.GsonHelper;
import org.jetbrains.annotations.Nullable;
public class ColorModeSerializer implements Serializer<Terminal.ColorMode> {

View File

@@ -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));
}
}

View File

@@ -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));
}
}

View File

@@ -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();
}

View File

@@ -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)));
}
}

View File

@@ -27,7 +27,9 @@ 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
@SuppressWarnings("all")
public final class OldTerminal {
public static final int WIDTH = 80, HEIGHT = 24;
public static final int CHAR_WIDTH = 8;
@@ -331,9 +333,7 @@ public final class OldTerminal {
} // DECKPAM Keypad Application Mode (DEC Private)
case '>' -> {
} // DECKPNM Keypad Numeric Mode (DEC Private)
default -> {
System.out.println("Invalid escape: " + ch);
}
default -> System.out.println("Invalid escape: " + ch);
}
}
}
@@ -943,7 +943,7 @@ public final class OldTerminal {
@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;

View File

@@ -5,16 +5,19 @@ import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import it.unimi.dsi.fastutil.bytes.ByteArrayFIFOQueue;
import li.cil.ceres.api.Serialized;
import li.cil.oc2.api.API;
import li.cil.oc2.common.vm.terminal.escapes.CSI.CSIManager;
import li.cil.oc2.common.vm.terminal.escapes.apc.APCManager;
import li.cil.oc2.common.vm.terminal.escapes.csi.CSIManager;
import li.cil.oc2.common.vm.terminal.escapes.*;
import li.cil.oc2.common.vm.terminal.escapes.dcs.DCSManager;
import li.cil.oc2.common.vm.terminal.escapes.osc.OSCManager;
import li.cil.oc2.common.vm.terminal.fonts.FontHandling;
import li.cil.oc2.common.vm.terminal.fonts.Glyph;
import li.cil.oc2.common.vm.terminal.modes.ModeState;
import li.cil.oc2.common.vm.terminal.modes.PrivateModeState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.ShaderInstance;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@@ -72,7 +75,7 @@ public class Terminal {
public State state = State.NORMAL;
public int scrollFirst = 0, scrollLast = HEIGHT - 1;
public int x, y;
public int savedX, savedY;
public int savedX, savedY, altSavedX, altSavedY;
public int lastRowToDisplay = 24, lastRowToDisplayMax = 24;
// Alt Buffer
@@ -86,7 +89,6 @@ public class Terminal {
public final transient Set<RendererModel> renderers = Collections.synchronizedSet(Collections.newSetFromMap(new WeakHashMap<>()));
public transient boolean displayOnly; // Set on client to not send responses to status requests.
public transient boolean hasPendingBell;
public char lastChar;
public boolean continuationByte;
public int unicode;
public int bytesRead;
@@ -96,7 +98,6 @@ public class Terminal {
public int drawingModeG1;
public int cursorMode;
public ModeState currentModeState = new ModeState();
public ModeState saveModeState = new ModeState();
public PrivateModeState currentPrivateModeState = new PrivateModeState();
public PrivateModeState savePrivateModeState = new PrivateModeState();
@@ -125,6 +126,7 @@ public class Terminal {
public static final int SPECIAL_GRAPHICS = 1; // BLINKING BLOCK
}
@SuppressWarnings("unused")
public static final class Color {
static final int BLACK = 0;
static final int RED = 1;
@@ -163,12 +165,6 @@ public class Terminal {
ColorMode Mode = ColorMode.SIXTEEN_COLOR;
}
public ColorData(final int r, final int g, final int b) {
R = r;
G = g;
B = b;
}
public ColorData(final int r, final int g, final int b, final ColorMode mode) {
R = r;
G = g;
@@ -186,7 +182,10 @@ public class Terminal {
}
// Instances
private final CSIManager csiManager = new CSIManager();
private final CSIManager csiManager = new CSIManager(this);
private final OSCManager oscManager = new OSCManager(this);
private final DCSManager dcsManager = new DCSManager(this);
private final APCManager apcManager = new APCManager(this);
// Nested interfaces
public interface RendererView {
@@ -199,10 +198,6 @@ public class Terminal {
void close();
}
public void setDefaultMode() {
}
// Generic Getters
public int getWidth() {
return WIDTH * CHAR_WIDTH;
@@ -235,6 +230,9 @@ public class Terminal {
if (originallyEqual) {
lastRowToDisplay = lastRowToDisplayMax;
}
else {
lastRowToDisplay = Math.min(lastRowToDisplay + 1, lastRowToDisplayMax);
}
int dirtyLinesMask = 0;
for (int i = 0; i <= 23; i++) {
@@ -436,7 +434,6 @@ public class Terminal {
bytesToRead++;
} else {
continuationByte = false;
System.out.println("ERR: Invalid first byte received");
return;
}
@@ -462,7 +459,6 @@ public class Terminal {
continuationByte = false;
bytesToRead = 0;
bytesRead = 0;
System.out.println("ERR: Invalid continuation byte received");
return;
}
@@ -482,12 +478,8 @@ public class Terminal {
switch (value) {
case '\007' -> hasPendingBell = true;
case '\033' -> state = State.ESCAPE;
case '\016' -> {
useG0 = false;
} // SO
case '\017' -> {
useG0 = true;
} // SI
case '\016' -> useG0 = false; // SO
case '\017' -> useG0 = true; // SI
case (byte) '\r' /* 015 */ -> setCursorPos(0, y);
case (byte) '\n' /* 012 */, '\013', '\014' -> {
@@ -520,14 +512,13 @@ public class Terminal {
} else if (ch == '#') { // # Intermediate
state = State.HASH;
} else if (ch == 'P') {
lastChar = '\0';
dcsManager.reset();
state = State.DCS;
} else if (ch == ']') {
System.out.println("OSC");
lastChar = '\0';
oscManager.reset();
state = State.OSC;
} else if (ch == '_') {
lastChar = '\0';
apcManager.reset();
state = State.APC;
} else {
state = State.NORMAL;
@@ -543,41 +534,18 @@ public class Terminal {
} // DECKPAM Keypad Application Mode (DEC public)
case '>' -> {
} // DECKPNM Keypad Numeric Mode (DEC public)
default -> {
System.out.println("Invalid escape: " + ch);
}
default -> System.out.println("Invalid escape: " + ch);
}
}
}
case CONTROL_SEQUENCE -> csiManager.handle(ch, this);
case SHIFT_IN_CHARACTER_SET -> {
case CONTROL_SEQUENCE -> csiManager.handle(ch);
case SHIFT_IN_CHARACTER_SET, SHIFT_OUT_CHARACTER_SET -> {
state = State.NORMAL;
switch (ch) {
case 'A' -> {
} // United Kingdom Set
case 'B' -> {
drawingModeG0 = DrawingMode.ASCII;
} // ASCII Set
case '0' -> {
drawingModeG0 = DrawingMode.SPECIAL_GRAPHICS;
} // Special Graphics
case '1' -> {
} // Alternate Character ROM Standard Character Set
case '2' -> {
} // Alternate Character ROM Special Graphics
}
}
case SHIFT_OUT_CHARACTER_SET -> {
state = State.NORMAL;
switch (ch) {
case 'A' -> {
} // United Kingdom Set
case 'B' -> {
drawingModeG1 = DrawingMode.ASCII;
} // ASCII Set
case '0' -> {
drawingModeG1 = DrawingMode.SPECIAL_GRAPHICS;
} // Special Graphics
case 'B' -> drawingModeG0 = DrawingMode.ASCII; // ASCII Set
case '0' -> drawingModeG0 = DrawingMode.SPECIAL_GRAPHICS; // Special Graphics
case '1' -> {
} // Alternate Character ROM Standard Character Set
case '2' -> {
@@ -605,29 +573,9 @@ public class Terminal {
}
}
}
case DCS -> {
if (lastChar == '\033' && ch == '\\') {
state = State.NORMAL;
} else {
lastChar = ch;
}
// Used for mapping Function keys and possibly other things
}
case OSC -> {
System.out.println("OSC: " + ch);
if (lastChar == '\033' && ch == '\\' || ch == '\007') {
state = State.NORMAL;
} else {
lastChar = ch;
}
}
case APC -> {
if (lastChar == '\033' && ch == '\\') {
state = State.NORMAL;
} else {
lastChar = ch;
}
}
case DCS -> dcsManager.handle(ch); // Used for mapping Function keys and possibly other things
case OSC -> oscManager.handle(ch);
case APC -> apcManager.handle(ch);
}
}
@@ -758,17 +706,18 @@ public class Terminal {
if (curMode == DrawingMode.SPECIAL_GRAPHICS) {
switch (ch) {
case 'q' -> ch = "".codePointAt(0);
case 'x' -> ch = "".codePointAt(0);
case 'l' -> ch = "".codePointAt(0);
case 'k' -> ch = "".codePointAt(0);
case 'm' -> ch = "".codePointAt(0);
case 'j' -> ch = "".codePointAt(0);
case 't' -> ch = "".codePointAt(0);
case 'u' -> ch = "".codePointAt(0);
case 'v' -> ch = "".codePointAt(0);
case 'w' -> ch = "".codePointAt(0);
case 'q' -> ch = "".codePointAt(0);
case 'x' -> ch = "".codePointAt(0);
case 'n' -> ch = "".codePointAt(0);
case '~' -> ch = "B".codePointAt(0);
case 'u' -> ch = "".codePointAt(0);
case 't' -> ch = "".codePointAt(0);
case 'v' -> ch = "".codePointAt(0);
case 'w' -> ch = "".codePointAt(0);
}
}
@@ -791,27 +740,15 @@ public class Terminal {
altBuffer[index] = ch;
switch (currentForegroundColorMode) {
case SIXTEEN_COLOR -> {
altColors[index] = sixteenColor.Copy();
}
case TWO_FIFTY_SIX_COLOR -> {
altColors[index] = twoFiftySixColor.Copy();
}
case TRUE_COLOR -> {
altColors[index] = foregroundColor.Copy();
}
case SIXTEEN_COLOR -> altColors[index] = sixteenColor.Copy();
case TWO_FIFTY_SIX_COLOR -> altColors[index] = twoFiftySixColor.Copy();
case TRUE_COLOR -> altColors[index] = foregroundColor.Copy();
}
switch (currentBackgroundColorMode) {
case SIXTEEN_COLOR -> {
altColorsBackground[index] = sixteenColor.Copy();
}
case TWO_FIFTY_SIX_COLOR -> {
altColorsBackground[index] = twoFiftySixColor.Copy();
}
case TRUE_COLOR -> {
altColorsBackground[index] = backgroundColor.Copy();
}
case SIXTEEN_COLOR -> altColorsBackground[index] = sixteenColor.Copy();
case TWO_FIFTY_SIX_COLOR -> altColorsBackground[index] = twoFiftySixColor.Copy();
case TRUE_COLOR -> altColorsBackground[index] = backgroundColor.Copy();
}
altStyles[index] = style;
@@ -823,27 +760,15 @@ public class Terminal {
buffer[index] = ch;
switch (currentForegroundColorMode) {
case SIXTEEN_COLOR -> {
colors[index] = sixteenColor.Copy();
}
case TWO_FIFTY_SIX_COLOR -> {
colors[index] = twoFiftySixColor.Copy();
}
case TRUE_COLOR -> {
colors[index] = foregroundColor.Copy();
}
case SIXTEEN_COLOR -> colors[index] = sixteenColor.Copy();
case TWO_FIFTY_SIX_COLOR -> colors[index] = twoFiftySixColor.Copy();
case TRUE_COLOR -> colors[index] = foregroundColor.Copy();
}
switch (currentBackgroundColorMode) {
case SIXTEEN_COLOR -> {
colorsBackground[index] = sixteenColor.Copy();
}
case TWO_FIFTY_SIX_COLOR -> {
colorsBackground[index] = twoFiftySixColor.Copy();
}
case TRUE_COLOR -> {
colorsBackground[index] = backgroundColor.Copy();
}
case SIXTEEN_COLOR -> colorsBackground[index] = sixteenColor.Copy();
case TWO_FIFTY_SIX_COLOR -> colorsBackground[index] = twoFiftySixColor.Copy();
case TRUE_COLOR -> colorsBackground[index] = backgroundColor.Copy();
}
styles[index] = style;
@@ -935,7 +860,7 @@ public class Terminal {
renderBuffer(stack, projectionMatrix);
boolean steady = switch (terminal.cursorMode) {
case 2, 4, 6 -> true;
case CursorMode.STEADY_BLOCK, CursorMode.STEADY_UNDERLINE, CursorMode.STEADY_BAR_LINE -> true;
default -> false;
};
@@ -998,6 +923,7 @@ public class Terminal {
RenderSystem.depthMask(true);
}
@SuppressWarnings("resource")
public void validateLineCache() {
if (dirty.get() == 0) {
return;
@@ -1165,19 +1091,19 @@ public class Terminal {
final float b = ((foreground) & 0xFF) / 255f;
switch (terminal.cursorMode) {
case 0, 1, 2: // BLOCK
case CursorMode.DEFAULT, CursorMode.BLINK_BLOCK, CursorMode.STEADY_BLOCK: // BLOCK
buffer.vertex(matrix, 0, CHAR_HEIGHT, 0).color(r, g, b, 1).endVertex();
buffer.vertex(matrix, CHAR_WIDTH, CHAR_HEIGHT, 0).color(r, g, b, 1).endVertex();
buffer.vertex(matrix, CHAR_WIDTH, 0, 0).color(r, g, b, 1).endVertex();
buffer.vertex(matrix, 0, 0, 0).color(r, g, b, 1).endVertex();
break;
case 3, 4: // UNDERLINE
case CursorMode.BLINK_UNDERLINE, CursorMode.STEADY_UNDERLINE: // UNDERLINE
buffer.vertex(matrix, 0, 1, 0).color(r, g, b, 1).endVertex();
buffer.vertex(matrix, CHAR_WIDTH, 1, 0).color(r, g, b, 1).endVertex();
buffer.vertex(matrix, CHAR_WIDTH, 0, 0).color(r, g, b, 1).endVertex();
buffer.vertex(matrix, 0, 0, 0).color(r, g, b, 1).endVertex();
break;
case 5, 6: // VERTICAL BAR LINE
case CursorMode.BLINKING_BAR_LINE, CursorMode.STEADY_BAR_LINE: // VERTICAL BAR LINE
buffer.vertex(matrix, 0, CHAR_HEIGHT, 0).color(r, g, b, 1).endVertex();
buffer.vertex(matrix, 1, CHAR_HEIGHT, 0).color(r, g, b, 1).endVertex();
buffer.vertex(matrix, 1, 0, 0).color(r, g, b, 1).endVertex();

View File

@@ -1,163 +0,0 @@
package li.cil.oc2.common.vm.terminal.escapes.CSI;
import li.cil.oc2.common.vm.terminal.Terminal;
import java.util.Arrays;
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;
public void handle(final char ch, final Terminal terminal) {
if (ch >= '0' && ch <= '9') {
if (argCount < args.length) {
final int digit = ch - '0';
if (args[argCount] < (Integer.MAX_VALUE - digit) / 10) {
args[argCount] = args[argCount] * 10 + digit;
} else {
args[argCount] = Integer.MAX_VALUE;
}
}
} else {
if (ch == '?') {
questionMark = true;
return;
}
if (ch == '>') {
greaterThan = true;
return;
}
if (ch == '$') {
hash = true;
return;
}
if (ch == '#') {
hash = true;
return;
}
if (ch == '"') {
quote = true;
return;
}
if (ch == '\'') {
singleQuote = true;
return;
}
if (ch == ' ') {
space = true;
return;
}
if (argCount < args.length) {
argCount++;
}
if (ch == ';') {
return; // Keep going, we have another argument.
}
terminal.state = Terminal.State.NORMAL;
switch (ch) {
case 'A' -> CUU.execute(terminal, args[0]); // CUU - Cursor Up
case 'B' -> CUD.execute(terminal, args[0]); // CUD Cursor Down
case 'C' -> CUF.execute(terminal, args[0]); // CUF Cursor Forward
case 'D' -> CUB.execute(terminal, args[0]); // CUB Cursor Backward
case 'H' -> CUP.execute(terminal, args[0] - 1, args[1] - 1); // CUP - Cursor Position
case 'f' -> HVP.execute(terminal, args[0] - 1, args[1] - 1); // HVP Horizontal and Vertical Position
case 'm' -> SGR.execute(terminal, args, argCount); // SGR Select Graphic Rendition
case 'K' -> EL.execute(terminal, args[0]); // EL Erase In Line
case 'J' -> ED.execute(terminal, args[0]); // ED Erase In Display
case 'r' -> {
if (questionMark) {
XTRESTORE.executePrivate(terminal, args[0]);
}
else if (argCount == 2) {
DECSTBM.execute(terminal, args, argCount);
}
} // DECSTBM Set Top and Bottom Margins (DEC public)
case 'g' -> TBC.execute(terminal, args[0]); // TBC Tabulation Clear
case 'h' -> {
if (questionMark) {
SM.executeDECSET(terminal, args, argCount);
} else {
SM.execute(terminal, args, argCount);
}
} // SM Set Mode
case 'l' -> {
if (questionMark) {
RM.executeDECSET(terminal, args, argCount);
} else {
RM.execute(terminal, args, argCount);
}
} // RM Reset Mode
case 'n' -> DSR.execute(terminal, args[0]); // DSR Device Status Report
case 'c' -> DA.execute(terminal); // DA Device Attributes
case 'd' -> terminal.setClampedCursorPos(terminal.x, args[0] - 1);
case 'G' -> terminal.setClampedCursorPos(args[0] - 1, terminal.y);
case 't' -> {
if (args[0] == 14) {
terminal.putResponse("\033[4;80;24t");
}
}
case 'p' -> {
int mode = args[0];
if (questionMark && dollarSign) { // DECSET
terminal.putResponse("\033[?" + mode + ";" + (terminal.currentPrivateModeState.getMode(mode) ? 1 : 0) + "$y");
}
else if (dollarSign) { // SM
terminal.putResponse("\033[" + mode + ";" + (terminal.currentModeState.getMode(mode) ? 1 : 0) + "$y");
}
}
case 's' -> {
if (questionMark) {
XTSAVE.executePrivate(terminal, args[0]);
}
else if (greaterThan) {
// Set/reset shift-escape options
}
else if (argCount == 2) {
// Set left/right margins if DECLRMM is enabled
}
else if (argCount == 0) {
if (!terminal.currentPrivateModeState.DECLRMM) {
terminal.savedX = terminal.x;
terminal.savedY = terminal.y;
}
}
}
case 'X' -> DELCHAR.execute(terminal, args[0]);
case 'q' -> DECSCUSR.execute(terminal, args[0]);
case 'L' -> IL.execute(terminal, args[0]);
case 'M' -> DL.execute(terminal, args[0]);
case 'S' -> UNKN2.execute(terminal, args, argCount);
case 'T' -> UNKN.execute(terminal, args, argCount);
default -> 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);
}
}

View File

@@ -1,9 +0,0 @@
package li.cil.oc2.common.vm.terminal.escapes.CSI;
import li.cil.oc2.common.vm.terminal.Terminal;
public class CUB {
public static void execute(Terminal terminal, int value) {
terminal.setClampedCursorPos(terminal.x - Math.max(1, value), terminal.y);
}
}

View File

@@ -1,9 +0,0 @@
package li.cil.oc2.common.vm.terminal.escapes.CSI;
import li.cil.oc2.common.vm.terminal.Terminal;
public class CUD {
public static void execute(Terminal terminal, int value) {
terminal.setClampedCursorPos(terminal.x, terminal.y + Math.max(1, value));
}
}

View File

@@ -1,9 +0,0 @@
package li.cil.oc2.common.vm.terminal.escapes.CSI;
import li.cil.oc2.common.vm.terminal.Terminal;
public class CUF {
public static void execute(Terminal terminal, int value) {
terminal.setClampedCursorPos(terminal.x + Math.max(1, value), terminal.y);
}
}

View File

@@ -1,9 +0,0 @@
package li.cil.oc2.common.vm.terminal.escapes.CSI;
import li.cil.oc2.common.vm.terminal.Terminal;
public class CUP {
public static void execute(Terminal terminal, int y, int x) {
terminal.setRelativeCursorPos(x, y);
}
}

View File

@@ -1,9 +0,0 @@
package li.cil.oc2.common.vm.terminal.escapes.CSI;
import li.cil.oc2.common.vm.terminal.Terminal;
public class CUU {
public static void execute(Terminal terminal, int value) {
terminal.setClampedCursorPos(terminal.x, terminal.y - Math.max(1, value));
}
}

View File

@@ -1,9 +0,0 @@
package li.cil.oc2.common.vm.terminal.escapes.CSI;
import li.cil.oc2.common.vm.terminal.Terminal;
public class DA {
public static void execute(Terminal terminal) {
terminal.putResponse("\033[?1;0c");
}
}

View File

@@ -1,13 +0,0 @@
package li.cil.oc2.common.vm.terminal.escapes.CSI;
import li.cil.oc2.common.vm.terminal.Terminal;
public class DECSCUSR {
public static void execute(Terminal terminal, int cursorStyle) {
if (cursorStyle < 0 || cursorStyle > 6) {
terminal.cursorMode = Terminal.CursorMode.DEFAULT;
return;
}
terminal.cursorMode = cursorStyle;
}
}

View File

@@ -1,22 +0,0 @@
package li.cil.oc2.common.vm.terminal.escapes.CSI;
import li.cil.oc2.common.vm.terminal.Terminal;
public class DECSTBM {
public static void execute(Terminal terminal, 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
}
}

View File

@@ -1,15 +0,0 @@
package li.cil.oc2.common.vm.terminal.escapes.CSI;
import li.cil.oc2.common.vm.terminal.Terminal;
public class DSR {
public static void execute(Terminal terminal, int value) {
switch (value) {
case 5 -> // Report console status
terminal.putResponse("\033[0n"); // Ready, No malfunctions detected
case 6 -> { // Report cursor position
terminal.putResponse(String.format("\033[?%d;%dR", terminal.y + 1, terminal.x + 1));
}
}
}
}

View File

@@ -1,9 +0,0 @@
package li.cil.oc2.common.vm.terminal.escapes.CSI;
import li.cil.oc2.common.vm.terminal.Terminal;
public class HVP {
public static void execute(Terminal terminal, int y, int x) {
CUP.execute(terminal, y, x);
}
}

View File

@@ -1,16 +0,0 @@
package li.cil.oc2.common.vm.terminal.escapes.CSI;
import li.cil.oc2.common.vm.terminal.Terminal;
public class IL {
public static void execute(Terminal terminal, int lines) {
boolean useAltBuffer = terminal.currentPrivateModeState.isAltBufferEnabled();
lines = Math.max(lines, 1);
if (useAltBuffer) {
terminal.shiftLines(terminal.y, terminal.scrollLast - lines, lines);
}
else {
terminal.shiftLines(useAltBuffer ? terminal.y : terminal.y + (terminal.lastRowToDisplayMax - Terminal.HEIGHT), useAltBuffer ? terminal.scrollLast - 1 : (Terminal.HEIGHT * terminal.SCROLL_BACK_COUNT) - 2, (Math.max(1, lines)));
}
}
}

View File

@@ -1,13 +0,0 @@
package li.cil.oc2.common.vm.terminal.escapes.CSI;
import li.cil.oc2.common.vm.terminal.Terminal;
public class UNKN {
public static void execute(Terminal terminal, int[] args, int argCount) {
if (argCount == 1) {
for (int i = 0; i < args[0]; i++) {
terminal.shiftDownOne();
}
}
}
}

View File

@@ -1,13 +0,0 @@
package li.cil.oc2.common.vm.terminal.escapes.CSI;
import li.cil.oc2.common.vm.terminal.Terminal;
public class UNKN2 {
public static void execute(Terminal terminal, int[] args, int argCount) {
if (argCount == 1) {
for (int i = 0; i < args[0]; i++) {
terminal.shiftUpOne();
}
}
}
}

View File

@@ -1,82 +0,0 @@
package li.cil.oc2.common.vm.terminal.escapes.CSI;
import li.cil.oc2.common.vm.terminal.Terminal;
public class XTRESTORE {
public static void executePrivate(Terminal terminal, 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;
}
}
}

View File

@@ -4,7 +4,12 @@ import li.cil.oc2.common.vm.terminal.Terminal;
public class DECRC {
public static void execute(Terminal terminal) {
terminal.x = terminal.savedX;
terminal.y = terminal.savedY;
if (terminal.currentPrivateModeState.isAltBufferEnabled()) {
terminal.x = terminal.altSavedX;
terminal.y = terminal.altSavedY;
} else {
terminal.x = terminal.savedX;
terminal.y = terminal.savedY;
}
}
}

View File

@@ -4,7 +4,12 @@ import li.cil.oc2.common.vm.terminal.Terminal;
public class DECSC {
public static void execute(Terminal terminal) {
terminal.savedX = terminal.x;
terminal.savedY = terminal.y;
if (terminal.currentPrivateModeState.isAltBufferEnabled()) {
terminal.altSavedX = terminal.x;
terminal.altSavedY = terminal.y;
} else {
terminal.savedX = terminal.x;
terminal.savedY = terminal.y;
}
}
}

View File

@@ -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;
}
}

View File

@@ -1,7 +1,7 @@
package li.cil.oc2.common.vm.terminal.escapes;
import li.cil.oc2.common.vm.terminal.ModeState;
import li.cil.oc2.common.vm.terminal.PrivateModeState;
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;

View File

@@ -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';
}
}

View 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
}
}

View File

@@ -1,21 +1,22 @@
package li.cil.oc2.common.vm.terminal.escapes.CSI;
package li.cil.oc2.common.vm.terminal.escapes.csi;
import li.cil.oc2.common.vm.terminal.ImplementedPrivateModes;
import li.cil.oc2.common.vm.terminal.Terminal;
import li.cil.oc2.common.vm.terminal.modes.ImplementedPrivateModes;
public class SM {
public static void execute(Terminal terminal, 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;
}
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);
}
}
public static void executeDECSET(Terminal terminal, int[] args, int argCount) {
private void handleDECSET(int[] args, int argCount) {
for (int i = 0; i < argCount; i++) {
switch (args[i]) {
case 1 -> terminal.currentPrivateModeState.DECCKM = true;
@@ -148,13 +149,23 @@ public class SM {
terminal.renderers.forEach(model -> model.getDirtyMask().accumulateAndGet(finalDirtyLinesMask, (left, right) -> left | right));
}
case 1048 -> {
terminal.savedX = terminal.x;
terminal.savedY = terminal.y;
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 -> {
terminal.savedX = terminal.x;
terminal.savedY = terminal.y;
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;
@@ -182,4 +193,15 @@ public class SM {
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;
}
}
}
}

View File

@@ -1,21 +1,23 @@
package li.cil.oc2.common.vm.terminal.escapes.CSI;
package li.cil.oc2.common.vm.terminal.escapes.csi;
import li.cil.oc2.common.vm.terminal.ImplementedPrivateModes;
import li.cil.oc2.common.vm.terminal.Terminal;
import li.cil.oc2.common.vm.terminal.modes.ImplementedPrivateModes;
public class RM {
public static void execute(Terminal terminal, 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;
}
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);
}
}
public static void executeDECSET(Terminal terminal, int[] args, int argCount) {
private void handleDECRST(int[] args, int argCount) {
for (int i = 0; i < argCount; i++) {
switch (args[i]) {
case 1 -> terminal.currentPrivateModeState.DECCKM = false;
@@ -98,13 +100,23 @@ public class RM {
}
case 1048 -> {
terminal.currentPrivateModeState.SAVE_CURSOR = false;
terminal.x = terminal.savedX;
terminal.y = terminal.savedY;
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;
terminal.x = terminal.savedX;
terminal.y = terminal.savedY;
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;
@@ -130,4 +142,15 @@ public class RM {
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;
}
}
}
}

View File

@@ -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);
}
}
}
}

View File

@@ -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");
}
}
}

View File

@@ -1,9 +1,31 @@
package li.cil.oc2.common.vm.terminal.escapes.CSI;
package li.cil.oc2.common.vm.terminal.escapes.csi;
import li.cil.oc2.common.vm.terminal.Terminal;
public class XTSAVE {
public static void executePrivate(Terminal terminal, int mode) {
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;

View File

@@ -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");
}
}
}

View File

@@ -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();
}
}
}
}

View File

@@ -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();
}
}
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}

View File

@@ -0,0 +1,23 @@
package li.cil.oc2.common.vm.terminal.escapes.csi;
public class CSIState {
public boolean questionMark;
public boolean greaterThan;
public boolean dollarSign;
public boolean hash;
public boolean quote;
public boolean singleQuote;
public boolean space;
public boolean exclamation;
public CSIState(boolean questionMark, boolean greaterThan, boolean dollarSign, boolean hash, boolean quote, boolean singleQuote, boolean space, boolean exclamation) {
this.questionMark = questionMark;
this.greaterThan = greaterThan;
this.dollarSign = dollarSign;
this.hash = hash;
this.quote = quote;
this.singleQuote = singleQuote;
this.space = space;
this.exclamation = exclamation;
}
}

View File

@@ -0,0 +1,13 @@
package li.cil.oc2.common.vm.terminal.escapes.csi;
import li.cil.oc2.common.vm.terminal.Terminal;
public class CUB extends CSISequenceHandler {
public CUB(Terminal terminal) {
super(terminal);
}
public void execute(int[] args, int argsCount, CSIState state) {
terminal.setClampedCursorPos(terminal.x - Math.max(1, args[0]), terminal.y);
}
}

View File

@@ -0,0 +1,13 @@
package li.cil.oc2.common.vm.terminal.escapes.csi;
import li.cil.oc2.common.vm.terminal.Terminal;
public class CUD extends CSISequenceHandler {
public CUD(final Terminal terminal) {
super(terminal);
}
public void execute(int[] args, int argsCount, CSIState state) {
terminal.setClampedCursorPos(terminal.x, terminal.y + Math.max(1, args[0]));
}
}

View File

@@ -0,0 +1,13 @@
package li.cil.oc2.common.vm.terminal.escapes.csi;
import li.cil.oc2.common.vm.terminal.Terminal;
public class CUF extends CSISequenceHandler {
public CUF(final Terminal terminal) {
super(terminal);
}
public void execute(int[] args, int argsCount, CSIState state) {
terminal.setClampedCursorPos(terminal.x + Math.max(1, args[0]), terminal.y);
}
}

View File

@@ -0,0 +1,13 @@
package li.cil.oc2.common.vm.terminal.escapes.csi;
import li.cil.oc2.common.vm.terminal.Terminal;
public class CUP extends CSISequenceHandler {
public CUP(final Terminal terminal) {
super(terminal);
}
public void execute(int[] args, int argsCount, CSIState state) {
terminal.setRelativeCursorPos(args[1] - 1, args[0] - 1);
}
}

View File

@@ -0,0 +1,13 @@
package li.cil.oc2.common.vm.terminal.escapes.csi;
import li.cil.oc2.common.vm.terminal.Terminal;
public class CUU extends CSISequenceHandler {
public CUU(final Terminal terminal) {
super(terminal);
}
public void execute(int[] args, int argsCount, CSIState state) {
terminal.setClampedCursorPos(terminal.x, terminal.y - Math.max(1, args[0]));
}
}

View File

@@ -0,0 +1,13 @@
package li.cil.oc2.common.vm.terminal.escapes.csi;
import li.cil.oc2.common.vm.terminal.Terminal;
public class DA extends CSISequenceHandler {
public DA(final Terminal terminal) {
super(terminal);
}
public void execute(int[] args, int argCount, CSIState state) {
terminal.putResponse("\033[?1;0c");
}
}

View File

@@ -1,12 +1,16 @@
package li.cil.oc2.common.vm.terminal.escapes.CSI;
package li.cil.oc2.common.vm.terminal.escapes.csi;
import li.cil.oc2.common.vm.terminal.Terminal;
public class DL {
public static void execute(Terminal terminal, int lines) {
public class DL extends CSISequenceHandler {
public DL(final Terminal terminal) {
super(terminal);
}
public void execute(int[] args, int argCount, CSIState state) {
terminal.setCursorPos(0, terminal.y);
lines = Math.max(lines, 1);
int lines = Math.max(args[0], 1);
for (int i = 0; i < lines; i++) {
terminal.clearLine(terminal.y + i);
@@ -17,7 +21,7 @@ public class DL {
if (useAltBuffer) {
terminal.shiftLines(terminal.y + lines, terminal.scrollLast, -lines);
} else {
terminal.shiftLines(useAltBuffer ? terminal.y - 1 : terminal.y + lines, useAltBuffer ? terminal.scrollLast : (Terminal.HEIGHT * terminal.SCROLL_BACK_COUNT) - 1, -lines);
terminal.shiftLines(terminal.y + lines, Terminal.HEIGHT * terminal.SCROLL_BACK_COUNT - 1, -lines);
}
}
}

View File

@@ -0,0 +1,16 @@
package li.cil.oc2.common.vm.terminal.escapes.csi;
import li.cil.oc2.common.vm.terminal.Terminal;
public class DSR extends CSISequenceHandler {
public DSR(final Terminal terminal) {
super(terminal);
}
public void execute(int[] args, int argCount, CSIState state) {
switch (args[0]) {
case 5 -> terminal.putResponse("\033[0n"); // Report console status
case 6 -> terminal.putResponse(String.format("\033[?%d;%dR", terminal.y + 1, terminal.x + 1)); // Report cursor position
}
}
}

Some files were not shown because too many files have changed in this diff Show More