Fixed setting sign text on 1.20

Dieser Commit ist enthalten in:
Alexander Brandes 2023-06-09 15:27:02 +02:00
Ursprung bb14d93a8d
Commit 689c7f62b8
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 158F5701A6AAD00C

Datei anzeigen

@ -20,27 +20,29 @@
package com.sk89q.worldedit.blocks;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.util.gson.GsonUtil;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Represents a sign block.
*
* @deprecated WorldEdit does not handle interpreting NBT,
* deprecated for removal without replacement
*/
@Deprecated(forRemoval = true)
public class SignBlock extends BaseBlock {
private String[] text;
private static String EMPTY = "{\"text\":\"\"}";
private static final String EMPTY = "{\"text\":\"\"}";
/**
* Construct the sign with text.
@ -64,6 +66,11 @@ public class SignBlock extends BaseBlock {
this.text = text;
}
private boolean isLegacy() {
int dataVersion = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getDataVersion();
return dataVersion < Constants.DATA_VERSION_MC_1_20;
}
/**
* Get the text.
*
@ -98,10 +105,17 @@ public class SignBlock extends BaseBlock {
@Override
public CompoundTag getNbtData() {
Map<String, Tag> values = new HashMap<>();
if (isLegacy()) {
values.put("Text1", new StringTag(text[0]));
values.put("Text2", new StringTag(text[1]));
values.put("Text3", new StringTag(text[2]));
values.put("Text4", new StringTag(text[3]));
} else {
ListTag messages = new ListTag(StringTag.class, Arrays.stream(text).map(StringTag::new).collect(Collectors.toList()));
Map<String, Tag> frontTextTag = new HashMap<>();
frontTextTag.put("messages", messages);
values.put("front_text", new CompoundTag(frontTextTag));
}
return new CompoundTag(values);
}
@ -122,6 +136,7 @@ public class SignBlock extends BaseBlock {
throw new RuntimeException(String.format("'%s' tile entity expected", getNbtId()));
}
if (isLegacy()) {
t = values.get("Text1");
if (t instanceof StringTag) {
text[0] = ((StringTag) t).getValue();
@ -141,6 +156,14 @@ public class SignBlock extends BaseBlock {
if (t instanceof StringTag) {
text[3] = ((StringTag) t).getValue();
}
} else {
CompoundTag frontTextTag = (CompoundTag) values.get("front_text");
ListTag messagesTag = frontTextTag.getListTag("messages");
for (int i = 0; i < messagesTag.getValue().size(); i++) {
StringTag tag = (StringTag) messagesTag.getValue().get(i);
text[i] = tag.getValue();
}
}
}
}