Search in sources :

Example 36 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project LogisticsPipes by RS485.

the class DebugHelper method addNBTToTree.

private void addNBTToTree(NBTBase nbt, DefaultMutableTreeNode node) throws SecurityException, IllegalArgumentException {
    if (nbt == null) {
        return;
    }
    if (nbt instanceof NBTTagByte) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagByte");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagByte) nbt).getByte()));
        node.add(type);
    } else if (nbt instanceof NBTTagByteArray) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagByteArray");
        DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
        int i = 0;
        for (byte byt : ((NBTTagByteArray) nbt).getByteArray()) {
            content.add(new DefaultMutableTreeNode("[" + i + "]: " + byt));
            i++;
        }
        node.add(content);
        node.add(type);
    } else if (nbt instanceof NBTTagDouble) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagDouble");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagDouble) nbt).getDouble()));
        node.add(type);
    } else if (nbt instanceof NBTTagFloat) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagFloat");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagFloat) nbt).getFloat()));
        node.add(type);
    } else if (nbt instanceof NBTTagInt) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagInt");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagInt) nbt).getInt()));
        node.add(type);
    } else if (nbt instanceof NBTTagIntArray) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagIntArray");
        DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
        int i = 0;
        for (int byt : ((NBTTagIntArray) nbt).getIntArray()) {
            content.add(new DefaultMutableTreeNode("[" + i + "]: " + byt));
            i++;
        }
        type.add(content);
        node.add(type);
    } else if (nbt instanceof NBTTagList) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagList");
        DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
        int i = 0;
        for (NBTBase object : (NBTTagList) nbt) {
            DefaultMutableTreeNode nbtNode = new DefaultMutableTreeNode("[" + i + "]");
            addNBTToTree(object, nbtNode);
            content.add(nbtNode);
            i++;
        }
        type.add(content);
        node.add(type);
    } else if (nbt instanceof NBTTagCompound) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagCompound");
        DefaultMutableTreeNode content = new DefaultMutableTreeNode("Data");
        for (String key : ((NBTTagCompound) nbt).getKeySet()) {
            NBTBase value = ((NBTTagCompound) nbt).getTag(key);
            DefaultMutableTreeNode nbtNode = new DefaultMutableTreeNode(key);
            addNBTToTree(value, nbtNode);
            content.add(nbtNode);
        }
        type.add(content);
        node.add(type);
    } else if (nbt instanceof NBTTagLong) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagLong");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagLong) nbt).getLong()));
        node.add(type);
    } else if (nbt instanceof NBTTagShort) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagShort");
        type.add(new DefaultMutableTreeNode("Data: " + ((NBTTagShort) nbt).getShort()));
        node.add(type);
    } else if (nbt instanceof NBTTagString) {
        DefaultMutableTreeNode type = new DefaultMutableTreeNode("NBTTagString");
        type.add(new DefaultMutableTreeNode("Data: '" + ((NBTTagString) nbt).getString() + "'"));
        node.add(type);
    } else {
        throw new UnsupportedOperationException("Unsupported NBTBase of type:" + nbt.getClass().getName());
    }
}
Also used : NBTTagFloat(net.minecraft.nbt.NBTTagFloat) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) NBTTagInt(net.minecraft.nbt.NBTTagInt) NBTTagByte(net.minecraft.nbt.NBTTagByte) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray) NBTTagList(net.minecraft.nbt.NBTTagList) NBTBase(net.minecraft.nbt.NBTBase) NBTTagShort(net.minecraft.nbt.NBTTagShort) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagByteArray(net.minecraft.nbt.NBTTagByteArray) NBTTagDouble(net.minecraft.nbt.NBTTagDouble) NBTTagLong(net.minecraft.nbt.NBTTagLong)

Example 37 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project LogisticsPipes by RS485.

the class GuiProgramCompiler method drawGuiContainerBackgroundLayer.

