Search in sources :

Example 16 with NBTBase

use of net.minecraft.nbt.NBTBase in project RFToolsDimensions by McJty.

the class RFToolsTools method convertNBTtoJson.

public static void convertNBTtoJson(StringBuffer buffer, NBTTagCompound tagCompound, int indent) {
    boolean first = true;
    for (Object o : tagCompound.getKeySet()) {
        if (!first) {
            buffer.append(",\n");
        }
        first = false;
        String key = (String) o;
        NBTBase tag = tagCompound.getTag(key);
        appendIndent(buffer, indent).append(key).append(':');
        if (tag instanceof NBTTagCompound) {
            NBTTagCompound compound = (NBTTagCompound) tag;
            buffer.append("{\n");
            convertNBTtoJson(buffer, compound, indent + 4);
            appendIndent(buffer, indent).append('}');
        } else if (tag instanceof NBTTagList) {
            NBTTagList list = (NBTTagList) tag;
            buffer.append("[\n");
            convertNBTtoJson(buffer, list, indent + 4);
            appendIndent(buffer, indent).append(']');
        } else {
            buffer.append(tag);
        }
    }
    if (!first) {
        buffer.append("\n");
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTBase(net.minecraft.nbt.NBTBase) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 17 with NBTBase

use of net.minecraft.nbt.NBTBase in project RecurrentComplex by Ivorforce.

the class TableDataSourceNBTTagCompound method cellForIndexInSegment.

@Override
public TableCell cellForIndexInSegment(GuiTable table, int index, int segment) {
    if (segment == 0) {
        TableCellButton load = new TableCellButton(null, "toString", "->", Collections.singletonList("Convert to String (slightly lossy)"), true);
        TableCellButton perform = new TableCellButton(null, "fromString", "O", Collections.singletonList("Load from String"), false);
        TableCellString cell = new TableCellString("tileEntityInfo", "");
        cell.addPropertyConsumer(val -> perform.setEnabled(WeightedBlockState.tryParse(val) != null));
        // FromGuiCommandBlock
        cell.setMaxStringLength(32500);
        load.addAction(() -> {
            cell.setPropertyValue(nbt.toString());
            perform.setEnabled(true);
        });
        perform.addAction(() -> {
            NBTTagCompound other = WeightedBlockState.tryParse(cell.getPropertyValue());
            if (other != null) {
                nbt.getKeySet().clear();
                other.getKeySet().forEach(s -> nbt.setTag(s, other.getTag(s)));
                resetSortedKeys();
                delegate.reloadData();
            }
        });
        TableCellMulti multi = new TableCellMulti(load, cell, perform);
        multi.setSize(0, 0.1f);
        multi.setSize(2, 0.1f);
        return new TitledCell("As String", multi);
    } else if (segment == 1 || segment == 3) {
        return new TableCellPresetAction(null, IntStream.range(0, 12).mapToObj((id) -> TableDataSourceNBT.addButton(id, n -> {
            nbt.setTag("", n);
            sortedKeys.removeIf(s -> s.equals(""));
            sortedKeys.add(segment == 1 ? 0 : sortedKeys.size(), "");
            delegate.reloadData();
        })).collect(Collectors.toList()));
    } else {
        String key = sortedKeys.get(index);
        String[] nextKey = new String[] { key };
        NBTBase cellNBT = nbt.getTag(key);
        TableCell nbtCell = TableDataSourceNBT.cell(cellNBT, delegate, navigator);
        TableCellString keyCell = new TableCellString(null, key);
        TableCellButton setKeyCell = new TableCellButton(null, "setKey", "O", Collections.singletonList("Set Key"), false);
        setKeyCell.addAction(() -> {
            sortedKeys.set(index, nextKey[0]);
            // If there was a previous entry
            sortedKeys.subList(index + 1, sortedKeys.size()).remove(nextKey[0]);
            sortedKeys.subList(0, index).remove(nextKey[0]);
            nbt.removeTag(key);
            nbt.setTag(nextKey[0], cellNBT);
            delegate.reloadData();
        });
        keyCell.addPropertyConsumer(value -> {
            nextKey[0] = value;
            setKeyCell.setEnabled(true);
        });
        TableCellButton deleteCell = new TableCellButton(null, null, TextFormatting.RED + "-");
        deleteCell.addAction(() -> {
            sortedKeys.remove(key);
            nbt.removeTag(key);
            delegate.reloadData();
        });
        TableCellMulti multi = new TableCellMulti(keyCell, setKeyCell, nbtCell, deleteCell);
        multi.setSize(1, 0.2f);
        multi.setSize(3, 0.2f);
        return multi;
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IntStream(java.util.stream.IntStream) WeightedBlockState(ivorius.reccomplex.world.gen.feature.structure.generic.WeightedBlockState) GuiTable(ivorius.reccomplex.gui.table.GuiTable) TableDataSourceSegmented(ivorius.reccomplex.gui.table.datasource.TableDataSourceSegmented) NBTBase(net.minecraft.nbt.NBTBase) TextFormatting(net.minecraft.util.text.TextFormatting) ivorius.reccomplex.gui.table.cell(ivorius.reccomplex.gui.table.cell) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) TableNavigator(ivorius.reccomplex.gui.table.TableNavigator) List(java.util.List) TableDelegate(ivorius.reccomplex.gui.table.TableDelegate) Nonnull(javax.annotation.Nonnull) Collections(java.util.Collections) NBTBase(net.minecraft.nbt.NBTBase) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 18 with NBTBase

use of net.minecraft.nbt.NBTBase in project Engine by VoltzEngine-Project.

the class EffectList method trigger.

@Override
public void trigger(World world, double x, double y, double z, double mx, double my, double mz, boolean endPoint, NBTTagCompound nbt) {
    for (IEffectData layer : layers) {
        NBTTagCompound usedNBT;
        if (nbt != null && !nbt.hasNoTags()) {
            usedNBT = (NBTTagCompound) nbt.copy();
            //Merges base NBT with server nbt
            if (this.getNbt() != null) {
                for (Object o : getNbt().func_150296_c()) {
                    if (o instanceof String) {
                        String key = (String) o;
                        NBTBase tag = getNbt().getTag(key);
                        if (tag != null) {
                            usedNBT.setTag(key, tag);
                        }
                    }
                }
            }
        } else if (this.getNbt() != null) {
            usedNBT = nbt;
        } else {
            usedNBT = new NBTTagCompound();
        }
        Pos renderOffset = this.renderOffset;
        if (renderOffset != Pos.zero && (usedNBT.hasKey("yaw") || usedNBT.hasKey("pitch"))) {
            float yaw = usedNBT.getFloat("yaw");
            float pitch = usedNBT.getFloat("pitch");
            angle.set(yaw, pitch, 0);
            renderOffset = (Pos) angle.transform(renderOffset);
        }
        layer.trigger(world, x + renderOffset.x(), y + renderOffset.y(), z + renderOffset.z(), mx, my, mz, endPoint, usedNBT);
    }
}
Also used : IEffectData(com.builtbroken.mc.client.json.imp.IEffectData) NBTBase(net.minecraft.nbt.NBTBase) Pos(com.builtbroken.mc.imp.transform.vector.Pos) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Aggregations

NBTBase (net.minecraft.nbt.NBTBase)18 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)15 NBTTagList (net.minecraft.nbt.NBTTagList)8 ItemStack (net.minecraft.item.ItemStack)6 NBTTagString (net.minecraft.nbt.NBTTagString)5 List (java.util.List)4 Map (java.util.Map)3 NBTTagIntArray (net.minecraft.nbt.NBTTagIntArray)3 Pos (com.builtbroken.mc.imp.transform.vector.Pos)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Nonnull (javax.annotation.Nonnull)2 NBTTagByte (net.minecraft.nbt.NBTTagByte)2 NBTTagByteArray (net.minecraft.nbt.NBTTagByteArray)2 NBTTagDouble (net.minecraft.nbt.NBTTagDouble)2 NBTTagFloat (net.minecraft.nbt.NBTTagFloat)2 NBTTagInt (net.minecraft.nbt.NBTTagInt)2 NBTTagLong (net.minecraft.nbt.NBTTagLong)2 NBTTagShort (net.minecraft.nbt.NBTTagShort)2 VisualEffectProvider (com.builtbroken.mc.client.effects.VisualEffectProvider)1