mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-06 16:37:38 +01:00
parent
ef0daa08bb
commit
833c5fe365
@ -157,17 +157,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
|
||||
final IntegerBiConsumer chunkAdder = (chunkX, chunkZ) -> {
|
||||
// Load new chunks
|
||||
this.instance.loadOptionalChunk(chunkX, chunkZ).thenAccept(chunk -> {
|
||||
if (chunk == null) return;
|
||||
chunkQueueLock.lock();
|
||||
try {
|
||||
chunkQueue.enqueue(ChunkUtils.getChunkIndex(chunkX, chunkZ));
|
||||
} catch (Exception e) {
|
||||
MinecraftServer.getExceptionManager().handleException(e);
|
||||
} finally {
|
||||
chunkQueueLock.unlock();
|
||||
}
|
||||
});
|
||||
this.instance.loadOptionalChunk(chunkX, chunkZ).thenAccept(this::sendChunk);
|
||||
};
|
||||
final IntegerBiConsumer chunkRemover = (chunkX, chunkZ) -> {
|
||||
// Unload old chunks
|
||||
|
@ -221,10 +221,13 @@ public class AnvilLoader implements IChunkLoader {
|
||||
Block[] convertedPalette = new Block[blockPalette.getSize()];
|
||||
for (int i = 0; i < convertedPalette.length; 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")) {
|
||||
convertedPalette[i] = Block.AIR;
|
||||
} else {
|
||||
if (blockName.equals("minecraft:grass")) {
|
||||
blockName = "minecraft:short_grass";
|
||||
}
|
||||
Block block = Objects.requireNonNull(Block.fromNamespaceId(blockName));
|
||||
// Properties
|
||||
final Map<String, String> properties = new HashMap<>();
|
||||
|
@ -41,6 +41,9 @@ public class WorldBorder {
|
||||
this.speed = 0;
|
||||
|
||||
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 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)))) {
|
||||
// If the block is still not replaceable, cancel the placement
|
||||
canPlaceBlock = false;
|
||||
|
@ -130,7 +130,7 @@ public class CommandSyntaxSingleTest {
|
||||
// enchant block block enchant
|
||||
{
|
||||
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("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)));
|
||||
CompletableFuture.allOf(chunks.toArray(CompletableFuture[]::new)).join();
|
||||
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);
|
||||
final CompletableFuture<@NotNull Player> future = connection.connect(flatInstance, new Pos(0.5, 40, 0.5));
|
||||
final Player player = future.join();
|
||||
// Initial join
|
||||
chunkDataPacketCollector.assertCount(MathUtils.square(viewDiameter));
|
||||
|
@ -82,7 +82,7 @@ public class BlockTest {
|
||||
Point start = Block.LANTERN.registry().collisionShape().relativeStart();
|
||||
Point end = Block.LANTERN.registry().collisionShape().relativeEnd();
|
||||
|
||||
assertEquals(start, new Vec(0.312, 0, 0.312));
|
||||
assertEquals(end, new Vec(0.687, 0.562, 0.687));
|
||||
assertEquals(start, new Vec(0.3125, 0, 0.3125));
|
||||
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 y = 0; y < Chunk.CHUNK_SECTION_SIZE; y++) {
|
||||
final BlockState blockState = section.get(x, y, z);
|
||||
final String blockName = blockState.getName();
|
||||
Block block = Objects.requireNonNull(Block.fromNamespaceId(blockName))
|
||||
String blockName = blockState.getName();
|
||||
if (blockName.equals("minecraft:grass"))
|
||||
blockName = "minecraft:short_grass";
|
||||
Block block = Objects.requireNonNull(Block.fromNamespaceId(blockName), blockName)
|
||||
.withProperties(blockState.getProperties());
|
||||
palette.set(x, y, z, block.stateId());
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ public class BlockIteratorTest {
|
||||
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, 50.0),
|
||||
new Vec(41.0, 0.0, 50.0),
|
||||
@ -173,7 +173,7 @@ public class BlockIteratorTest {
|
||||
points.add(iterator.next());
|
||||
}
|
||||
|
||||
Point[] validPoints = new Point[] {
|
||||
Point[] validPoints = new Point[]{
|
||||
new Vec(0.0, 40.0, 0.0),
|
||||
new Vec(1.0, 40.0, 0.0),
|
||||
new Vec(1.0, 40.0, 1.0),
|
||||
@ -264,7 +264,7 @@ public class BlockIteratorTest {
|
||||
points.add(iterator.next());
|
||||
}
|
||||
|
||||
Point[] validPoints = new Point[] {
|
||||
Point[] validPoints = new Point[]{
|
||||
new Vec(0.0, 0.0, 0.0),
|
||||
new Vec(1.0, 0.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(1.0, 2.0, 1.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) {
|
||||
@ -293,7 +301,7 @@ public class BlockIteratorTest {
|
||||
points.add(iterator.next());
|
||||
}
|
||||
|
||||
Point[] validPoints = new Point[] {
|
||||
Point[] validPoints = new Point[]{
|
||||
new Vec(0.0, 0.0, 0.0),
|
||||
new Vec(1.0, 0.0, 0.0),
|
||||
new Vec(2.0, 0.0, 0.0),
|
||||
@ -319,7 +327,7 @@ public class BlockIteratorTest {
|
||||
points.add(iterator.next());
|
||||
}
|
||||
|
||||
Point[] validPoints = new Point[] {
|
||||
Point[] validPoints = new Point[]{
|
||||
new Vec(0.0, 0.0, 0.0),
|
||||
new Vec(-1.0, 0.0, 0.0),
|
||||
new Vec(-2.0, 0.0, 0.0),
|
||||
@ -346,7 +354,7 @@ public class BlockIteratorTest {
|
||||
points.add(iterator.next());
|
||||
}
|
||||
|
||||
Point[] validPoints = new Point[] {
|
||||
Point[] validPoints = new Point[]{
|
||||
new Vec(0.0, 0.0, 0.0),
|
||||
new Vec(-1.0, 0.0, 0.0),
|
||||
new Vec(0.0, -1.0, 0.0),
|
||||
|
@ -36,6 +36,9 @@ final class TestConnectionImpl implements TestConnection {
|
||||
|
||||
@Override
|
||||
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);
|
||||
var player = process.connection().createPlayer(playerConnection, UUID.randomUUID(), "RandName");
|
||||
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