Ensure that block placements send BlockChangePacket

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-01-22 04:02:35 +01:00
parent 57976a1595
commit d3fa4c810f
2 changed files with 35 additions and 0 deletions

View File

@ -15,6 +15,10 @@ public interface TestConnection {
<T extends ServerPacket> @NotNull PacketTracker<T> trackIncoming(@NotNull Class<T> type); <T extends ServerPacket> @NotNull PacketTracker<T> trackIncoming(@NotNull Class<T> type);
default @NotNull PacketTracker<ServerPacket> trackIncoming(){
return trackIncoming(ServerPacket.class);
}
interface PacketTracker<T> { interface PacketTracker<T> {
@NotNull List<@NotNull T> collect(); @NotNull List<@NotNull T> collect();

View File

@ -0,0 +1,31 @@
package net.minestom.server.instance;
import net.minestom.server.api.Env;
import net.minestom.server.api.EnvTest;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.coordinate.Vec;
import net.minestom.server.instance.block.Block;
import net.minestom.server.network.packet.server.play.BlockChangePacket;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@EnvTest
public class InstanceBlockIntegrationTest {
@Test
public void playerUpdate(Env env) {
var instance = env.createFlatInstance();
var connection = env.createConnection();
connection.connect(instance, new Pos(0, 40, 0)).join();
var tracker = connection.trackIncoming();
// Replace air
tracker = connection.trackIncoming();
instance.setBlock(5, 41, 0, Block.STONE);
tracker.assertSingle(BlockChangePacket.class, packet -> {
assertEquals(new Vec(5, 41, 0), packet.blockPosition());
assertEquals(Block.STONE.stateId(), packet.blockStateId());
});
}
}