From 39b60aa7428eb26287442ca297b0eb1e77148b0d Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Mon, 9 Dec 2019 22:36:52 +0100 Subject: [PATCH] Fix legacy id conversion --- .../world/registry/LegacyMapper.java | 71 ++++++++++++------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java index b49b59a5e..f4af74483 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java @@ -33,6 +33,7 @@ import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.math.Vector3; +import com.sk89q.worldedit.registry.state.PropertyKey; import com.sk89q.worldedit.util.gson.VectorAdapter; import com.sk89q.worldedit.util.io.ResourceLoader; import com.sk89q.worldedit.world.DataFixer; @@ -81,10 +82,6 @@ public final class LegacyMapper { private LegacyMapper() { } - public final static LegacyMapper getInstance() { - return INSTANCE; - } - /** * Attempt to load the data from file. * @@ -110,33 +107,53 @@ public final class LegacyMapper { for (Map.Entry blockEntry : dataFile.blocks.entrySet()) { String id = blockEntry.getKey(); + Integer combinedId = getCombinedId(blockEntry.getKey()); final String value = blockEntry.getValue(); blockEntries.put(id, value); BlockState blockState = null; - BlockFactory blockFactory = WorldEdit.getInstance().getBlockFactory(); - - if (fixer != null) { - try { - String newEntry = fixer.fixUp(DataFixer.FixTypes.BLOCK_STATE, value, 1631); - blockState = blockFactory.parseFromInput(newEntry, parserContext).toImmutableState(); - } catch (InputParseException e) { + try { + blockState = BlockState.get(null, blockEntry.getValue()); + BlockType type = blockState.getBlockType(); + if (type.hasProperty(PropertyKey.WATERLOGGED)) { + blockState = blockState.with(PropertyKey.WATERLOGGED, false); + } + } catch (InputParseException e) { + BlockFactory blockFactory = WorldEdit.getInstance().getBlockFactory(); + if (fixer != null) { + try { + String newEntry = fixer.fixUp(DataFixer.FixTypes.BLOCK_STATE, value, 1631); + blockState = blockFactory.parseFromInput(newEntry, parserContext).toImmutableState(); + } catch (InputParseException f) { + } + } + // if it's still null, the fixer was unavailable or failed + if (blockState == null) { + try { + blockState = blockFactory.parseFromInput(value, parserContext).toImmutableState(); + } catch (InputParseException f) { + } + } + // if it's still null, both fixer and default failed + if (blockState == null) { + log.warn("Unknown block: " + value); + } else { + // it's not null so one of them succeeded, now use it + blockToStringMap.put(blockState, id); + stringToBlockMap.put(id, blockState); } } - // if it's still null, the fixer was unavailable or failed - if (blockState == null) { - try { - blockState = blockFactory.parseFromInput(value, parserContext).toImmutableState(); - } catch (InputParseException e) { + blockArr[combinedId] = blockState.getInternalId(); + blockStateToLegacyId4Data.put(blockState.getInternalId(), (Integer) combinedId); + blockStateToLegacyId4Data.putIfAbsent(blockState.getInternalBlockTypeId(), combinedId); + } + for (int id = 0; id < 256; id++) { + int combinedId = id << 4; + int base = blockArr[combinedId]; + if (base != 0) { + for (int data = 0; data < 16; data++, combinedId++) { + if (blockArr[combinedId] == 0) blockArr[combinedId] = base; } } - // if it's still null, both fixer and default failed - if (blockState == null) { - log.warn("Unknown block: " + value); - } else { - // it's not null so one of them succeeded, now use it - blockToStringMap.put(blockState, id); - stringToBlockMap.put(id, blockState); - } } for (Map.Entry itemEntry : dataFile.items.entrySet()) { @@ -267,7 +284,11 @@ public final class LegacyMapper { @Deprecated public int[] getLegacyFromBlock(BlockState blockState) { Integer combinedId = getLegacyCombined(blockState); - return combinedId == null ? null : new int[]{combinedId >> 4, combinedId & 0xF}; + return combinedId == null ? null : new int[] { combinedId >> 4, combinedId & 0xF }; + } + + public final static LegacyMapper getInstance() { + return INSTANCE; } @SuppressWarnings({"MismatchedQueryAndUpdateOfCollection"})