Permalink
Browse files

BREAKING CHANGE: Update biome types (affects get|set_biome())

  • Loading branch information...
PseudoKnight committed Aug 3, 2018
1 parent b8dd666 commit 26b2c61becd7657d4f770ed1b516d2871401983f
@@ -7,16 +7,15 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@MDynamicEnum("BiomeType")
public abstract class MCBiomeType<Concrete> extends DynamicEnum<MCBiomeType.MCVanillaBiomeType, Concrete> {
// To be filled by the implementer
protected static Map<String, MCBiomeType> mappings;
protected static Map<MCVanillaBiomeType, MCBiomeType> vanilla;
protected static final Map<String, MCBiomeType> MAP = new HashMap<>();
@SuppressWarnings("checkstyle:staticvariablename") // Fixing this violation might break dependents.
public static MCBiomeType NULL = null;
@@ -26,20 +25,13 @@ public MCBiomeType(MCVanillaBiomeType mcVanillaBiomeType, Concrete concrete) {
}
public static MCBiomeType valueOf(String test) throws IllegalArgumentException {
if(mappings == null) {
return null;
}
MCBiomeType ret = mappings.get(test);
MCBiomeType ret = MAP.get(test);
if(ret == null) {
throw new IllegalArgumentException("Unknown biome type: " + test);
}
return ret;
}
public static MCBiomeType valueOfVanillaType(MCVanillaBiomeType type) {
return vanilla.get(type);
}
/**
* @return Names of available biome types
*/
@@ -51,7 +43,7 @@ public static MCBiomeType valueOfVanillaType(MCVanillaBiomeType type) {
}
return dummy;
}
return mappings.keySet();
return MAP.keySet();
}
/**
@@ -75,73 +67,84 @@ public String concreteName() {
}
return dummy;
}
return mappings.values();
return MAP.values();
}
@MEnum("VanillaBiomeType")
public enum MCVanillaBiomeType {
OCEAN,
PLAINS,
DESERT,
EXTREME_HILLS,
MOUNTAINS,
FOREST,
TAIGA,
SWAMPLAND,
SWAMP,
RIVER,
HELL,
SKY,
NETHER,
THE_END,
FROZEN_OCEAN,
FROZEN_RIVER,
ICE_PLAINS,
ICE_MOUNTAINS,
MUSHROOM_ISLAND,
MUSHROOM_SHORE,
BEACH(MCVersion.MC1_1),
DESERT_HILLS(MCVersion.MC1_1),
FOREST_HILLS(MCVersion.MC1_1),
TAIGA_HILLS(MCVersion.MC1_1),
SMALL_MOUNTAINS(MCVersion.MC1_1),
JUNGLE(MCVersion.MC1_2),
JUNGLE_HILLS(MCVersion.MC1_2),
JUNGLE_EDGE(MCVersion.MC1_7_2),
DEEP_OCEAN(MCVersion.MC1_7_2),
STONE_BEACH(MCVersion.MC1_7_2),
COLD_BEACH(MCVersion.MC1_7_2),
BIRCH_FOREST(MCVersion.MC1_7_2),
BIRCH_FOREST_HILLS(MCVersion.MC1_7_2),
ROOFED_FOREST(MCVersion.MC1_7_2),
COLD_TAIGA(MCVersion.MC1_7_2),
COLD_TAIGA_HILLS(MCVersion.MC1_7_2),
MEGA_TAIGA(MCVersion.MC1_7_2),
MEGA_TAIGA_HILLS(MCVersion.MC1_7_2),
EXTREME_HILLS_PLUS(MCVersion.MC1_7_2),
SAVANNA(MCVersion.MC1_7_2),
SAVANNA_PLATEAU(MCVersion.MC1_7_2),
MESA(MCVersion.MC1_7_2),
MESA_PLATEAU_FOREST(MCVersion.MC1_7_2),
MESA_PLATEAU(MCVersion.MC1_7_2),
SUNFLOWER_PLAINS(MCVersion.MC1_7_2),
DESERT_MOUNTAINS(MCVersion.MC1_7_2),
FLOWER_FOREST(MCVersion.MC1_7_2),
TAIGA_MOUNTAINS(MCVersion.MC1_7_2),
ICE_PLAINS_SPIKES(MCVersion.MC1_7_2),
JUNGLE_MOUNTAINS(MCVersion.MC1_7_2),
JUNGLE_EDGE_MOUNTAINS(MCVersion.MC1_7_2),
COLD_TAIGA_MOUNTAINS(MCVersion.MC1_7_2),
SAVANNA_MOUNTAINS(MCVersion.MC1_7_2),
SAVANNA_PLATEAU_MOUNTAINS(MCVersion.MC1_7_2),
MESA_BRYCE(MCVersion.MC1_7_2),
MESA_PLATEAU_FOREST_MOUNTAINS(MCVersion.MC1_7_2),
MESA_PLATEAU_MOUNTAINS(MCVersion.MC1_7_2),
BIRCH_FOREST_MOUNTAINS(MCVersion.MC1_7_2),
BIRCH_FOREST_HILLS_MOUNTAINS(MCVersion.MC1_7_2),
ROOFED_FOREST_MOUNTAINS(MCVersion.MC1_7_2),
MEGA_SPRUCE_TAIGA(MCVersion.MC1_7_2),
EXTREME_HILLS_MOUNTAINS(MCVersion.MC1_7_2),
EXTREME_HILLS_PLUS_MOUNTAINS(MCVersion.MC1_7_2),
SWAMPLAND_MOUNTAINS(MCVersion.MC1_7_2),
MEGA_SPRUCE_TAIGA_HILLS(MCVersion.MC1_7_2),
VOID(MCVersion.MC1_9),
SNOWY_TUNDRA,
SNOWY_MOUNTAINS,
MUSHROOM_FIELDS,
MUSHROOM_FIELD_SHORE,
BEACH,
DESERT_HILLS,
WOODED_HILLS,
TAIGA_HILLS,
MOUNTAIN_EDGE,
JUNGLE,
JUNGLE_HILLS,
JUNGLE_EDGE,
DEEP_OCEAN,
STONE_SHORE,
SNOWY_BEACH,
BIRCH_FOREST,
BIRCH_FOREST_HILLS,
DARK_FOREST,
SNOWY_TAIGA,
SNOWY_TAIGA_HILLS,
GIANT_TREE_TAIGA,
GIANT_TREE_TAIGA_HILLS,
WOODED_MOUNTAINS,
SAVANNA,
SAVANNA_PLATEAU,
BADLANDS,
WOODED_BADLANDS_PLATEAU,
BADLANDS_PLATEAU,
SUNFLOWER_PLAINS,
DESERT_LAKES,
FLOWER_FOREST,
TAIGA_MOUNTAINS,
ICE_SPIKES,
MODIFIED_JUNGLE,
MODIFIED_JUNGLE_EDGE,
SNOWY_TAIGA_MOUNTAINS,
SHATTERED_SAVANNA,
SHATTERED_SAVANNA_PLATEAU,
ERODED_BADLANDS,
MODIFIED_WOODED_BADLANDS_PLATEAU,
MODIFIED_BADLANDS_PLATEAU,
TALL_BIRCH_FOREST,
TALL_BIRCH_HILLS,
DARK_FOREST_HILLS,
GIANT_SPRUCE_TAIGA,
GRAVELLY_MOUNTAINS,
MODIFIED_GRAVELLY_MOUNTAINS,
SWAMP_HILLS,
GIANT_SPRUCE_TAIGA_HILLS,
THE_VOID,
SMALL_END_ISLANDS,
END_MIDLANDS,
END_HIGHLANDS,
END_BARRENS,
WARM_OCEAN,
LUKEWARM_OCEAN,
COLD_OCEAN,
DEEP_WARM_OCEAN,
DEEP_LUKEWARM_OCEAN,
DEEP_COLD_OCEAN,
DEEP_FROZEN_OCEAN,
UNKNOWN(MCVersion.NEVER);
private final MCVersion since;
@@ -1,17 +1,17 @@
package com.laytonsmith.abstraction.enums.bukkit;
import com.laytonsmith.abstraction.enums.MCBiomeType;
import com.laytonsmith.abstraction.enums.MCVersion;
import com.laytonsmith.core.CHLog;
import com.laytonsmith.core.Static;
import com.laytonsmith.core.constructs.Target;
import org.bukkit.block.Biome;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class BukkitMCBiomeType extends MCBiomeType<Biome> {
private static final Map<Biome, MCBiomeType> BUKKIT_MAP = new HashMap<>();
public BukkitMCBiomeType(MCVanillaBiomeType vanillaBiomeType, Biome biome) {
super(vanillaBiomeType, biome);
}
@@ -30,123 +30,41 @@ public String concreteName() {
return b.name();
}
public static BukkitMCBiomeType valueOfConcrete(Biome test) {
for(MCBiomeType t : mappings.values()) {
if(((BukkitMCBiomeType) t).getConcrete().equals(test)) {
return (BukkitMCBiomeType) t;
}
}
return (BukkitMCBiomeType) NULL;
}
public static BukkitMCBiomeType valueOfConcrete(String test) {
try {
return valueOfConcrete(Biome.valueOf(test));
} catch (IllegalArgumentException iae) {
return (BukkitMCBiomeType) NULL;
public static MCBiomeType valueOfConcrete(Biome test) {
MCBiomeType type = BUKKIT_MAP.get(test);
if(type == null) {
return NULL;
}
return type;
}
// This way we don't take up extra memory on non-bukkit implementations
public static void build() {
vanilla = new HashMap<>();
mappings = new HashMap<>();
NULL = new BukkitMCBiomeType(MCVanillaBiomeType.UNKNOWN, null);
ArrayList<Biome> counted = new ArrayList<>();
for(MCVanillaBiomeType v : MCVanillaBiomeType.values()) {
if(v.existsInCurrent()) {
Biome type;
try {
type = getBukkitType(v);
} catch (IllegalArgumentException | NoSuchFieldError ex) {
CHLog.GetLogger().w(CHLog.Tags.RUNTIME, "Could not find a Bukkit BiomeType for " + v.name(), Target.UNKNOWN);
CHLog.GetLogger().w(CHLog.Tags.RUNTIME, "Could not find a Bukkit BiomeType for " + v.name(),
Target.UNKNOWN);
continue;
}
BukkitMCBiomeType wrapper = new BukkitMCBiomeType(v, type);
vanilla.put(v, wrapper);
mappings.put(v.name(), wrapper);
counted.add(type);
MAP.put(v.name(), wrapper);
BUKKIT_MAP.put(type, wrapper);
}
}
for(Biome b : Biome.values()) {
if(!counted.contains(b)) {
mappings.put(b.name(), new BukkitMCBiomeType(MCVanillaBiomeType.UNKNOWN, b));
if(!BUKKIT_MAP.containsKey(b)) {
MAP.put(b.name(), new BukkitMCBiomeType(MCVanillaBiomeType.UNKNOWN, b));
BUKKIT_MAP.put(b, new BukkitMCBiomeType(MCVanillaBiomeType.UNKNOWN, b));
}
}
}
private static Biome getBukkitType(MCVanillaBiomeType v) {
// A switch statement for values that don't translate directly to a Bukkit value
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_9)) {
switch(v) {
case ICE_PLAINS:
return Biome.ICE_FLATS;
case MUSHROOM_SHORE:
return Biome.MUSHROOM_ISLAND_SHORE;
case BEACH:
return Biome.BEACHES;
case SMALL_MOUNTAINS:
return Biome.SMALLER_EXTREME_HILLS;
case COLD_TAIGA:
return Biome.TAIGA_COLD;
case COLD_TAIGA_HILLS:
return Biome.TAIGA_COLD_HILLS;
case MEGA_TAIGA:
return Biome.REDWOOD_TAIGA;
case MEGA_TAIGA_HILLS:
return Biome.REDWOOD_TAIGA_HILLS;
case EXTREME_HILLS_PLUS:
return Biome.EXTREME_HILLS_WITH_TREES;
case SAVANNA_PLATEAU:
return Biome.SAVANNA_ROCK;
case JUNGLE_MOUNTAINS:
return Biome.MUTATED_JUNGLE;
case JUNGLE_EDGE_MOUNTAINS:
return Biome.MUTATED_JUNGLE_EDGE;
case MEGA_SPRUCE_TAIGA:
return Biome.MUTATED_REDWOOD_TAIGA;
case MEGA_SPRUCE_TAIGA_HILLS:
return Biome.MUTATED_REDWOOD_TAIGA_HILLS;
case BIRCH_FOREST_MOUNTAINS:
return Biome.MUTATED_BIRCH_FOREST;
case BIRCH_FOREST_HILLS_MOUNTAINS:
return Biome.MUTATED_BIRCH_FOREST_HILLS;
case SAVANNA_MOUNTAINS:
return Biome.MUTATED_SAVANNA;
case SAVANNA_PLATEAU_MOUNTAINS:
return Biome.MUTATED_SAVANNA_ROCK;
case MESA_PLATEAU_FOREST:
return Biome.MESA_ROCK;
case MESA_PLATEAU:
return Biome.MESA_CLEAR_ROCK;
case SUNFLOWER_PLAINS:
return Biome.MUTATED_PLAINS;
case DESERT_MOUNTAINS:
return Biome.MUTATED_DESERT;
case SWAMPLAND_MOUNTAINS:
return Biome.MUTATED_SWAMPLAND;
case ROOFED_FOREST_MOUNTAINS:
return Biome.MUTATED_ROOFED_FOREST;
case TAIGA_MOUNTAINS:
return Biome.MUTATED_TAIGA;
case COLD_TAIGA_MOUNTAINS:
return Biome.MUTATED_TAIGA_COLD;
case FLOWER_FOREST:
return Biome.MUTATED_FOREST;
case ICE_PLAINS_SPIKES:
return Biome.MUTATED_ICE_FLATS;
case EXTREME_HILLS_MOUNTAINS:
return Biome.MUTATED_EXTREME_HILLS;
case EXTREME_HILLS_PLUS_MOUNTAINS:
return Biome.MUTATED_EXTREME_HILLS_WITH_TREES;
case MESA_BRYCE:
return Biome.MUTATED_MESA;
case MESA_PLATEAU_MOUNTAINS:
return Biome.MUTATED_MESA_CLEAR_ROCK;
case MESA_PLATEAU_FOREST_MOUNTAINS:
return Biome.MUTATED_MESA_ROCK;
}
}
return Biome.valueOf(v.name());
}
}

0 comments on commit 26b2c61

Please sign in to comment.