Patch skull owner on 1.16+

This commit is contained in:
Octavia Togami 2020-08-21 13:35:05 -07:00
parent 46c3fccae1
commit 5f868d58e2
2 changed files with 12 additions and 2 deletions

View File

@ -22,6 +22,7 @@
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.internal.util.DeprecationUtil;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
@ -94,7 +95,7 @@ public CompoundTag getNbtData() {
Map<String, Tag> values = new HashMap<>();
Map<String, Tag> inner = new HashMap<>();
inner.put("Name", new StringTag(owner));
values.put("Owner", new CompoundTag(inner));
values.put(DeprecationUtil.getHeadOwnerKey(), new CompoundTag(inner));
return new CompoundTag(values);
}
@ -113,7 +114,7 @@ public void setNbtData(CompoundTag rootTag) {
throw new RuntimeException(String.format("'%s' tile entity expected", getNbtId()));
}
t = values.get("Owner");
t = values.get(DeprecationUtil.getHeadOwnerKey());
if (t instanceof CompoundTag) {
setOwner(((CompoundTag) t).getValue().get("Name").getValue().toString());
}

View File

@ -21,6 +21,9 @@
import com.google.common.base.Joiner;
import com.google.common.base.Throwables;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.world.block.BlockCategories;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
@ -106,4 +109,10 @@ public static boolean isSign(BlockType blockType) {
|| BlockCategories.SIGNS.contains(blockType);
}
public static String getHeadOwnerKey() {
int dataVersion = WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.GAME_HOOKS).getDataVersion();
return dataVersion >= Constants.DATA_VERSION_MC_1_16 ? "SkullOwner" : "Owner";
}
}