mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-12-04 21:01:02 -05:00
Fixed BlockChangePacket after last changes
This commit is contained in:
parent
471d98ee4b
commit
074d2b1849
2 changed files with 37 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
package org.spacehq.mc.protocol.packet.ingame.server.world;
|
||||
|
||||
import org.spacehq.mc.protocol.data.game.Position;
|
||||
import org.spacehq.mc.protocol.data.game.values.world.block.BlockChangeRecord;
|
||||
import org.spacehq.mc.protocol.util.NetUtil;
|
||||
import org.spacehq.packetlib.io.NetInput;
|
||||
|
@ -26,8 +27,10 @@ public class ServerBlockChangePacket implements Packet {
|
|||
|
||||
@Override
|
||||
public void read(NetInput in) throws IOException {
|
||||
Position position = NetUtil.readPosition(in);
|
||||
int block = in.readVarInt();
|
||||
this.record = new BlockChangeRecord(NetUtil.readPosition(in), block >> 4, block & 0xF);
|
||||
|
||||
this.record = new BlockChangeRecord(position, block >> 4, block & 0xF);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
package org.spacehq.mc.protocol;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.spacehq.mc.auth.data.GameProfile;
|
||||
import org.spacehq.mc.protocol.data.game.Position;
|
||||
import org.spacehq.mc.protocol.data.game.values.world.block.BlockChangeRecord;
|
||||
import org.spacehq.mc.protocol.data.message.TextMessage;
|
||||
import org.spacehq.mc.protocol.data.status.PlayerInfo;
|
||||
import org.spacehq.mc.protocol.data.status.ServerStatusInfo;
|
||||
|
@ -12,6 +16,7 @@ import org.spacehq.mc.protocol.data.status.VersionInfo;
|
|||
import org.spacehq.mc.protocol.data.status.handler.ServerInfoBuilder;
|
||||
import org.spacehq.mc.protocol.data.status.handler.ServerInfoHandler;
|
||||
import org.spacehq.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
||||
import org.spacehq.mc.protocol.packet.ingame.server.world.ServerBlockChangePacket;
|
||||
import org.spacehq.packetlib.Client;
|
||||
import org.spacehq.packetlib.Server;
|
||||
import org.spacehq.packetlib.Session;
|
||||
|
@ -20,7 +25,10 @@ import org.spacehq.packetlib.event.session.PacketReceivedEvent;
|
|||
import org.spacehq.packetlib.event.session.SessionAdapter;
|
||||
import org.spacehq.packetlib.packet.Packet;
|
||||
import org.spacehq.packetlib.tcp.TcpSessionFactory;
|
||||
import org.spacehq.packetlib.tcp.io.ByteBufNetInput;
|
||||
import org.spacehq.packetlib.tcp.io.ByteBufNetOutput;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
|
@ -110,6 +118,31 @@ public class MinecraftProtocolTest {
|
|||
assertFalse("Received incorrect reduced debug info flag.", packet.getReducedDebugInfo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBlockBreak() throws IOException {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
|
||||
ByteBufNetOutput out = new ByteBufNetOutput(buffer);
|
||||
ByteBufNetInput in = new ByteBufNetInput(buffer);
|
||||
|
||||
Position position = new Position(1, 61, -1);
|
||||
BlockChangeRecord record = new BlockChangeRecord(position, 3, 2);
|
||||
|
||||
new ServerBlockChangePacket(record).write(out);
|
||||
ServerBlockChangePacket packet = new ServerBlockChangePacket(record);
|
||||
packet.read(in);
|
||||
|
||||
record = packet.getRecord();
|
||||
position = record.getPosition();
|
||||
|
||||
assertFalse("Buffer is not empty", buffer.isReadable());
|
||||
assertEquals("Received incorrect X position", 1, position.getX());
|
||||
assertEquals("Received incorrect Y position", 61, position.getY());
|
||||
assertEquals("Received incorrect Z position", -1, position.getZ());
|
||||
assertEquals("Received incorrect block id", 3, record.getId());
|
||||
assertEquals("Received incorrect block data", 2, record.getData());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDownClient() {
|
||||
if(this.client != null) {
|
||||
|
|
Loading…
Reference in a new issue