mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-04 23:53:01 +00:00
Remove all Minecraft references from the core package
This is an initial step before refactoring this into a separate module. It's definitely not complete - there's a lot of work needed to remove referneces to the main ComputerCraft class for instance - but is a useful first step.
This commit is contained in:
@@ -22,7 +22,7 @@ import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
|||||||
import dan200.computercraft.core.apis.ApiFactories;
|
import dan200.computercraft.core.apis.ApiFactories;
|
||||||
import dan200.computercraft.core.asm.GenericMethod;
|
import dan200.computercraft.core.asm.GenericMethod;
|
||||||
import dan200.computercraft.core.filesystem.FileMount;
|
import dan200.computercraft.core.filesystem.FileMount;
|
||||||
import dan200.computercraft.core.filesystem.ResourceMount;
|
import dan200.computercraft.shared.computer.core.ResourceMount;
|
||||||
import dan200.computercraft.impl.ComputerCraftAPIService;
|
import dan200.computercraft.impl.ComputerCraftAPIService;
|
||||||
import dan200.computercraft.impl.detail.DetailRegistryImpl;
|
import dan200.computercraft.impl.detail.DetailRegistryImpl;
|
||||||
import dan200.computercraft.shared.BundledRedstone;
|
import dan200.computercraft.shared.BundledRedstone;
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ package dan200.computercraft.client.pocket;
|
|||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.core.terminal.Terminal;
|
import dan200.computercraft.core.terminal.Terminal;
|
||||||
import dan200.computercraft.shared.computer.core.ComputerState;
|
import dan200.computercraft.shared.computer.core.ComputerState;
|
||||||
import dan200.computercraft.shared.network.client.TerminalState;
|
import dan200.computercraft.shared.computer.terminal.NetworkedTerminal;
|
||||||
|
import dan200.computercraft.shared.computer.terminal.TerminalState;
|
||||||
import dan200.computercraft.shared.pocket.core.PocketServerComputer;
|
import dan200.computercraft.shared.pocket.core.PocketServerComputer;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@@ -25,13 +26,13 @@ import javax.annotation.Nonnull;
|
|||||||
*/
|
*/
|
||||||
public class PocketComputerData
|
public class PocketComputerData
|
||||||
{
|
{
|
||||||
private final Terminal terminal;
|
private final NetworkedTerminal terminal;
|
||||||
private ComputerState state = ComputerState.OFF;
|
private ComputerState state = ComputerState.OFF;
|
||||||
private int lightColour = -1;
|
private int lightColour = -1;
|
||||||
|
|
||||||
public PocketComputerData( boolean colour )
|
public PocketComputerData( boolean colour )
|
||||||
{
|
{
|
||||||
terminal = new Terminal( ComputerCraft.pocketTermWidth, ComputerCraft.pocketTermHeight, colour );
|
terminal = new NetworkedTerminal( ComputerCraft.pocketTermWidth, ComputerCraft.pocketTermHeight, colour );
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLightState()
|
public int getLightState()
|
||||||
|
|||||||
@@ -5,14 +5,11 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.core.computer;
|
package dan200.computercraft.core.computer;
|
||||||
|
|
||||||
import net.minecraft.core.Direction;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A side on a computer. Unlike {@link Direction}, this is relative to the direction the computer is
|
* A side on a computer. This is relative to the direction the computer is facing.
|
||||||
* facing..
|
|
||||||
*/
|
*/
|
||||||
public enum ComputerSide
|
public enum ComputerSide
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import dan200.computercraft.api.peripheral.IWorkMonitor;
|
|||||||
import dan200.computercraft.core.computer.Computer;
|
import dan200.computercraft.core.computer.Computer;
|
||||||
import dan200.computercraft.core.metrics.Metrics;
|
import dan200.computercraft.core.metrics.Metrics;
|
||||||
import dan200.computercraft.core.metrics.MetricsObserver;
|
import dan200.computercraft.core.metrics.MetricsObserver;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
@@ -28,7 +27,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* this tick. At the beginning of the tick, we execute as many {@link MainThread} tasks as possible, until our
|
* this tick. At the beginning of the tick, we execute as many {@link MainThread} tasks as possible, until our
|
||||||
* time-frame or the global time frame has expired.
|
* time-frame or the global time frame has expired.
|
||||||
* <p>
|
* <p>
|
||||||
* Then, when other objects (such as {@link BlockEntity}) are ticked, we update how much time we've used using
|
* Then, when other objects (such as block entities or entities) are ticked, we update how much time we've used via
|
||||||
* {@link IWorkMonitor#trackWork(long, TimeUnit)}.
|
* {@link IWorkMonitor#trackWork(long, TimeUnit)}.
|
||||||
* <p>
|
* <p>
|
||||||
* Now, if anywhere during this period, we use more than our allocated time slice, the executor is marked as
|
* Now, if anywhere during this period, we use more than our allocated time slice, the executor is marked as
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ package dan200.computercraft.core.terminal;
|
|||||||
|
|
||||||
import dan200.computercraft.shared.util.Colour;
|
import dan200.computercraft.shared.util.Colour;
|
||||||
import dan200.computercraft.shared.util.Palette;
|
import dan200.computercraft.shared.util.Palette;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -16,23 +14,23 @@ import java.nio.ByteBuffer;
|
|||||||
|
|
||||||
public class Terminal
|
public class Terminal
|
||||||
{
|
{
|
||||||
private static final String BASE_16 = "0123456789abcdef";
|
protected static final String BASE_16 = "0123456789abcdef";
|
||||||
|
|
||||||
private int width;
|
protected int width;
|
||||||
private int height;
|
protected int height;
|
||||||
private final boolean colour;
|
protected final boolean colour;
|
||||||
|
|
||||||
private int cursorX = 0;
|
protected int cursorX = 0;
|
||||||
private int cursorY = 0;
|
protected int cursorY = 0;
|
||||||
private boolean cursorBlink = false;
|
protected boolean cursorBlink = false;
|
||||||
private int cursorColour = 0;
|
protected int cursorColour = 0;
|
||||||
private int cursorBackgroundColour = 15;
|
protected int cursorBackgroundColour = 15;
|
||||||
|
|
||||||
private TextBuffer[] text;
|
protected TextBuffer[] text;
|
||||||
private TextBuffer[] textColour;
|
protected TextBuffer[] textColour;
|
||||||
private TextBuffer[] backgroundColour;
|
protected TextBuffer[] backgroundColour;
|
||||||
|
|
||||||
private final Palette palette;
|
protected final Palette palette;
|
||||||
|
|
||||||
private final @Nullable Runnable onChanged;
|
private final @Nullable Runnable onChanged;
|
||||||
|
|
||||||
@@ -320,110 +318,6 @@ public class Terminal
|
|||||||
if( onChanged != null ) onChanged.run();
|
if( onChanged != null ) onChanged.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void write( FriendlyByteBuf buffer )
|
|
||||||
{
|
|
||||||
buffer.writeInt( cursorX );
|
|
||||||
buffer.writeInt( cursorY );
|
|
||||||
buffer.writeBoolean( cursorBlink );
|
|
||||||
buffer.writeByte( cursorBackgroundColour << 4 | cursorColour );
|
|
||||||
|
|
||||||
for( int y = 0; y < height; y++ )
|
|
||||||
{
|
|
||||||
TextBuffer text = this.text[y];
|
|
||||||
TextBuffer textColour = this.textColour[y];
|
|
||||||
TextBuffer backColour = backgroundColour[y];
|
|
||||||
|
|
||||||
for( int x = 0; x < width; x++ ) buffer.writeByte( text.charAt( x ) & 0xFF );
|
|
||||||
for( int x = 0; x < width; x++ )
|
|
||||||
{
|
|
||||||
buffer.writeByte( getColour(
|
|
||||||
backColour.charAt( x ), Colour.BLACK ) << 4 |
|
|
||||||
getColour( textColour.charAt( x ), Colour.WHITE )
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
palette.write( buffer );
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void read( FriendlyByteBuf buffer )
|
|
||||||
{
|
|
||||||
cursorX = buffer.readInt();
|
|
||||||
cursorY = buffer.readInt();
|
|
||||||
cursorBlink = buffer.readBoolean();
|
|
||||||
|
|
||||||
byte cursorColour = buffer.readByte();
|
|
||||||
cursorBackgroundColour = (cursorColour >> 4) & 0xF;
|
|
||||||
this.cursorColour = cursorColour & 0xF;
|
|
||||||
|
|
||||||
for( int y = 0; y < height; y++ )
|
|
||||||
{
|
|
||||||
TextBuffer text = this.text[y];
|
|
||||||
TextBuffer textColour = this.textColour[y];
|
|
||||||
TextBuffer backColour = backgroundColour[y];
|
|
||||||
|
|
||||||
for( int x = 0; x < width; x++ ) text.setChar( x, (char) (buffer.readByte() & 0xFF) );
|
|
||||||
for( int x = 0; x < width; x++ )
|
|
||||||
{
|
|
||||||
byte colour = buffer.readByte();
|
|
||||||
backColour.setChar( x, BASE_16.charAt( (colour >> 4) & 0xF ) );
|
|
||||||
textColour.setChar( x, BASE_16.charAt( colour & 0xF ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
palette.read( buffer );
|
|
||||||
setChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized CompoundTag writeToNBT( CompoundTag nbt )
|
|
||||||
{
|
|
||||||
nbt.putInt( "term_cursorX", cursorX );
|
|
||||||
nbt.putInt( "term_cursorY", cursorY );
|
|
||||||
nbt.putBoolean( "term_cursorBlink", cursorBlink );
|
|
||||||
nbt.putInt( "term_textColour", cursorColour );
|
|
||||||
nbt.putInt( "term_bgColour", cursorBackgroundColour );
|
|
||||||
for( int n = 0; n < height; n++ )
|
|
||||||
{
|
|
||||||
nbt.putString( "term_text_" + n, text[n].toString() );
|
|
||||||
nbt.putString( "term_textColour_" + n, textColour[n].toString() );
|
|
||||||
nbt.putString( "term_textBgColour_" + n, backgroundColour[n].toString() );
|
|
||||||
}
|
|
||||||
|
|
||||||
palette.writeToNBT( nbt );
|
|
||||||
return nbt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void readFromNBT( CompoundTag nbt )
|
|
||||||
{
|
|
||||||
cursorX = nbt.getInt( "term_cursorX" );
|
|
||||||
cursorY = nbt.getInt( "term_cursorY" );
|
|
||||||
cursorBlink = nbt.getBoolean( "term_cursorBlink" );
|
|
||||||
cursorColour = nbt.getInt( "term_textColour" );
|
|
||||||
cursorBackgroundColour = nbt.getInt( "term_bgColour" );
|
|
||||||
|
|
||||||
for( int n = 0; n < height; n++ )
|
|
||||||
{
|
|
||||||
text[n].fill( ' ' );
|
|
||||||
if( nbt.contains( "term_text_" + n ) )
|
|
||||||
{
|
|
||||||
text[n].write( nbt.getString( "term_text_" + n ) );
|
|
||||||
}
|
|
||||||
textColour[n].fill( BASE_16.charAt( cursorColour ) );
|
|
||||||
if( nbt.contains( "term_textColour_" + n ) )
|
|
||||||
{
|
|
||||||
textColour[n].write( nbt.getString( "term_textColour_" + n ) );
|
|
||||||
}
|
|
||||||
backgroundColour[n].fill( BASE_16.charAt( cursorBackgroundColour ) );
|
|
||||||
if( nbt.contains( "term_textBgColour_" + n ) )
|
|
||||||
{
|
|
||||||
backgroundColour[n].write( nbt.getString( "term_textBgColour_" + n ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
palette.readFromNBT( nbt );
|
|
||||||
setChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getColour( char c, Colour def )
|
public static int getColour( char c, Colour def )
|
||||||
{
|
{
|
||||||
if( c >= '0' && c <= '9' ) return c - '0';
|
if( c >= '0' && c <= '9' ) return c - '0';
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ package dan200.computercraft.shared;
|
|||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.core.apis.http.NetworkUtils;
|
import dan200.computercraft.core.apis.http.NetworkUtils;
|
||||||
import dan200.computercraft.core.filesystem.ResourceMount;
|
import dan200.computercraft.shared.computer.core.ResourceMount;
|
||||||
import dan200.computercraft.shared.command.CommandComputerCraft;
|
import dan200.computercraft.shared.command.CommandComputerCraft;
|
||||||
import dan200.computercraft.shared.computer.core.ServerContext;
|
import dan200.computercraft.shared.computer.core.ServerContext;
|
||||||
import dan200.computercraft.shared.computer.metrics.ComputerMBean;
|
import dan200.computercraft.shared.computer.metrics.ComputerMBean;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||||
* Send enquiries to dratcliffe@gmail.com
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
*/
|
*/
|
||||||
package dan200.computercraft.core.filesystem;
|
package dan200.computercraft.shared.computer.core;
|
||||||
|
|
||||||
import com.google.common.cache.Cache;
|
import com.google.common.cache.Cache;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
@@ -11,6 +11,7 @@ import com.google.common.io.ByteStreams;
|
|||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.IMount;
|
||||||
import dan200.computercraft.core.apis.handles.ArrayByteChannel;
|
import dan200.computercraft.core.apis.handles.ArrayByteChannel;
|
||||||
|
import dan200.computercraft.core.filesystem.FileSystem;
|
||||||
import dan200.computercraft.shared.util.IoUtil;
|
import dan200.computercraft.shared.util.IoUtil;
|
||||||
import net.minecraft.ResourceLocationException;
|
import net.minecraft.ResourceLocationException;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
@@ -15,12 +15,12 @@ import dan200.computercraft.core.computer.Computer;
|
|||||||
import dan200.computercraft.core.computer.ComputerEnvironment;
|
import dan200.computercraft.core.computer.ComputerEnvironment;
|
||||||
import dan200.computercraft.core.computer.ComputerSide;
|
import dan200.computercraft.core.computer.ComputerSide;
|
||||||
import dan200.computercraft.core.metrics.MetricsObserver;
|
import dan200.computercraft.core.metrics.MetricsObserver;
|
||||||
import dan200.computercraft.core.terminal.Terminal;
|
|
||||||
import dan200.computercraft.shared.computer.menu.ComputerMenu;
|
import dan200.computercraft.shared.computer.menu.ComputerMenu;
|
||||||
|
import dan200.computercraft.shared.computer.terminal.NetworkedTerminal;
|
||||||
|
import dan200.computercraft.shared.computer.terminal.TerminalState;
|
||||||
import dan200.computercraft.shared.network.NetworkHandler;
|
import dan200.computercraft.shared.network.NetworkHandler;
|
||||||
import dan200.computercraft.shared.network.NetworkMessage;
|
import dan200.computercraft.shared.network.NetworkMessage;
|
||||||
import dan200.computercraft.shared.network.client.ComputerTerminalClientMessage;
|
import dan200.computercraft.shared.network.client.ComputerTerminalClientMessage;
|
||||||
import dan200.computercraft.shared.network.client.TerminalState;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
@@ -41,7 +41,7 @@ public class ServerComputer implements InputHandler, ComputerEnvironment
|
|||||||
private final MetricsObserver metrics;
|
private final MetricsObserver metrics;
|
||||||
private final Computer computer;
|
private final Computer computer;
|
||||||
|
|
||||||
private final Terminal terminal;
|
private final NetworkedTerminal terminal;
|
||||||
private final AtomicBoolean terminalChanged = new AtomicBoolean( false );
|
private final AtomicBoolean terminalChanged = new AtomicBoolean( false );
|
||||||
|
|
||||||
private boolean changedLastFrame;
|
private boolean changedLastFrame;
|
||||||
@@ -54,7 +54,7 @@ public class ServerComputer implements InputHandler, ComputerEnvironment
|
|||||||
|
|
||||||
ServerContext context = ServerContext.get( level.getServer() );
|
ServerContext context = ServerContext.get( level.getServer() );
|
||||||
instanceID = context.registry().getUnusedInstanceID();
|
instanceID = context.registry().getUnusedInstanceID();
|
||||||
terminal = new Terminal( terminalWidth, terminalHeight, family != ComputerFamily.NORMAL, this::markTerminalChanged );
|
terminal = new NetworkedTerminal( terminalWidth, terminalHeight, family != ComputerFamily.NORMAL, this::markTerminalChanged );
|
||||||
metrics = context.metrics().createMetricObserver( this );
|
metrics = context.metrics().createMetricObserver( this );
|
||||||
|
|
||||||
computer = new Computer( context.computerContext(), this, terminal, computerID );
|
computer = new Computer( context.computerContext(), this, terminal, computerID );
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ import dan200.computercraft.shared.computer.core.ServerComputer;
|
|||||||
import dan200.computercraft.shared.computer.menu.ComputerMenu;
|
import dan200.computercraft.shared.computer.menu.ComputerMenu;
|
||||||
import dan200.computercraft.shared.computer.menu.ServerInputHandler;
|
import dan200.computercraft.shared.computer.menu.ServerInputHandler;
|
||||||
import dan200.computercraft.shared.computer.menu.ServerInputState;
|
import dan200.computercraft.shared.computer.menu.ServerInputState;
|
||||||
import dan200.computercraft.shared.network.client.TerminalState;
|
import dan200.computercraft.shared.computer.terminal.NetworkedTerminal;
|
||||||
|
import dan200.computercraft.shared.computer.terminal.TerminalState;
|
||||||
import dan200.computercraft.shared.network.container.ComputerContainerData;
|
import dan200.computercraft.shared.network.container.ComputerContainerData;
|
||||||
import dan200.computercraft.shared.util.SingleIntArray;
|
import dan200.computercraft.shared.util.SingleIntArray;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
@@ -34,7 +35,7 @@ public abstract class ContainerComputerBase extends AbstractContainerMenu implem
|
|||||||
private final @Nullable ServerComputer computer;
|
private final @Nullable ServerComputer computer;
|
||||||
private final @Nullable ServerInputState<ContainerComputerBase> input;
|
private final @Nullable ServerInputState<ContainerComputerBase> input;
|
||||||
|
|
||||||
private final @Nullable Terminal terminal;
|
private final @Nullable NetworkedTerminal terminal;
|
||||||
|
|
||||||
private final ItemStack displayStack;
|
private final ItemStack displayStack;
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
package dan200.computercraft.shared.computer.menu;
|
package dan200.computercraft.shared.computer.menu;
|
||||||
|
|
||||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||||
import dan200.computercraft.shared.network.client.TerminalState;
|
import dan200.computercraft.shared.computer.terminal.TerminalState;
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
package dan200.computercraft.shared.computer.terminal;
|
||||||
|
|
||||||
|
import dan200.computercraft.core.terminal.Terminal;
|
||||||
|
import dan200.computercraft.core.terminal.TextBuffer;
|
||||||
|
import dan200.computercraft.shared.util.Colour;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
|
||||||
|
public class NetworkedTerminal extends Terminal
|
||||||
|
{
|
||||||
|
public NetworkedTerminal( int width, int height, boolean colour )
|
||||||
|
{
|
||||||
|
super( width, height, colour );
|
||||||
|
}
|
||||||
|
|
||||||
|
public NetworkedTerminal( int width, int height, boolean colour, Runnable changedCallback )
|
||||||
|
{
|
||||||
|
super( width, height, colour, changedCallback );
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void write( FriendlyByteBuf buffer )
|
||||||
|
{
|
||||||
|
buffer.writeInt( cursorX );
|
||||||
|
buffer.writeInt( cursorY );
|
||||||
|
buffer.writeBoolean( cursorBlink );
|
||||||
|
buffer.writeByte( cursorBackgroundColour << 4 | cursorColour );
|
||||||
|
|
||||||
|
for( int y = 0; y < height; y++ )
|
||||||
|
{
|
||||||
|
TextBuffer text = this.text[y];
|
||||||
|
TextBuffer textColour = this.textColour[y];
|
||||||
|
TextBuffer backColour = backgroundColour[y];
|
||||||
|
|
||||||
|
for( int x = 0; x < width; x++ ) buffer.writeByte( text.charAt( x ) & 0xFF );
|
||||||
|
for( int x = 0; x < width; x++ )
|
||||||
|
{
|
||||||
|
buffer.writeByte( getColour(
|
||||||
|
backColour.charAt( x ), Colour.BLACK ) << 4 |
|
||||||
|
getColour( textColour.charAt( x ), Colour.WHITE )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
palette.write( buffer );
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void read( FriendlyByteBuf buffer )
|
||||||
|
{
|
||||||
|
cursorX = buffer.readInt();
|
||||||
|
cursorY = buffer.readInt();
|
||||||
|
cursorBlink = buffer.readBoolean();
|
||||||
|
|
||||||
|
byte cursorColour = buffer.readByte();
|
||||||
|
cursorBackgroundColour = (cursorColour >> 4) & 0xF;
|
||||||
|
this.cursorColour = cursorColour & 0xF;
|
||||||
|
|
||||||
|
for( int y = 0; y < height; y++ )
|
||||||
|
{
|
||||||
|
TextBuffer text = this.text[y];
|
||||||
|
TextBuffer textColour = this.textColour[y];
|
||||||
|
TextBuffer backColour = backgroundColour[y];
|
||||||
|
|
||||||
|
for( int x = 0; x < width; x++ ) text.setChar( x, (char) (buffer.readByte() & 0xFF) );
|
||||||
|
for( int x = 0; x < width; x++ )
|
||||||
|
{
|
||||||
|
byte colour = buffer.readByte();
|
||||||
|
backColour.setChar( x, BASE_16.charAt( (colour >> 4) & 0xF ) );
|
||||||
|
textColour.setChar( x, BASE_16.charAt( colour & 0xF ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
palette.read( buffer );
|
||||||
|
setChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized CompoundTag writeToNBT( CompoundTag nbt )
|
||||||
|
{
|
||||||
|
nbt.putInt( "term_cursorX", cursorX );
|
||||||
|
nbt.putInt( "term_cursorY", cursorY );
|
||||||
|
nbt.putBoolean( "term_cursorBlink", cursorBlink );
|
||||||
|
nbt.putInt( "term_textColour", cursorColour );
|
||||||
|
nbt.putInt( "term_bgColour", cursorBackgroundColour );
|
||||||
|
for( int n = 0; n < height; n++ )
|
||||||
|
{
|
||||||
|
nbt.putString( "term_text_" + n, text[n].toString() );
|
||||||
|
nbt.putString( "term_textColour_" + n, textColour[n].toString() );
|
||||||
|
nbt.putString( "term_textBgColour_" + n, backgroundColour[n].toString() );
|
||||||
|
}
|
||||||
|
|
||||||
|
palette.writeToNBT( nbt );
|
||||||
|
return nbt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void readFromNBT( CompoundTag nbt )
|
||||||
|
{
|
||||||
|
cursorX = nbt.getInt( "term_cursorX" );
|
||||||
|
cursorY = nbt.getInt( "term_cursorY" );
|
||||||
|
cursorBlink = nbt.getBoolean( "term_cursorBlink" );
|
||||||
|
cursorColour = nbt.getInt( "term_textColour" );
|
||||||
|
cursorBackgroundColour = nbt.getInt( "term_bgColour" );
|
||||||
|
|
||||||
|
for( int n = 0; n < height; n++ )
|
||||||
|
{
|
||||||
|
text[n].fill( ' ' );
|
||||||
|
if( nbt.contains( "term_text_" + n ) )
|
||||||
|
{
|
||||||
|
text[n].write( nbt.getString( "term_text_" + n ) );
|
||||||
|
}
|
||||||
|
textColour[n].fill( BASE_16.charAt( cursorColour ) );
|
||||||
|
if( nbt.contains( "term_textColour_" + n ) )
|
||||||
|
{
|
||||||
|
textColour[n].write( nbt.getString( "term_textColour_" + n ) );
|
||||||
|
}
|
||||||
|
backgroundColour[n].fill( BASE_16.charAt( cursorBackgroundColour ) );
|
||||||
|
if( nbt.contains( "term_textBgColour_" + n ) )
|
||||||
|
{
|
||||||
|
backgroundColour[n].write( nbt.getString( "term_textBgColour_" + n ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
palette.readFromNBT( nbt );
|
||||||
|
setChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,9 +3,8 @@
|
|||||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||||
* Send enquiries to dratcliffe@gmail.com
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
*/
|
*/
|
||||||
package dan200.computercraft.shared.network.client;
|
package dan200.computercraft.shared.computer.terminal;
|
||||||
|
|
||||||
import dan200.computercraft.core.terminal.Terminal;
|
|
||||||
import dan200.computercraft.shared.util.IoUtil;
|
import dan200.computercraft.shared.util.IoUtil;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufInputStream;
|
import io.netty.buffer.ByteBufInputStream;
|
||||||
@@ -42,12 +41,12 @@ public class TerminalState
|
|||||||
|
|
||||||
private ByteBuf compressed;
|
private ByteBuf compressed;
|
||||||
|
|
||||||
public TerminalState( @Nullable Terminal terminal )
|
public TerminalState( @Nullable NetworkedTerminal terminal )
|
||||||
{
|
{
|
||||||
this( terminal, true );
|
this( terminal, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
public TerminalState( @Nullable Terminal terminal, boolean compress )
|
public TerminalState( @Nullable NetworkedTerminal terminal, boolean compress )
|
||||||
{
|
{
|
||||||
this.compress = compress;
|
this.compress = compress;
|
||||||
|
|
||||||
@@ -115,17 +114,17 @@ public class TerminalState
|
|||||||
return buffer == null ? 0 : buffer.readableBytes();
|
return buffer == null ? 0 : buffer.readableBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void apply( Terminal terminal )
|
public void apply( NetworkedTerminal terminal )
|
||||||
{
|
{
|
||||||
if( buffer == null ) throw new NullPointerException( "buffer" );
|
if( buffer == null ) throw new NullPointerException( "buffer" );
|
||||||
terminal.resize( width, height );
|
terminal.resize( width, height );
|
||||||
terminal.read( new FriendlyByteBuf( buffer ) );
|
terminal.read( new FriendlyByteBuf( buffer ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Terminal create()
|
public NetworkedTerminal create()
|
||||||
{
|
{
|
||||||
if( buffer == null ) throw new NullPointerException( "Terminal does not exist" );
|
if( buffer == null ) throw new NullPointerException( "Terminal does not exist" );
|
||||||
Terminal terminal = new Terminal( width, height, colour );
|
NetworkedTerminal terminal = new NetworkedTerminal( width, height, colour );
|
||||||
terminal.read( new FriendlyByteBuf( buffer ) );
|
terminal.read( new FriendlyByteBuf( buffer ) );
|
||||||
return terminal;
|
return terminal;
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
package dan200.computercraft.shared.network.client;
|
package dan200.computercraft.shared.network.client;
|
||||||
|
|
||||||
import dan200.computercraft.shared.computer.menu.ComputerMenu;
|
import dan200.computercraft.shared.computer.menu.ComputerMenu;
|
||||||
|
import dan200.computercraft.shared.computer.terminal.TerminalState;
|
||||||
import dan200.computercraft.shared.network.NetworkMessage;
|
import dan200.computercraft.shared.network.NetworkMessage;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.shared.network.client;
|
package dan200.computercraft.shared.network.client;
|
||||||
|
|
||||||
|
import dan200.computercraft.shared.computer.terminal.TerminalState;
|
||||||
import dan200.computercraft.shared.network.NetworkMessage;
|
import dan200.computercraft.shared.network.NetworkMessage;
|
||||||
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ package dan200.computercraft.shared.network.client;
|
|||||||
|
|
||||||
import dan200.computercraft.client.pocket.ClientPocketComputers;
|
import dan200.computercraft.client.pocket.ClientPocketComputers;
|
||||||
import dan200.computercraft.client.pocket.PocketComputerData;
|
import dan200.computercraft.client.pocket.PocketComputerData;
|
||||||
import dan200.computercraft.core.terminal.Terminal;
|
|
||||||
import dan200.computercraft.shared.computer.core.ComputerState;
|
import dan200.computercraft.shared.computer.core.ComputerState;
|
||||||
|
import dan200.computercraft.shared.computer.terminal.NetworkedTerminal;
|
||||||
|
import dan200.computercraft.shared.computer.terminal.TerminalState;
|
||||||
import dan200.computercraft.shared.network.NetworkMessage;
|
import dan200.computercraft.shared.network.NetworkMessage;
|
||||||
import dan200.computercraft.shared.pocket.core.PocketServerComputer;
|
import dan200.computercraft.shared.pocket.core.PocketServerComputer;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
@@ -29,7 +30,7 @@ public class PocketComputerDataMessage implements NetworkMessage
|
|||||||
instanceId = computer.getInstanceID();
|
instanceId = computer.getInstanceID();
|
||||||
state = computer.getState();
|
state = computer.getState();
|
||||||
lightState = computer.getLight();
|
lightState = computer.getLight();
|
||||||
terminal = sendTerminal ? computer.getTerminalState() : new TerminalState( (Terminal) null );
|
terminal = sendTerminal ? computer.getTerminalState() : new TerminalState( (NetworkedTerminal) null );
|
||||||
}
|
}
|
||||||
|
|
||||||
public PocketComputerDataMessage( FriendlyByteBuf buf )
|
public PocketComputerDataMessage( FriendlyByteBuf buf )
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ package dan200.computercraft.shared.network.container;
|
|||||||
|
|
||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||||
import dan200.computercraft.shared.network.client.TerminalState;
|
import dan200.computercraft.shared.computer.terminal.TerminalState;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ import com.mojang.blaze3d.platform.GlStateManager;
|
|||||||
import dan200.computercraft.client.util.DirectBuffers;
|
import dan200.computercraft.client.util.DirectBuffers;
|
||||||
import dan200.computercraft.client.util.DirectVertexBuffer;
|
import dan200.computercraft.client.util.DirectVertexBuffer;
|
||||||
import dan200.computercraft.core.terminal.Terminal;
|
import dan200.computercraft.core.terminal.Terminal;
|
||||||
import dan200.computercraft.shared.network.client.TerminalState;
|
import dan200.computercraft.shared.computer.terminal.NetworkedTerminal;
|
||||||
|
import dan200.computercraft.shared.computer.terminal.TerminalState;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
@@ -36,7 +37,7 @@ public final class ClientMonitor
|
|||||||
public int tboUniform;
|
public int tboUniform;
|
||||||
public DirectVertexBuffer backgroundBuffer;
|
public DirectVertexBuffer backgroundBuffer;
|
||||||
public DirectVertexBuffer foregroundBuffer;
|
public DirectVertexBuffer foregroundBuffer;
|
||||||
private Terminal terminal;
|
private NetworkedTerminal terminal;
|
||||||
private boolean terminalChanged;
|
private boolean terminalChanged;
|
||||||
|
|
||||||
public ClientMonitor( TileMonitor origin )
|
public ClientMonitor( TileMonitor origin )
|
||||||
@@ -182,7 +183,7 @@ public final class ClientMonitor
|
|||||||
{
|
{
|
||||||
if( state.hasTerminal() )
|
if( state.hasTerminal() )
|
||||||
{
|
{
|
||||||
if( terminal == null ) terminal = new Terminal( state.width, state.height, state.colour );
|
if( terminal == null ) terminal = new NetworkedTerminal( state.width, state.height, state.colour );
|
||||||
state.apply( terminal );
|
state.apply( terminal );
|
||||||
terminalChanged = true;
|
terminalChanged = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ package dan200.computercraft.shared.peripheral.monitor;
|
|||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.shared.network.NetworkHandler;
|
import dan200.computercraft.shared.network.NetworkHandler;
|
||||||
import dan200.computercraft.shared.network.client.MonitorClientMessage;
|
import dan200.computercraft.shared.network.client.MonitorClientMessage;
|
||||||
import dan200.computercraft.shared.network.client.TerminalState;
|
import dan200.computercraft.shared.computer.terminal.TerminalState;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ package dan200.computercraft.shared.peripheral.monitor;
|
|||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import dan200.computercraft.core.terminal.Terminal;
|
import dan200.computercraft.core.terminal.Terminal;
|
||||||
|
import dan200.computercraft.shared.computer.terminal.NetworkedTerminal;
|
||||||
import dan200.computercraft.shared.util.TickScheduler;
|
import dan200.computercraft.shared.util.TickScheduler;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -18,7 +19,7 @@ public class ServerMonitor
|
|||||||
|
|
||||||
private final boolean colour;
|
private final boolean colour;
|
||||||
private int textScale = 2;
|
private int textScale = 2;
|
||||||
private @Nullable Terminal terminal;
|
private @Nullable NetworkedTerminal terminal;
|
||||||
private final AtomicBoolean resized = new AtomicBoolean( false );
|
private final AtomicBoolean resized = new AtomicBoolean( false );
|
||||||
private final AtomicBoolean changed = new AtomicBoolean( false );
|
private final AtomicBoolean changed = new AtomicBoolean( false );
|
||||||
|
|
||||||
@@ -46,7 +47,7 @@ public class ServerMonitor
|
|||||||
|
|
||||||
if( terminal == null )
|
if( terminal == null )
|
||||||
{
|
{
|
||||||
terminal = new Terminal( termWidth, termHeight, colour, this::markChanged );
|
terminal = new NetworkedTerminal( termWidth, termHeight, colour, this::markChanged );
|
||||||
markChanged();
|
markChanged();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -91,7 +92,7 @@ public class ServerMonitor
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public Terminal getTerminal()
|
public NetworkedTerminal getTerminal()
|
||||||
{
|
{
|
||||||
return terminal;
|
return terminal;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import dan200.computercraft.api.peripheral.IComputerAccess;
|
|||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.core.terminal.Terminal;
|
import dan200.computercraft.core.terminal.Terminal;
|
||||||
import dan200.computercraft.shared.common.TileGeneric;
|
import dan200.computercraft.shared.common.TileGeneric;
|
||||||
import dan200.computercraft.shared.network.client.TerminalState;
|
import dan200.computercraft.shared.computer.terminal.TerminalState;
|
||||||
import dan200.computercraft.shared.util.CapabilityUtil;
|
import dan200.computercraft.shared.util.CapabilityUtil;
|
||||||
import dan200.computercraft.shared.util.TickScheduler;
|
import dan200.computercraft.shared.util.TickScheduler;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ package dan200.computercraft.shared.peripheral.printer;
|
|||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.core.terminal.Terminal;
|
import dan200.computercraft.core.terminal.Terminal;
|
||||||
import dan200.computercraft.shared.common.TileGeneric;
|
import dan200.computercraft.shared.common.TileGeneric;
|
||||||
|
import dan200.computercraft.shared.computer.terminal.NetworkedTerminal;
|
||||||
import dan200.computercraft.shared.media.items.ItemPrintout;
|
import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||||
import dan200.computercraft.shared.util.*;
|
import dan200.computercraft.shared.util.*;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
@@ -63,7 +64,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
|||||||
SidedCaps.ofNullable( facing -> facing == null ? new InvWrapper( this ) : new SidedInvWrapper( this, facing ) );
|
SidedCaps.ofNullable( facing -> facing == null ? new InvWrapper( this ) : new SidedInvWrapper( this, facing ) );
|
||||||
private LazyOptional<IPeripheral> peripheralCap;
|
private LazyOptional<IPeripheral> peripheralCap;
|
||||||
|
|
||||||
private final Terminal page = new Terminal( ItemPrintout.LINE_MAX_LENGTH, ItemPrintout.LINES_PER_PAGE, true );
|
private final NetworkedTerminal page = new NetworkedTerminal( ItemPrintout.LINE_MAX_LENGTH, ItemPrintout.LINES_PER_PAGE, true );
|
||||||
private String pageTitle = "";
|
private String pageTitle = "";
|
||||||
private boolean printing = false;
|
private boolean printing = false;
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,6 @@ import dan200.computercraft.api.lua.LuaValues;
|
|||||||
import dan200.computercraft.shared.util.Colour;
|
import dan200.computercraft.shared.util.Colour;
|
||||||
import dan200.computercraft.test.core.CallCounter;
|
import dan200.computercraft.test.core.CallCounter;
|
||||||
import dan200.computercraft.test.core.terminal.TerminalMatchers;
|
import dan200.computercraft.test.core.terminal.TerminalMatchers;
|
||||||
import io.netty.buffer.Unpooled;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
|
||||||
import org.hamcrest.Matcher;
|
import org.hamcrest.Matcher;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@@ -597,92 +594,6 @@ class TerminalTest
|
|||||||
callCounter.assertNotCalled();
|
callCounter.assertNotCalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void testPacketBufferRoundtrip()
|
|
||||||
{
|
|
||||||
Terminal writeTerminal = new Terminal( 2, 1, true );
|
|
||||||
|
|
||||||
blit( writeTerminal, "hi", "11", "ee" );
|
|
||||||
writeTerminal.setCursorPos( 2, 5 );
|
|
||||||
writeTerminal.setTextColour( 3 );
|
|
||||||
writeTerminal.setBackgroundColour( 5 );
|
|
||||||
|
|
||||||
FriendlyByteBuf packetBuffer = new FriendlyByteBuf( Unpooled.buffer() );
|
|
||||||
writeTerminal.write( packetBuffer );
|
|
||||||
|
|
||||||
CallCounter callCounter = new CallCounter();
|
|
||||||
Terminal readTerminal = new Terminal( 2, 1, true, callCounter );
|
|
||||||
packetBuffer.writeBytes( packetBuffer );
|
|
||||||
readTerminal.read( packetBuffer );
|
|
||||||
|
|
||||||
assertThat( readTerminal, allOf(
|
|
||||||
textMatches( new String[] { "hi", } ),
|
|
||||||
textColourMatches( new String[] { "11", } ),
|
|
||||||
backgroundColourMatches( new String[] { "ee", } )
|
|
||||||
) );
|
|
||||||
|
|
||||||
assertEquals( 2, readTerminal.getCursorX() );
|
|
||||||
assertEquals( 5, readTerminal.getCursorY() );
|
|
||||||
assertEquals( 3, readTerminal.getTextColour() );
|
|
||||||
assertEquals( 5, readTerminal.getBackgroundColour() );
|
|
||||||
callCounter.assertCalledTimes( 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testNbtRoundtrip()
|
|
||||||
{
|
|
||||||
Terminal writeTerminal = new Terminal( 10, 5, true );
|
|
||||||
blit( writeTerminal, "hi", "11", "ee" );
|
|
||||||
writeTerminal.setCursorPos( 2, 5 );
|
|
||||||
writeTerminal.setTextColour( 3 );
|
|
||||||
writeTerminal.setBackgroundColour( 5 );
|
|
||||||
|
|
||||||
CompoundTag nbt = new CompoundTag();
|
|
||||||
writeTerminal.writeToNBT( nbt );
|
|
||||||
|
|
||||||
CallCounter callCounter = new CallCounter();
|
|
||||||
Terminal readTerminal = new Terminal( 2, 1, true, callCounter );
|
|
||||||
|
|
||||||
readTerminal.readFromNBT( nbt );
|
|
||||||
|
|
||||||
assertThat( readTerminal, allOf(
|
|
||||||
textMatches( new String[] { "hi", } ),
|
|
||||||
textColourMatches( new String[] { "11", } ),
|
|
||||||
backgroundColourMatches( new String[] { "ee", } )
|
|
||||||
) );
|
|
||||||
|
|
||||||
assertEquals( 2, readTerminal.getCursorX() );
|
|
||||||
assertEquals( 5, readTerminal.getCursorY() );
|
|
||||||
assertEquals( 3, readTerminal.getTextColour() );
|
|
||||||
assertEquals( 5, readTerminal.getBackgroundColour() );
|
|
||||||
callCounter.assertCalledTimes( 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testReadWriteNBTEmpty()
|
|
||||||
{
|
|
||||||
Terminal terminal = new Terminal( 0, 0, true );
|
|
||||||
|
|
||||||
CompoundTag nbt = new CompoundTag();
|
|
||||||
terminal.writeToNBT( nbt );
|
|
||||||
|
|
||||||
CallCounter callCounter = new CallCounter();
|
|
||||||
terminal = new Terminal( 0, 1, true, callCounter );
|
|
||||||
terminal.readFromNBT( nbt );
|
|
||||||
|
|
||||||
assertThat( terminal, allOf(
|
|
||||||
textMatches( new String[] { "", } ),
|
|
||||||
textColourMatches( new String[] { "", } ),
|
|
||||||
backgroundColourMatches( new String[] { "", } )
|
|
||||||
) );
|
|
||||||
|
|
||||||
assertEquals( 0, terminal.getCursorX() );
|
|
||||||
assertEquals( 0, terminal.getCursorY() );
|
|
||||||
assertEquals( 0, terminal.getTextColour() );
|
|
||||||
assertEquals( 15, terminal.getBackgroundColour() );
|
|
||||||
callCounter.assertCalledTimes( 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testGetColour()
|
void testGetColour()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||||
* Send enquiries to dratcliffe@gmail.com
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
*/
|
*/
|
||||||
package dan200.computercraft.core.filesystem;
|
package dan200.computercraft.shared.computer.core;
|
||||||
|
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.IMount;
|
||||||
import net.minecraft.Util;
|
import net.minecraft.Util;
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
package dan200.computercraft.shared.computer.terminal;
|
||||||
|
|
||||||
|
import dan200.computercraft.api.lua.LuaValues;
|
||||||
|
import dan200.computercraft.core.terminal.Terminal;
|
||||||
|
import dan200.computercraft.test.core.CallCounter;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static dan200.computercraft.test.core.terminal.TerminalMatchers.*;
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.hamcrest.Matchers.allOf;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
class NetworkedTerminalTest
|
||||||
|
{
|
||||||
|
@Test
|
||||||
|
void testPacketBufferRoundtrip()
|
||||||
|
{
|
||||||
|
var writeTerminal = new NetworkedTerminal( 2, 1, true );
|
||||||
|
|
||||||
|
blit( writeTerminal, "hi", "11", "ee" );
|
||||||
|
writeTerminal.setCursorPos( 2, 5 );
|
||||||
|
writeTerminal.setTextColour( 3 );
|
||||||
|
writeTerminal.setBackgroundColour( 5 );
|
||||||
|
|
||||||
|
FriendlyByteBuf packetBuffer = new FriendlyByteBuf( Unpooled.buffer() );
|
||||||
|
writeTerminal.write( packetBuffer );
|
||||||
|
|
||||||
|
CallCounter callCounter = new CallCounter();
|
||||||
|
var readTerminal = new NetworkedTerminal( 2, 1, true, callCounter );
|
||||||
|
packetBuffer.writeBytes( packetBuffer );
|
||||||
|
readTerminal.read( packetBuffer );
|
||||||
|
|
||||||
|
assertThat( readTerminal, allOf(
|
||||||
|
textMatches( new String[] { "hi", } ),
|
||||||
|
textColourMatches( new String[] { "11", } ),
|
||||||
|
backgroundColourMatches( new String[] { "ee", } )
|
||||||
|
) );
|
||||||
|
|
||||||
|
assertEquals( 2, readTerminal.getCursorX() );
|
||||||
|
assertEquals( 5, readTerminal.getCursorY() );
|
||||||
|
assertEquals( 3, readTerminal.getTextColour() );
|
||||||
|
assertEquals( 5, readTerminal.getBackgroundColour() );
|
||||||
|
callCounter.assertCalledTimes( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testNbtRoundtrip()
|
||||||
|
{
|
||||||
|
var writeTerminal = new NetworkedTerminal( 10, 5, true );
|
||||||
|
blit( writeTerminal, "hi", "11", "ee" );
|
||||||
|
writeTerminal.setCursorPos( 2, 5 );
|
||||||
|
writeTerminal.setTextColour( 3 );
|
||||||
|
writeTerminal.setBackgroundColour( 5 );
|
||||||
|
|
||||||
|
CompoundTag nbt = new CompoundTag();
|
||||||
|
writeTerminal.writeToNBT( nbt );
|
||||||
|
|
||||||
|
CallCounter callCounter = new CallCounter();
|
||||||
|
var readTerminal = new NetworkedTerminal( 2, 1, true, callCounter );
|
||||||
|
|
||||||
|
readTerminal.readFromNBT( nbt );
|
||||||
|
|
||||||
|
assertThat( readTerminal, allOf(
|
||||||
|
textMatches( new String[] { "hi", } ),
|
||||||
|
textColourMatches( new String[] { "11", } ),
|
||||||
|
backgroundColourMatches( new String[] { "ee", } )
|
||||||
|
) );
|
||||||
|
|
||||||
|
assertEquals( 2, readTerminal.getCursorX() );
|
||||||
|
assertEquals( 5, readTerminal.getCursorY() );
|
||||||
|
assertEquals( 3, readTerminal.getTextColour() );
|
||||||
|
assertEquals( 5, readTerminal.getBackgroundColour() );
|
||||||
|
callCounter.assertCalledTimes( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testReadWriteNBTEmpty()
|
||||||
|
{
|
||||||
|
var terminal = new NetworkedTerminal( 0, 0, true );
|
||||||
|
|
||||||
|
CompoundTag nbt = new CompoundTag();
|
||||||
|
terminal.writeToNBT( nbt );
|
||||||
|
|
||||||
|
CallCounter callCounter = new CallCounter();
|
||||||
|
terminal = new NetworkedTerminal( 0, 1, true, callCounter );
|
||||||
|
terminal.readFromNBT( nbt );
|
||||||
|
|
||||||
|
assertThat( terminal, allOf(
|
||||||
|
textMatches( new String[] { "", } ),
|
||||||
|
textColourMatches( new String[] { "", } ),
|
||||||
|
backgroundColourMatches( new String[] { "", } )
|
||||||
|
) );
|
||||||
|
|
||||||
|
assertEquals( 0, terminal.getCursorX() );
|
||||||
|
assertEquals( 0, terminal.getCursorY() );
|
||||||
|
assertEquals( 0, terminal.getTextColour() );
|
||||||
|
assertEquals( 15, terminal.getBackgroundColour() );
|
||||||
|
callCounter.assertCalledTimes( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void blit( Terminal terminal, String text, String fg, String bg )
|
||||||
|
{
|
||||||
|
terminal.blit( LuaValues.encode( text ), LuaValues.encode( fg ), LuaValues.encode( bg ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||||
* Send enquiries to dratcliffe@gmail.com
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
*/
|
*/
|
||||||
package dan200.computercraft.shared.network.client;
|
package dan200.computercraft.shared.computer.terminal;
|
||||||
|
|
||||||
import dan200.computercraft.core.terminal.Terminal;
|
import dan200.computercraft.core.terminal.Terminal;
|
||||||
import dan200.computercraft.core.terminal.TextBuffer;
|
import dan200.computercraft.core.terminal.TextBuffer;
|
||||||
@@ -23,7 +23,7 @@ public class TerminalStateTest
|
|||||||
@RepeatedTest( 5 )
|
@RepeatedTest( 5 )
|
||||||
public void testCompressed()
|
public void testCompressed()
|
||||||
{
|
{
|
||||||
Terminal terminal = randomTerminal();
|
var terminal = randomTerminal();
|
||||||
|
|
||||||
FriendlyByteBuf buffer = new FriendlyByteBuf( Unpooled.directBuffer() );
|
FriendlyByteBuf buffer = new FriendlyByteBuf( Unpooled.directBuffer() );
|
||||||
new TerminalState( terminal, true ).write( buffer );
|
new TerminalState( terminal, true ).write( buffer );
|
||||||
@@ -35,7 +35,7 @@ public class TerminalStateTest
|
|||||||
@RepeatedTest( 5 )
|
@RepeatedTest( 5 )
|
||||||
public void testUncompressed()
|
public void testUncompressed()
|
||||||
{
|
{
|
||||||
Terminal terminal = randomTerminal();
|
var terminal = randomTerminal();
|
||||||
|
|
||||||
FriendlyByteBuf buffer = new FriendlyByteBuf( Unpooled.directBuffer() );
|
FriendlyByteBuf buffer = new FriendlyByteBuf( Unpooled.directBuffer() );
|
||||||
new TerminalState( terminal, false ).write( buffer );
|
new TerminalState( terminal, false ).write( buffer );
|
||||||
@@ -44,10 +44,10 @@ public class TerminalStateTest
|
|||||||
assertEquals( 0, buffer.readableBytes() );
|
assertEquals( 0, buffer.readableBytes() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Terminal randomTerminal()
|
private static NetworkedTerminal randomTerminal()
|
||||||
{
|
{
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
Terminal terminal = new Terminal( 10, 5, true );
|
NetworkedTerminal terminal = new NetworkedTerminal( 10, 5, true );
|
||||||
for( int y = 0; y < terminal.getHeight(); y++ )
|
for( int y = 0; y < terminal.getHeight(); y++ )
|
||||||
{
|
{
|
||||||
TextBuffer buffer = terminal.getLine( y );
|
TextBuffer buffer = terminal.getLine( y );
|
||||||
@@ -70,14 +70,14 @@ public class TerminalStateTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Terminal read( FriendlyByteBuf buffer )
|
private static NetworkedTerminal read( FriendlyByteBuf buffer )
|
||||||
{
|
{
|
||||||
TerminalState state = new TerminalState( buffer );
|
TerminalState state = new TerminalState( buffer );
|
||||||
assertTrue( state.colour );
|
assertTrue( state.colour );
|
||||||
|
|
||||||
if( !state.hasTerminal() ) return null;
|
if( !state.hasTerminal() ) return null;
|
||||||
|
|
||||||
Terminal other = new Terminal( state.width, state.height, true );
|
var other = new NetworkedTerminal( state.width, state.height, true );
|
||||||
state.apply( other );
|
state.apply( other );
|
||||||
return other;
|
return other;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user