2017-05-07 00:18:59 +00:00
|
|
|
/*
|
2017-05-01 13:32:39 +00:00
|
|
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
2020-01-01 00:09:18 +00:00
|
|
|
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
2017-05-01 13:32:39 +00:00
|
|
|
* Send enquiries to dratcliffe@gmail.com
|
|
|
|
*/
|
|
|
|
package dan200.computercraft.core.terminal;
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2020-05-04 08:15:23 +00:00
|
|
|
import dan200.computercraft.shared.util.Colour;
|
2017-05-05 13:24:29 +00:00
|
|
|
import dan200.computercraft.shared.util.Palette;
|
2019-06-08 12:36:31 +00:00
|
|
|
import net.minecraft.nbt.CompoundNBT;
|
2020-05-03 09:34:24 +00:00
|
|
|
import net.minecraft.network.PacketBuffer;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2020-07-09 20:59:19 +00:00
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
public class Terminal
|
2018-12-23 17:46:58 +00:00
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
private static final String base16 = "0123456789abcdef";
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2020-05-03 09:34:24 +00:00
|
|
|
private int m_cursorX = 0;
|
|
|
|
private int m_cursorY = 0;
|
|
|
|
private boolean m_cursorBlink = false;
|
|
|
|
private int m_cursorColour = 0;
|
|
|
|
private int m_cursorBackgroundColour = 15;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
private int m_width;
|
|
|
|
private int m_height;
|
|
|
|
|
2019-03-29 21:21:39 +00:00
|
|
|
private TextBuffer[] m_text;
|
|
|
|
private TextBuffer[] m_textColour;
|
|
|
|
private TextBuffer[] m_backgroundColour;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2020-05-03 09:34:24 +00:00
|
|
|
private final Palette m_palette = new Palette();
|
2017-05-05 13:24:29 +00:00
|
|
|
|
2019-01-20 15:35:48 +00:00
|
|
|
private final Runnable onChanged;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
public Terminal( int width, int height )
|
2019-01-20 15:35:48 +00:00
|
|
|
{
|
|
|
|
this( width, height, null );
|
|
|
|
}
|
|
|
|
|
|
|
|
public Terminal( int width, int height, Runnable changedCallback )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
m_width = width;
|
|
|
|
m_height = height;
|
2019-03-29 21:21:39 +00:00
|
|
|
onChanged = changedCallback;
|
2018-12-23 17:46:58 +00:00
|
|
|
|
|
|
|
m_text = new TextBuffer[m_height];
|
|
|
|
m_textColour = new TextBuffer[m_height];
|
|
|
|
m_backgroundColour = new TextBuffer[m_height];
|
|
|
|
for( int i = 0; i < m_height; i++ )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
m_text[i] = new TextBuffer( ' ', m_width );
|
|
|
|
m_textColour[i] = new TextBuffer( base16.charAt( m_cursorColour ), m_width );
|
|
|
|
m_backgroundColour[i] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2018-02-22 21:20:08 +00:00
|
|
|
public synchronized void reset()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
m_cursorColour = 0;
|
|
|
|
m_cursorBackgroundColour = 15;
|
|
|
|
m_cursorX = 0;
|
|
|
|
m_cursorY = 0;
|
|
|
|
m_cursorBlink = false;
|
|
|
|
clear();
|
2019-01-20 15:35:48 +00:00
|
|
|
setChanged();
|
2017-05-05 13:24:29 +00:00
|
|
|
m_palette.resetColours();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
|
|
|
public int getWidth()
|
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
return m_width;
|
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
|
|
|
public int getHeight()
|
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
return m_height;
|
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2018-02-22 21:20:08 +00:00
|
|
|
public synchronized void resize( int width, int height )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
if( width == m_width && height == m_height )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
int oldHeight = m_height;
|
|
|
|
int oldWidth = m_width;
|
|
|
|
TextBuffer[] oldText = m_text;
|
2017-05-01 13:32:39 +00:00
|
|
|
TextBuffer[] oldTextColour = m_textColour;
|
|
|
|
TextBuffer[] oldBackgroundColour = m_backgroundColour;
|
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
m_width = width;
|
|
|
|
m_height = height;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2018-12-23 17:46:58 +00:00
|
|
|
m_text = new TextBuffer[m_height];
|
|
|
|
m_textColour = new TextBuffer[m_height];
|
|
|
|
m_backgroundColour = new TextBuffer[m_height];
|
|
|
|
for( int i = 0; i < m_height; i++ )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
if( i >= oldHeight )
|
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
m_text[i] = new TextBuffer( ' ', m_width );
|
|
|
|
m_textColour[i] = new TextBuffer( base16.charAt( m_cursorColour ), m_width );
|
|
|
|
m_backgroundColour[i] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
else if( m_width == oldWidth )
|
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
m_text[i] = oldText[i];
|
|
|
|
m_textColour[i] = oldTextColour[i];
|
|
|
|
m_backgroundColour[i] = oldBackgroundColour[i];
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
m_text[i] = new TextBuffer( ' ', m_width );
|
|
|
|
m_textColour[i] = new TextBuffer( base16.charAt( m_cursorColour ), m_width );
|
|
|
|
m_backgroundColour[i] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width );
|
|
|
|
m_text[i].write( oldText[i] );
|
|
|
|
m_textColour[i].write( oldTextColour[i] );
|
|
|
|
m_backgroundColour[i].write( oldBackgroundColour[i] );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2019-01-20 15:35:48 +00:00
|
|
|
setChanged();
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
public void setCursorPos( int x, int y )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
if( m_cursorX != x || m_cursorY != y )
|
|
|
|
{
|
|
|
|
m_cursorX = x;
|
|
|
|
m_cursorY = y;
|
2019-01-20 15:35:48 +00:00
|
|
|
setChanged();
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
public void setCursorBlink( boolean blink )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
if( m_cursorBlink != blink )
|
|
|
|
{
|
|
|
|
m_cursorBlink = blink;
|
2019-01-20 15:35:48 +00:00
|
|
|
setChanged();
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
public void setTextColour( int colour )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
if( m_cursorColour != colour )
|
|
|
|
{
|
|
|
|
m_cursorColour = colour;
|
2019-01-20 15:35:48 +00:00
|
|
|
setChanged();
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
public void setBackgroundColour( int colour )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
if( m_cursorBackgroundColour != colour )
|
|
|
|
{
|
|
|
|
m_cursorBackgroundColour = colour;
|
2019-01-20 15:35:48 +00:00
|
|
|
setChanged();
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
public int getCursorX()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
return m_cursorX;
|
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
public int getCursorY()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
return m_cursorY;
|
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
public boolean getCursorBlink()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
return m_cursorBlink;
|
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
public int getTextColour()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
return m_cursorColour;
|
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
public int getBackgroundColour()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
return m_cursorBackgroundColour;
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2020-07-09 20:59:19 +00:00
|
|
|
@Nonnull
|
2017-05-05 13:24:29 +00:00
|
|
|
public Palette getPalette()
|
|
|
|
{
|
|
|
|
return m_palette;
|
|
|
|
}
|
|
|
|
|
2018-02-22 21:20:08 +00:00
|
|
|
public synchronized void blit( String text, String textColour, String backgroundColour )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
int x = m_cursorX;
|
|
|
|
int y = m_cursorY;
|
|
|
|
if( y >= 0 && y < m_height )
|
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
m_text[y].write( text, x );
|
|
|
|
m_textColour[y].write( textColour, x );
|
|
|
|
m_backgroundColour[y].write( backgroundColour, x );
|
2019-01-20 15:35:48 +00:00
|
|
|
setChanged();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-22 21:20:08 +00:00
|
|
|
public synchronized void write( String text )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
int x = m_cursorX;
|
|
|
|
int y = m_cursorY;
|
|
|
|
if( y >= 0 && y < m_height )
|
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
m_text[y].write( text, x );
|
|
|
|
m_textColour[y].fill( base16.charAt( m_cursorColour ), x, x + text.length() );
|
|
|
|
m_backgroundColour[y].fill( base16.charAt( m_cursorBackgroundColour ), x, x + text.length() );
|
2019-01-20 15:35:48 +00:00
|
|
|
setChanged();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2018-02-22 21:20:08 +00:00
|
|
|
public synchronized void scroll( int yDiff )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
if( yDiff != 0 )
|
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
TextBuffer[] newText = new TextBuffer[m_height];
|
|
|
|
TextBuffer[] newTextColour = new TextBuffer[m_height];
|
|
|
|
TextBuffer[] newBackgroundColour = new TextBuffer[m_height];
|
|
|
|
for( int y = 0; y < m_height; y++ )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
int oldY = y + yDiff;
|
|
|
|
if( oldY >= 0 && oldY < m_height )
|
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
newText[y] = m_text[oldY];
|
|
|
|
newTextColour[y] = m_textColour[oldY];
|
|
|
|
newBackgroundColour[y] = m_backgroundColour[oldY];
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
newText[y] = new TextBuffer( ' ', m_width );
|
|
|
|
newTextColour[y] = new TextBuffer( base16.charAt( m_cursorColour ), m_width );
|
|
|
|
newBackgroundColour[y] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
m_text = newText;
|
|
|
|
m_textColour = newTextColour;
|
|
|
|
m_backgroundColour = newBackgroundColour;
|
2019-01-20 15:35:48 +00:00
|
|
|
setChanged();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2018-02-22 21:20:08 +00:00
|
|
|
public synchronized void clear()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
for( int y = 0; y < m_height; y++ )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
m_text[y].fill( ' ' );
|
|
|
|
m_textColour[y].fill( base16.charAt( m_cursorColour ) );
|
|
|
|
m_backgroundColour[y].fill( base16.charAt( m_cursorBackgroundColour ) );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2019-01-20 15:35:48 +00:00
|
|
|
setChanged();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 21:20:08 +00:00
|
|
|
public synchronized void clearLine()
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
int y = m_cursorY;
|
2017-05-01 14:48:44 +00:00
|
|
|
if( y >= 0 && y < m_height )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
m_text[y].fill( ' ' );
|
|
|
|
m_textColour[y].fill( base16.charAt( m_cursorColour ) );
|
|
|
|
m_backgroundColour[y].fill( base16.charAt( m_cursorBackgroundColour ) );
|
2019-01-20 15:35:48 +00:00
|
|
|
setChanged();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2018-02-22 21:20:08 +00:00
|
|
|
public synchronized TextBuffer getLine( int y )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
if( y >= 0 && y < m_height )
|
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
return m_text[y];
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
return null;
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2018-02-22 21:20:08 +00:00
|
|
|
public synchronized void setLine( int y, String text, String textColour, String backgroundColour )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
m_text[y].write( text );
|
|
|
|
m_textColour[y].write( textColour );
|
|
|
|
m_backgroundColour[y].write( backgroundColour );
|
2019-01-20 15:35:48 +00:00
|
|
|
setChanged();
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2018-02-22 21:20:08 +00:00
|
|
|
public synchronized TextBuffer getTextColourLine( int y )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
if( y >= 0 && y < m_height )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
return m_textColour[y];
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2018-02-22 21:20:08 +00:00
|
|
|
public synchronized TextBuffer getBackgroundColourLine( int y )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
if( y >= 0 && y < m_height )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
return m_backgroundColour[y];
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-01-20 15:35:48 +00:00
|
|
|
public final void setChanged()
|
2017-05-05 15:21:53 +00:00
|
|
|
{
|
2019-01-20 15:35:48 +00:00
|
|
|
if( onChanged != null ) onChanged.run();
|
2017-05-05 15:21:53 +00:00
|
|
|
}
|
|
|
|
|
2020-05-03 09:34:24 +00:00
|
|
|
public synchronized void write( PacketBuffer buffer )
|
|
|
|
{
|
|
|
|
buffer.writeInt( m_cursorX );
|
|
|
|
buffer.writeInt( m_cursorY );
|
|
|
|
buffer.writeBoolean( m_cursorBlink );
|
|
|
|
buffer.writeByte( m_cursorBackgroundColour << 4 | m_cursorColour );
|
|
|
|
|
|
|
|
for( int y = 0; y < m_height; y++ )
|
|
|
|
{
|
|
|
|
TextBuffer text = m_text[y];
|
|
|
|
TextBuffer textColour = m_textColour[y];
|
|
|
|
TextBuffer backColour = m_backgroundColour[y];
|
|
|
|
|
|
|
|
for( int x = 0; x < m_width; x++ )
|
|
|
|
{
|
|
|
|
buffer.writeByte( text.charAt( x ) & 0xFF );
|
2020-05-04 08:15:23 +00:00
|
|
|
buffer.writeByte( getColour(
|
2020-05-04 09:05:32 +00:00
|
|
|
backColour.charAt( x ), Colour.BLACK ) << 4 |
|
|
|
|
getColour( textColour.charAt( x ), Colour.WHITE )
|
2020-05-04 08:15:23 +00:00
|
|
|
);
|
2020-05-03 09:34:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_palette.write( buffer );
|
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized void read( PacketBuffer buffer )
|
|
|
|
{
|
|
|
|
m_cursorX = buffer.readInt();
|
|
|
|
m_cursorY = buffer.readInt();
|
|
|
|
m_cursorBlink = buffer.readBoolean();
|
|
|
|
|
|
|
|
byte cursorColour = buffer.readByte();
|
|
|
|
m_cursorBackgroundColour = (cursorColour >> 4) & 0xF;
|
|
|
|
m_cursorColour = cursorColour & 0xF;
|
|
|
|
|
|
|
|
for( int y = 0; y < m_height; y++ )
|
|
|
|
{
|
|
|
|
TextBuffer text = m_text[y];
|
|
|
|
TextBuffer textColour = m_textColour[y];
|
|
|
|
TextBuffer backColour = m_backgroundColour[y];
|
|
|
|
|
|
|
|
for( int x = 0; x < m_width; x++ )
|
|
|
|
{
|
|
|
|
text.setChar( x, (char) (buffer.readByte() & 0xFF) );
|
|
|
|
|
|
|
|
byte colour = buffer.readByte();
|
|
|
|
backColour.setChar( x, base16.charAt( (colour >> 4) & 0xF ) );
|
|
|
|
textColour.setChar( x, base16.charAt( colour & 0xF ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_palette.read( buffer );
|
|
|
|
setChanged();
|
|
|
|
}
|
|
|
|
|
2019-06-08 12:36:31 +00:00
|
|
|
public synchronized CompoundNBT writeToNBT( CompoundNBT nbt )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
nbt.putInt( "term_cursorX", m_cursorX );
|
|
|
|
nbt.putInt( "term_cursorY", m_cursorY );
|
|
|
|
nbt.putBoolean( "term_cursorBlink", m_cursorBlink );
|
|
|
|
nbt.putInt( "term_textColour", m_cursorColour );
|
|
|
|
nbt.putInt( "term_bgColour", m_cursorBackgroundColour );
|
2018-12-23 17:46:58 +00:00
|
|
|
for( int n = 0; n < m_height; n++ )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
nbt.putString( "term_text_" + n, m_text[n].toString() );
|
|
|
|
nbt.putString( "term_textColour_" + n, m_textColour[n].toString() );
|
|
|
|
nbt.putString( "term_textBgColour_" + n, m_backgroundColour[n].toString() );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2020-05-03 09:34:24 +00:00
|
|
|
|
|
|
|
m_palette.writeToNBT( nbt );
|
2018-12-29 14:01:00 +00:00
|
|
|
return nbt;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2019-06-08 12:36:31 +00:00
|
|
|
public synchronized void readFromNBT( CompoundNBT nbt )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
m_cursorX = nbt.getInt( "term_cursorX" );
|
|
|
|
m_cursorY = nbt.getInt( "term_cursorY" );
|
2018-12-29 14:01:00 +00:00
|
|
|
m_cursorBlink = nbt.getBoolean( "term_cursorBlink" );
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
m_cursorColour = nbt.getInt( "term_textColour" );
|
|
|
|
m_cursorBackgroundColour = nbt.getInt( "term_bgColour" );
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2018-12-23 17:46:58 +00:00
|
|
|
for( int n = 0; n < m_height; n++ )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
m_text[n].fill( ' ' );
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
if( nbt.contains( "term_text_" + n ) )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-29 14:01:00 +00:00
|
|
|
m_text[n].write( nbt.getString( "term_text_" + n ) );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
m_textColour[n].fill( base16.charAt( m_cursorColour ) );
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
if( nbt.contains( "term_textColour_" + n ) )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-29 14:01:00 +00:00
|
|
|
m_textColour[n].write( nbt.getString( "term_textColour_" + n ) );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
m_backgroundColour[n].fill( base16.charAt( m_cursorBackgroundColour ) );
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
if( nbt.contains( "term_textBgColour_" + n ) )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-29 14:01:00 +00:00
|
|
|
m_backgroundColour[n].write( nbt.getString( "term_textBgColour_" + n ) );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-03 09:34:24 +00:00
|
|
|
|
|
|
|
m_palette.readFromNBT( nbt );
|
2019-01-20 15:35:48 +00:00
|
|
|
setChanged();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2020-05-03 09:34:24 +00:00
|
|
|
|
2020-05-04 08:15:23 +00:00
|
|
|
public static int getColour( char c, Colour def )
|
2020-05-03 09:34:24 +00:00
|
|
|
{
|
|
|
|
if( c >= '0' && c <= '9' ) return c - '0';
|
|
|
|
if( c >= 'a' && c <= 'f' ) return c - 'a' + 10;
|
2020-05-04 08:15:23 +00:00
|
|
|
return 15 - def.ordinal();
|
2020-05-03 09:34:24 +00:00
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|