More work

This commit is contained in:
KennyTV 2021-06-13 13:40:34 +02:00
parent d42140148f
commit 19da14ee00
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
23 changed files with 276 additions and 307 deletions

View File

@ -9,7 +9,7 @@ a ton of noise to plugin developers.
These do not help plugin developers if they bring moise noise than value.
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index dcaefdaf5a0de8486f59115c8c4d4c211b7d64cd..e3304fcc8c4fd176abd3fb7d4b47e5ccb7bdd37f 100644
index a69e0b0c9f515256c6406ef8ff55f72c98dabe0d..7dd3fc9301de9a88313179088f6b5ce4c1362f06 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -1389,7 +1389,7 @@ public final class Bukkit {
@ -62,7 +62,7 @@ index 9c91c49ed7302c12fcb1d8e9bc58712efc199954..d5d67b3d84cd88ed0f858497e68535ec
if (this.world == null) {
return null;
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index 9b8e6b7bbbed44e2659379c8046acaa35aaa8910..989a732e5ef2053deede245d65fbf99cdf117c5e 100644
index 17f8dd9870a47227a7c9bb09cceedb94f7190ead..139a96d01e3a7e2e298592ce5d485dfc21c9c6c7 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -1171,7 +1171,7 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
@ -84,7 +84,7 @@ index 9b8e6b7bbbed44e2659379c8046acaa35aaa8910..989a732e5ef2053deede245d65fbf99c
/**
diff --git a/src/main/java/org/bukkit/inventory/ItemFactory.java b/src/main/java/org/bukkit/inventory/ItemFactory.java
index 591e095dabd4cb72881abf206b1d7f0c8818cef3..ecf509a970ed4f0052d5d2c756406bf96052a680 100644
index 71e5ee496a947fbd8e3ec579833b157c76b51833..d773e8594f91017bddd7ea8aada3a1ff2781d05b 100644
--- a/src/main/java/org/bukkit/inventory/ItemFactory.java
+++ b/src/main/java/org/bukkit/inventory/ItemFactory.java
@@ -3,6 +3,7 @@ package org.bukkit.inventory;

View File

@ -103,7 +103,7 @@ index d5d67b3d84cd88ed0f858497e68535ec0162c700..432d5711b7ec34eafeb27df82d367612
* Creates explosion at this location with given power
*
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
index 19060c7d9c74b9b2808103f3d5627444aece6ccb..f8e104d5e61e52c5fe658d7cda373f62424c7bea 100644
index b80a2fe9eb6824d986126e451900a62244d3a8e7..6fe2875f95bb600606d66e2f7113d325d10a9b9c 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -160,6 +160,87 @@ public interface World extends PluginMessageRecipient, Metadatable, net.kyori.ad

View File

@ -4,12 +4,13 @@ Date: Mon, 27 May 2019 17:35:39 -0500
Subject: [PATCH] MC-114618 - Fix EntityAreaEffectCloud from going negative
size
1.17 update note: Likely fixed in 1.17
diff --git a/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java b/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java
index 949553229a55f8c8b9a5c0141409d1520eff22c7..fe4312a58b0b2ffd63db14068d99c5391e0eb0a0 100644
index 4733f74ff028c03a60b73280caf9e4d1e2f0ca30..882c216b508a8623c2393b668cff6d702fe738b9 100644
--- a/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java
+++ b/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java
@@ -194,6 +194,12 @@ public class AreaEffectCloud extends Entity {
@@ -197,6 +197,12 @@ public class AreaEffectCloud extends Entity {
super.tick();
boolean flag = this.isWaiting();
float f = this.getRadius();
@ -21,4 +22,4 @@ index 949553229a55f8c8b9a5c0141409d1520eff22c7..fe4312a58b0b2ffd63db14068d99c539
+ // Paper end
if (this.level.isClientSide) {
ParticleOptions particleparam = this.getParticle();
if (flag && this.random.nextBoolean()) {

View File

@ -1,32 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sat, 6 Apr 2019 10:16:48 -0400
Subject: [PATCH] Optimize Captured TileEntity Lookup
upstream was doing a containsKey/get pattern, and always doing it at that.
that scenario is only even valid if were in the middle of a block place.
Optimize to check if the captured list even has values in it, and also to
just do a get call since the value can never be null.
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index c8542636e89748699d608eb29569cacb6321d334..5193271bc257248e0d2bc9d9a477e999a97deada 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -968,12 +968,13 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
return null;
} else {
// CraftBukkit start
- if (capturedTileEntities.containsKey(blockposition)) {
- return capturedTileEntities.get(blockposition);
+ BlockEntity tileentity = null; // Paper
+ if (!capturedTileEntities.isEmpty() && (tileentity = capturedTileEntities.get(blockposition)) != null) { // Paper
+ return tileentity; // Paper
}
// CraftBukkit end
- BlockEntity tileentity = null;
+ //TileEntity tileentity = null; // Paper - move up
if (this.updatingBlockEntities) {
tileentity = this.getPendingBlockEntityAt(blockposition);

View File

@ -1,55 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Tue, 1 Jan 2019 02:22:01 -0800
Subject: [PATCH] Add Heightmap API
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index 5193271bc257248e0d2bc9d9a477e999a97deada..eb88d830fb45a6b8c990e8bdc1943d80f63c8b93 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -670,8 +670,8 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
}
}
- @Override
- public int getHeight(Heightmap.Types heightmap, int x, int z) {
+ public final int getHighestBlockY(final Heightmap.Types heightmap, final int x, final int z) { return this.getHeight(heightmap, x, z); } // Paper - OBFHELPER
+ @Override public int getHeight(Heightmap.Types heightmap, int x, int z) { // Paper - OBFHELPER
int k;
if (x >= -30000000 && z >= -30000000 && x < 30000000 && z < 30000000) {
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 7b5abccac9793811bd56340c8f9d23806e832365..a4231e1c3d468355c0b55ac9d2c239f1b4c54594 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -325,6 +325,29 @@ public class CraftWorld implements World {
return getHighestBlockYAt(x, z, org.bukkit.HeightMap.MOTION_BLOCKING);
}
+ // Paper start - Implement heightmap api
+ @Override
+ public int getHighestBlockYAt(final int x, final int z, final com.destroystokyo.paper.HeightmapType heightmap) throws UnsupportedOperationException {
+ this.getChunkAt(x >> 4, z >> 4); // heightmap will ret 0 on unloaded areas
+
+ switch (heightmap) {
+ case LIGHT_BLOCKING:
+ throw new UnsupportedOperationException(); // TODO
+ //return this.world.getHighestBlockY(HeightMap.Type.LIGHT_BLOCKING, x, z);
+ case ANY:
+ return this.world.getHighestBlockY(net.minecraft.world.level.levelgen.Heightmap.Types.WORLD_SURFACE, x, z);
+ case SOLID:
+ return this.world.getHighestBlockY(net.minecraft.world.level.levelgen.Heightmap.Types.OCEAN_FLOOR, x, z);
+ case SOLID_OR_LIQUID:
+ return this.world.getHighestBlockY(net.minecraft.world.level.levelgen.Heightmap.Types.MOTION_BLOCKING, x, z);
+ case SOLID_OR_LIQUID_NO_LEAVES:
+ return this.world.getHighestBlockY(net.minecraft.world.level.levelgen.Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, x, z);
+ default:
+ throw new UnsupportedOperationException();
+ }
+ }
+ // Paper end
+
@Override
public Location getSpawnLocation() {
BlockPos spawn = world.getSpawn();

View File

@ -1,139 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Fri, 19 Apr 2019 12:41:13 -0500
Subject: [PATCH] Mob Spawner API Enhancements
diff --git a/src/main/java/net/minecraft/world/level/BaseSpawner.java b/src/main/java/net/minecraft/world/level/BaseSpawner.java
index 3a7aec9bd2f3fd1b4a1981fb6a8c64b69e4875f8..6ca378ec7868b855d46c749910c656f82ddb009f 100644
--- a/src/main/java/net/minecraft/world/level/BaseSpawner.java
+++ b/src/main/java/net/minecraft/world/level/BaseSpawner.java
@@ -65,6 +65,7 @@ public abstract class BaseSpawner {
this.spawnPotentials.clear(); // CraftBukkit - SPIGOT-3496, MC-92282
}
+ public boolean isActivated() { return isNearPlayer(); } // Paper - OBFHELPER
private boolean isNearPlayer() {
BlockPos blockposition = this.getPos();
@@ -221,6 +222,7 @@ public abstract class BaseSpawner {
}
}
+ public void resetTimer() { delay(); } // Paper - OBFHELPER
private void delay() {
if (this.maxSpawnDelay <= this.minSpawnDelay) {
this.spawnDelay = this.minSpawnDelay;
@@ -238,7 +240,13 @@ public abstract class BaseSpawner {
}
public void load(CompoundTag tag) {
+ // Paper start - use larger int if set
+ if (tag.contains("Paper.Delay")) {
+ this.spawnDelay = tag.getInt("Paper.Delay");
+ } else {
this.spawnDelay = tag.getShort("Delay");
+ }
+ // Paper end
this.spawnPotentials.clear();
if (tag.contains("SpawnPotentials", 9)) {
ListTag nbttaglist = tag.getList("SpawnPotentials", 10);
@@ -253,10 +261,15 @@ public abstract class BaseSpawner {
} else if (!this.spawnPotentials.isEmpty()) {
this.setNextSpawnData((SpawnData) WeighedRandom.getRandomItem(this.getLevel().random, this.spawnPotentials));
}
-
+ // Paper start - use ints if set
+ if (tag.contains("Paper.MinSpawnDelay", 99)) {
+ this.minSpawnDelay = tag.getInt("Paper.MinSpawnDelay");
+ this.maxSpawnDelay = tag.getInt("Paper.MaxSpawnDelay");
+ this.spawnCount = tag.getShort("SpawnCount");
+ } else // Paper end
if (tag.contains("MinSpawnDelay", 99)) {
- this.minSpawnDelay = tag.getShort("MinSpawnDelay");
- this.maxSpawnDelay = tag.getShort("MaxSpawnDelay");
+ this.minSpawnDelay = tag.getInt("MinSpawnDelay");
+ this.maxSpawnDelay = tag.getInt("MaxSpawnDelay");
this.spawnCount = tag.getShort("SpawnCount");
}
@@ -281,9 +294,20 @@ public abstract class BaseSpawner {
if (minecraftkey == null) {
return tag;
} else {
- tag.putShort("Delay", (short) this.spawnDelay);
- tag.putShort("MinSpawnDelay", (short) this.minSpawnDelay);
- tag.putShort("MaxSpawnDelay", (short) this.maxSpawnDelay);
+ // Paper start
+ if (spawnDelay > Short.MAX_VALUE) {
+ tag.putInt("Paper.Delay", this.spawnDelay);
+ }
+ tag.putShort("Delay", (short) Math.min(Short.MAX_VALUE, this.spawnDelay));
+
+ if (minSpawnDelay > Short.MAX_VALUE || maxSpawnDelay > Short.MAX_VALUE) {
+ tag.putInt("Paper.MinSpawnDelay", this.minSpawnDelay);
+ tag.putInt("Paper.MaxSpawnDelay", this.maxSpawnDelay);
+ }
+
+ tag.putShort("MinSpawnDelay", (short) Math.min(Short.MAX_VALUE, this.minSpawnDelay));
+ tag.putShort("MaxSpawnDelay", (short) Math.min(Short.MAX_VALUE, this.maxSpawnDelay));
+ // Paper end
tag.putShort("SpawnCount", (short) this.spawnCount);
tag.putShort("MaxNearbyEntities", (short) this.maxNearbyEntities);
tag.putShort("RequiredPlayerRange", (short) this.requiredPlayerRange);
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java b/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java
index daaf861041cf7c8f59c85535ecb99e402ab4f658..a5b88b545e08eaabf894305a9bee31c55c5b1b87 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java
@@ -1,12 +1,20 @@
package org.bukkit.craftbukkit.block;
import com.google.common.base.Preconditions;
+import net.minecraft.core.Registry;
+import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
+import net.minecraft.world.level.SpawnData;
import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.entity.EntityType;
+// Paper start
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
+import org.bukkit.inventory.ItemStack;
+// Paper end
public class CraftCreatureSpawner extends CraftBlockEntityState<SpawnerBlockEntity> implements CreatureSpawner {
@@ -120,4 +128,30 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<SpawnerBlockEnti
public void setSpawnRange(int spawnRange) {
this.getSnapshot().getSpawner().spawnRange = spawnRange;
}
+
+ // Paper start
+ @Override
+ public boolean isActivated() {
+ return this.getSnapshot().getSpawner().isActivated();
+ }
+
+ @Override
+ public void resetTimer() {
+ this.getSnapshot().getSpawner().resetTimer();
+ }
+
+ @Override
+ public void setSpawnedItem(ItemStack itemStack) {
+ Preconditions.checkArgument(itemStack != null && !itemStack.getType().isAir(), "spawners cannot spawn air");
+ net.minecraft.world.item.ItemStack item = CraftItemStack.asNMSCopy(itemStack);
+ CompoundTag compound = new CompoundTag();
+ CompoundTag entity = new CompoundTag();
+ entity.putString("id", Registry.ENTITY_TYPE.getKey(net.minecraft.world.entity.EntityType.ITEM).toString());
+ entity.put("Item", item.save(new CompoundTag()));
+ compound.put("Entity", entity);
+ compound.putInt("Weight", this.getSnapshotNBT().contains("Weight", CraftMagicNumbers.NBT.TAG_ANY_NUMBER) ? this.getSnapshotNBT().getInt("Weight") : 1);
+ this.getSnapshot().getSpawner().setNextSpawnData(new SpawnData(compound));
+ this.getSnapshot().getSpawner().spawnPotentials.clear();
+ }
+ // Paper end
}

View File

@ -6,10 +6,10 @@ Subject: [PATCH] don't go below 0 for pickupDelay, breaks picking up items
vanilla checks for == 0
diff --git a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
index 70f719ba3c68c8e9414e6b4bc68002f7c962e2b9..281f5646980afc70890bdafd358ff9b20d32420d 100644
index 0741dcbd06395b4696eb6083128a5d9b679cb3fb..82ffe3624943d2e931e2cc2f85ede94f369bd06b 100644
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
@@ -86,6 +86,7 @@ public class ItemEntity extends Entity {
@@ -105,6 +105,7 @@ public class ItemEntity extends Entity {
// CraftBukkit start - Use wall time for pickup and despawn timers
int elapsedTicks = MinecraftServer.currentTick - this.lastTick;
if (this.pickupDelay != 32767) this.pickupDelay -= elapsedTicks;
@ -17,7 +17,7 @@ index 70f719ba3c68c8e9414e6b4bc68002f7c962e2b9..281f5646980afc70890bdafd358ff9b2
if (this.age != -32768) this.age += elapsedTicks;
this.lastTick = MinecraftServer.currentTick;
// CraftBukkit end
@@ -178,6 +179,7 @@ public class ItemEntity extends Entity {
@@ -193,6 +194,7 @@ public class ItemEntity extends Entity {
// CraftBukkit start - Use wall time for pickup and despawn timers
int elapsedTicks = MinecraftServer.currentTick - this.lastTick;
if (this.pickupDelay != 32767) this.pickupDelay -= elapsedTicks;

View File

@ -6,10 +6,10 @@ Subject: [PATCH] Server Tick Events
Fires event at start and end of a server tick
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 6ccc0be795e3ac7689de0eff6f9142d13161a29c..35984c7e994570a909ed4ffaabe64ae941b15e71 100644
index a1c65ea148692e50dbc466d87dae5198e0b6a51f..eb103c15218c334b9f85a57e30582e9efb188704 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1237,6 +1237,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1310,6 +1310,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
});
isOversleep = false;MinecraftTimings.serverOversleep.stopTiming();
// Paper end
@ -17,7 +17,7 @@ index 6ccc0be795e3ac7689de0eff6f9142d13161a29c..35984c7e994570a909ed4ffaabe64ae9
++this.tickCount;
this.tickChildren(shouldKeepTicking);
@@ -1280,6 +1281,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1353,6 +1354,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
// Paper end

View File

@ -8,10 +8,10 @@ Exposes a mutable array on items a player should keep on death
Example Usage: https://gist.github.com/aikar/5bb202de6057a051a950ce1f29feb0b4
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index fd2717a00a85f91ee23a1c0f929f856972892a9b..d6cfe68be1a944ff5d5780666467f5fd8e2794e3 100644
index 955a7fcd80a57f920e402a5533f5029b9683104c..679f1e3ef4c19ab466cf2d06c47b1018aabaa7bf 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -692,6 +692,46 @@ public class ServerPlayer extends Player implements ContainerListener {
@@ -729,6 +729,46 @@ public class ServerPlayer extends Player {
});
}
@ -32,7 +32,7 @@ index fd2717a00a85f91ee23a1c0f929f856972892a9b..d6cfe68be1a944ff5d5780666467f5fd
+ for (int i = 0; i < inv.size(); ++i) {
+ ItemStack item = inv.get(i);
+ if (EnchantmentHelper.hasVanishingCurse(item) || itemsToKeep.isEmpty() || item.isEmpty()) {
+ inv.set(i, ItemStack.NULL_ITEM);
+ inv.set(i, ItemStack.EMPTY);
+ continue;
+ }
+
@ -49,7 +49,7 @@ index fd2717a00a85f91ee23a1c0f929f856972892a9b..d6cfe68be1a944ff5d5780666467f5fd
+ }
+
+ if (!keep) {
+ inv.set(i, ItemStack.NULL_ITEM);
+ inv.set(i, ItemStack.EMPTY);
+ }
+ }
+ }
@ -58,13 +58,12 @@ index fd2717a00a85f91ee23a1c0f929f856972892a9b..d6cfe68be1a944ff5d5780666467f5fd
@Override
public void die(DamageSource source) {
boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
@@ -775,7 +815,12 @@ public class ServerPlayer extends Player implements ContainerListener {
this.dropExperience();
@@ -813,6 +853,12 @@ public class ServerPlayer extends Player {
// we clean the player's inventory after the EntityDeathEvent is called so plugins can get the exact state of the inventory.
if (!event.getKeepInventory()) {
- this.inventory.clearContent();
this.getInventory().clearContent();
+ // Paper start - replace logic
+ for (NonNullList<ItemStack> inv : this.inventory.getComponents()) {
+ for (NonNullList<ItemStack> inv : this.getInventory().getComponents()) {
+ processKeep(event, inv);
+ }
+ processKeep(event, null);

View File

@ -0,0 +1,30 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sat, 6 Apr 2019 10:16:48 -0400
Subject: [PATCH] Optimize Captured TileEntity Lookup
upstream was doing a containsKey/get pattern, and always doing it at that.
that scenario is only even valid if were in the middle of a block place.
Optimize to check if the captured list even has values in it, and also to
just do a get call since the value can never be null.
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index a1b713391c2445967c3b5a645304f193c013d551..9891e40972c1dc6bebe8ccec2bf82123dcdd7e94 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -869,9 +869,12 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@Nullable
public BlockEntity getTileEntity(BlockPos blockposition, boolean validate) {
- if (this.capturedTileEntities.containsKey(blockposition)) {
- return this.capturedTileEntities.get(blockposition);
+ // Paper start - Optimize capturedTileEntities lookup
+ net.minecraft.world.level.block.entity.BlockEntity blockEntity;
+ if (!this.capturedTileEntities.isEmpty() && (blockEntity = this.capturedTileEntities.get(blockposition)) != null) {
+ return blockEntity;
}
+ // Paper end
// CraftBukkit end
return this.isOutsideBuildHeight(blockposition) ? null : (!this.isClientSide && Thread.currentThread() != this.thread ? null : this.getChunkAt(blockposition).getBlockEntity(blockposition, LevelChunk.EntityCreationType.IMMEDIATE));
}

View File

@ -0,0 +1,40 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Tue, 1 Jan 2019 02:22:01 -0800
Subject: [PATCH] Add Heightmap API
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index fda8858375a08e0aac15ca00751df5a34ed6a0f2..5f93589106bcf29eabd4544951fa3ad36e00c5a6 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -341,6 +341,29 @@ public class CraftWorld implements World {
return this.getHighestBlockYAt(x, z, org.bukkit.HeightMap.MOTION_BLOCKING);
}
+ // Paper start - Implement heightmap api
+ @Override
+ public int getHighestBlockYAt(final int x, final int z, final com.destroystokyo.paper.HeightmapType heightmap) throws UnsupportedOperationException {
+ this.getChunkAt(x >> 4, z >> 4); // heightmap will ret 0 on unloaded areas
+
+ switch (heightmap) {
+ case LIGHT_BLOCKING:
+ throw new UnsupportedOperationException(); // TODO
+ //return this.world.getHighestBlockY(HeightMap.Type.LIGHT_BLOCKING, x, z);
+ case ANY:
+ return this.world.getHeight(net.minecraft.world.level.levelgen.Heightmap.Types.WORLD_SURFACE, x, z);
+ case SOLID:
+ return this.world.getHeight(net.minecraft.world.level.levelgen.Heightmap.Types.OCEAN_FLOOR, x, z);
+ case SOLID_OR_LIQUID:
+ return this.world.getHeight(net.minecraft.world.level.levelgen.Heightmap.Types.MOTION_BLOCKING, x, z);
+ case SOLID_OR_LIQUID_NO_LEAVES:
+ return this.world.getHeight(net.minecraft.world.level.levelgen.Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, x, z);
+ default:
+ throw new UnsupportedOperationException();
+ }
+ }
+ // Paper end
+
@Override
public Location getSpawnLocation() {
BlockPos spawn = this.world.getSharedSpawnPos();

View File

@ -0,0 +1,129 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Fri, 19 Apr 2019 12:41:13 -0500
Subject: [PATCH] Mob Spawner API Enhancements
diff --git a/src/main/java/net/minecraft/world/level/BaseSpawner.java b/src/main/java/net/minecraft/world/level/BaseSpawner.java
index 3aadcb472ab808ee981065ddfa86be6cbf38c8d9..c6298b12e4e0c20be20e7e493be728f028f9eb31 100644
--- a/src/main/java/net/minecraft/world/level/BaseSpawner.java
+++ b/src/main/java/net/minecraft/world/level/BaseSpawner.java
@@ -31,7 +31,7 @@ public abstract class BaseSpawner {
private static final Logger LOGGER = LogManager.getLogger();
private static final int EVENT_SPAWN = 1;
- private static WeightedRandomList<SpawnData> EMPTY_POTENTIALS = WeightedRandomList.create();
+ public static WeightedRandomList<SpawnData> EMPTY_POTENTIALS = WeightedRandomList.create(); // Paper - private->public
public int spawnDelay = 20;
public WeightedRandomList<SpawnData> spawnPotentials;
public SpawnData nextSpawnData;
@@ -77,7 +77,7 @@ public abstract class BaseSpawner {
this.spawnPotentials = BaseSpawner.EMPTY_POTENTIALS; // CraftBukkit - SPIGOT-3496, MC-92282
}
- private boolean isNearPlayer(Level world, BlockPos pos) {
+ public boolean isNearPlayer(Level world, BlockPos pos) { // Paper private->public
return world.isAffectsSpawningPlayerNearby((double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, (double) this.requiredPlayerRange); // Paper
}
@@ -204,7 +204,7 @@ public abstract class BaseSpawner {
}
}
- private void delay(Level world, BlockPos pos) {
+ public void delay(Level world, BlockPos pos) { // Paper private->public
if (this.maxSpawnDelay <= this.minSpawnDelay) {
this.spawnDelay = this.minSpawnDelay;
} else {
@@ -218,7 +218,13 @@ public abstract class BaseSpawner {
}
public void load(@Nullable Level world, BlockPos pos, CompoundTag nbt) {
+ // Paper start - use larger int if set
+ if (nbt.contains("Paper.Delay")) {
+ this.spawnDelay = nbt.getInt("Paper.Delay");
+ } else {
this.spawnDelay = nbt.getShort("Delay");
+ }
+ // Paper end
List<SpawnData> list = Lists.newArrayList();
if (nbt.contains("SpawnPotentials", 9)) {
@@ -237,10 +243,15 @@ public abstract class BaseSpawner {
this.setSpawnData(world, pos, mobspawnerdata);
});
}
-
+ // Paper start - use ints if set
+ if (nbt.contains("Paper.MinSpawnDelay", 99)) {
+ this.minSpawnDelay = nbt.getInt("Paper.MinSpawnDelay");
+ this.maxSpawnDelay = nbt.getInt("Paper.MaxSpawnDelay");
+ this.spawnCount = nbt.getShort("SpawnCount");
+ } else // Paper end
if (nbt.contains("MinSpawnDelay", 99)) {
- this.minSpawnDelay = nbt.getShort("MinSpawnDelay");
- this.maxSpawnDelay = nbt.getShort("MaxSpawnDelay");
+ this.minSpawnDelay = nbt.getInt("MinSpawnDelay"); // Paper - short->int
+ this.maxSpawnDelay = nbt.getInt("MaxSpawnDelay"); // Paper - short->int
this.spawnCount = nbt.getShort("SpawnCount");
}
@@ -262,9 +273,20 @@ public abstract class BaseSpawner {
if (minecraftkey == null) {
return nbt;
} else {
- nbt.putShort("Delay", (short) this.spawnDelay);
- nbt.putShort("MinSpawnDelay", (short) this.minSpawnDelay);
- nbt.putShort("MaxSpawnDelay", (short) this.maxSpawnDelay);
+ // Paper start
+ if (spawnDelay > Short.MAX_VALUE) {
+ nbt.putInt("Paper.Delay", this.spawnDelay);
+ }
+ nbt.putShort("Delay", (short) Math.min(Short.MAX_VALUE, this.spawnDelay));
+
+ if (minSpawnDelay > Short.MAX_VALUE || maxSpawnDelay > Short.MAX_VALUE) {
+ nbt.putInt("Paper.MinSpawnDelay", this.minSpawnDelay);
+ nbt.putInt("Paper.MaxSpawnDelay", this.maxSpawnDelay);
+ }
+
+ nbt.putShort("MinSpawnDelay", (short) Math.min(Short.MAX_VALUE, this.minSpawnDelay));
+ nbt.putShort("MaxSpawnDelay", (short) Math.min(Short.MAX_VALUE, this.maxSpawnDelay));
+ // Paper end
nbt.putShort("SpawnCount", (short) this.spawnCount);
nbt.putShort("MaxNearbyEntities", (short) this.maxNearbyEntities);
nbt.putShort("RequiredPlayerRange", (short) this.requiredPlayerRange);
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java b/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java
index ff8eba31e6169b5a1debe47f17a40e6d0be67897..75575b24aa0291c26d65de9787bc9d2f88c867e4 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java
@@ -121,4 +121,30 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<SpawnerBlockEnti
public void setSpawnRange(int spawnRange) {
this.getSnapshot().getSpawner().spawnRange = spawnRange;
}
+
+ // Paper start
+ @Override
+ public boolean isActivated() {
+ return this.getSnapshot().getSpawner().isNearPlayer(world.getHandle(), getPosition());
+ }
+
+ @Override
+ public void resetTimer() {
+ this.getSnapshot().getSpawner().delay(world.getHandle(), getPosition());
+ }
+
+ @Override
+ public void setSpawnedItem(org.bukkit.inventory.ItemStack itemStack) {
+ Preconditions.checkArgument(itemStack != null && !itemStack.getType().isAir(), "spawners cannot spawn air");
+ net.minecraft.world.item.ItemStack item = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(itemStack);
+ net.minecraft.nbt.CompoundTag compound = new net.minecraft.nbt.CompoundTag();
+ net.minecraft.nbt.CompoundTag entity = new net.minecraft.nbt.CompoundTag();
+ entity.putString("id", net.minecraft.core.Registry.ENTITY_TYPE.getKey(net.minecraft.world.entity.EntityType.ITEM).toString());
+ entity.put("Item", item.save(new net.minecraft.nbt.CompoundTag()));
+ compound.put("Entity", entity);
+ compound.putInt("Weight", this.getSnapshotNBT().contains("Weight", org.bukkit.craftbukkit.util.CraftMagicNumbers.NBT.TAG_ANY_NUMBER) ? this.getSnapshotNBT().getInt("Weight") : 1);
+ this.getSnapshot().getSpawner().setSpawnData(world.getHandle(), getPosition(), new net.minecraft.world.level.SpawnData(compound));
+ this.getSnapshot().getSpawner().spawnPotentials= net.minecraft.world.level.BaseSpawner.EMPTY_POTENTIALS;
+ }
+ // Paper end
}

View File

@ -5,15 +5,15 @@ Subject: [PATCH] Fix CB call to changed postToMainThread method
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index ed4129a51351aff16455960d71a0add1b8209c02..4f99c3d06e3b994708c699395adf481a6828e097 100644
index 6c4266d847b1181a055fa425d5734032dadabf93..377e224acb06bfd5f769b5f75b7f52129394b494 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -443,7 +443,7 @@ public class ServerGamePacketListenerImpl implements ServerGamePacketListener {
@@ -440,7 +440,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
this.connection.getClass();
Objects.requireNonNull(this.connection);
// CraftBukkit - Don't wait
- minecraftserver.wrapRunnable(networkmanager::handleDisconnection);
+ minecraftserver.scheduleOnMain(networkmanager::handleDisconnection); // Paper
}
private <T> void filterTextPacket(T text, Consumer<T> consumer, BiFunction<TextFilter, T, CompletableFuture<Optional<T>>> backingFilterer) {
private <T, R> void filterTextPacket(T text, Consumer<R> consumer, BiFunction<TextFilter, T, CompletableFuture<R>> backingFilterer) {

View File

@ -6,15 +6,15 @@ Subject: [PATCH] Fix sounds when item frames are modified (MC-123450)
This also fixes the adding sound playing when the item frame direction is changed.
diff --git a/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java b/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java
index d6e6846a12a889222ced67937c09d184a64c60b9..429d8a50a35f07bfc16dbedf28560fa6df817644 100644
index 5fab5f74f7ef2ba94d7dae1679653201d7ccb30f..b829efdb40051a41b3bf1cabb8bf7d7c952797b5 100644
--- a/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java
+++ b/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java
@@ -277,7 +277,7 @@ public class ItemFrame extends HangingEntity {
@@ -307,7 +307,7 @@ public class ItemFrame extends HangingEntity {
}
this.getEntityData().set(ItemFrame.DATA_ITEM, itemstack);
- if (!itemstack.isEmpty() && playSound) { // CraftBukkit
+ if (!itemstack.isEmpty() && flag && playSound) { // CraftBukkit // Paper - only play sound when update flag is set
this.playSound(SoundEvents.ITEM_FRAME_ADD_ITEM, 1.0F, 1.0F);
this.playSound(this.getAddItemSound(), 1.0F, 1.0F);
}

View File

@ -16,10 +16,10 @@ handling that should have been handled synchronously will be handled
synchronously when the server gets shut down.
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 35984c7e994570a909ed4ffaabe64ae941b15e71..9beda5e429b5c520a41d9c7f536dc48dbb6f6f9e 100644
index eb103c15218c334b9f85a57e30582e9efb188704..c8a59de4673d430fc8ec2e53315f107293122e7e 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -2190,7 +2190,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -2262,7 +2262,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// CraftBukkit start
@Override
public boolean isSameThread() {
@ -29,14 +29,14 @@ index 35984c7e994570a909ed4ffaabe64ae941b15e71..9beda5e429b5c520a41d9c7f536dc48d
public boolean isDebugging() {
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 590687d5941cbed3a330bcd749f8d52cd4b5e3ae..96a3a4d89df858d4e46a36f110dd9ad3a2061433 100644
index 0448e6b4c512f512bda13f41f1feb58de02fc9d4..58d7fec472dd8c8d7775eb6d931be29871102054 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1839,7 +1839,7 @@ public final class CraftServer implements Server {
@@ -1840,7 +1840,7 @@ public final class CraftServer implements Server {
@Override
public boolean isPrimaryThread() {
- return Thread.currentThread().equals(console.serverThread) || console.hasStopped() || !org.spigotmc.AsyncCatcher.enabled; // All bets are off if we have shut down (e.g. due to watchdog)
- return Thread.currentThread().equals(console.serverThread) || this.console.hasStopped() || !org.spigotmc.AsyncCatcher.enabled; // All bets are off if we have shut down (e.g. due to watchdog)
+ return Thread.currentThread().equals(console.serverThread); // Paper - Fix issues with detecting main thread properly
}

View File

@ -9,22 +9,22 @@ waiting for the execution queue to get to our request; We can just query
the chunk status and get a response now, vs having to wait
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index a4231e1c3d468355c0b55ac9d2c239f1b4c54594..6e9e2149d854f26826d030ee6e655ca8fa7b5141 100644
index 5f93589106bcf29eabd4544951fa3ad36e00c5a6..a7eb8f69b49bb0229de9e5a4400a4424555ac1dd 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -396,13 +396,13 @@ public class CraftWorld implements World {
@@ -412,13 +412,13 @@ public class CraftWorld implements World {
@Override
public boolean isChunkLoaded(int x, int z) {
- return world.getChunkSource().isChunkLoaded(x, z);
+ return world.getChunkSource().getChunkAtIfLoadedImmediately(x, z) != null; // Paper
- return this.world.getChunkSource().isChunkLoaded(x, z);
+ return this.world.getChunkSource().getChunkAtIfLoadedImmediately(x, z) != null; // Paper
}
@Override
public boolean isChunkGenerated(int x, int z) {
try {
- return isChunkLoaded(x, z) || world.getChunkSource().chunkMap.read(new ChunkPos(x, z)) != null;
+ return world.getChunkSource().getChunkAtIfCachedImmediately(x, z) != null || world.getChunkSource().chunkMap.read(new ChunkPos(x, z)) != null; // Paper (TODO check if the first part can be removed)
- return this.isChunkLoaded(x, z) || this.world.getChunkSource().chunkMap.read(new ChunkPos(x, z)) != null;
+ return this.world.getChunkSource().getChunkAtIfCachedImmediately(x, z) != null || this.world.getChunkSource().chunkMap.read(new ChunkPos(x, z)) != null; // Paper (TODO check if the first part can be removed)
} catch (IOException ex) {
throw new RuntimeException(ex);
}

View File

@ -6,25 +6,27 @@ Subject: [PATCH] Configurable Keep Spawn Loaded range per world
This lets you disable it for some worlds and lower it for others.
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
index 38d25a12c6a52d8a83214e2a0f43a218cf15ceac..ffe9b1a63d78925e1d77b9e730aef42fed6d58fa 100644
index 13e730b18c346934c061fb570048623ad66e7344..090958a30ce20ff01ae77d4cd821a167474f0214 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -440,4 +440,10 @@ public class PaperWorldConfig {
break;
@@ -36,6 +36,12 @@ public class PaperWorldConfig {
}
}
+
+ public short keepLoadedRange;
+ private void keepLoadedRange() {
+ keepLoadedRange = (short) (getInt("keep-spawn-loaded-range", Math.min(spigotConfig.viewDistance, 10)) * 16);
+ log( "Keep Spawn Loaded Range: " + (keepLoadedRange/16));
+ }
}
+
private boolean getBoolean(String path, boolean def) {
config.addDefault("world-settings.default." + path, def);
return config.getBoolean("world-settings." + worldName + "." + path, config.getBoolean("world-settings.default." + path));
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 9beda5e429b5c520a41d9c7f536dc48dbb6f6f9e..0efe7024493f96bb54e7d8c1ea7b233a1b481a04 100644
index c8a59de4673d430fc8ec2e53315f107293122e7e..40e48c3f1199b127066732e3c8a6d40c232215b2 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -716,35 +716,36 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -775,35 +775,36 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// CraftBukkit start
public void loadSpawn(ChunkProgressListener worldloadlistener, ServerLevel worldserver) {
@ -33,13 +35,13 @@ index 9beda5e429b5c520a41d9c7f536dc48dbb6f6f9e..0efe7024493f96bb54e7d8c1ea7b233a
- }
+ ServerChunkCache chunkproviderserver = worldserver.getChunkSource(); // Paper
// WorldServer worldserver = this.E();
// WorldServer worldserver = this.F();
this.forceTicks = true;
// CraftBukkit end
+ if (worldserver.getWorld().getKeepSpawnInMemory()) { // Paper
MinecraftServer.LOGGER.info("Preparing start region for dimension {}", worldserver.dimension().location());
BlockPos blockposition = worldserver.getSpawn();
BlockPos blockposition = worldserver.getSharedSpawnPos();
worldloadlistener.updateSpawnPos(new ChunkPos(blockposition));
- ServerChunkCache chunkproviderserver = worldserver.getChunkSource();
@ -51,11 +53,10 @@ index 9beda5e429b5c520a41d9c7f536dc48dbb6f6f9e..0efe7024493f96bb54e7d8c1ea7b233a
-
- while (chunkproviderserver.getTickingGenerated() != 441) {
- // CraftBukkit start
- // this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
- // this.nextTickTime = SystemUtils.getMonotonicMillis() + 10L;
- this.executeModerately();
- // CraftBukkit end
- }
-
+ // Paper start - configurable spawn reason
+ int radiusBlocks = worldserver.paperConfig.keepLoadedRange;
+ int radiusChunks = radiusBlocks / 16 + ((radiusBlocks & 15) != 0 ? 1 : 0);
@ -64,17 +65,17 @@ index 9beda5e429b5c520a41d9c7f536dc48dbb6f6f9e..0efe7024493f96bb54e7d8c1ea7b233a
+ worldloadlistener.setChunkRadius(radiusBlocks / 16);
+
+ worldserver.addTicketsForSpawn(radiusBlocks, blockposition);
+ //LOGGER.info("Loaded " + chunkproviderserver.b() + " spawn chunks for world " + worldserver.getWorld().getName()); // Paper
+ // Paper end
// CraftBukkit start
// this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
// this.nextTickTime = SystemUtils.getMonotonicMillis() + 10L;
this.executeModerately();
// Iterator iterator = this.worldServer.values().iterator();
+ }
if (true) {
ServerLevel worldserver1 = worldserver;
@@ -767,7 +768,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -826,7 +827,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
this.executeModerately();
// CraftBukkit end
@ -84,19 +85,19 @@ index 9beda5e429b5c520a41d9c7f536dc48dbb6f6f9e..0efe7024493f96bb54e7d8c1ea7b233a
// CraftBukkit start
// this.updateSpawnFlags();
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 20b74fc8e1273fcd07ea4417eaedc8bd9aba93b3..b2ddf145ae9f581ec6820deb9cb6a98be87658d7 100644
index 940e6587125df1f203cdeeefc31658635badea81..420ecc61be194486d335c44fc743894023d3f115 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -66,6 +66,7 @@ import net.minecraft.network.protocol.game.ClientboundSoundPacket;
@@ -61,6 +61,7 @@ import net.minecraft.network.protocol.game.ClientboundSoundEntityPacket;
import net.minecraft.network.protocol.game.ClientboundSoundPacket;
import net.minecraft.network.protocol.game.DebugPackets;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
+import net.minecraft.server.MCUtil;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ServerScoreboard;
import net.minecraft.server.level.progress.ChunkProgressListener;
@@ -1667,12 +1668,88 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
return ((MapIndex) this.getServer().overworld().getDataStorage().computeIfAbsent(MapIndex::new, "idcounts")).getFreeAuxValueForMap();
@@ -1486,12 +1487,88 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
return ((MapIndex) this.getServer().overworld().getDataStorage().computeIfAbsent(MapIndex::load, MapIndex::new, "idcounts")).getFreeAuxValueForMap();
}
+ // Paper start - helper function for configurable spawn radius
@ -188,23 +189,23 @@ index 20b74fc8e1273fcd07ea4417eaedc8bd9aba93b3..b2ddf145ae9f581ec6820deb9cb6a98b
}
diff --git a/src/main/java/net/minecraft/server/level/progress/ChunkProgressListener.java b/src/main/java/net/minecraft/server/level/progress/ChunkProgressListener.java
index 2860a16c80e56edb333115f6f64f65d0e56feb11..85863211a666b299cae8a3791c182ae5094b94d9 100644
index 1b565b2809c2d367e21971c5154f35c9763995e6..b0f899835ded29aff108d1674bf4a1a6c89693db 100644
--- a/src/main/java/net/minecraft/server/level/progress/ChunkProgressListener.java
+++ b/src/main/java/net/minecraft/server/level/progress/ChunkProgressListener.java
@@ -11,4 +11,6 @@ public interface ChunkProgressListener {
void onStatusChange(ChunkPos pos, @Nullable ChunkStatus status);
@@ -12,4 +12,6 @@ public interface ChunkProgressListener {
void start();
void stop();
+
+ void setChunkRadius(int radius); // Paper - allow changing chunk radius
}
diff --git a/src/main/java/net/minecraft/server/level/progress/LoggerChunkProgressListener.java b/src/main/java/net/minecraft/server/level/progress/LoggerChunkProgressListener.java
index 4a541f0b2582430abda6e5ff8f492e37fc903483..e810843fae13d3e83e8f509810b781859217c48b 100644
index 4185e6bcf9b2bb65b2a0fa5fcbeb5684615169a7..dbc29442f2b2ad3ea451910f4944e90114a317c7 100644
--- a/src/main/java/net/minecraft/server/level/progress/LoggerChunkProgressListener.java
+++ b/src/main/java/net/minecraft/server/level/progress/LoggerChunkProgressListener.java
@@ -12,16 +12,24 @@ import org.apache.logging.log4j.Logger;
public class LoggerChunkProgressListener implements ChunkProgressListener {
@@ -11,12 +11,19 @@ import org.apache.logging.log4j.Logger;
public class LoggerChunkProgressListener implements ChunkProgressListener {
private static final Logger LOGGER = LogManager.getLogger();
- private final int maxCount;
+ private int maxCount; // Paper - remove final
@ -219,40 +220,35 @@ index 4a541f0b2582430abda6e5ff8f492e37fc903483..e810843fae13d3e83e8f509810b78185
+
+ @Override
+ public void setChunkRadius(int radius) {
+ // Paper - copied from above
int j = radius * 2 + 1;
this.maxCount = j * j;
+ // Paper end
int i = radius * 2 + 1;
this.maxCount = i * i;
}
+ // Paper end
@Override
public void updateSpawnPos(ChunkPos spawnPos) {
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 6e9e2149d854f26826d030ee6e655ca8fa7b5141..0cb0021fac211996c5bdbb2cfc8f54addc3b49f6 100644
index a7eb8f69b49bb0229de9e5a4400a4424555ac1dd..30305736b7dc023ad5eb3a177914560b3fec64ee 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -1954,15 +1954,21 @@ public class CraftWorld implements World {
@@ -1974,15 +1974,21 @@ public class CraftWorld implements World {
@Override
public void setKeepSpawnInMemory(boolean keepLoaded) {
- world.keepSpawnInMemory = keepLoaded;
+ // Paper start - Configurable spawn radius
+ if (keepLoaded == world.keepSpawnInMemory) {
+ // do nothing, nothing has changed
+ return;
+ }
world.keepSpawnInMemory = keepLoaded;
+ this.world.keepSpawnInMemory = keepLoaded;
// Grab the worlds spawn chunk
- BlockPos chunkcoordinates = this.world.getSpawn();
+ BlockPos prevSpawn = this.world.getSpawn();
BlockPos chunkcoordinates = this.world.getSharedSpawnPos();
if (keepLoaded) {
- world.getChunkSource().addRegionTicket(TicketType.START, new ChunkPos(chunkcoordinates), 11, Unit.INSTANCE);
+ world.addTicketsForSpawn(world.paperConfig.keepLoadedRange, prevSpawn);
- this.world.getChunkSource().addRegionTicket(TicketType.START, new ChunkPos(chunkcoordinates), 11, Unit.INSTANCE);
+ this.world.addTicketsForSpawn(this.world.paperConfig.keepLoadedRange, chunkcoordinates);
} else {
- // TODO: doesn't work well if spawn changed....
- world.getChunkSource().removeRegionTicket(TicketType.START, new ChunkPos(chunkcoordinates), 11, Unit.INSTANCE);
- this.world.getChunkSource().removeRegionTicket(TicketType.START, new ChunkPos(chunkcoordinates), 11, Unit.INSTANCE);
+ // TODO: doesn't work well if spawn changed.... // paper - resolved
+ world.removeTicketsForSpawn(world.paperConfig.keepLoadedRange, prevSpawn);
+ this.world.removeTicketsForSpawn(this.world.paperConfig.keepLoadedRange, chunkcoordinates);
}
+ // Paper end
}