mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-08 01:17:47 +01:00
parent
ef0daa08bb
commit
833c5fe365
@ -157,17 +157,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
|
|
||||||
final IntegerBiConsumer chunkAdder = (chunkX, chunkZ) -> {
|
final IntegerBiConsumer chunkAdder = (chunkX, chunkZ) -> {
|
||||||
// Load new chunks
|
// Load new chunks
|
||||||
this.instance.loadOptionalChunk(chunkX, chunkZ).thenAccept(chunk -> {
|
this.instance.loadOptionalChunk(chunkX, chunkZ).thenAccept(this::sendChunk);
|
||||||
if (chunk == null) return;
|
|
||||||
chunkQueueLock.lock();
|
|
||||||
try {
|
|
||||||
chunkQueue.enqueue(ChunkUtils.getChunkIndex(chunkX, chunkZ));
|
|
||||||
} catch (Exception e) {
|
|
||||||
MinecraftServer.getExceptionManager().handleException(e);
|
|
||||||
} finally {
|
|
||||||
chunkQueueLock.unlock();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
final IntegerBiConsumer chunkRemover = (chunkX, chunkZ) -> {
|
final IntegerBiConsumer chunkRemover = (chunkX, chunkZ) -> {
|
||||||
// Unload old chunks
|
// Unload old chunks
|
||||||
|
@ -221,10 +221,13 @@ public class AnvilLoader implements IChunkLoader {
|
|||||||
Block[] convertedPalette = new Block[blockPalette.getSize()];
|
Block[] convertedPalette = new Block[blockPalette.getSize()];
|
||||||
for (int i = 0; i < convertedPalette.length; i++) {
|
for (int i = 0; i < convertedPalette.length; i++) {
|
||||||
final NBTCompound paletteEntry = blockPalette.get(i);
|
final NBTCompound paletteEntry = blockPalette.get(i);
|
||||||
final String blockName = Objects.requireNonNull(paletteEntry.getString("Name"));
|
String blockName = Objects.requireNonNull(paletteEntry.getString("Name"));
|
||||||
if (blockName.equals("minecraft:air")) {
|
if (blockName.equals("minecraft:air")) {
|
||||||
convertedPalette[i] = Block.AIR;
|
convertedPalette[i] = Block.AIR;
|
||||||
} else {
|
} else {
|
||||||
|
if (blockName.equals("minecraft:grass")) {
|
||||||
|
blockName = "minecraft:short_grass";
|
||||||
|
}
|
||||||
Block block = Objects.requireNonNull(Block.fromNamespaceId(blockName));
|
Block block = Objects.requireNonNull(Block.fromNamespaceId(blockName));
|
||||||
// Properties
|
// Properties
|
||||||
final Map<String, String> properties = new HashMap<>();
|
final Map<String, String> properties = new HashMap<>();
|
||||||
|
@ -41,6 +41,9 @@ public class WorldBorder {
|
|||||||
this.speed = 0;
|
this.speed = 0;
|
||||||
|
|
||||||
this.portalTeleportBoundary = ServerFlag.WORLD_BORDER_SIZE;
|
this.portalTeleportBoundary = ServerFlag.WORLD_BORDER_SIZE;
|
||||||
|
|
||||||
|
// Update immediately so the current size is present on init
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,7 +107,7 @@ public class BlockPlacementListener {
|
|||||||
|
|
||||||
var placementBlock = instance.getBlock(placementPosition);
|
var placementBlock = instance.getBlock(placementPosition);
|
||||||
var placementRule = BLOCK_MANAGER.getBlockPlacementRule(placementBlock);
|
var placementRule = BLOCK_MANAGER.getBlockPlacementRule(placementBlock);
|
||||||
if (!placementBlock.registry().isReplaceable() && (placementRule == null || !placementRule.isSelfReplaceable(
|
if (!placementBlock.registry().isReplaceable() && !(placementRule != null && placementRule.isSelfReplaceable(
|
||||||
new BlockPlacementRule.Replacement(placementBlock, blockFace, cursorPosition, useMaterial)))) {
|
new BlockPlacementRule.Replacement(placementBlock, blockFace, cursorPosition, useMaterial)))) {
|
||||||
// If the block is still not replaceable, cancel the placement
|
// If the block is still not replaceable, cancel the placement
|
||||||
canPlaceBlock = false;
|
canPlaceBlock = false;
|
||||||
|
@ -130,7 +130,7 @@ public class CommandSyntaxSingleTest {
|
|||||||
// enchant block block enchant
|
// enchant block block enchant
|
||||||
{
|
{
|
||||||
var context1 = new CommandContext("minecraft:sharpness minecraft:stone");
|
var context1 = new CommandContext("minecraft:sharpness minecraft:stone");
|
||||||
var context2 = new CommandContext("minecraft:grass minecraft:efficiency");
|
var context2 = new CommandContext("minecraft:grass_block minecraft:efficiency");
|
||||||
|
|
||||||
context1.setArg("enchant", Enchantment.SHARPNESS, "minecraft:sharpness");
|
context1.setArg("enchant", Enchantment.SHARPNESS, "minecraft:sharpness");
|
||||||
context1.setArg("block", Block.STONE, "minecraft:stone");
|
context1.setArg("block", Block.STONE, "minecraft:stone");
|
||||||
|
@ -71,8 +71,8 @@ public class PlayerMovementIntegrationTest {
|
|||||||
ChunkUtils.forChunksInRange(0, 0, viewDiameter+2, (x, z) -> chunks.add(flatInstance.loadChunk(x, z)));
|
ChunkUtils.forChunksInRange(0, 0, viewDiameter+2, (x, z) -> chunks.add(flatInstance.loadChunk(x, z)));
|
||||||
CompletableFuture.allOf(chunks.toArray(CompletableFuture[]::new)).join();
|
CompletableFuture.allOf(chunks.toArray(CompletableFuture[]::new)).join();
|
||||||
final TestConnection connection = env.createConnection();
|
final TestConnection connection = env.createConnection();
|
||||||
final CompletableFuture<@NotNull Player> future = connection.connect(flatInstance, new Pos(0.5, 40, 0.5));
|
|
||||||
Collector<ChunkDataPacket> chunkDataPacketCollector = connection.trackIncoming(ChunkDataPacket.class);
|
Collector<ChunkDataPacket> chunkDataPacketCollector = connection.trackIncoming(ChunkDataPacket.class);
|
||||||
|
final CompletableFuture<@NotNull Player> future = connection.connect(flatInstance, new Pos(0.5, 40, 0.5));
|
||||||
final Player player = future.join();
|
final Player player = future.join();
|
||||||
// Initial join
|
// Initial join
|
||||||
chunkDataPacketCollector.assertCount(MathUtils.square(viewDiameter));
|
chunkDataPacketCollector.assertCount(MathUtils.square(viewDiameter));
|
||||||
|
@ -82,7 +82,7 @@ public class BlockTest {
|
|||||||
Point start = Block.LANTERN.registry().collisionShape().relativeStart();
|
Point start = Block.LANTERN.registry().collisionShape().relativeStart();
|
||||||
Point end = Block.LANTERN.registry().collisionShape().relativeEnd();
|
Point end = Block.LANTERN.registry().collisionShape().relativeEnd();
|
||||||
|
|
||||||
assertEquals(start, new Vec(0.312, 0, 0.312));
|
assertEquals(start, new Vec(0.3125, 0, 0.3125));
|
||||||
assertEquals(end, new Vec(0.687, 0.562, 0.687));
|
assertEquals(end, new Vec(0.6875, 0.5625, 0.6875));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,8 +158,10 @@ public class LightParityIntegrationTest {
|
|||||||
for (int z = 0; z < Chunk.CHUNK_SECTION_SIZE; z++) {
|
for (int z = 0; z < Chunk.CHUNK_SECTION_SIZE; z++) {
|
||||||
for (int y = 0; y < Chunk.CHUNK_SECTION_SIZE; y++) {
|
for (int y = 0; y < Chunk.CHUNK_SECTION_SIZE; y++) {
|
||||||
final BlockState blockState = section.get(x, y, z);
|
final BlockState blockState = section.get(x, y, z);
|
||||||
final String blockName = blockState.getName();
|
String blockName = blockState.getName();
|
||||||
Block block = Objects.requireNonNull(Block.fromNamespaceId(blockName))
|
if (blockName.equals("minecraft:grass"))
|
||||||
|
blockName = "minecraft:short_grass";
|
||||||
|
Block block = Objects.requireNonNull(Block.fromNamespaceId(blockName), blockName)
|
||||||
.withProperties(blockState.getProperties());
|
.withProperties(blockState.getProperties());
|
||||||
palette.set(x, y, z, block.stateId());
|
palette.set(x, y, z, block.stateId());
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ public class BlockIteratorTest {
|
|||||||
points.add(iterator.next());
|
points.add(iterator.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
Point[] validPoints = new Point[] {
|
Point[] validPoints = new Point[]{
|
||||||
new Vec(42.0, 0.0, 51.0),
|
new Vec(42.0, 0.0, 51.0),
|
||||||
new Vec(42.0, 0.0, 50.0),
|
new Vec(42.0, 0.0, 50.0),
|
||||||
new Vec(41.0, 0.0, 50.0),
|
new Vec(41.0, 0.0, 50.0),
|
||||||
@ -173,7 +173,7 @@ public class BlockIteratorTest {
|
|||||||
points.add(iterator.next());
|
points.add(iterator.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
Point[] validPoints = new Point[] {
|
Point[] validPoints = new Point[]{
|
||||||
new Vec(0.0, 40.0, 0.0),
|
new Vec(0.0, 40.0, 0.0),
|
||||||
new Vec(1.0, 40.0, 0.0),
|
new Vec(1.0, 40.0, 0.0),
|
||||||
new Vec(1.0, 40.0, 1.0),
|
new Vec(1.0, 40.0, 1.0),
|
||||||
@ -264,7 +264,7 @@ public class BlockIteratorTest {
|
|||||||
points.add(iterator.next());
|
points.add(iterator.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
Point[] validPoints = new Point[] {
|
Point[] validPoints = new Point[]{
|
||||||
new Vec(0.0, 0.0, 0.0),
|
new Vec(0.0, 0.0, 0.0),
|
||||||
new Vec(1.0, 0.0, 0.0),
|
new Vec(1.0, 0.0, 0.0),
|
||||||
new Vec(0.0, 1.0, 0.0),
|
new Vec(0.0, 1.0, 0.0),
|
||||||
@ -273,7 +273,15 @@ public class BlockIteratorTest {
|
|||||||
new Vec(2.0, 1.0, 1.0),
|
new Vec(2.0, 1.0, 1.0),
|
||||||
new Vec(1.0, 2.0, 1.0),
|
new Vec(1.0, 2.0, 1.0),
|
||||||
new Vec(1.0, 1.0, 2.0),
|
new Vec(1.0, 1.0, 2.0),
|
||||||
new Vec(2.0, 2.0, 2.0)
|
new Vec(2.0, 2.0, 2.0),
|
||||||
|
|
||||||
|
// todo(mattw): I need to confirm that these are correct
|
||||||
|
new Vec(1.0, 1.0, 0.0),
|
||||||
|
new Vec(0.0, 1.0, 1.0),
|
||||||
|
new Vec(1.0, 0.0, 1.0),
|
||||||
|
new Vec(2.0, 2.0, 1.0),
|
||||||
|
new Vec(1.0, 2.0, 2.0),
|
||||||
|
new Vec(2.0, 1.0, 2.0)
|
||||||
};
|
};
|
||||||
|
|
||||||
for (Point p : validPoints) {
|
for (Point p : validPoints) {
|
||||||
@ -293,7 +301,7 @@ public class BlockIteratorTest {
|
|||||||
points.add(iterator.next());
|
points.add(iterator.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
Point[] validPoints = new Point[] {
|
Point[] validPoints = new Point[]{
|
||||||
new Vec(0.0, 0.0, 0.0),
|
new Vec(0.0, 0.0, 0.0),
|
||||||
new Vec(1.0, 0.0, 0.0),
|
new Vec(1.0, 0.0, 0.0),
|
||||||
new Vec(2.0, 0.0, 0.0),
|
new Vec(2.0, 0.0, 0.0),
|
||||||
@ -319,7 +327,7 @@ public class BlockIteratorTest {
|
|||||||
points.add(iterator.next());
|
points.add(iterator.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
Point[] validPoints = new Point[] {
|
Point[] validPoints = new Point[]{
|
||||||
new Vec(0.0, 0.0, 0.0),
|
new Vec(0.0, 0.0, 0.0),
|
||||||
new Vec(-1.0, 0.0, 0.0),
|
new Vec(-1.0, 0.0, 0.0),
|
||||||
new Vec(-2.0, 0.0, 0.0),
|
new Vec(-2.0, 0.0, 0.0),
|
||||||
@ -346,7 +354,7 @@ public class BlockIteratorTest {
|
|||||||
points.add(iterator.next());
|
points.add(iterator.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
Point[] validPoints = new Point[] {
|
Point[] validPoints = new Point[]{
|
||||||
new Vec(0.0, 0.0, 0.0),
|
new Vec(0.0, 0.0, 0.0),
|
||||||
new Vec(-1.0, 0.0, 0.0),
|
new Vec(-1.0, 0.0, 0.0),
|
||||||
new Vec(0.0, -1.0, 0.0),
|
new Vec(0.0, -1.0, 0.0),
|
||||||
|
@ -36,6 +36,9 @@ final class TestConnectionImpl implements TestConnection {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull CompletableFuture<Player> connect(@NotNull Instance instance, @NotNull Pos pos) {
|
public @NotNull CompletableFuture<Player> connect(@NotNull Instance instance, @NotNull Pos pos) {
|
||||||
|
// Use player provider to disable queued chunk sending
|
||||||
|
process.connection().setPlayerProvider(TestPlayerImpl::new);
|
||||||
|
|
||||||
playerConnection.setServerState(ConnectionState.LOGIN);
|
playerConnection.setServerState(ConnectionState.LOGIN);
|
||||||
var player = process.connection().createPlayer(playerConnection, UUID.randomUUID(), "RandName");
|
var player = process.connection().createPlayer(playerConnection, UUID.randomUUID(), "RandName");
|
||||||
player.eventNode().addListener(AsyncPlayerConfigurationEvent.class, event -> {
|
player.eventNode().addListener(AsyncPlayerConfigurationEvent.class, event -> {
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package net.minestom.testing;
|
||||||
|
|
||||||
|
import net.minestom.server.entity.Player;
|
||||||
|
import net.minestom.server.instance.Chunk;
|
||||||
|
import net.minestom.server.network.player.PlayerConnection;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class TestPlayerImpl extends Player {
|
||||||
|
public TestPlayerImpl(@NotNull UUID uuid, @NotNull String username, @NotNull PlayerConnection playerConnection) {
|
||||||
|
super(uuid, username, playerConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendChunk(@NotNull Chunk chunk) {
|
||||||
|
// Send immediately
|
||||||
|
sendPacket(chunk.getFullDataPacket());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user