|
| 1 | +package org.bukkit.block; |
| 2 | + |
| 3 | +import org.bukkit.Keyed; |
| 4 | +import org.bukkit.NamespacedKey; |
| 5 | + |
| 6 | +import java.util.HashMap; |
| 7 | +import java.util.Locale; |
| 8 | +import java.util.Map; |
| 9 | + |
| 10 | +/** |
| 11 | + * Test shim for org.bukkit.block.Biome. |
| 12 | + * Replaces the registry-backed Paper 26.1 interface to avoid requiring a running |
| 13 | + * server (RegistryAccess) in unit tests. Must be an interface (not an enum) so that |
| 14 | + * bytecode compiled against the real Paper Biome interface resolves correctly. |
| 15 | + */ |
| 16 | +public interface Biome extends Keyed { |
| 17 | + |
| 18 | + Biome BADLANDS = BiomeShim.of("BADLANDS"); |
| 19 | + Biome BAMBOO_JUNGLE = BiomeShim.of("BAMBOO_JUNGLE"); |
| 20 | + Biome BASALT_DELTAS = BiomeShim.of("BASALT_DELTAS"); |
| 21 | + Biome BEACH = BiomeShim.of("BEACH"); |
| 22 | + Biome BIRCH_FOREST = BiomeShim.of("BIRCH_FOREST"); |
| 23 | + Biome CHERRY_GROVE = BiomeShim.of("CHERRY_GROVE"); |
| 24 | + Biome COLD_OCEAN = BiomeShim.of("COLD_OCEAN"); |
| 25 | + Biome CRIMSON_FOREST = BiomeShim.of("CRIMSON_FOREST"); |
| 26 | + Biome DARK_FOREST = BiomeShim.of("DARK_FOREST"); |
| 27 | + Biome DEEP_COLD_OCEAN = BiomeShim.of("DEEP_COLD_OCEAN"); |
| 28 | + Biome DEEP_DARK = BiomeShim.of("DEEP_DARK"); |
| 29 | + Biome DEEP_FROZEN_OCEAN = BiomeShim.of("DEEP_FROZEN_OCEAN"); |
| 30 | + Biome DEEP_LUKEWARM_OCEAN = BiomeShim.of("DEEP_LUKEWARM_OCEAN"); |
| 31 | + Biome DEEP_OCEAN = BiomeShim.of("DEEP_OCEAN"); |
| 32 | + Biome DESERT = BiomeShim.of("DESERT"); |
| 33 | + Biome DRIPSTONE_CAVES = BiomeShim.of("DRIPSTONE_CAVES"); |
| 34 | + Biome END_BARRENS = BiomeShim.of("END_BARRENS"); |
| 35 | + Biome END_HIGHLANDS = BiomeShim.of("END_HIGHLANDS"); |
| 36 | + Biome END_MIDLANDS = BiomeShim.of("END_MIDLANDS"); |
| 37 | + Biome ERODED_BADLANDS = BiomeShim.of("ERODED_BADLANDS"); |
| 38 | + Biome FLOWER_FOREST = BiomeShim.of("FLOWER_FOREST"); |
| 39 | + Biome FOREST = BiomeShim.of("FOREST"); |
| 40 | + Biome FROZEN_OCEAN = BiomeShim.of("FROZEN_OCEAN"); |
| 41 | + Biome FROZEN_PEAKS = BiomeShim.of("FROZEN_PEAKS"); |
| 42 | + Biome FROZEN_RIVER = BiomeShim.of("FROZEN_RIVER"); |
| 43 | + Biome GROVE = BiomeShim.of("GROVE"); |
| 44 | + Biome ICE_SPIKES = BiomeShim.of("ICE_SPIKES"); |
| 45 | + Biome JAGGED_PEAKS = BiomeShim.of("JAGGED_PEAKS"); |
| 46 | + Biome JUNGLE = BiomeShim.of("JUNGLE"); |
| 47 | + Biome LUKEWARM_OCEAN = BiomeShim.of("LUKEWARM_OCEAN"); |
| 48 | + Biome LUSH_CAVES = BiomeShim.of("LUSH_CAVES"); |
| 49 | + Biome MANGROVE_SWAMP = BiomeShim.of("MANGROVE_SWAMP"); |
| 50 | + Biome MEADOW = BiomeShim.of("MEADOW"); |
| 51 | + Biome MUSHROOM_FIELDS = BiomeShim.of("MUSHROOM_FIELDS"); |
| 52 | + Biome NETHER_WASTES = BiomeShim.of("NETHER_WASTES"); |
| 53 | + Biome OCEAN = BiomeShim.of("OCEAN"); |
| 54 | + Biome OLD_GROWTH_BIRCH_FOREST = BiomeShim.of("OLD_GROWTH_BIRCH_FOREST"); |
| 55 | + Biome OLD_GROWTH_PINE_TAIGA = BiomeShim.of("OLD_GROWTH_PINE_TAIGA"); |
| 56 | + Biome OLD_GROWTH_SPRUCE_TAIGA = BiomeShim.of("OLD_GROWTH_SPRUCE_TAIGA"); |
| 57 | + Biome PALE_GARDEN = BiomeShim.of("PALE_GARDEN"); |
| 58 | + Biome PLAINS = BiomeShim.of("PLAINS"); |
| 59 | + Biome RIVER = BiomeShim.of("RIVER"); |
| 60 | + Biome SAVANNA = BiomeShim.of("SAVANNA"); |
| 61 | + Biome SAVANNA_PLATEAU = BiomeShim.of("SAVANNA_PLATEAU"); |
| 62 | + Biome SMALL_END_ISLANDS = BiomeShim.of("SMALL_END_ISLANDS"); |
| 63 | + Biome SNOWY_BEACH = BiomeShim.of("SNOWY_BEACH"); |
| 64 | + Biome SNOWY_PLAINS = BiomeShim.of("SNOWY_PLAINS"); |
| 65 | + Biome SNOWY_SLOPES = BiomeShim.of("SNOWY_SLOPES"); |
| 66 | + Biome SNOWY_TAIGA = BiomeShim.of("SNOWY_TAIGA"); |
| 67 | + Biome SOUL_SAND_VALLEY = BiomeShim.of("SOUL_SAND_VALLEY"); |
| 68 | + Biome SPARSE_JUNGLE = BiomeShim.of("SPARSE_JUNGLE"); |
| 69 | + Biome STONY_PEAKS = BiomeShim.of("STONY_PEAKS"); |
| 70 | + Biome STONY_SHORE = BiomeShim.of("STONY_SHORE"); |
| 71 | + Biome SUNFLOWER_PLAINS = BiomeShim.of("SUNFLOWER_PLAINS"); |
| 72 | + Biome SWAMP = BiomeShim.of("SWAMP"); |
| 73 | + Biome TAIGA = BiomeShim.of("TAIGA"); |
| 74 | + Biome THE_END = BiomeShim.of("THE_END"); |
| 75 | + Biome THE_VOID = BiomeShim.of("THE_VOID"); |
| 76 | + Biome WARM_OCEAN = BiomeShim.of("WARM_OCEAN"); |
| 77 | + Biome WARPED_FOREST = BiomeShim.of("WARPED_FOREST"); |
| 78 | + Biome WINDSWEPT_FOREST = BiomeShim.of("WINDSWEPT_FOREST"); |
| 79 | + Biome WINDSWEPT_GRAVELLY_HILLS = BiomeShim.of("WINDSWEPT_GRAVELLY_HILLS"); |
| 80 | + Biome WINDSWEPT_HILLS = BiomeShim.of("WINDSWEPT_HILLS"); |
| 81 | + Biome WINDSWEPT_SAVANNA = BiomeShim.of("WINDSWEPT_SAVANNA"); |
| 82 | + Biome WOODED_BADLANDS = BiomeShim.of("WOODED_BADLANDS"); |
| 83 | + Biome CUSTOM = BiomeShim.of("CUSTOM"); |
| 84 | + |
| 85 | + /** Returns the constant name (mirrors Enum.name() / OldEnum behaviour). */ |
| 86 | + String name(); |
| 87 | + |
| 88 | + static Biome valueOf(String name) { |
| 89 | + if (name == null) { |
| 90 | + return null; |
| 91 | + } |
| 92 | + Biome biome = BiomeShim.REGISTRY.get(name.toUpperCase(Locale.ROOT)); |
| 93 | + if (biome == null) { |
| 94 | + throw new IllegalArgumentException("No Biome constant: " + name); |
| 95 | + } |
| 96 | + return biome; |
| 97 | + } |
| 98 | + |
| 99 | + static Biome[] values() { |
| 100 | + return BiomeShim.REGISTRY.values().toArray(new Biome[0]); |
| 101 | + } |
| 102 | + |
| 103 | + /** Concrete backing class for test Biome constants. */ |
| 104 | + final class BiomeShim implements Biome { |
| 105 | + static final Map<String, Biome> REGISTRY = new HashMap<>(); |
| 106 | + |
| 107 | + private final String name; |
| 108 | + |
| 109 | + private BiomeShim(String name) { |
| 110 | + this.name = name; |
| 111 | + } |
| 112 | + |
| 113 | + static BiomeShim of(String n) { |
| 114 | + BiomeShim b = new BiomeShim(n.toUpperCase(Locale.ROOT)); |
| 115 | + REGISTRY.put(b.name, b); |
| 116 | + return b; |
| 117 | + } |
| 118 | + |
| 119 | + @Override |
| 120 | + public String name() { |
| 121 | + return name; |
| 122 | + } |
| 123 | + |
| 124 | + @Override |
| 125 | + public NamespacedKey getKey() { |
| 126 | + return NamespacedKey.minecraft(name.toLowerCase(Locale.ROOT)); |
| 127 | + } |
| 128 | + |
| 129 | + @Override |
| 130 | + public String toString() { |
| 131 | + return name; |
| 132 | + } |
| 133 | + |
| 134 | + @Override |
| 135 | + public boolean equals(Object o) { |
| 136 | + if (this == o) return true; |
| 137 | + if (o instanceof BiomeShim) return name.equals(((BiomeShim) o).name); |
| 138 | + return false; |
| 139 | + } |
| 140 | + |
| 141 | + @Override |
| 142 | + public int hashCode() { |
| 143 | + return name.hashCode(); |
| 144 | + } |
| 145 | + } |
| 146 | +} |
0 commit comments