@Override
protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {
    GuiGraphics.drawGuiBackGround(mc, guiLeft, guiTop, right, bottom, zLevel, true);
    GuiGraphics.drawPlayerInventoryBackground(mc, guiLeft + 10, guiTop + 105);
    GuiGraphics.drawSlotDiskBackground(mc, guiLeft + 9, guiTop + 9);
    GuiGraphics.drawSlotProgrammerBackground(mc, guiLeft + 153, guiTop + 9);
    if (compiler.getCurrentTask() != null) {
        fontRenderer.drawString(TextUtil.translate("gui.compiler.processing"), guiLeft + 10, guiTop + 39, 0x000000);
        String name;
        Item item = Item.REGISTRY.getObject(compiler.getCurrentTask());
        if (item != null) {
            name = item.getUnlocalizedName() + ".name";
        } else {
            name = "gui.compiler." + compiler.getCurrentTask().toString().replace(':', '.');
        }
        String text = TextUtil.getTrimmedString(TextUtil.translate(name), 160, fontRenderer, "...");
        fontRenderer.drawString(text, guiLeft + 10, guiTop + 70, 0x000000);
        drawRect(guiLeft + 9, guiTop + 50, guiLeft + 171, guiTop + 66, Color.BLACK);
        drawRect(guiLeft + 10, guiTop + 51, guiLeft + 170, guiTop + 65, Color.WHITE);
        drawRect(guiLeft + 11, guiTop + 52, guiLeft + 11 + (int) (158 * compiler.getTaskProgress()), guiTop + 64, Color.GREEN);
        if (!compiler.isWasAbleToConsumePower()) {
            fontRenderer.drawString(TextUtil.translate("gui.compiler.nopower.1"), guiLeft + 68, guiTop + 10, 0x000000);
            fontRenderer.drawString(TextUtil.translate("gui.compiler.nopower.2"), guiLeft + 35, guiTop + 20, 0x000000);
        }
        buttonList.forEach(b -> b.visible = false);
    } else {
        buttonList.forEach(b -> b.visible = true);
        if (categoryTextList.getSize() == 0 && programTextList.getSize() != 0) {
            buttonList.stream().limit(3).forEach(b -> b.visible = false);
            programListLarge.renderGuiBackground(var2, var3);
        } else {
            buttonList.stream().limit(3).forEach(b -> b.visible = true);
            categoryList.renderGuiBackground(var2, var3);
            programList.renderGuiBackground(var2, var3);
        }
        search.drawTextBox();
        int selIndex = programList.getSelected();
        if (categoryTextList.getSize() == 0 && programTextList.getSize() != 0) {
            selIndex = programListLarge.getSelected();
        }
        if (selIndex != -1) {
            NBTTagList list = compiler.getNBTTagListForKey("compilerCategories");
            ResourceLocation sel = getProgramListForSelectionIndex(list).get(selIndex);
            NBTTagList listProgramms = compiler.getNBTTagListForKey("compilerPrograms");
            if (StreamSupport.stream(listProgramms.spliterator(), false).anyMatch(it -> new ResourceLocation(((NBTTagString) it).getString()).equals(sel))) {
                programmerButton.displayString = "Flash";
                programmerButton.enabled = !compiler.getInventory().getStackInSlot(1).isEmpty();
            } else {
                programmerButton.displayString = "Compile";
                programmerButton.enabled = true;
            }
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) Item(net.minecraft.item.Item) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 38 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project LogisticsPipes by RS485.

the class GuiProgramCompiler method actionPerformed.

@Override
protected void actionPerformed(GuiButton button) throws IOException {
    super.actionPerformed(button);
    switch(button.id) {
        case 0:
            categoryList.scrollDown();
            break;
        case 1:
            categoryList.scrollUp();
            break;
        case 2:
            if (categoryList.getSelected() != -1) {
                NBTTagList list = compiler.getNBTTagListForKey("compilerCategories");
                LogisticsProgramCompilerTileEntity.programByCategory.keySet().stream().filter(it -> StreamSupport.stream(list.spliterator(), false).noneMatch(nbtBase -> ((NBTTagString) nbtBase).getString().equals(it.toString()))).skip(categoryList.getSelected()).findFirst().ifPresent(it -> {
                    MainProxy.sendPacketToServer(PacketHandler.getPacket(CompilerTriggerTaskPacket.class).setCategory(it).setType("category").setTilePos(compiler));
                });
            }
            break;
        case 3:
            if (categoryTextList.getSize() == 0 && programTextList.getSize() != 0) {
                programListLarge.scrollDown();
            } else {
                programList.scrollDown();
            }
            break;
        case 4:
            if (categoryTextList.getSize() == 0 && programTextList.getSize() != 0) {
                programListLarge.scrollUp();
            } else {
                programList.scrollUp();
            }
            break;
        case 5:
            int selIndex = programList.getSelected();
            if (categoryTextList.getSize() == 0 && programTextList.getSize() != 0) {
                selIndex = programListLarge.getSelected();
            }
            if (selIndex != -1) {
                NBTTagList list = compiler.getNBTTagListForKey("compilerCategories");
                ResourceLocation sel = getProgramListForSelectionIndex(list).get(selIndex);
                NBTTagList listPrograms = compiler.getNBTTagListForKey("compilerPrograms");
                boolean flag = StreamSupport.stream(listPrograms.spliterator(), false).anyMatch(it -> new ResourceLocation(((NBTTagString) it).getString()).equals(sel));
                MainProxy.sendPacketToServer(PacketHandler.getPacket(CompilerTriggerTaskPacket.class).setCategory(sel).setType(flag ? "flash" : "program").setTilePos(compiler));
            }
            break;
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ItemLogisticsPipe(logisticspipes.items.ItemLogisticsPipe) DummyContainer(logisticspipes.utils.gui.DummyContainer) CompilerTriggerTaskPacket(logisticspipes.network.packets.block.CompilerTriggerTaskPacket) TextUtil(network.rs485.logisticspipes.util.TextUtil) ItemUpgrade(logisticspipes.items.ItemUpgrade) TextListDisplay(logisticspipes.utils.gui.TextListDisplay) Item(net.minecraft.item.Item) ItemModule(logisticspipes.items.ItemModule) Keyboard(org.lwjgl.input.Keyboard) MainProxy(logisticspipes.proxy.MainProxy) Color(logisticspipes.utils.Color) SmallGuiButton(logisticspipes.utils.gui.SmallGuiButton) NBTTagString(net.minecraft.nbt.NBTTagString) LogisticsBaseGuiScreen(logisticspipes.utils.gui.LogisticsBaseGuiScreen) LPItems(logisticspipes.LPItems) NBTTagList(net.minecraft.nbt.NBTTagList) StreamSupport(java.util.stream.StreamSupport) GuiButton(net.minecraft.client.gui.GuiButton) InputBar(logisticspipes.utils.gui.InputBar) IOException(java.io.IOException) LogisticsProgramCompilerTileEntity(logisticspipes.blocks.LogisticsProgramCompilerTileEntity) PacketHandler(logisticspipes.network.PacketHandler) Collectors(java.util.stream.Collectors) List(java.util.List) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ResourceLocation(net.minecraft.util.ResourceLocation) GuiGraphics(logisticspipes.utils.gui.GuiGraphics) Comparator(java.util.Comparator) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 39 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project LogisticsPipes by RS485.

the class LogisticsTileGenericSubMultiBlock method writeToNBT.

@Nonnull
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
    nbt = super.writeToNBT(nbt);
    NBTTagList nbtList = new NBTTagList();
    for (DoubleCoordinates pos : mainPipePos) {
        NBTTagCompound compound = new NBTTagCompound();
        pos.writeToNBT("MainPipePos_", compound);
        nbtList.appendTag(compound);
    }
    nbt.setTag("MainPipePosList", nbtList);
    NBTTagList nbtTypeList = new NBTTagList();
    for (CoreMultiBlockPipe.SubBlockTypeForShare type : subTypes) {
        if (type == null)
            continue;
        nbtTypeList.appendTag(new NBTTagString(type.name()));
    }
    nbt.setTag("SubTypeList", nbtTypeList);
    return nbt;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) Nonnull(javax.annotation.Nonnull)

Example 40 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project ImmersiveEngineering by BluSunrize.

the class ItemNBTHelper method setLore.

public static void setLore(ItemStack stack, String... lore) {
    NBTTagCompound displayTag = getTagCompound(stack, "display");
    NBTTagList list = new NBTTagList();
    for (String s : lore) list.appendTag(new NBTTagString(s));
    displayTag.setTag("Lore", list);
    setTagCompound(stack, "display", displayTag);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagString(net.minecraft.nbt.NBTTagString)

Aggregations

NBTTagString (net.minecraft.nbt.NBTTagString)98 NBTTagList (net.minecraft.nbt.NBTTagList)79 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)57 ItemStack (net.minecraft.item.ItemStack)16 NBTTagIntArray (net.minecraft.nbt.NBTTagIntArray)11 NBTTagByteArray (net.minecraft.nbt.NBTTagByteArray)10 NBTTagInt (net.minecraft.nbt.NBTTagInt)10 NBTBase (net.minecraft.nbt.NBTBase)9 NBTTagDouble (net.minecraft.nbt.NBTTagDouble)9 NBTTagFloat (net.minecraft.nbt.NBTTagFloat)9 NBTTagByte (net.minecraft.nbt.NBTTagByte)8 NBTTagLong (net.minecraft.nbt.NBTTagLong)8 ResourceLocation (net.minecraft.util.ResourceLocation)8 NBTTagShort (net.minecraft.nbt.NBTTagShort)7 List (java.util.List)6 Map (java.util.Map)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Item (net.minecraft.item.Item)4