Merge pull request 'main' (#2) from Mirrors/FastAsyncWorldEdit:main into upstream

Reviewed-on: https://steamwar.de/devlabs/SteamWar/FastAsyncWorldEdit/pulls/2
This commit is contained in:
Lixfel
2022-09-06 21:32:29 +02:00
14 changed files with 67 additions and 54 deletions

View File

@@ -455,7 +455,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
state = item.getType().getBlockType().getDefaultState();
nbt = item.getNbtData();
} else {
BlockType type = BlockTypes.parse(typeString.toLowerCase(Locale.ROOT));
BlockType type = BlockTypes.parse(typeString.toLowerCase(Locale.ROOT), context);
if (type != null) {
state = type.getDefaultState();

View File

@@ -484,7 +484,12 @@ public class MCEditSchematicReader extends NBTSchematicReader {
}
private BlockState getBlockState(int id, int data) {
return LegacyMapper.getInstance().getBlockFromLegacy(id, data);
BlockState foundBlock = LegacyMapper.getInstance().getBlockFromLegacy(id, data);
if (foundBlock == null && data != 0) {
// Some schematics contain invalid data values, so try without the data value
return LegacyMapper.getInstance().getBlockFromLegacy(id, 0);
}
return foundBlock;
}
@Override

View File

@@ -23,6 +23,7 @@ import com.fastasyncworldedit.core.command.SuggestInputParseException;
import com.fastasyncworldedit.core.util.JoinedCharSequence;
import com.fastasyncworldedit.core.util.StringMan;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import javax.annotation.Nullable;
@@ -1948,6 +1949,9 @@ public final class BlockTypes {
*/
public static BlockType parse(final String type) throws InputParseException {
return parse(type, new ParserContext());
}
public static BlockType parse(final String type, final ParserContext context) throws InputParseException {
final String inputLower = type.toLowerCase(Locale.ROOT);
String input = inputLower;
@@ -1958,13 +1962,14 @@ public final class BlockTypes {
if (result != null) {
return result;
}
try {
BlockStateHolder<BlockState> block = LegacyMapper.getInstance().getBlockFromLegacy(input);
if (block != null) {
return block.getBlockType();
if (context.isTryingLegacy()) {
try {
BlockStateHolder<BlockState> block = LegacyMapper.getInstance().getBlockFromLegacy(input);
if (block != null) {
return block.getBlockType();
}
} catch (NumberFormatException | IndexOutOfBoundsException ignored) {
}
} catch (NumberFormatException | IndexOutOfBoundsException ignored) {
}
throw new SuggestInputParseException("Does not match a valid block type: " + inputLower, inputLower, () -> Stream.of(