mirror of
https://github.com/EngineHub/WorldEdit.git
synced 2025-03-07 13:48:00 +08:00
Further work on migrating to Adventure NBT
This commit is contained in:
parent
85c150e017
commit
4ac2bb3e25
@ -299,7 +299,7 @@ public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B bl
|
||||
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||
if (adapter != null) {
|
||||
if (block.getBlockType() == BlockTypes.STRUCTURE_BLOCK) {
|
||||
adapter.sendFakeNBT(player, pos, ((BaseBlock) block).getNbtData());
|
||||
adapter.sendFakeNBT(player, pos, ((BaseBlock) block).getNbt());
|
||||
adapter.sendFakeOP(player);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.bukkit.adapter;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
@ -31,6 +30,7 @@
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.SideEffect;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
||||
import com.sk89q.worldedit.world.DataFixer;
|
||||
import com.sk89q.worldedit.world.RegenOptions;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
@ -151,7 +151,7 @@ default void tickWatchdog() {
|
||||
* @param pos The position
|
||||
* @param nbtData The NBT Data
|
||||
*/
|
||||
void sendFakeNBT(Player player, BlockVector3 pos, CompoundTag nbtData);
|
||||
void sendFakeNBT(Player player, BlockVector3 pos, CompoundBinaryTag nbtData);
|
||||
|
||||
/**
|
||||
* Make the client think it has operator status.
|
||||
|
Binary file not shown.
@ -60,8 +60,8 @@ public BaseItem(ItemType itemType) {
|
||||
* @param nbtData NBT Compound tag
|
||||
*/
|
||||
@Deprecated
|
||||
public BaseItem(ItemType itemType, CompoundTag nbtData) {
|
||||
this(itemType, checkNotNull(nbtData).asBinaryTag());
|
||||
public BaseItem(ItemType itemType, @Nullable CompoundTag nbtData) {
|
||||
this(itemType, nbtData == null ? null : nbtData.asBinaryTag());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,11 +19,14 @@
|
||||
|
||||
package com.sk89q.worldedit.internal.wna;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.util.SideEffect;
|
||||
import com.sk89q.worldedit.util.SideEffectSet;
|
||||
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.IntBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
@ -66,14 +69,15 @@ default <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position,
|
||||
if (successful || old == newState) {
|
||||
if (block instanceof BaseBlock) {
|
||||
BaseBlock baseBlock = (BaseBlock) block;
|
||||
CompoundTag tag = baseBlock.getNbtData();
|
||||
CompoundBinaryTag tag = baseBlock.getNbt();
|
||||
if (tag != null) {
|
||||
tag = tag.createBuilder()
|
||||
.putString("id", baseBlock.getNbtId())
|
||||
.putInt("x", position.getX())
|
||||
.putInt("y", position.getY())
|
||||
.putInt("z", position.getZ())
|
||||
.build();
|
||||
tag = tag.put(ImmutableMap.of(
|
||||
"id", StringBinaryTag.of(baseBlock.getNbtId()),
|
||||
"x", IntBinaryTag.of(position.getX()),
|
||||
"y", IntBinaryTag.of(position.getY()),
|
||||
"z", IntBinaryTag.of(position.getZ())
|
||||
));
|
||||
|
||||
// update if TE changed as well
|
||||
successful = updateTileEntity(pos, tag);
|
||||
}
|
||||
@ -136,7 +140,7 @@ default void setCurrentSideEffectSet(SideEffectSet sideEffectSet) {
|
||||
|
||||
void updateLightingForBlock(NP position);
|
||||
|
||||
boolean updateTileEntity(NP position, CompoundTag tag);
|
||||
boolean updateTileEntity(NP position, CompoundBinaryTag tag);
|
||||
|
||||
void notifyBlockUpdate(NP position, NBS oldState, NBS newState);
|
||||
|
||||
|
@ -62,7 +62,8 @@ default boolean hasNbtData() {
|
||||
@Deprecated
|
||||
@Nullable
|
||||
default CompoundTag getNbtData() {
|
||||
return AdventureNBTConverter.fromAdventure(getNbt());
|
||||
CompoundBinaryTag tag = getNbt();
|
||||
return tag == null ? null : AdventureNBTConverter.fromAdventure(tag);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,8 +20,6 @@
|
||||
package com.sk89q.worldedit.fabric;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.fabric.internal.NBTConverter;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
@ -32,6 +30,8 @@
|
||||
import com.sk89q.worldedit.registry.state.IntegerProperty;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.nbt.BinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
@ -228,8 +228,8 @@ public static ItemType adapt(Item item) {
|
||||
|
||||
public static ItemStack adapt(BaseItemStack baseItemStack) {
|
||||
net.minecraft.nbt.CompoundTag fabricCompound = null;
|
||||
if (baseItemStack.getNbtData() != null) {
|
||||
fabricCompound = NBTConverter.toNative(baseItemStack.getNbtData());
|
||||
if (baseItemStack.getNbt() != null) {
|
||||
fabricCompound = NBTConverter.toNative(baseItemStack.getNbt());
|
||||
}
|
||||
final ItemStack itemStack = new ItemStack(adapt(baseItemStack.getType()), baseItemStack.getAmount());
|
||||
itemStack.setTag(fabricCompound);
|
||||
@ -237,13 +237,13 @@ public static ItemStack adapt(BaseItemStack baseItemStack) {
|
||||
}
|
||||
|
||||
public static BaseItemStack adapt(ItemStack itemStack) {
|
||||
CompoundTag tag = NBTConverter.fromNative(itemStack.toTag(new net.minecraft.nbt.CompoundTag()));
|
||||
if (tag.getValue().isEmpty()) {
|
||||
CompoundBinaryTag tag = NBTConverter.fromNative(itemStack.toTag(new net.minecraft.nbt.CompoundTag()));
|
||||
if (tag.keySet().isEmpty()) {
|
||||
tag = null;
|
||||
} else {
|
||||
final Tag tagTag = tag.getValue().get("tag");
|
||||
if (tagTag instanceof CompoundTag) {
|
||||
tag = ((CompoundTag) tagTag);
|
||||
final BinaryTag tagTag = tag.get("tag");
|
||||
if (tagTag instanceof CompoundBinaryTag) {
|
||||
tag = ((CompoundBinaryTag) tagTag);
|
||||
} else {
|
||||
tag = null;
|
||||
}
|
||||
|
@ -35,8 +35,8 @@
|
||||
import com.mojang.datafixers.DataFixerBuilder;
|
||||
import com.mojang.datafixers.schemas.Schema;
|
||||
import com.mojang.serialization.Dynamic;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.fabric.internal.NBTConverter;
|
||||
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
||||
import net.minecraft.datafixer.Schemas;
|
||||
import net.minecraft.datafixer.TypeReferences;
|
||||
import net.minecraft.nbt.FloatTag;
|
||||
@ -92,11 +92,11 @@ class FabricDataFixer extends DataFixerBuilder implements com.sk89q.worldedit.wo
|
||||
@Override
|
||||
public <T> T fixUp(FixType<T> type, T original, int srcVer) {
|
||||
if (type == FixTypes.CHUNK) {
|
||||
return (T) fixChunk((CompoundTag) original, srcVer);
|
||||
return (T) fixChunk((CompoundBinaryTag) original, srcVer);
|
||||
} else if (type == FixTypes.BLOCK_ENTITY) {
|
||||
return (T) fixBlockEntity((CompoundTag) original, srcVer);
|
||||
return (T) fixBlockEntity((CompoundBinaryTag) original, srcVer);
|
||||
} else if (type == FixTypes.ENTITY) {
|
||||
return (T) fixEntity((CompoundTag) original, srcVer);
|
||||
return (T) fixEntity((CompoundBinaryTag) original, srcVer);
|
||||
} else if (type == FixTypes.BLOCK_STATE) {
|
||||
return (T) fixBlockState((String) original, srcVer);
|
||||
} else if (type == FixTypes.ITEM_TYPE) {
|
||||
@ -107,19 +107,19 @@ public <T> T fixUp(FixType<T> type, T original, int srcVer) {
|
||||
return original;
|
||||
}
|
||||
|
||||
private CompoundTag fixChunk(CompoundTag originalChunk, int srcVer) {
|
||||
private CompoundBinaryTag fixChunk(CompoundBinaryTag originalChunk, int srcVer) {
|
||||
net.minecraft.nbt.CompoundTag tag = NBTConverter.toNative(originalChunk);
|
||||
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.CHUNK, tag, srcVer);
|
||||
return NBTConverter.fromNative(fixed);
|
||||
}
|
||||
|
||||
private CompoundTag fixBlockEntity(CompoundTag origTileEnt, int srcVer) {
|
||||
private CompoundBinaryTag fixBlockEntity(CompoundBinaryTag origTileEnt, int srcVer) {
|
||||
net.minecraft.nbt.CompoundTag tag = NBTConverter.toNative(origTileEnt);
|
||||
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.BLOCK_ENTITY, tag, srcVer);
|
||||
return NBTConverter.fromNative(fixed);
|
||||
}
|
||||
|
||||
private CompoundTag fixEntity(CompoundTag origEnt, int srcVer) {
|
||||
private CompoundBinaryTag fixEntity(CompoundBinaryTag origEnt, int srcVer) {
|
||||
net.minecraft.nbt.CompoundTag tag = NBTConverter.toNative(origEnt);
|
||||
net.minecraft.nbt.CompoundTag fixed = convert(LegacyType.ENTITY, tag, srcVer);
|
||||
return NBTConverter.fromNative(fixed);
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.fabric;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.util.StringUtil;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
@ -38,6 +37,7 @@
|
||||
import com.sk89q.worldedit.util.formatting.component.TextUtils;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer;
|
||||
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
@ -55,7 +55,6 @@
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -243,7 +242,7 @@ public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B bl
|
||||
player.networkHandler.sendPacket(packetOut);
|
||||
if (block instanceof BaseBlock && block.getBlockType().equals(BlockTypes.STRUCTURE_BLOCK)) {
|
||||
final BaseBlock baseBlock = (BaseBlock) block;
|
||||
final CompoundTag nbtData = baseBlock.getNbtData();
|
||||
final CompoundBinaryTag nbtData = baseBlock.getNbt();
|
||||
if (nbtData != null) {
|
||||
player.networkHandler.sendPacket(new BlockEntityUpdateS2CPacket(
|
||||
new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()),
|
||||
|
@ -28,7 +28,6 @@
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.mojang.serialization.Dynamic;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
@ -53,6 +52,7 @@
|
||||
import com.sk89q.worldedit.util.SideEffectSet;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
import com.sk89q.worldedit.util.io.file.SafeFiles;
|
||||
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
||||
import com.sk89q.worldedit.world.AbstractWorld;
|
||||
import com.sk89q.worldedit.world.RegenOptions;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
@ -248,7 +248,7 @@ public boolean setBiome(BlockVector3 position, BiomeType biome) {
|
||||
|
||||
@Override
|
||||
public boolean useItem(BlockVector3 position, BaseItem item, Direction face) {
|
||||
ItemStack stack = FabricAdapter.adapt(new BaseItemStack(item.getType(), item.getNbtData(), 1));
|
||||
ItemStack stack = FabricAdapter.adapt(new BaseItemStack(item.getType(), item.getNbt(), 1));
|
||||
ServerWorld world = (ServerWorld) getWorld();
|
||||
final WorldEditFakePlayer fakePlayer;
|
||||
try {
|
||||
@ -667,9 +667,9 @@ public Entity createEntity(Location location, BaseEntity entity) {
|
||||
}
|
||||
net.minecraft.entity.Entity createdEntity = entityType.get().create(world);
|
||||
if (createdEntity != null) {
|
||||
CompoundTag nativeTag = entity.getNbtData();
|
||||
CompoundBinaryTag nativeTag = entity.getNbt();
|
||||
if (nativeTag != null) {
|
||||
net.minecraft.nbt.CompoundTag tag = NBTConverter.toNative(entity.getNbtData());
|
||||
net.minecraft.nbt.CompoundTag tag = NBTConverter.toNative(nativeTag);
|
||||
for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
|
||||
tag.remove(name);
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
|
||||
import com.sk89q.worldedit.util.SideEffect;
|
||||
import com.sk89q.worldedit.util.SideEffectSet;
|
||||
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
@ -103,7 +104,7 @@ public void updateLightingForBlock(BlockPos position) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateTileEntity(BlockPos position, com.sk89q.jnbt.CompoundTag tag) {
|
||||
public boolean updateTileEntity(BlockPos position, CompoundBinaryTag tag) {
|
||||
CompoundTag nativeTag = NBTConverter.toNative(tag);
|
||||
BlockEntity tileEntity = getWorld().getWorldChunk(position).getBlockEntity(position);
|
||||
if (tileEntity == null) {
|
||||
|
@ -19,27 +19,22 @@
|
||||
|
||||
package com.sk89q.worldedit.fabric.internal;
|
||||
|
||||
import com.sk89q.jnbt.ByteArrayTag;
|
||||
import com.sk89q.jnbt.ByteTag;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.DoubleTag;
|
||||
import com.sk89q.jnbt.EndTag;
|
||||
import com.sk89q.jnbt.FloatTag;
|
||||
import com.sk89q.jnbt.IntArrayTag;
|
||||
import com.sk89q.jnbt.IntTag;
|
||||
import com.sk89q.jnbt.ListTag;
|
||||
import com.sk89q.jnbt.LongArrayTag;
|
||||
import com.sk89q.jnbt.LongTag;
|
||||
import com.sk89q.jnbt.ShortTag;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.util.nbt.BinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.ByteArrayBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.ByteBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.DoubleBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.EndBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.FloatBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.IntArrayBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.IntBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.ListBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.LongArrayBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.LongBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.ShortBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@ -50,56 +45,56 @@ public final class NBTConverter {
|
||||
private NBTConverter() {
|
||||
}
|
||||
|
||||
public static net.minecraft.nbt.Tag toNative(Tag tag) {
|
||||
if (tag instanceof IntArrayTag) {
|
||||
return toNative((IntArrayTag) tag);
|
||||
public static net.minecraft.nbt.Tag toNative(BinaryTag tag) {
|
||||
if (tag instanceof IntArrayBinaryTag) {
|
||||
return toNative((IntArrayBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof ListTag) {
|
||||
return toNative((ListTag) tag);
|
||||
} else if (tag instanceof ListBinaryTag) {
|
||||
return toNative((ListBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof LongTag) {
|
||||
return toNative((LongTag) tag);
|
||||
} else if (tag instanceof LongBinaryTag) {
|
||||
return toNative((LongBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof LongArrayTag) {
|
||||
return toNative((LongArrayTag) tag);
|
||||
} else if (tag instanceof LongArrayBinaryTag) {
|
||||
return toNative((LongArrayBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof StringTag) {
|
||||
return toNative((StringTag) tag);
|
||||
} else if (tag instanceof StringBinaryTag) {
|
||||
return toNative((StringBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof IntTag) {
|
||||
return toNative((IntTag) tag);
|
||||
} else if (tag instanceof IntBinaryTag) {
|
||||
return toNative((IntBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof ByteTag) {
|
||||
return toNative((ByteTag) tag);
|
||||
} else if (tag instanceof ByteBinaryTag) {
|
||||
return toNative((ByteBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof ByteArrayTag) {
|
||||
return toNative((ByteArrayTag) tag);
|
||||
} else if (tag instanceof ByteArrayBinaryTag) {
|
||||
return toNative((ByteArrayBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof CompoundTag) {
|
||||
return toNative((CompoundTag) tag);
|
||||
} else if (tag instanceof CompoundBinaryTag) {
|
||||
return toNative((CompoundBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof FloatTag) {
|
||||
return toNative((FloatTag) tag);
|
||||
} else if (tag instanceof FloatBinaryTag) {
|
||||
return toNative((FloatBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof ShortTag) {
|
||||
return toNative((ShortTag) tag);
|
||||
} else if (tag instanceof ShortBinaryTag) {
|
||||
return toNative((ShortBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof DoubleTag) {
|
||||
return toNative((DoubleTag) tag);
|
||||
} else if (tag instanceof DoubleBinaryTag) {
|
||||
return toNative((DoubleBinaryTag) tag);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Can't convert tag of type " + tag.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
public static net.minecraft.nbt.IntArrayTag toNative(IntArrayTag tag) {
|
||||
int[] value = tag.getValue();
|
||||
public static net.minecraft.nbt.IntArrayTag toNative(IntArrayBinaryTag tag) {
|
||||
int[] value = tag.value();
|
||||
return new net.minecraft.nbt.IntArrayTag(Arrays.copyOf(value, value.length));
|
||||
}
|
||||
|
||||
public static net.minecraft.nbt.ListTag toNative(ListTag tag) {
|
||||
public static net.minecraft.nbt.ListTag toNative(ListBinaryTag tag) {
|
||||
net.minecraft.nbt.ListTag list = new net.minecraft.nbt.ListTag();
|
||||
for (Tag child : tag.getValue()) {
|
||||
if (child instanceof EndTag) {
|
||||
for (BinaryTag child : tag) {
|
||||
if (child instanceof EndBinaryTag) {
|
||||
continue;
|
||||
}
|
||||
list.add(toNative(child));
|
||||
@ -107,51 +102,51 @@ public static net.minecraft.nbt.ListTag toNative(ListTag tag) {
|
||||
return list;
|
||||
}
|
||||
|
||||
public static net.minecraft.nbt.LongTag toNative(LongTag tag) {
|
||||
return net.minecraft.nbt.LongTag.of(tag.getValue());
|
||||
public static net.minecraft.nbt.LongTag toNative(LongBinaryTag tag) {
|
||||
return net.minecraft.nbt.LongTag.of(tag.value());
|
||||
}
|
||||
|
||||
public static net.minecraft.nbt.LongArrayTag toNative(LongArrayTag tag) {
|
||||
return new net.minecraft.nbt.LongArrayTag(tag.getValue().clone());
|
||||
public static net.minecraft.nbt.LongArrayTag toNative(LongArrayBinaryTag tag) {
|
||||
return new net.minecraft.nbt.LongArrayTag(tag.value().clone());
|
||||
}
|
||||
|
||||
public static net.minecraft.nbt.StringTag toNative(StringTag tag) {
|
||||
return net.minecraft.nbt.StringTag.of(tag.getValue());
|
||||
public static net.minecraft.nbt.StringTag toNative(StringBinaryTag tag) {
|
||||
return net.minecraft.nbt.StringTag.of(tag.value());
|
||||
}
|
||||
|
||||
public static net.minecraft.nbt.IntTag toNative(IntTag tag) {
|
||||
return net.minecraft.nbt.IntTag.of(tag.getValue());
|
||||
public static net.minecraft.nbt.IntTag toNative(IntBinaryTag tag) {
|
||||
return net.minecraft.nbt.IntTag.of(tag.value());
|
||||
}
|
||||
|
||||
public static net.minecraft.nbt.ByteTag toNative(ByteTag tag) {
|
||||
return net.minecraft.nbt.ByteTag.of(tag.getValue());
|
||||
public static net.minecraft.nbt.ByteTag toNative(ByteBinaryTag tag) {
|
||||
return net.minecraft.nbt.ByteTag.of(tag.value());
|
||||
}
|
||||
|
||||
public static net.minecraft.nbt.ByteArrayTag toNative(ByteArrayTag tag) {
|
||||
return new net.minecraft.nbt.ByteArrayTag(tag.getValue().clone());
|
||||
public static net.minecraft.nbt.ByteArrayTag toNative(ByteArrayBinaryTag tag) {
|
||||
return new net.minecraft.nbt.ByteArrayTag(tag.value().clone());
|
||||
}
|
||||
|
||||
public static net.minecraft.nbt.CompoundTag toNative(CompoundTag tag) {
|
||||
public static net.minecraft.nbt.CompoundTag toNative(CompoundBinaryTag tag) {
|
||||
net.minecraft.nbt.CompoundTag compound = new net.minecraft.nbt.CompoundTag();
|
||||
for (Entry<String, Tag> child : tag.getValue().entrySet()) {
|
||||
compound.put(child.getKey(), toNative(child.getValue()));
|
||||
for (String key : tag.keySet()) {
|
||||
compound.put(key, toNative(tag.get(key)));
|
||||
}
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static net.minecraft.nbt.FloatTag toNative(FloatTag tag) {
|
||||
return net.minecraft.nbt.FloatTag.of(tag.getValue());
|
||||
public static net.minecraft.nbt.FloatTag toNative(FloatBinaryTag tag) {
|
||||
return net.minecraft.nbt.FloatTag.of(tag.value());
|
||||
}
|
||||
|
||||
public static net.minecraft.nbt.ShortTag toNative(ShortTag tag) {
|
||||
return net.minecraft.nbt.ShortTag.of(tag.getValue());
|
||||
public static net.minecraft.nbt.ShortTag toNative(ShortBinaryTag tag) {
|
||||
return net.minecraft.nbt.ShortTag.of(tag.value());
|
||||
}
|
||||
|
||||
public static net.minecraft.nbt.DoubleTag toNative(DoubleTag tag) {
|
||||
return net.minecraft.nbt.DoubleTag.of(tag.getValue());
|
||||
public static net.minecraft.nbt.DoubleTag toNative(DoubleBinaryTag tag) {
|
||||
return net.minecraft.nbt.DoubleTag.of(tag.value());
|
||||
}
|
||||
|
||||
public static Tag fromNative(net.minecraft.nbt.Tag other) {
|
||||
public static BinaryTag fromNative(net.minecraft.nbt.Tag other) {
|
||||
if (other instanceof net.minecraft.nbt.IntArrayTag) {
|
||||
return fromNative((net.minecraft.nbt.IntArrayTag) other);
|
||||
|
||||
@ -195,71 +190,69 @@ public static Tag fromNative(net.minecraft.nbt.Tag other) {
|
||||
}
|
||||
}
|
||||
|
||||
public static IntArrayTag fromNative(net.minecraft.nbt.IntArrayTag other) {
|
||||
public static IntArrayBinaryTag fromNative(net.minecraft.nbt.IntArrayTag other) {
|
||||
int[] value = other.getIntArray();
|
||||
return new IntArrayTag(Arrays.copyOf(value, value.length));
|
||||
return IntArrayBinaryTag.of(Arrays.copyOf(value, value.length));
|
||||
}
|
||||
|
||||
public static ListTag fromNative(net.minecraft.nbt.ListTag other) {
|
||||
public static ListBinaryTag fromNative(net.minecraft.nbt.ListTag other) {
|
||||
other = other.copy();
|
||||
List<Tag> list = new ArrayList<>();
|
||||
Class<? extends Tag> listClass = StringTag.class;
|
||||
ListBinaryTag.Builder list = ListBinaryTag.builder();
|
||||
int tags = other.size();
|
||||
for (int i = 0; i < tags; i++) {
|
||||
Tag child = fromNative(other.remove(0));
|
||||
BinaryTag child = fromNative(other.remove(0));
|
||||
list.add(child);
|
||||
listClass = child.getClass();
|
||||
}
|
||||
return new ListTag(listClass, list);
|
||||
return list.build();
|
||||
}
|
||||
|
||||
public static EndTag fromNative(net.minecraft.nbt.EndTag other) {
|
||||
return new EndTag();
|
||||
public static EndBinaryTag fromNative(net.minecraft.nbt.EndTag other) {
|
||||
return EndBinaryTag.get();
|
||||
}
|
||||
|
||||
public static LongTag fromNative(net.minecraft.nbt.LongTag other) {
|
||||
return new LongTag(other.getLong());
|
||||
public static LongBinaryTag fromNative(net.minecraft.nbt.LongTag other) {
|
||||
return LongBinaryTag.of(other.getLong());
|
||||
}
|
||||
|
||||
public static LongArrayTag fromNative(net.minecraft.nbt.LongArrayTag other) {
|
||||
return new LongArrayTag(other.getLongArray().clone());
|
||||
public static LongArrayBinaryTag fromNative(net.minecraft.nbt.LongArrayTag other) {
|
||||
return LongArrayBinaryTag.of(other.getLongArray().clone());
|
||||
}
|
||||
|
||||
public static StringTag fromNative(net.minecraft.nbt.StringTag other) {
|
||||
return new StringTag(other.asString());
|
||||
public static StringBinaryTag fromNative(net.minecraft.nbt.StringTag other) {
|
||||
return StringBinaryTag.of(other.asString());
|
||||
}
|
||||
|
||||
public static IntTag fromNative(net.minecraft.nbt.IntTag other) {
|
||||
return new IntTag(other.getInt());
|
||||
public static IntBinaryTag fromNative(net.minecraft.nbt.IntTag other) {
|
||||
return IntBinaryTag.of(other.getInt());
|
||||
}
|
||||
|
||||
public static ByteTag fromNative(net.minecraft.nbt.ByteTag other) {
|
||||
return new ByteTag(other.getByte());
|
||||
public static ByteBinaryTag fromNative(net.minecraft.nbt.ByteTag other) {
|
||||
return ByteBinaryTag.of(other.getByte());
|
||||
}
|
||||
|
||||
public static ByteArrayTag fromNative(net.minecraft.nbt.ByteArrayTag other) {
|
||||
return new ByteArrayTag(other.getByteArray().clone());
|
||||
public static ByteArrayBinaryTag fromNative(net.minecraft.nbt.ByteArrayTag other) {
|
||||
return ByteArrayBinaryTag.of(other.getByteArray().clone());
|
||||
}
|
||||
|
||||
public static CompoundTag fromNative(net.minecraft.nbt.CompoundTag other) {
|
||||
public static CompoundBinaryTag fromNative(net.minecraft.nbt.CompoundTag other) {
|
||||
Set<String> tags = other.getKeys();
|
||||
Map<String, Tag> map = new HashMap<>();
|
||||
CompoundBinaryTag.Builder builder = CompoundBinaryTag.builder();
|
||||
for (String tagName : tags) {
|
||||
map.put(tagName, fromNative(other.get(tagName)));
|
||||
builder.put(tagName, fromNative(other.get(tagName)));
|
||||
}
|
||||
return new CompoundTag(map);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static FloatTag fromNative(net.minecraft.nbt.FloatTag other) {
|
||||
return new FloatTag(other.getFloat());
|
||||
public static FloatBinaryTag fromNative(net.minecraft.nbt.FloatTag other) {
|
||||
return FloatBinaryTag.of(other.getFloat());
|
||||
}
|
||||
|
||||
public static ShortTag fromNative(net.minecraft.nbt.ShortTag other) {
|
||||
return new ShortTag(other.getShort());
|
||||
public static ShortBinaryTag fromNative(net.minecraft.nbt.ShortTag other) {
|
||||
return ShortBinaryTag.of(other.getShort());
|
||||
}
|
||||
|
||||
public static DoubleTag fromNative(net.minecraft.nbt.DoubleTag other) {
|
||||
return new DoubleTag(other.getDouble());
|
||||
public static DoubleBinaryTag fromNative(net.minecraft.nbt.DoubleTag other) {
|
||||
return DoubleBinaryTag.of(other.getDouble());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,8 +20,6 @@
|
||||
package com.sk89q.worldedit.forge;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.forge.internal.NBTConverter;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
@ -32,6 +30,8 @@
|
||||
import com.sk89q.worldedit.registry.state.IntegerProperty;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.nbt.BinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
@ -224,8 +224,8 @@ public static ItemType adapt(Item item) {
|
||||
|
||||
public static ItemStack adapt(BaseItemStack baseItemStack) {
|
||||
CompoundNBT forgeCompound = null;
|
||||
if (baseItemStack.getNbtData() != null) {
|
||||
forgeCompound = NBTConverter.toNative(baseItemStack.getNbtData());
|
||||
if (baseItemStack.getNbt() != null) {
|
||||
forgeCompound = NBTConverter.toNative(baseItemStack.getNbt());
|
||||
}
|
||||
final ItemStack itemStack = new ItemStack(adapt(baseItemStack.getType()), baseItemStack.getAmount());
|
||||
itemStack.setTag(forgeCompound);
|
||||
@ -233,13 +233,13 @@ public static ItemStack adapt(BaseItemStack baseItemStack) {
|
||||
}
|
||||
|
||||
public static BaseItemStack adapt(ItemStack itemStack) {
|
||||
CompoundTag tag = NBTConverter.fromNative(itemStack.serializeNBT());
|
||||
if (tag.getValue().isEmpty()) {
|
||||
CompoundBinaryTag tag = NBTConverter.fromNative(itemStack.serializeNBT());
|
||||
if (tag.keySet().isEmpty()) {
|
||||
tag = null;
|
||||
} else {
|
||||
final Tag tagTag = tag.getValue().get("tag");
|
||||
if (tagTag instanceof CompoundTag) {
|
||||
tag = ((CompoundTag) tagTag);
|
||||
final BinaryTag tagTag = tag.get("tag");
|
||||
if (tagTag instanceof CompoundBinaryTag) {
|
||||
tag = ((CompoundBinaryTag) tagTag);
|
||||
} else {
|
||||
tag = null;
|
||||
}
|
||||
|
@ -34,8 +34,8 @@
|
||||
import com.mojang.datafixers.DataFixerBuilder;
|
||||
import com.mojang.datafixers.schemas.Schema;
|
||||
import com.mojang.serialization.Dynamic;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.forge.internal.NBTConverter;
|
||||
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
||||
import net.minecraft.item.DyeColor;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.FloatNBT;
|
||||
@ -94,11 +94,11 @@ class ForgeDataFixer extends DataFixerBuilder implements com.sk89q.worldedit.wor
|
||||
@Override
|
||||
public <T> T fixUp(FixType<T> type, T original, int srcVer) {
|
||||
if (type == FixTypes.CHUNK) {
|
||||
return (T) fixChunk((CompoundTag) original, srcVer);
|
||||
return (T) fixChunk((CompoundBinaryTag) original, srcVer);
|
||||
} else if (type == FixTypes.BLOCK_ENTITY) {
|
||||
return (T) fixBlockEntity((CompoundTag) original, srcVer);
|
||||
return (T) fixBlockEntity((CompoundBinaryTag) original, srcVer);
|
||||
} else if (type == FixTypes.ENTITY) {
|
||||
return (T) fixEntity((CompoundTag) original, srcVer);
|
||||
return (T) fixEntity((CompoundBinaryTag) original, srcVer);
|
||||
} else if (type == FixTypes.BLOCK_STATE) {
|
||||
return (T) fixBlockState((String) original, srcVer);
|
||||
} else if (type == FixTypes.ITEM_TYPE) {
|
||||
@ -109,19 +109,19 @@ public <T> T fixUp(FixType<T> type, T original, int srcVer) {
|
||||
return original;
|
||||
}
|
||||
|
||||
private CompoundTag fixChunk(CompoundTag originalChunk, int srcVer) {
|
||||
private CompoundBinaryTag fixChunk(CompoundBinaryTag originalChunk, int srcVer) {
|
||||
CompoundNBT tag = NBTConverter.toNative(originalChunk);
|
||||
CompoundNBT fixed = convert(LegacyType.CHUNK, tag, srcVer);
|
||||
return NBTConverter.fromNative(fixed);
|
||||
}
|
||||
|
||||
private CompoundTag fixBlockEntity(CompoundTag origTileEnt, int srcVer) {
|
||||
private CompoundBinaryTag fixBlockEntity(CompoundBinaryTag origTileEnt, int srcVer) {
|
||||
CompoundNBT tag = NBTConverter.toNative(origTileEnt);
|
||||
CompoundNBT fixed = convert(LegacyType.BLOCK_ENTITY, tag, srcVer);
|
||||
return NBTConverter.fromNative(fixed);
|
||||
}
|
||||
|
||||
private CompoundTag fixEntity(CompoundTag origEnt, int srcVer) {
|
||||
private CompoundBinaryTag fixEntity(CompoundBinaryTag origEnt, int srcVer) {
|
||||
CompoundNBT tag = NBTConverter.toNative(origEnt);
|
||||
CompoundNBT fixed = convert(LegacyType.ENTITY, tag, srcVer);
|
||||
return NBTConverter.fromNative(fixed);
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.forge;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.util.StringUtil;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
@ -36,6 +35,7 @@
|
||||
import com.sk89q.worldedit.util.formatting.component.TextUtils;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer;
|
||||
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
@ -244,7 +244,7 @@ public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B bl
|
||||
player.connection.sendPacket(packetOut);
|
||||
if (block instanceof BaseBlock && block.getBlockType().equals(BlockTypes.STRUCTURE_BLOCK)) {
|
||||
final BaseBlock baseBlock = (BaseBlock) block;
|
||||
final CompoundTag nbtData = baseBlock.getNbtData();
|
||||
final CompoundBinaryTag nbtData = baseBlock.getNbt();
|
||||
if (nbtData != null) {
|
||||
player.connection.sendPacket(new SUpdateTileEntityPacket(
|
||||
new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()),
|
||||
|
@ -29,7 +29,6 @@
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.Dynamic;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
@ -53,6 +52,7 @@
|
||||
import com.sk89q.worldedit.util.SideEffectSet;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
import com.sk89q.worldedit.util.io.file.SafeFiles;
|
||||
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
||||
import com.sk89q.worldedit.world.AbstractWorld;
|
||||
import com.sk89q.worldedit.world.RegenOptions;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
@ -253,7 +253,7 @@ public boolean setBiome(BlockVector3 position, BiomeType biome) {
|
||||
|
||||
@Override
|
||||
public boolean useItem(BlockVector3 position, BaseItem item, Direction face) {
|
||||
ItemStack stack = ForgeAdapter.adapt(new BaseItemStack(item.getType(), item.getNbtData(), 1));
|
||||
ItemStack stack = ForgeAdapter.adapt(new BaseItemStack(item.getType(), item.getNbt(), 1));
|
||||
ServerWorld world = (ServerWorld) getWorld();
|
||||
final WorldEditFakePlayer fakePlayer;
|
||||
try {
|
||||
@ -677,9 +677,9 @@ public Entity createEntity(Location location, BaseEntity entity) {
|
||||
}
|
||||
net.minecraft.entity.Entity createdEntity = entityType.get().create(world);
|
||||
if (createdEntity != null) {
|
||||
CompoundTag nativeTag = entity.getNbtData();
|
||||
CompoundBinaryTag nativeTag = entity.getNbt();
|
||||
if (nativeTag != null) {
|
||||
CompoundNBT tag = NBTConverter.toNative(entity.getNbtData());
|
||||
CompoundNBT tag = NBTConverter.toNative(nativeTag);
|
||||
for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
|
||||
tag.remove(name);
|
||||
}
|
||||
|
@ -19,12 +19,12 @@
|
||||
|
||||
package com.sk89q.worldedit.forge.internal;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.forge.ForgeAdapter;
|
||||
import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
|
||||
import com.sk89q.worldedit.internal.wna.WorldNativeAccess;
|
||||
import com.sk89q.worldedit.util.SideEffect;
|
||||
import com.sk89q.worldedit.util.SideEffectSet;
|
||||
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
@ -98,7 +98,7 @@ public void updateLightingForBlock(BlockPos position) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateTileEntity(BlockPos position, CompoundTag tag) {
|
||||
public boolean updateTileEntity(BlockPos position, CompoundBinaryTag tag) {
|
||||
CompoundNBT nativeTag = NBTConverter.toNative(tag);
|
||||
return TileEntityUtils.setTileEntity(getWorld(), position, nativeTag);
|
||||
}
|
||||
|
@ -19,20 +19,20 @@
|
||||
|
||||
package com.sk89q.worldedit.forge.internal;
|
||||
|
||||
import com.sk89q.jnbt.ByteArrayTag;
|
||||
import com.sk89q.jnbt.ByteTag;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.DoubleTag;
|
||||
import com.sk89q.jnbt.EndTag;
|
||||
import com.sk89q.jnbt.FloatTag;
|
||||
import com.sk89q.jnbt.IntArrayTag;
|
||||
import com.sk89q.jnbt.IntTag;
|
||||
import com.sk89q.jnbt.ListTag;
|
||||
import com.sk89q.jnbt.LongArrayTag;
|
||||
import com.sk89q.jnbt.LongTag;
|
||||
import com.sk89q.jnbt.ShortTag;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.util.nbt.BinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.ByteArrayBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.ByteBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.DoubleBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.EndBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.FloatBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.IntArrayBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.IntBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.ListBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.LongArrayBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.LongBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.ShortBinaryTag;
|
||||
import com.sk89q.worldedit.util.nbt.StringBinaryTag;
|
||||
import net.minecraft.nbt.ByteArrayNBT;
|
||||
import net.minecraft.nbt.ByteNBT;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
@ -48,12 +48,7 @@
|
||||
import net.minecraft.nbt.ShortNBT;
|
||||
import net.minecraft.nbt.StringNBT;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@ -64,56 +59,56 @@ public final class NBTConverter {
|
||||
private NBTConverter() {
|
||||
}
|
||||
|
||||
public static INBT toNative(Tag tag) {
|
||||
if (tag instanceof IntArrayTag) {
|
||||
return toNative((IntArrayTag) tag);
|
||||
public static INBT toNative(BinaryTag tag) {
|
||||
if (tag instanceof IntArrayBinaryTag) {
|
||||
return toNative((IntArrayBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof ListTag) {
|
||||
return toNative((ListTag) tag);
|
||||
} else if (tag instanceof ListBinaryTag) {
|
||||
return toNative((ListBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof LongTag) {
|
||||
return toNative((LongTag) tag);
|
||||
} else if (tag instanceof LongBinaryTag) {
|
||||
return toNative((LongBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof LongArrayTag) {
|
||||
return toNative((LongArrayTag) tag);
|
||||
} else if (tag instanceof LongArrayBinaryTag) {
|
||||
return toNative((LongArrayBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof StringTag) {
|
||||
return toNative((StringTag) tag);
|
||||
} else if (tag instanceof StringBinaryTag) {
|
||||
return toNative((StringBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof IntTag) {
|
||||
return toNative((IntTag) tag);
|
||||
} else if (tag instanceof IntBinaryTag) {
|
||||
return toNative((IntBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof ByteTag) {
|
||||
return toNative((ByteTag) tag);
|
||||
} else if (tag instanceof ByteBinaryTag) {
|
||||
return toNative((ByteBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof ByteArrayTag) {
|
||||
return toNative((ByteArrayTag) tag);
|
||||
} else if (tag instanceof ByteArrayBinaryTag) {
|
||||
return toNative((ByteArrayBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof CompoundTag) {
|
||||
return toNative((CompoundTag) tag);
|
||||
} else if (tag instanceof CompoundBinaryTag) {
|
||||
return toNative((CompoundBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof FloatTag) {
|
||||
return toNative((FloatTag) tag);
|
||||
} else if (tag instanceof FloatBinaryTag) {
|
||||
return toNative((FloatBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof ShortTag) {
|
||||
return toNative((ShortTag) tag);
|
||||
} else if (tag instanceof ShortBinaryTag) {
|
||||
return toNative((ShortBinaryTag) tag);
|
||||
|
||||
} else if (tag instanceof DoubleTag) {
|
||||
return toNative((DoubleTag) tag);
|
||||
} else if (tag instanceof DoubleBinaryTag) {
|
||||
return toNative((DoubleBinaryTag) tag);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Can't convert tag of type " + tag.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
public static IntArrayNBT toNative(IntArrayTag tag) {
|
||||
int[] value = tag.getValue();
|
||||
public static IntArrayNBT toNative(IntArrayBinaryTag tag) {
|
||||
int[] value = tag.value();
|
||||
return new IntArrayNBT(Arrays.copyOf(value, value.length));
|
||||
}
|
||||
|
||||
public static ListNBT toNative(ListTag tag) {
|
||||
public static ListNBT toNative(ListBinaryTag tag) {
|
||||
ListNBT list = new ListNBT();
|
||||
for (Tag child : tag.getValue()) {
|
||||
if (child instanceof EndTag) {
|
||||
for (BinaryTag child : tag) {
|
||||
if (child instanceof EndBinaryTag) {
|
||||
continue;
|
||||
}
|
||||
list.add(toNative(child));
|
||||
@ -121,51 +116,51 @@ public static ListNBT toNative(ListTag tag) {
|
||||
return list;
|
||||
}
|
||||
|
||||
public static LongNBT toNative(LongTag tag) {
|
||||
return LongNBT.valueOf(tag.getValue());
|
||||
public static LongNBT toNative(LongBinaryTag tag) {
|
||||
return LongNBT.valueOf(tag.value());
|
||||
}
|
||||
|
||||
public static LongArrayNBT toNative(LongArrayTag tag) {
|
||||
return new LongArrayNBT(tag.getValue().clone());
|
||||
public static LongArrayNBT toNative(LongArrayBinaryTag tag) {
|
||||
return new LongArrayNBT(tag.value().clone());
|
||||
}
|
||||
|
||||
public static StringNBT toNative(StringTag tag) {
|
||||
return StringNBT.valueOf(tag.getValue());
|
||||
public static StringNBT toNative(StringBinaryTag tag) {
|
||||
return StringNBT.valueOf(tag.value());
|
||||
}
|
||||
|
||||
public static IntNBT toNative(IntTag tag) {
|
||||
return IntNBT.valueOf(tag.getValue());
|
||||
public static IntNBT toNative(IntBinaryTag tag) {
|
||||
return IntNBT.valueOf(tag.value());
|
||||
}
|
||||
|
||||
public static ByteNBT toNative(ByteTag tag) {
|
||||
return ByteNBT.valueOf(tag.getValue());
|
||||
public static ByteNBT toNative(ByteBinaryTag tag) {
|
||||
return ByteNBT.valueOf(tag.value());
|
||||
}
|
||||
|
||||
public static ByteArrayNBT toNative(ByteArrayTag tag) {
|
||||
return new ByteArrayNBT(tag.getValue().clone());
|
||||
public static ByteArrayNBT toNative(ByteArrayBinaryTag tag) {
|
||||
return new ByteArrayNBT(tag.value().clone());
|
||||
}
|
||||
|
||||
public static CompoundNBT toNative(CompoundTag tag) {
|
||||
public static CompoundNBT toNative(CompoundBinaryTag tag) {
|
||||
CompoundNBT compound = new CompoundNBT();
|
||||
for (Entry<String, Tag> child : tag.getValue().entrySet()) {
|
||||
compound.put(child.getKey(), toNative(child.getValue()));
|
||||
for (String key : tag.keySet()) {
|
||||
compound.put(key, toNative(tag.get(key)));
|
||||
}
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static FloatNBT toNative(FloatTag tag) {
|
||||
return FloatNBT.valueOf(tag.getValue());
|
||||
public static FloatNBT toNative(FloatBinaryTag tag) {
|
||||
return FloatNBT.valueOf(tag.value());
|
||||
}
|
||||
|
||||
public static ShortNBT toNative(ShortTag tag) {
|
||||
return ShortNBT.valueOf(tag.getValue());
|
||||
public static ShortNBT toNative(ShortBinaryTag tag) {
|
||||
return ShortNBT.valueOf(tag.value());
|
||||
}
|
||||
|
||||
public static DoubleNBT toNative(DoubleTag tag) {
|
||||
return DoubleNBT.valueOf(tag.getValue());
|
||||
public static DoubleNBT toNative(DoubleBinaryTag tag) {
|
||||
return DoubleNBT.valueOf(tag.value());
|
||||
}
|
||||
|
||||
public static Tag fromNative(INBT other) {
|
||||
public static BinaryTag fromNative(INBT other) {
|
||||
if (other instanceof IntArrayNBT) {
|
||||
return fromNative((IntArrayNBT) other);
|
||||
|
||||
@ -209,71 +204,69 @@ public static Tag fromNative(INBT other) {
|
||||
}
|
||||
}
|
||||
|
||||
public static IntArrayTag fromNative(IntArrayNBT other) {
|
||||
public static IntArrayBinaryTag fromNative(IntArrayNBT other) {
|
||||
int[] value = other.getIntArray();
|
||||
return new IntArrayTag(Arrays.copyOf(value, value.length));
|
||||
return IntArrayBinaryTag.of(Arrays.copyOf(value, value.length));
|
||||
}
|
||||
|
||||
public static ListTag fromNative(ListNBT other) {
|
||||
public static ListBinaryTag fromNative(ListNBT other) {
|
||||
other = other.copy();
|
||||
List<Tag> list = new ArrayList<>();
|
||||
Class<? extends Tag> listClass = StringTag.class;
|
||||
ListBinaryTag.Builder list = ListBinaryTag.builder();
|
||||
int tags = other.size();
|
||||
for (int i = 0; i < tags; i++) {
|
||||
Tag child = fromNative(other.remove(0));
|
||||
BinaryTag child = fromNative(other.remove(0));
|
||||
list.add(child);
|
||||
listClass = child.getClass();
|
||||
}
|
||||
return new ListTag(listClass, list);
|
||||
return list.build();
|
||||
}
|
||||
|
||||
public static EndTag fromNative(EndNBT other) {
|
||||
return new EndTag();
|
||||
public static EndBinaryTag fromNative(EndNBT other) {
|
||||
return EndBinaryTag.get();
|
||||
}
|
||||
|
||||
public static LongTag fromNative(LongNBT other) {
|
||||
return new LongTag(other.getLong());
|
||||
public static LongBinaryTag fromNative(LongNBT other) {
|
||||
return LongBinaryTag.of(other.getLong());
|
||||
}
|
||||
|
||||
public static LongArrayTag fromNative(LongArrayNBT other) {
|
||||
return new LongArrayTag(other.getAsLongArray().clone());
|
||||
public static LongArrayBinaryTag fromNative(LongArrayNBT other) {
|
||||
return LongArrayBinaryTag.of(other.getAsLongArray().clone());
|
||||
}
|
||||
|
||||
public static StringTag fromNative(StringNBT other) {
|
||||
return new StringTag(other.getString());
|
||||
public static StringBinaryTag fromNative(StringNBT other) {
|
||||
return StringBinaryTag.of(other.getString());
|
||||
}
|
||||
|
||||
public static IntTag fromNative(IntNBT other) {
|
||||
return new IntTag(other.getInt());
|
||||
public static IntBinaryTag fromNative(IntNBT other) {
|
||||
return IntBinaryTag.of(other.getInt());
|
||||
}
|
||||
|
||||
public static ByteTag fromNative(ByteNBT other) {
|
||||
return new ByteTag(other.getByte());
|
||||
public static ByteBinaryTag fromNative(ByteNBT other) {
|
||||
return ByteBinaryTag.of(other.getByte());
|
||||
}
|
||||
|
||||
public static ByteArrayTag fromNative(ByteArrayNBT other) {
|
||||
return new ByteArrayTag(other.getByteArray().clone());
|
||||
public static ByteArrayBinaryTag fromNative(ByteArrayNBT other) {
|
||||
return ByteArrayBinaryTag.of(other.getByteArray().clone());
|
||||
}
|
||||
|
||||
public static CompoundTag fromNative(CompoundNBT other) {
|
||||
public static CompoundBinaryTag fromNative(CompoundNBT other) {
|
||||
Set<String> tags = other.keySet();
|
||||
Map<String, Tag> map = new HashMap<>();
|
||||
CompoundBinaryTag.Builder map = CompoundBinaryTag.builder();
|
||||
for (String tagName : tags) {
|
||||
map.put(tagName, fromNative(other.get(tagName)));
|
||||
}
|
||||
return new CompoundTag(map);
|
||||
return map.build();
|
||||
}
|
||||
|
||||
public static FloatTag fromNative(FloatNBT other) {
|
||||
return new FloatTag(other.getFloat());
|
||||
public static FloatBinaryTag fromNative(FloatNBT other) {
|
||||
return FloatBinaryTag.of(other.getFloat());
|
||||
}
|
||||
|
||||
public static ShortTag fromNative(ShortNBT other) {
|
||||
return new ShortTag(other.getShort());
|
||||
public static ShortBinaryTag fromNative(ShortNBT other) {
|
||||
return ShortBinaryTag.of(other.getShort());
|
||||
}
|
||||
|
||||
public static DoubleTag fromNative(DoubleNBT other) {
|
||||
return new DoubleTag(other.getDouble());
|
||||
public static DoubleBinaryTag fromNative(DoubleNBT other) {
|
||||
return DoubleBinaryTag.of(other.getDouble());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user