forked from SteamWar/SteamWar
Hotfix: 1.20 Schematic Reader
This commit is contained in:
@@ -54,6 +54,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
@SuppressWarnings("removal")
|
||||||
public class WorldEditWrapper14 implements WorldEditWrapper {
|
public class WorldEditWrapper14 implements WorldEditWrapper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -88,7 +89,7 @@ public class WorldEditWrapper14 implements WorldEditWrapper {
|
|||||||
switch (schemFormat) {
|
switch (schemFormat) {
|
||||||
case SPONGE_V2:
|
case SPONGE_V2:
|
||||||
case SPONGE_V3:
|
case SPONGE_V3:
|
||||||
return new SpongeSchematicReader(new NBTInputStream(is)).read();
|
return new SpongeSchematicReader(new NBTInputStream(is), this).read();
|
||||||
case MCEDIT:
|
case MCEDIT:
|
||||||
return new MCEditSchematicReader(new NBTInputStream(is)).read();
|
return new MCEditSchematicReader(new NBTInputStream(is)).read();
|
||||||
default:
|
default:
|
||||||
@@ -126,6 +127,10 @@ public class WorldEditWrapper14 implements WorldEditWrapper {
|
|||||||
return NodeData.SchematicFormat.SPONGE_V2;
|
return NodeData.SchematicFormat.SPONGE_V2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, Tag> applyDataFixer(DataFixer fixer, int dataVersion, Map<String, Tag> values) {
|
||||||
|
return fixer.fixUp(DataFixer.FixTypes.BLOCK_ENTITY, new CompoundTag(values), dataVersion).getValue();
|
||||||
|
}
|
||||||
|
|
||||||
private static class MCEditSchematicReader extends NBTSchematicReader {
|
private static class MCEditSchematicReader extends NBTSchematicReader {
|
||||||
|
|
||||||
private final NBTInputStream inputStream;
|
private final NBTInputStream inputStream;
|
||||||
@@ -396,15 +401,17 @@ public class WorldEditWrapper14 implements WorldEditWrapper {
|
|||||||
private int schematicVersion = -1;
|
private int schematicVersion = -1;
|
||||||
private int dataVersion = -1;
|
private int dataVersion = -1;
|
||||||
private boolean faweSchem = false;
|
private boolean faweSchem = false;
|
||||||
|
private final WorldEditWrapper14 wrapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance.
|
* Create a new instance.
|
||||||
*
|
*
|
||||||
* @param inputStream the input stream to read from
|
* @param inputStream the input stream to read from
|
||||||
*/
|
*/
|
||||||
public SpongeSchematicReader(NBTInputStream inputStream) {
|
public SpongeSchematicReader(NBTInputStream inputStream, WorldEditWrapper14 wrapper) {
|
||||||
checkNotNull(inputStream);
|
checkNotNull(inputStream);
|
||||||
this.inputStream = inputStream;
|
this.inputStream = inputStream;
|
||||||
|
this.wrapper = wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -572,7 +579,7 @@ public class WorldEditWrapper14 implements WorldEditWrapper {
|
|||||||
values.remove("Id");
|
values.remove("Id");
|
||||||
values.remove("Pos");
|
values.remove("Pos");
|
||||||
if (fixer != null) {
|
if (fixer != null) {
|
||||||
tileEntity = fixer.fixUp(DataFixer.FixTypes.BLOCK_ENTITY, new CompoundTag(values), dataVersion).getValue();
|
tileEntity = wrapper.applyDataFixer(fixer, dataVersion, values);
|
||||||
} else {
|
} else {
|
||||||
tileEntity = values;
|
tileEntity = values;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,34 +19,18 @@
|
|||||||
|
|
||||||
package de.steamwar.core;
|
package de.steamwar.core;
|
||||||
|
|
||||||
import com.sk89q.jnbt.NBTInputStream;
|
import com.sk89q.jnbt.AdventureNBTConverter;
|
||||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
import com.sk89q.worldedit.extent.clipboard.io.*;
|
import com.sk89q.jnbt.Tag;
|
||||||
import de.steamwar.sql.NoClipboardException;
|
import com.sk89q.worldedit.world.DataFixer;
|
||||||
import de.steamwar.sql.NodeData;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.util.Map;
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
public class WorldEditWrapper18 extends WorldEditWrapper14 {
|
public class WorldEditWrapper18 extends WorldEditWrapper14 {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("removal")
|
@SuppressWarnings("removal")
|
||||||
public Clipboard getClipboard(InputStream is, NodeData.SchematicFormat schemFormat) throws IOException {
|
public Map<String, Tag> applyDataFixer(DataFixer fixer, int dataVersion, Map<String, Tag> values) {
|
||||||
NBTInputStream nbtStream = new NBTInputStream(is);
|
return ((CompoundTag) AdventureNBTConverter.fromAdventure(fixer.fixUp(DataFixer.FixTypes.BLOCK_ENTITY, new CompoundTag(values).asBinaryTag(), dataVersion))).getValue();
|
||||||
//Use FAWE reader due to FAWE capability of reading corrupt FAWE schems
|
|
||||||
try {
|
|
||||||
switch (schemFormat) {
|
|
||||||
case MCEDIT:
|
|
||||||
return new MCEditSchematicReader(nbtStream).read();
|
|
||||||
case SPONGE_V2:
|
|
||||||
case SPONGE_V3:
|
|
||||||
return new WorldEditWrapper14.SpongeSchematicReader(nbtStream).read();
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("Unsupported schematic format");
|
|
||||||
}
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
throw new NoClipboardException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ public class WorldEditWrapper21 implements WorldEditWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("removal")
|
||||||
public Clipboard getClipboard(InputStream is, NodeData.SchematicFormat schemFormat) throws IOException {
|
public Clipboard getClipboard(InputStream is, NodeData.SchematicFormat schemFormat) throws IOException {
|
||||||
return switch (schemFormat) {
|
return switch (schemFormat) {
|
||||||
case MCEDIT -> new MCEditSchematicReader(new NBTInputStream(is)).read();
|
case MCEDIT -> new MCEditSchematicReader(new NBTInputStream(is)).read();
|
||||||
|
|||||||
Reference in New Issue
Block a user