From 074d2b18491ad3cd47495fea456de2decc288b25 Mon Sep 17 00:00:00 2001 From: Vladislavs Golubs Date: Wed, 23 Sep 2015 14:39:36 +0300 Subject: [PATCH] Fixed BlockChangePacket after last changes --- .../server/world/ServerBlockChangePacket.java | 5 ++- .../mc/protocol/MinecraftProtocolTest.java | 33 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/world/ServerBlockChangePacket.java b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/world/ServerBlockChangePacket.java index 772fa8ba..40839f4a 100644 --- a/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/world/ServerBlockChangePacket.java +++ b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/world/ServerBlockChangePacket.java @@ -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 diff --git a/src/test/java/org/spacehq/mc/protocol/MinecraftProtocolTest.java b/src/test/java/org/spacehq/mc/protocol/MinecraftProtocolTest.java index 40732d13..8d828391 100644 --- a/src/test/java/org/spacehq/mc/protocol/MinecraftProtocolTest.java +++ b/src/test/java/org/spacehq/mc/protocol/MinecraftProtocolTest.java @@ -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) {