Skip to content

Commit db35db7

Browse files
committed
Implement legacy custom biome
1 parent e753417 commit db35db7

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBiome.java

+58
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
import io.papermc.paper.util.OldEnumHolderable;
44
import net.minecraft.core.Holder;
55
import net.minecraft.core.registries.Registries;
6+
import org.bukkit.NamespacedKey;
67
import org.bukkit.block.Biome;
78
import org.bukkit.craftbukkit.CraftRegistry;
9+
import org.jetbrains.annotations.ApiStatus;
10+
import org.jetbrains.annotations.NotNull;
811
import org.jspecify.annotations.NullMarked;
912
import org.jspecify.annotations.Nullable;
13+
import java.util.Objects;
1014

1115
@NullMarked
1216
public class CraftBiome extends OldEnumHolderable<Biome, net.minecraft.world.level.biome.Biome> implements Biome {
@@ -39,4 +43,58 @@ public static Biome minecraftHolderToBukkit(Holder<net.minecraft.world.level.bio
3943
public CraftBiome(final Holder<net.minecraft.world.level.biome.Biome> holder) {
4044
super(holder, count++);
4145
}
46+
47+
/**
48+
* Implementation for the deprecated, API only, CUSTOM biome.
49+
* As per {@link #bukkitToMinecraft(Biome)} and {@link #bukkitToMinecraftHolder(Biome)} it cannot be
50+
* converted into an internal biome and only serves backwards compatibility reasons.
51+
*/
52+
@Deprecated(forRemoval = true, since = "1.21.5")
53+
@ApiStatus.ScheduledForRemoval(inVersion = "1.22")
54+
public static class LegacyCustomBiomeImpl implements Biome {
55+
56+
private static final NamespacedKey LEGACY_CUSTOM_KEY = new NamespacedKey("minecraft", "custom");
57+
private final int ordinal;
58+
59+
public LegacyCustomBiomeImpl() {
60+
this.ordinal = count++;
61+
}
62+
63+
@Override
64+
public @NotNull NamespacedKey getKey() {
65+
return LEGACY_CUSTOM_KEY;
66+
}
67+
68+
@Override
69+
public int compareTo(@NotNull final Biome other) {
70+
return this.ordinal - other.ordinal();
71+
}
72+
73+
@Override
74+
public @NotNull String name() {
75+
return "CUSTOM";
76+
}
77+
78+
@Override
79+
public int ordinal() {
80+
return this.ordinal;
81+
}
82+
83+
@Override
84+
public boolean equals(final Object object) {
85+
if (object == null || getClass() != object.getClass()) return false;
86+
final LegacyCustomBiomeImpl that = (LegacyCustomBiomeImpl) object;
87+
return ordinal == that.ordinal;
88+
}
89+
90+
@Override
91+
public int hashCode() {
92+
return Objects.hashCode(ordinal);
93+
}
94+
95+
@Override
96+
public String toString() {
97+
return "CUSTOM";
98+
}
99+
}
42100
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ public <B extends Keyed> B get(RegistryKey<B> registry, NamespacedKey namespaced
483483
@Override
484484
public Biome getCustomBiome() {
485485
if (this.customBiome == null) {
486-
this.customBiome = new CraftBiome(NamespacedKey.minecraft("custom"), null);
486+
this.customBiome = new CraftBiome.LegacyCustomBiomeImpl();
487487
}
488488

489489
return this.customBiome;

0 commit comments

Comments
 (0)