diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/BlockIdConfig.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/BlockIdConfig.java index 5291205e..f1889195 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/BlockIdConfig.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/BlockIdConfig.java @@ -38,7 +38,8 @@ public class BlockIdConfig implements BlockIdMapper { private ConfigurationLoader autopoulationConfigLoader; - private Map mappings; + private Map numeralMappings; + private Map idMappings; public BlockIdConfig(ConfigurationNode node) { this(node, null); @@ -47,29 +48,39 @@ public BlockIdConfig(ConfigurationNode node) { public BlockIdConfig(ConfigurationNode node, ConfigurationLoader autopoulationConfigLoader) { this.autopoulationConfigLoader = autopoulationConfigLoader; - mappings = new HashMap<>(); + numeralMappings = new HashMap<>(); + idMappings = new HashMap<>(); for (Entry e : node.getChildrenMap().entrySet()){ String key = e.getKey().toString(); String value = e.getValue().getString(); try { - int splitIndex = key.indexOf(':'); - int blockId, blockMeta; - if (splitIndex > 0 && splitIndex < key.length() - 1) { - blockId = Integer.parseInt(key.substring(0, splitIndex)); - blockMeta = Integer.parseInt(key.substring(splitIndex + 1)); - } else { - blockId = Integer.parseInt(key); - blockMeta = 0; + int splitIndex = key.lastIndexOf(':'); + + if (splitIndex <= 0 || splitIndex >= key.length() - 1) { + Logger.global.logWarning("Loading BlockIdConfig: Failed to parse blockid:meta from key '" + key + "'"); + continue; } - - BlockIDMeta idmeta = new BlockIDMeta(blockId, blockMeta); - BlockState state = BlockState.fromString(value); - if (blockId == 0) state = BlockState.AIR; //use the static field to increase render speed (== comparison) + String blockId = key.substring(0, splitIndex); + int blockNumeralId; + try { + blockNumeralId = Integer.parseInt(blockId); + } catch (NumberFormatException ex) { + blockNumeralId = -1; + } + int blockMeta = Integer.parseInt(key.substring(splitIndex + 1)); + BlockState state = BlockState.fromString(value); - mappings.put(idmeta, state); + if (blockNumeralId >= 0) { + BlockNumeralIDMeta idmeta = new BlockNumeralIDMeta(blockNumeralId, blockMeta); + if (blockNumeralId == 0) state = BlockState.AIR; //use the static field to increase render speed (== comparison) + numeralMappings.put(idmeta, state); + } else { + BlockIDMeta idmeta = new BlockIDMeta(blockId, blockMeta); + idMappings.put(idmeta, state); + } } catch (NumberFormatException ex) { Logger.global.logWarning("Loading BlockIdConfig: Failed to parse blockid:meta from key '" + key + "'"); } catch (IllegalArgumentException ex) { @@ -79,22 +90,22 @@ public BlockIdConfig(ConfigurationNode node, ConfigurationLoader mapping = new BlockStateMapping<>(bsKey, bsValue); diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/ConfigManager.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/ConfigManager.java index 67d1f536..89f00861 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/ConfigManager.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/config/ConfigManager.java @@ -154,7 +154,7 @@ public void loadResourceConfigs(ResourcePack resourcePack) throws IOException { blockIdsConfigNode = joinFromResourcePack(resourcePack, "blockIds.json", blockIdsConfigNode); blockIdConfig = new BlockIdConfig( blockIdsConfigNode, - null //getLoader(makeAutogen(getBlockIdConfigFile())) + getLoader(makeAutogen(getBlockIdConfigFile())) ); //load blockProperties.json from resources, config-folder and resourcepack @@ -170,7 +170,7 @@ public void loadResourceConfigs(ResourcePack resourcePack) throws IOException { blockPropertiesConfig = new BlockPropertiesConfig( blockPropertiesConfigNode, resourcePack, - null //getLoader(makeAutogen(getBlockPropertiesConfigFile())) + getLoader(makeAutogen(getBlockPropertiesConfigFile())) ); //load biomes.json from resources, config-folder and resourcepack @@ -185,7 +185,7 @@ public void loadResourceConfigs(ResourcePack resourcePack) throws IOException { biomeConfigNode = joinFromResourcePack(resourcePack, "biomes.json", biomeConfigNode); biomeConfig = new BiomeConfig( biomeConfigNode, - null //getLoader(makeAutogen(getBiomeConfigFile())) + getLoader(makeAutogen(getBiomeConfigFile())) ); } @@ -255,13 +255,11 @@ private ConfigurationNode loadOrCreate(File configFile, URL defaultConfig, URL d return configNode; } - /* private File makeAutogen(File file) throws IOException { - File autogenFile = file.getCanonicalFile().toPath().getParent().resolve("generated").resolve(file.getName()).toFile(); + File autogenFile = file.getCanonicalFile().toPath().getParent().resolve("missing-configs").resolve(file.getName()).toFile(); autogenFile.getParentFile().mkdirs(); return autogenFile; } - */ private ConfigurationLoader getLoader(String filename, InputStream is){ BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil112.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil112.java index 519d0686..42cd5c38 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil112.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/ChunkAnvil112.java @@ -149,9 +149,12 @@ public BlockState getBlockState(Vector3i pos) { int blockData = getByteHalf(this.data[blockHalfByteIndex], largeHalf); - BlockState blockState = blockIdMapper.get(blockId, blockData); - - return blockState; + String forgeIdMapping = getWorld().getForgeBlockIdMapping(blockId); + if (forgeIdMapping != null) { + return blockIdMapper.get(forgeIdMapping, blockId, blockData); + } else { + return blockIdMapper.get(blockId, blockData); + } } public String getBlockIdMeta(Vector3i pos) { @@ -169,8 +172,9 @@ public String getBlockIdMeta(Vector3i pos) { } int blockData = getByteHalf(this.data[blockHalfByteIndex], largeHalf); + String forgeIdMapping = getWorld().getForgeBlockIdMapping(blockId); - return blockId + ":" + blockData; + return blockId + ":" + blockData + " " + forgeIdMapping; } public LightData getLightData(Vector3i pos) { diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/MCAWorld.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/MCAWorld.java index bff559b3..abea65c7 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/MCAWorld.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/MCAWorld.java @@ -35,7 +35,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.UUID; import java.util.concurrent.ExecutionException; @@ -71,6 +73,7 @@ import de.bluecolored.bluemap.core.world.LightData; import de.bluecolored.bluemap.core.world.World; import net.querz.nbt.CompoundTag; +import net.querz.nbt.ListTag; import net.querz.nbt.NBTUtil; import net.querz.nbt.Tag; import net.querz.nbt.mca.CompressionType; @@ -105,6 +108,8 @@ public class MCAWorld implements World { private BlockPropertiesMapper blockPropertiesMapper; private BiomeMapper biomeMapper; + private Map forgeBlockMappings; + private MCAWorld( Path worldFolder, UUID uuid, @@ -125,8 +130,10 @@ private MCAWorld( this.blockIdMapper = blockIdMapper; this.blockPropertiesMapper = blockPropertiesMapper; this.biomeMapper = biomeMapper; + + this.forgeBlockMappings = new HashMap<>(); } - + public BlockState getBlockState(Vector3i pos) { try { @@ -335,6 +342,10 @@ public void setBiomeMapper(BiomeMapper biomeMapper) { public Path getWorldFolder() { return worldFolder; } + + public String getForgeBlockIdMapping(int id) { + return forgeBlockMappings.get(id); + } private Path getRegionFolder() { return worldFolder.resolve("region"); @@ -360,7 +371,8 @@ public static MCAWorld load(Path worldFolder, UUID uuid, BlockIdMapper blockIdMa CHUNK_CACHE.invalidateAll(); - return new MCAWorld( + + MCAWorld world = new MCAWorld( worldFolder, uuid, name, @@ -371,6 +383,21 @@ public static MCAWorld load(Path worldFolder, UUID uuid, BlockIdMapper blockIdMa blockPropertiesMapper, biomeIdMapper ); + + try { + ListTag> blockIdReg = level.getCompoundTag("FML").getCompoundTag("Registries").getCompoundTag("minecraft:blocks").getListTag("ids"); + for (Tag tag : blockIdReg) { + if (tag instanceof CompoundTag) { + CompoundTag entry = (CompoundTag) tag; + String blockId = entry.getString("K"); + int numeralId = entry.getInt("V"); + + world.forgeBlockMappings.put(numeralId, blockId); + } + } + } catch (NullPointerException ignore) {} + + return world; } catch (ClassCastException | NullPointerException ex) { throw new IOException("Invaid level.dat format!", ex); } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/mapping/BlockIdMapper.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/mapping/BlockIdMapper.java index 26b2d3c7..9af9ca0d 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/mapping/BlockIdMapper.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/mapping/BlockIdMapper.java @@ -26,9 +26,10 @@ import de.bluecolored.bluemap.core.world.BlockState; -@FunctionalInterface public interface BlockIdMapper { BlockState get(int id, int meta); + + BlockState get(String id, int numeralId, int meta); } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BlockStateResource.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BlockStateResource.java index 59a97667..dcc29242 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BlockStateResource.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resourcepack/BlockStateResource.java @@ -86,6 +86,11 @@ public Collection getModels(BlockState blockState models.add(variant.getModel(pos)); } } + + //fallback to first variant + if (models.isEmpty() && !variants.isEmpty()) { + models.add(variants.get(0).getModel(pos)); + } return models; } diff --git a/BlueMapSponge/src/main/java/de/bluecolored/bluemap/sponge/Commands.java b/BlueMapSponge/src/main/java/de/bluecolored/bluemap/sponge/Commands.java index 47a0e649..2641bafd 100644 --- a/BlueMapSponge/src/main/java/de/bluecolored/bluemap/sponge/Commands.java +++ b/BlueMapSponge/src/main/java/de/bluecolored/bluemap/sponge/Commands.java @@ -45,7 +45,6 @@ public Commands(SpongePlugin plugin) { public CommandSpec createRootCommand() { - @SuppressWarnings("unused") CommandSpec debugCommand = CommandSpec.builder() .executor((source, args) -> { if (source instanceof Locatable) { @@ -62,8 +61,8 @@ public CommandSpec createRootCommand() { try { Chunk chunk = ((MCAWorld) world).getChunk(MCAWorld.blockToChunk(loc.getBlockPosition())); if (chunk instanceof ChunkAnvil112) { - blockIdMeta = " (id:" + ((ChunkAnvil112) chunk).getBlockIdMeta(loc.getBlockPosition()) + ")"; - blockBelowIdMeta = " (id:" + ((ChunkAnvil112) chunk).getBlockIdMeta(loc.getBlockPosition().add(0, -1, 0)) + ")"; + blockIdMeta = " (" + ((ChunkAnvil112) chunk).getBlockIdMeta(loc.getBlockPosition()) + ")"; + blockBelowIdMeta = " (" + ((ChunkAnvil112) chunk).getBlockIdMeta(loc.getBlockPosition().add(0, -1, 0)) + ")"; } } catch (IOException ex) { Logger.global.logError("Failed to read chunk for debug!", ex); @@ -71,8 +70,8 @@ public CommandSpec createRootCommand() { } source.sendMessages(Lists.newArrayList( - Text.of("Block: " + block + blockIdMeta), - Text.of("Block below: " + blockBelow + blockBelowIdMeta) + Text.of(TextColors.GOLD, "Block at you: ", TextColors.RESET, block, TextColors.GRAY, blockIdMeta), + Text.of(TextColors.GOLD, "Block below you: ", TextColors.RESET, blockBelow, TextColors.GRAY, blockBelowIdMeta) )); } @@ -88,7 +87,7 @@ public CommandSpec createRootCommand() { .child(createPauseRenderCommand(), "pause") .child(createResumeRenderCommand(), "resume") .child(createRenderCommand(), "render") - //.child(debugCommand, "debug") + .child(debugCommand, "debug") .executor((source, args) -> { source.sendMessages(createStatusMessage()); return CommandResult.success();