mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-14 20:20:30 +00:00
Fix term.blit failing on substrings
Hahah. Serves me right for trying to optimise too much. Fixes #1123.
This commit is contained in:
parent
4e438df9ad
commit
56f0e0674f
@ -47,13 +47,15 @@ public class TextBuffer
|
||||
public void write( ByteBuffer text, int start )
|
||||
{
|
||||
int pos = start;
|
||||
int bufferPos = text.position();
|
||||
|
||||
start = Math.max( start, 0 );
|
||||
int length = text.remaining();
|
||||
int end = Math.min( start + length, pos + length );
|
||||
end = Math.min( end, this.text.length );
|
||||
for( int i = start; i < end; i++ )
|
||||
{
|
||||
this.text[i] = (char) (text.get( i - pos ) & 0xFF);
|
||||
this.text[i] = (char) (text.get( bufferPos + i - pos ) & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,9 +14,12 @@ import net.minecraft.network.PacketBuffer;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static dan200.computercraft.core.terminal.TerminalMatchers.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class TerminalTest
|
||||
@ -366,6 +369,19 @@ class TerminalTest
|
||||
callCounter.assertNotCalled();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBlitPartialBuffer()
|
||||
{
|
||||
Terminal terminal = new Terminal( 4, 3 );
|
||||
|
||||
ByteBuffer text = LuaValues.encode( "123456" );
|
||||
text.position( 1 );
|
||||
|
||||
terminal.blit( text, LuaValues.encode( "aaaaaa" ), LuaValues.encode( "aaaaaa" ) );
|
||||
|
||||
assertThat( terminal.getLine( 0 ).toString(), equalTo( "2345" ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWriteFromOrigin()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user