Few tweaks to schematic loading and error fixes.

* Not all EntityTypes in Bukkit have the correct enum name.
* Don't read entire schematic files to list. Go off file extension only.
   (Reading in files is more accurate, but slow.)
* Enforce extensions. (Due to the above, while you can technically make a
   schematic called 'test.txt', it's better that we save it as
   'test.txt.schem'.)
* Fix a few minor warnings.
This commit is contained in:
wizjany
2019-03-08 16:00:42 -05:00
parent eebba8e324
commit 7c89ece96e
5 changed files with 38 additions and 20 deletions

View File

@ -46,9 +46,7 @@ public abstract class NBTSchematicReader implements ClipboardReader {
}
@Nullable
protected static <T extends Tag> T getTag(CompoundTag tag, Class<T> expected, String key) {
Map<String, Tag> items = tag.getValue();
protected static <T extends Tag> T getTag(Map<String, Tag> items, String key, Class<T> expected) {
if (!items.containsKey(key)) {
return null;
}

View File

@ -88,16 +88,16 @@ public class SpongeSchematicReader extends NBTSchematicReader {
int version = requireTag(schematic, "Version", IntTag.class).getValue();
switch (version) {
case 1:
return readVersion1(schematic);
return readVersion1(schematicTag);
default:
throw new IOException("This schematic version is currently not supported");
}
}
private Clipboard readVersion1(Map<String, Tag> schematic) throws IOException {
private Clipboard readVersion1(CompoundTag schematicTag) throws IOException {
BlockVector3 origin;
Region region;
Map<String, Tag> schematic = schematicTag.getValue();
Map<String, Tag> metadata = requireTag(schematic, "Metadata", CompoundTag.class).getValue();
int width = requireTag(schematic, "Width", ShortTag.class).getValue();
@ -143,7 +143,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
try {
state = WorldEdit.getInstance().getBlockFactory().parseFromInput(palettePart, parserContext).toImmutableState();
} catch (InputParseException e) {
throw new IOException("Invalid BlockState in schematic: " + palettePart + ". Are you missing a mod of using a schematic made in a newer version of Minecraft?");
throw new IOException("Invalid BlockState in schematic: " + palettePart + ". Are you missing a mod or using a schematic made in a newer version of Minecraft?");
}
palette.put(id, state);
}