call me the abuser the way i be absuing nea
This commit is contained in:
parent
17e10c0775
commit
db4031f568
2 changed files with 19 additions and 12 deletions
|
@ -14,16 +14,13 @@ import net.minecraft.nbt.NbtOps;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.world.SimpleMenuProvider;
|
import net.minecraft.world.SimpleMenuProvider;
|
||||||
import net.minecraft.world.entity.player.Player;
|
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.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ComputerBlockEntity extends BlockEntity {
|
public class ComputerBlockEntity extends BlockEntity {
|
||||||
public ComputerBlockEntity(BlockPos pPos, BlockState pBlockState) {
|
public ComputerBlockEntity(BlockPos pPos, BlockState pBlockState) {
|
||||||
|
@ -40,7 +37,7 @@ public class ComputerBlockEntity extends BlockEntity {
|
||||||
.fieldOf("screen")
|
.fieldOf("screen")
|
||||||
.setPartial(() -> ComputerTerminal.ofSize(20, 30));
|
.setPartial(() -> ComputerTerminal.ofSize(20, 30));
|
||||||
JsVm jsVm = new JsVm(this);
|
JsVm jsVm = new JsVm(this);
|
||||||
private List<String> lines = new ArrayList<>();
|
private char[] chars = new char[screen.dimensions().columns() * screen.dimensions().rows()];
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void loadAdditional(@NotNull CompoundTag pTag, @NotNull HolderLookup.Provider pRegistries) {
|
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)
|
builder.build((CompoundTag) null).resultOrPartial(Ajar.LOGGER::error)
|
||||||
.ifPresent(it -> pTag.merge((CompoundTag) it));
|
.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) {
|
public void openMenu(Player pPlayer) {
|
||||||
pPlayer.openMenu(new SimpleMenuProvider(
|
pPlayer.openMenu(new SimpleMenuProvider(
|
||||||
|
@ -87,13 +95,13 @@ public class ComputerBlockEntity extends BlockEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void executeCommand(String line) {
|
public void executeCommand(String line) {
|
||||||
lines.add("$ " + line);
|
setScreenChar(new ComputerTerminal.Dimensions(0,0), '$');
|
||||||
if (line.equals("small")) {
|
if (line.equals("small")) {
|
||||||
screen = ComputerTerminal.ofSize(10, 20);
|
screen = ComputerTerminal.ofSize(10, 20);
|
||||||
lines.add("Made small!");
|
setScreenString(new ComputerTerminal.Dimensions(0,0), "Made small!");
|
||||||
} else if (line.equals("big")) {
|
} else if (line.equals("big")) {
|
||||||
screen = ComputerTerminal.ofSize(20, 30);
|
screen = ComputerTerminal.ofSize(20, 30);
|
||||||
lines.add("Made big!");
|
setScreenString(new ComputerTerminal.Dimensions(0,0), "Made big!");
|
||||||
} else if (line.startsWith("resetfs")) {
|
} else if (line.startsWith("resetfs")) {
|
||||||
var root = fileSystem.root().listing();
|
var root = fileSystem.root().listing();
|
||||||
var directory = (AjarDirectory) root.compute("bin", (ignored, old) ->
|
var directory = (AjarDirectory) root.compute("bin", (ignored, old) ->
|
||||||
|
@ -124,12 +132,12 @@ public class ComputerBlockEntity extends BlockEntity {
|
||||||
|
|
||||||
public ComputerScreenUpdate getSyncPacket(int windowId) {
|
public ComputerScreenUpdate getSyncPacket(int windowId) {
|
||||||
return new ComputerScreenUpdate(windowId,
|
return new ComputerScreenUpdate(windowId,
|
||||||
lines,
|
chars,
|
||||||
screen.dimensions().rows(),
|
screen.dimensions().rows(),
|
||||||
screen.dimensions().columns());
|
screen.dimensions().columns());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addLine(String line) {
|
public void addLine(ComputerTerminal.Dimensions dimensions, String line) {
|
||||||
lines.add(line);
|
setScreenString(dimensions, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,10 @@ import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public record ComputerScreenUpdate(
|
public record ComputerScreenUpdate(
|
||||||
int windowId,
|
int windowId,
|
||||||
List<String> lines,
|
char[] lines,
|
||||||
int rows,
|
int rows,
|
||||||
int columns
|
int columns
|
||||||
) implements CustomPacketPayload {
|
) implements CustomPacketPayload {
|
||||||
|
|
Loading…
Reference in a new issue