From db4031f568316875e1a28a21bd6a420ba30ddf5d Mon Sep 17 00:00:00 2001 From: echo Date: Wed, 24 Jul 2024 01:14:15 +0330 Subject: [PATCH] call me the abuser the way i be absuing nea --- .../ajarc/computer/ComputerBlockEntity.java | 28 ++++++++++++------- .../ajarc/network/ComputerScreenUpdate.java | 3 +- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/main/java/dev/exhq/ajarc/computer/ComputerBlockEntity.java b/src/main/java/dev/exhq/ajarc/computer/ComputerBlockEntity.java index 9554a8f..9bb1b6c 100644 --- a/src/main/java/dev/exhq/ajarc/computer/ComputerBlockEntity.java +++ b/src/main/java/dev/exhq/ajarc/computer/ComputerBlockEntity.java @@ -14,16 +14,13 @@ import net.minecraft.nbt.NbtOps; import net.minecraft.network.chat.Component; import net.minecraft.world.SimpleMenuProvider; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.block.PumpkinBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import org.apache.commons.io.IOUtils; import org.jetbrains.annotations.NotNull; import java.io.IOException; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; public class ComputerBlockEntity extends BlockEntity { public ComputerBlockEntity(BlockPos pPos, BlockState pBlockState) { @@ -40,7 +37,7 @@ public class ComputerBlockEntity extends BlockEntity { .fieldOf("screen") .setPartial(() -> ComputerTerminal.ofSize(20, 30)); JsVm jsVm = new JsVm(this); - private List lines = new ArrayList<>(); + private char[] chars = new char[screen.dimensions().columns() * screen.dimensions().rows()]; @Override protected void loadAdditional(@NotNull CompoundTag pTag, @NotNull HolderLookup.Provider pRegistries) { @@ -70,6 +67,17 @@ public class ComputerBlockEntity extends BlockEntity { builder.build((CompoundTag) null).resultOrPartial(Ajar.LOGGER::error) .ifPresent(it -> pTag.merge((CompoundTag) it)); } + public void setScreenString(ComputerTerminal.Dimensions startingPos, String value){ + var bytes = value.toCharArray(); + System.arraycopy(chars, startingPos.rows() * screen.dimensions().columns() + startingPos.columns(), bytes, 0, Math.min(bytes.length, screen.dimensions().columns() - startingPos.columns())); + } + + public void setScreenChar(ComputerTerminal.Dimensions dimensions, char value){ + chars[dimensions.rows() * screen.dimensions().columns() + dimensions.rows()] = value; + } + public char getScreenChar(ComputerTerminal.Dimensions dimensions){ + return chars[dimensions.rows() * screen.dimensions().columns() + dimensions.rows()]; + } public void openMenu(Player pPlayer) { pPlayer.openMenu(new SimpleMenuProvider( @@ -87,13 +95,13 @@ public class ComputerBlockEntity extends BlockEntity { } public void executeCommand(String line) { - lines.add("$ " + line); + setScreenChar(new ComputerTerminal.Dimensions(0,0), '$'); if (line.equals("small")) { screen = ComputerTerminal.ofSize(10, 20); - lines.add("Made small!"); + setScreenString(new ComputerTerminal.Dimensions(0,0), "Made small!"); } else if (line.equals("big")) { screen = ComputerTerminal.ofSize(20, 30); - lines.add("Made big!"); + setScreenString(new ComputerTerminal.Dimensions(0,0), "Made big!"); } else if (line.startsWith("resetfs")) { var root = fileSystem.root().listing(); var directory = (AjarDirectory) root.compute("bin", (ignored, old) -> @@ -124,12 +132,12 @@ public class ComputerBlockEntity extends BlockEntity { public ComputerScreenUpdate getSyncPacket(int windowId) { return new ComputerScreenUpdate(windowId, - lines, + chars, screen.dimensions().rows(), screen.dimensions().columns()); } - public void addLine(String line) { - lines.add(line); + public void addLine(ComputerTerminal.Dimensions dimensions, String line) { + setScreenString(dimensions, line); } } diff --git a/src/main/java/dev/exhq/ajarc/network/ComputerScreenUpdate.java b/src/main/java/dev/exhq/ajarc/network/ComputerScreenUpdate.java index c45ae1a..b6c86bb 100644 --- a/src/main/java/dev/exhq/ajarc/network/ComputerScreenUpdate.java +++ b/src/main/java/dev/exhq/ajarc/network/ComputerScreenUpdate.java @@ -10,11 +10,10 @@ import net.neoforged.neoforge.network.handling.IPayloadContext; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; -import java.util.List; public record ComputerScreenUpdate( int windowId, - List lines, + char[] lines, int rows, int columns ) implements CustomPacketPayload {