Skip to content
Permalink
Browse files

Fix legacy import (#534)

* always use data fixer

* undo reformat

* fixer -> no fixer -> fail

* extract variable
  • Loading branch information
MicleBrick authored and octylFractal committed Nov 28, 2019
1 parent 77ef0ae commit b425649df0a5e40fd71b925f6541a86ba379e2e9
Showing with 26 additions and 16 deletions.
  1. +26 −16 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java
@@ -26,6 +26,7 @@
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.factory.BlockFactory;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Capability;
@@ -95,26 +96,35 @@ private void loadFromResource() throws IOException {
String id = blockEntry.getKey();
final String value = blockEntry.getValue();
blockEntries.put(id, value);
try {
BlockState state = WorldEdit.getInstance().getBlockFactory().parseFromInput(value, parserContext).toImmutableState();
blockToStringMap.put(state, id);
stringToBlockMap.put(id, state);
} catch (InputParseException e) {
boolean fixed = false;
if (fixer != null) {

BlockState state = null;
BlockFactory blockFactory = WorldEdit.getInstance().getBlockFactory();

// if fixer is available, try using that first, as some old blocks that were renamed share names with new blocks
if (fixer != null) {
try {
String newEntry = fixer.fixUp(DataFixer.FixTypes.BLOCK_STATE, value, 1631);
try {
BlockState state = WorldEdit.getInstance().getBlockFactory().parseFromInput(newEntry, parserContext).toImmutableState();
blockToStringMap.put(state, id);
stringToBlockMap.put(id, state);
fixed = true;
} catch (InputParseException ignored) {
}
state = blockFactory.parseFromInput(newEntry, parserContext).toImmutableState();
} catch (InputParseException e) {
}
if (!fixed) {
log.warn("Unknown block: " + value);
}

// if it's still null, the fixer was unavailable or failed
if (state == null) {
try {
state = blockFactory.parseFromInput(value, parserContext).toImmutableState();
} catch (InputParseException e) {
}
}

// if it's still null, both fixer and default failed
if (state == null) {
log.warn("Unknown block: " + value);
} else {
// it's not null so one of them succeeded, now use it
blockToStringMap.put(state, id);
stringToBlockMap.put(id, state);
}
}

for (Map.Entry<String, String> itemEntry : dataFile.items.entrySet()) {

0 comments on commit b425649

Please sign in to comment.
You can’t perform that action at this time.