From bea1953ce878c3884a5af2413bf71d9d941d1fa4 Mon Sep 17 00:00:00 2001 From: echo Date: Thu, 25 Jul 2024 13:31:50 +0330 Subject: [PATCH] Revert "call me the abuser the way i be absuing nea" This reverts commit db4031f568316875e1a28a21bd6a420ba30ddf5d. --- .../ajarc/computer/ComputerBlockEntity.java | 28 +++++++------------ .../ajarc/network/ComputerScreenUpdate.java | 3 +- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/main/java/dev/exhq/ajarc/computer/ComputerBlockEntity.java b/src/main/java/dev/exhq/ajarc/computer/ComputerBlockEntity.java index 9bb1b6c..9554a8f 100644 --- a/src/main/java/dev/exhq/ajarc/computer/ComputerBlockEntity.java +++ b/src/main/java/dev/exhq/ajarc/computer/ComputerBlockEntity.java @@ -14,13 +14,16 @@ 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) { @@ -37,7 +40,7 @@ public class ComputerBlockEntity extends BlockEntity { .fieldOf("screen") .setPartial(() -> ComputerTerminal.ofSize(20, 30)); JsVm jsVm = new JsVm(this); - private char[] chars = new char[screen.dimensions().columns() * screen.dimensions().rows()]; + private List lines = new ArrayList<>(); @Override protected void loadAdditional(@NotNull CompoundTag pTag, @NotNull HolderLookup.Provider pRegistries) { @@ -67,17 +70,6 @@ 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( @@ -95,13 +87,13 @@ public class ComputerBlockEntity extends BlockEntity { } public void executeCommand(String line) { - setScreenChar(new ComputerTerminal.Dimensions(0,0), '$'); + lines.add("$ " + line); if (line.equals("small")) { screen = ComputerTerminal.ofSize(10, 20); - setScreenString(new ComputerTerminal.Dimensions(0,0), "Made small!"); + lines.add("Made small!"); } else if (line.equals("big")) { screen = ComputerTerminal.ofSize(20, 30); - setScreenString(new ComputerTerminal.Dimensions(0,0), "Made big!"); + lines.add("Made big!"); } else if (line.startsWith("resetfs")) { var root = fileSystem.root().listing(); var directory = (AjarDirectory) root.compute("bin", (ignored, old) -> @@ -132,12 +124,12 @@ public class ComputerBlockEntity extends BlockEntity { public ComputerScreenUpdate getSyncPacket(int windowId) { return new ComputerScreenUpdate(windowId, - chars, + lines, screen.dimensions().rows(), screen.dimensions().columns()); } - public void addLine(ComputerTerminal.Dimensions dimensions, String line) { - setScreenString(dimensions, line); + public void addLine(String line) { + lines.add(line); } } diff --git a/src/main/java/dev/exhq/ajarc/network/ComputerScreenUpdate.java b/src/main/java/dev/exhq/ajarc/network/ComputerScreenUpdate.java index b6c86bb..c45ae1a 100644 --- a/src/main/java/dev/exhq/ajarc/network/ComputerScreenUpdate.java +++ b/src/main/java/dev/exhq/ajarc/network/ComputerScreenUpdate.java @@ -10,10 +10,11 @@ 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, - char[] lines, + List lines, int rows, int columns ) implements CustomPacketPayload {