Java Code Examples for com.github.steveice10.opennbt.tag.builtin.StringTag#setValue()

The following examples show how to use com.github.steveice10.opennbt.tag.builtin.StringTag#setValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemRewriter.java    From ViaVersion with MIT License 6 votes vote down vote up
public static void rewriteBookToServer(Item item) {
    int id = item.getIdentifier();
    if (id != 387) {
        return;
    }
    CompoundTag tag = item.getTag();
    ListTag pages = tag.get("pages");
    if (pages == null) { // is this even possible?
        return;
    }
    for (int i = 0; i < pages.size(); i++) {
        Tag pageTag = pages.get(i);
        if (!(pageTag instanceof StringTag)) {
            continue;
        }
        StringTag stag = (StringTag) pageTag;
        String value = stag.getValue();
        if (value.replaceAll(" ", "").isEmpty()) {
            value = "\"" + fixBookSpaceChars(value) + "\"";
        } else {
            value = fixBookSpaceChars(value);
        }
        stag.setValue(value);
    }
}
 
Example 2
Source File: EntityIdRewriter.java    From ViaVersion with MIT License 5 votes vote down vote up
public static void toClient(CompoundTag tag, boolean backwards) {
    Tag idTag = tag.get("id");
    if (idTag instanceof StringTag) {
        StringTag id = (StringTag) idTag;
        String newName = backwards ? oldToNewNames.inverse().get(id.getValue()) : oldToNewNames.get(id.getValue());
        if (newName != null) {
            id.setValue(newName);
        }
    }
}
 
Example 3
Source File: EntityIdRewriter.java    From ViaVersion with MIT License 5 votes vote down vote up
public static void toServerItem(Item item, boolean backwards) {
    if (!hasEntityTag(item)) return;

    CompoundTag entityTag = item.getTag().get("EntityTag");
    Tag idTag = entityTag.get("id");
    if (idTag instanceof StringTag) {
        StringTag id = (StringTag) idTag;
        String newName = backwards ? oldToNewNames.get(id.getValue()) : oldToNewNames.inverse().get(id.getValue());
        if (newName != null) {
            id.setValue(newName);
        }
    }
}
 
Example 4
Source File: SpawnerHandler.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public int transform(UserConnection user, CompoundTag tag) {
    if (tag.contains("SpawnData") && tag.get("SpawnData") instanceof CompoundTag) {
        CompoundTag data = tag.get("SpawnData");
        if (data.contains("id") && data.get("id") instanceof StringTag) {
            StringTag s = data.get("id");
            s.setValue(EntityNameRewriter.rewrite(s.getValue()));
        }

    }

    // Always return -1 because the block is still the same id
    return -1;
}
 
Example 5
Source File: ItemRewriter_1_11_TO_1_10.java    From ChatItem with GNU General Public License v3.0 5 votes vote down vote up
static void toClient(Item item) {
    if (hasEntityTag(item)) {
        CompoundTag entityTag = item.getTag().get("EntityTag");
        if (entityTag.get("id") instanceof StringTag) {
            StringTag id = entityTag.get("id");
            if (oldToNewNames.containsKey(id.getValue())) {
                id.setValue(oldToNewNames.get(id.getValue()));
            }
        }
    }
}
 
Example 6
Source File: ItemRewriter_1_11_TO_1_10.java    From ChatItem with GNU General Public License v3.0 5 votes vote down vote up
static void reverseToClient(Item item) {
    if (hasEntityTag(item)) {
        CompoundTag entityTag = item.getTag().get("EntityTag");
        if (entityTag.get("id") instanceof StringTag) {
            StringTag id = entityTag.get("id");
            if (oldToNewNames.containsKey(id.getValue())) {
                id.setValue(oldToNewNames.get(id.getValue()));
            }
        }
    }
}