Skip to content

Commit c7b2270

Browse files
committed
Implement custom legacy biome
Also move wrongly registered moonrise ticket type to the vanilla type.
1 parent 18b06e3 commit c7b2270

File tree

10 files changed

+43
-28
lines changed

10 files changed

+43
-28
lines changed

paper-api/src/main/java/io/papermc/paper/InternalAPIBridge.java

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.papermc.paper;
22

33
import net.kyori.adventure.util.Services;
4+
import org.bukkit.block.Biome;
45
import org.bukkit.damage.DamageEffect;
56
import org.jetbrains.annotations.ApiStatus;
67
import org.jspecify.annotations.NullMarked;
@@ -35,5 +36,14 @@ class Holder {
3536
* @return the damage effect.
3637
*/
3738
DamageEffect getDamageEffect(String key);
39+
40+
/**
41+
* Constructs the legacy custom biome instance for the biome enum.
42+
*
43+
* @return the created biome.
44+
*/
45+
@Deprecated(forRemoval = true, since = "1.21.5")
46+
@ApiStatus.ScheduledForRemoval(inVersion = "1.22")
47+
Biome constructLegacyCustomBiome();
3848
}
3949

paper-api/src/main/java/org/bukkit/UnsafeValues.java

-3
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,6 @@ public interface UnsafeValues {
142142
@ApiStatus.Internal
143143
<B extends Keyed> B get(RegistryKey<B> registry, NamespacedKey key);
144144

145-
@ApiStatus.Internal
146-
Biome getCustomBiome();
147-
148145
// Paper start
149146
@Deprecated(forRemoval = true)
150147
boolean isSupportedApiVersion(String apiVersion);

paper-api/src/main/java/org/bukkit/block/Biome.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.common.base.Preconditions;
44
import com.google.common.collect.Lists;
5+
import io.papermc.paper.InternalAPIBridge;
56
import io.papermc.paper.registry.RegistryAccess;
67
import io.papermc.paper.registry.RegistryKey;
78
import java.util.Locale;
@@ -95,7 +96,7 @@ public interface Biome extends OldEnum<Biome>, Keyed, net.kyori.adventure.transl
9596
* @deprecated Biome is no longer an enum, custom biomes will have their own biome instance.
9697
*/
9798
@Deprecated(since = "1.21.3", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils
98-
Biome CUSTOM = Bukkit.getUnsafe().getCustomBiome();
99+
Biome CUSTOM = InternalAPIBridge.get().constructLegacyCustomBiome();
99100

100101
@NotNull
101102
private static Biome getBiome(@NotNull String key) {

paper-server/patches/sources/ca/spottedleaf/moonrise/paper/util/BaseChunkSystemHooks.java.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
+
2929
+ private static final Logger LOGGER = LogUtils.getLogger();
3030
+ private static final ChunkStep FULL_CHUNK_STEP = ChunkPyramid.GENERATION_PYRAMID.getStepTo(ChunkStatus.FULL);
31-
+ private static final TicketType CHUNK_LOAD = TicketType.register("chunk_load", TicketType.NO_TIMEOUT, false, TicketType.TicketUse.LOADING);
31+
+ private static final TicketType CHUNK_LOAD = TicketType.CHUNK_LOAD;
3232
+
3333
+ private long chunkLoadCounter = 0L;
3434
+
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
--- a/net/minecraft/server/level/Ticket.java
22
+++ b/net/minecraft/server/level/Ticket.java
3-
@@ -19,6 +_,7 @@
4-
private final TicketType type;
5-
private final int ticketLevel;
6-
private long ticksLeft;
3+
@@ -66,4 +_,13 @@
4+
public boolean isTimedOut() {
5+
return this.type.hasTimeout() && this.ticksLeft < 0L;
6+
}
7+
+
8+
+ // Paper start - plugin chunk tickets
79
+ public [email protected] Plugin key;
8-
9-
public Ticket(TicketType type, int ticketLevel) {
10-
this(type, ticketLevel, type.timeout());
10+
+ public Ticket withPluginRef(org.bukkit.plugin.Plugin plugin) {
11+
+ com.google.common.base.Preconditions.checkState(this.type == net.minecraft.server.level.TicketType.PLUGIN_TICKET);
12+
+ this.key = plugin;
13+
+ return this;
14+
+ }
15+
+ // Paper end - plugin chunk tickets
16+
}

paper-server/patches/sources/net/minecraft/server/level/TicketType.java.patch

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
--- a/net/minecraft/server/level/TicketType.java
22
+++ b/net/minecraft/server/level/TicketType.java
3-
@@ -13,11 +_,23 @@
3+
@@ -13,11 +_,24 @@
44
public static final TicketType PORTAL = register("portal", 300L, true, TicketType.TicketUse.LOADING_AND_SIMULATION);
55
public static final TicketType ENDER_PEARL = register("ender_pearl", 40L, false, TicketType.TicketUse.LOADING_AND_SIMULATION);
66
public static final TicketType UNKNOWN = register("unknown", 1L, false, TicketType.TicketUse.LOADING);
77
+ public static final TicketType PLUGIN = register("plugin", 0L, false, TicketType.TicketUse.LOADING_AND_SIMULATION); // CraftBukkit
88
+ public static final TicketType POST_TELEPORT = register("post_teleport", 5L, false, TicketType.TicketUse.LOADING_AND_SIMULATION); // Paper
99
+ public static final TicketType PLUGIN_TICKET = register("plugin_ticket", 0L, false, TicketType.TicketUse.LOADING_AND_SIMULATION); // Paper
1010
+ public static final TicketType FUTURE_AWAIT = register("future_await", 0L, false, TicketType.TicketUse.LOADING_AND_SIMULATION); // Paper
11+
+ public static final TicketType CHUNK_LOAD = TicketType.register("chunk_load", TicketType.NO_TIMEOUT, false, TicketType.TicketUse.LOADING); // Paper - moonrise // TODO maybe move to moonrise
1112

1213
public static TicketType register(String name, long timeout, boolean persist, TicketType.TicketUse use) {
1314
return Registry.register(BuiltInRegistries.TICKET_TYPE, name, new TicketType(timeout, persist, use));

paper-server/patches/sources/net/minecraft/world/level/TicketStorage.java.patch

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@
5252
+ // Paper start
5353
+ public boolean addPluginRegionTicket(final ChunkPos pos, final org.bukkit.plugin.Plugin value) {
5454
+ // Keep inline with force loading
55-
+ return addTicket(pos.toLong(), new Ticket(TicketType.PLUGIN_TICKET, ChunkMap.FORCED_TICKET_LEVEL)); // TODO
55+
+ return addTicket(pos.toLong(), new Ticket(TicketType.PLUGIN_TICKET, ChunkMap.FORCED_TICKET_LEVEL).withPluginRef(value));
5656
+ }
5757
+
5858
+ public boolean removePluginRegionTicket(final ChunkPos pos, final org.bukkit.plugin.Plugin value) {
5959
+ // Keep inline with force loading
60-
+ return removeTicket(pos.toLong(), new Ticket(TicketType.PLUGIN_TICKET, ChunkMap.FORCED_TICKET_LEVEL)); // TODO
60+
+ return removeTicket(pos.toLong(), new Ticket(TicketType.PLUGIN_TICKET, ChunkMap.FORCED_TICKET_LEVEL).withPluginRef(value));
6161
+ }
6262
+
63-
+ public <T> void removeAllTicketsFor(TicketType ticketType, int ticketLevel, T ticketIdentifier) {
64-
+ removeTicketIf(ticket -> ticket.getType() == ticketType && ticket.getTicketLevel() == ticketLevel, null); // TODO
63+
+ public void removeAllPluignRegionTickets(TicketType ticketType, int ticketLevel, org.bukkit.plugin.Plugin ticketIdentifier) {
64+
+ removeTicketIf(ticket -> ticket.getType() == ticketType && ticket.getTicketLevel() == ticketLevel && ticket.key == ticketIdentifier, null);
6565
+ }
6666
+
6767
+ private boolean isForced(TicketType type) {

paper-server/src/main/java/io/papermc/paper/PaperServerInternalAPIBridge.java

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.papermc.paper;
22

3+
import org.bukkit.block.Biome;
4+
import org.bukkit.craftbukkit.block.CraftBiome;
35
import org.bukkit.craftbukkit.damage.CraftDamageEffect;
46
import org.bukkit.damage.DamageEffect;
57
import org.jspecify.annotations.NullMarked;
@@ -12,4 +14,12 @@ public class PaperServerInternalAPIBridge implements InternalAPIBridge {
1214
public DamageEffect getDamageEffect(final String key) {
1315
return CraftDamageEffect.getById(key);
1416
}
17+
18+
@Override
19+
public Biome constructLegacyCustomBiome() {
20+
class Holder {
21+
static final Biome LEGACY_CUSTOM = new CraftBiome.LegacyCustomBiomeImpl();
22+
}
23+
return Holder.LEGACY_CUSTOM;
24+
}
1525
}

paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ public void removePluginChunkTickets(Plugin plugin) {
583583
Preconditions.checkNotNull(plugin, "null plugin");
584584

585585
DistanceManager chunkDistanceManager = this.world.getChunkSource().chunkMap.distanceManager;
586-
chunkDistanceManager.ticketStorage.removeAllTicketsFor(TicketType.PLUGIN_TICKET, ChunkMap.FORCED_TICKET_LEVEL, plugin);
586+
chunkDistanceManager.ticketStorage.removeAllPluignRegionTickets(TicketType.PLUGIN_TICKET, ChunkMap.FORCED_TICKET_LEVEL, plugin);
587587
}
588588

589589
@Override

paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java

-10
Original file line numberDiff line numberDiff line change
@@ -479,16 +479,6 @@ public <B extends Keyed> B get(RegistryKey<B> registry, NamespacedKey namespaced
479479
return CraftRegistry.get(registry, namespacedKey, ApiVersion.CURRENT);
480480
}
481481

482-
private Biome customBiome;
483-
@Override
484-
public Biome getCustomBiome() {
485-
if (this.customBiome == null) {
486-
this.customBiome = new CraftBiome.LegacyCustomBiomeImpl();
487-
}
488-
489-
return this.customBiome;
490-
}
491-
492482
@Override
493483
public com.destroystokyo.paper.util.VersionFetcher getVersionFetcher() {
494484
return new com.destroystokyo.paper.PaperVersionFetcher();

0 commit comments

Comments
 (0)