From 48356275af1eae87a4c03621fbe505382aca82dd Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 17 Jul 2019 06:36:48 +1000 Subject: [PATCH] fix loading legacy biomes --- .../boydti/fawe/jnbt/SchematicStreamer.java | 7 +- .../registry/NamespacedRegistry.java | 8 +- .../worldedit/world/biome/BiomeType.java | 10 ++- .../worldedit/world/biome/BiomeTypes.java | 87 +++++++++++++++++++ 4 files changed, 108 insertions(+), 4 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java index d20c2405b..180d9a1b7 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java @@ -22,6 +22,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.registry.state.PropertyKey; import com.sk89q.worldedit.util.Direction; +import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.block.BlockID; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -109,7 +110,6 @@ public class SchematicStreamer extends NBTStreamer { if (value != 0) { int first = value & 0x0F; int second = (value & 0xF0) >> 4; - int gIndex = index << 1; try { if (first != 0) adds.write(first); if (second != 0) adds.write(second); @@ -122,7 +122,10 @@ public class SchematicStreamer extends NBTStreamer { ByteReader biomeReader = new ByteReader() { @Override public void run(int index, int value) { - fc.setBiome(index, BiomeTypes.get(value)); + BiomeType biome = BiomeTypes.getLegacy(value); + if (biome != null) { + fc.setBiome(index, biome); + } } }; NBTStreamReader initializer23 = new NBTStreamReader() { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/NamespacedRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/NamespacedRegistry.java index 4d362bde8..17fb15a97 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/NamespacedRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/NamespacedRegistry.java @@ -23,6 +23,8 @@ import static com.google.common.base.Preconditions.checkState; import static java.util.Objects.requireNonNull; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.List; public final class NamespacedRegistry extends Registry { @@ -59,7 +61,11 @@ public final class NamespacedRegistry extends Registry REGISTRY = new NamespacedRegistry<>("biome type"); private final String id; + private int legacyId = -1; + private int internalId; public BiomeType(String id) { this.id = id; } - private int internalId; + public int getLegacyId() { + return legacyId; + } + + public void setLegacyId(int legacyId) { + this.legacyId = legacyId; + } @Override public void setInternalId(int internalId) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeTypes.java index d8eec08be..20280eb99 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeTypes.java @@ -108,6 +108,15 @@ public class BiomeTypes { return BiomeType.REGISTRY.get(id); } + public static BiomeType getLegacy(int legacyId) { + for (BiomeType type : values()) { + if (type.getLegacyId() == legacyId) { + return type; + } + } + return null; + } + public static BiomeType get(int internalId) { return BiomeType.REGISTRY.getByInternalId(internalId); } @@ -115,4 +124,82 @@ public class BiomeTypes { public static Collection values() { return BiomeType.REGISTRY.values(); } + + static { + OCEAN.setLegacyId(0); + PLAINS.setLegacyId(1); + DESERT.setLegacyId(2); + MOUNTAINS.setLegacyId(3); + FOREST.setLegacyId(4); + TAIGA.setLegacyId(5); + SWAMP.setLegacyId(6); + RIVER.setLegacyId(7); + NETHER.setLegacyId(8); + THE_END.setLegacyId(9); + FROZEN_OCEAN.setLegacyId(10); + FROZEN_RIVER.setLegacyId(11); + SNOWY_TUNDRA.setLegacyId(12); + SNOWY_MOUNTAINS.setLegacyId(13); + MUSHROOM_FIELDS.setLegacyId(14); + MUSHROOM_FIELD_SHORE.setLegacyId(15); + BEACH.setLegacyId(16); + DESERT_HILLS.setLegacyId(17); + WOODED_HILLS.setLegacyId(18); + TAIGA_HILLS.setLegacyId(19); + MOUNTAIN_EDGE.setLegacyId(20); + JUNGLE.setLegacyId(21); + JUNGLE_HILLS.setLegacyId(22); + JUNGLE_EDGE.setLegacyId(23); + DEEP_OCEAN.setLegacyId(24); + STONE_SHORE.setLegacyId(25); + SNOWY_BEACH.setLegacyId(26); + BIRCH_FOREST.setLegacyId(27); + BIRCH_FOREST_HILLS.setLegacyId(28); + DARK_FOREST.setLegacyId(29); + SNOWY_TAIGA.setLegacyId(30); + SNOWY_TAIGA_HILLS.setLegacyId(31); + GIANT_TREE_TAIGA.setLegacyId(32); + GIANT_TREE_TAIGA_HILLS.setLegacyId(33); + WOODED_MOUNTAINS.setLegacyId(34); + SAVANNA.setLegacyId(35); + SAVANNA_PLATEAU.setLegacyId(36); + BADLANDS.setLegacyId(37); + WOODED_BADLANDS_PLATEAU.setLegacyId(38); + BADLANDS_PLATEAU.setLegacyId(39); + SMALL_END_ISLANDS.setLegacyId(40); + END_MIDLANDS.setLegacyId(41); + END_HIGHLANDS.setLegacyId(42); + END_BARRENS.setLegacyId(43); + WARM_OCEAN.setLegacyId(44); + LUKEWARM_OCEAN.setLegacyId(45); + COLD_OCEAN.setLegacyId(46); + DEEP_WARM_OCEAN.setLegacyId(47); + DEEP_LUKEWARM_OCEAN.setLegacyId(48); + DEEP_COLD_OCEAN.setLegacyId(49); + DEEP_FROZEN_OCEAN.setLegacyId(50); + THE_VOID.setLegacyId(127); + SUNFLOWER_PLAINS.setLegacyId(129); + DESERT_LAKES.setLegacyId(130); + GRAVELLY_MOUNTAINS.setLegacyId(131); + FLOWER_FOREST.setLegacyId(132); + TAIGA_MOUNTAINS.setLegacyId(133); + SWAMP_HILLS.setLegacyId(134); + ICE_SPIKES.setLegacyId(140); + MODIFIED_JUNGLE.setLegacyId(149); + MODIFIED_JUNGLE_EDGE.setLegacyId(151); + TALL_BIRCH_FOREST.setLegacyId(155); + TALL_BIRCH_HILLS.setLegacyId(156); + DARK_FOREST_HILLS.setLegacyId(157); + SNOWY_TAIGA_MOUNTAINS.setLegacyId(158); + GIANT_SPRUCE_TAIGA.setLegacyId(160); + GIANT_SPRUCE_TAIGA_HILLS.setLegacyId(161); + MODIFIED_GRAVELLY_MOUNTAINS.setLegacyId(162); + SHATTERED_SAVANNA.setLegacyId(163); + SHATTERED_SAVANNA_PLATEAU.setLegacyId(164); + ERODED_BADLANDS.setLegacyId(165); + MODIFIED_WOODED_BADLANDS_PLATEAU.setLegacyId(166); + MODIFIED_BADLANDS_PLATEAU.setLegacyId(167); +// BAMBOO_JUNGLE.setLegacyId(168); +// BAMBOO_JUNGLE_HILLS.setLegacyId(169); + } }