mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-16 03:14:04 +00:00
Fix //snapshot in 1.18 and re-implement biome/entity restoration (#1620)
* Re-add "//snap" and "//snapshot" * Place code in correct method * Use CompoundBinaryTags in AnvilChunk18 and implement biome/entity restoration * Address comments * Fix biome reading * Fix retrieval of entities from zipped snapshot world Co-authored-by: Alex <mc.cache@web.de>
This commit is contained in:
@@ -2,9 +2,16 @@ package com.fastasyncworldedit.core.util;
|
||||
|
||||
import com.sk89q.worldedit.util.nbt.BinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.BinaryTagType;
|
||||
import com.sk89q.worldedit.util.nbt.BinaryTagTypes;
|
||||
import com.sk89q.worldedit.util.nbt.ByteBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.IntBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.ShortBinaryTag;
|
||||
import com.sk89q.worldedit.world.storage.InvalidFormatException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class NbtUtils {
|
||||
|
||||
/**
|
||||
@@ -32,4 +39,45 @@ public class NbtUtils {
|
||||
return childTagCast;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an integer from a tag.
|
||||
*
|
||||
* @param tag the tag to read from
|
||||
* @param key the key to look for
|
||||
* @return child tag
|
||||
* @throws InvalidFormatException if the format of the items is invalid
|
||||
* @since TODO
|
||||
*/
|
||||
public static int getInt(CompoundBinaryTag tag, String key) throws InvalidFormatException {
|
||||
BinaryTag childTag = tag.get(key);
|
||||
if (childTag == null) {
|
||||
throw new InvalidFormatException("Missing a \"" + key + "\" tag");
|
||||
}
|
||||
|
||||
BinaryTagType<?> type = childTag.type();
|
||||
if (type == BinaryTagTypes.INT) {
|
||||
return ((IntBinaryTag) childTag).intValue();
|
||||
}
|
||||
if (type == BinaryTagTypes.BYTE) {
|
||||
return ((ByteBinaryTag) childTag).intValue();
|
||||
}
|
||||
if (type == BinaryTagTypes.SHORT) {
|
||||
return ((ShortBinaryTag) childTag).intValue();
|
||||
}
|
||||
throw new InvalidFormatException(key + " tag is not of int, short or byte tag type.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a mutable map of the values stored inside a {@link CompoundBinaryTag}
|
||||
*
|
||||
* @param tag {@link CompoundBinaryTag} to get values for
|
||||
* @return Mutable map of values
|
||||
* @since TODO
|
||||
*/
|
||||
public static Map<String, BinaryTag> getCompoundBinaryTagValues(CompoundBinaryTag tag) {
|
||||
Map<String, BinaryTag> value = new HashMap<>();
|
||||
tag.forEach((e) -> value.put(e.getKey(), e.getValue()));
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user