Search in sources :

Example 6 with StringNBT

use of net.minecraft.nbt.StringNBT in project Enigmatic-Legacy by Aizistral-Studios.

the class OblivionStoneCombineRecipe method getCraftingResult.

@Override
public ItemStack getCraftingResult(CraftingInventory inv) {
    List<ItemStack> stackList = new ArrayList<ItemStack>();
    ItemStack voidStone = null;
    for (int i = 0; i < inv.getSizeInventory(); i++) {
        ItemStack checkedItemStack = inv.getStackInSlot(i);
        if (!checkedItemStack.isEmpty()) {
            if (checkedItemStack.getItem() == EnigmaticLegacy.oblivionStone) {
                if (voidStone == null)
                    voidStone = checkedItemStack;
                else
                    return ItemStack.EMPTY;
            } else {
                stackList.add(checkedItemStack);
            }
        }
    }
    if (voidStone != null & stackList.size() == 1) {
        ItemStack savedStack = stackList.get(0).copy();
        CompoundNBT nbt = voidStone.getOrCreateTag();
        ListNBT arr = nbt.getList("SupersolidID", 8);
        int counter = 0;
        if (arr.size() >= ConfigHandler.OBLIVION_STONE_HARDCAP.getValue())
            return null;
        for (INBT s_uncast : arr) {
            counter++;
            String s = ((StringNBT) s_uncast).getString();
            if (s.equals(ForgeRegistries.ITEMS.getKey(savedStack.getItem()).toString()))
                return ItemStack.EMPTY;
        }
        ListNBT arrCopy = arr.copy();
        CompoundNBT nbtCopy = nbt.copy();
        arrCopy.add(new StringNBT(ForgeRegistries.ITEMS.getKey(savedStack.getItem()).toString()));
        nbtCopy.put("SupersolidID", arrCopy);
        ItemStack returnedStack = voidStone.copy();
        returnedStack.setTag(nbtCopy);
        return returnedStack;
    } else if (voidStone != null & stackList.size() == 0) {
        ItemStack returnedStack = new ItemStack(EnigmaticLegacy.oblivionStone, 1);
        returnedStack.setTag(voidStone.getOrCreateTag().copy());
        returnedStack.removeChildTag("SupersolidID");
        return returnedStack;
    } else
        return ItemStack.EMPTY;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) INBT(net.minecraft.nbt.INBT) StringNBT(net.minecraft.nbt.StringNBT) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 7 with StringNBT

use of net.minecraft.nbt.StringNBT in project Enigmatic-Legacy by Aizistral-Studios.

the class ItemLoreHelper method setLastLoreString.

public static ItemStack setLastLoreString(ItemStack stack, String string) {
    CompoundNBT nbt = stack.getOrCreateChildTag("display");
    ListNBT loreList = nbt.getList("Lore", 8);
    if (loreList.size() > 0)
        loreList.set(loreList.size() - 1, new StringNBT(ITextComponent.Serializer.toJson(new StringTextComponent(string))));
    else
        loreList.add(new StringNBT(ITextComponent.Serializer.toJson(new StringTextComponent(string))));
    nbt.put("Lore", loreList);
    return stack;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) StringNBT(net.minecraft.nbt.StringNBT) StringTextComponent(net.minecraft.util.text.StringTextComponent)

Example 8 with StringNBT

use of net.minecraft.nbt.StringNBT in project Enigmatic-Legacy by Aizistral-Studios.

the class ItemLoreHelper method mergeDisplayData.

public static ItemStack mergeDisplayData(ItemStack from, ItemStack to) {
    CompoundNBT nbt = from.getOrCreateChildTag("display");
    ListNBT loreList = nbt.getList("Lore", 8).size() > 0 ? nbt.getList("Lore", 8) : to.getOrCreateChildTag("display").getList("Lore", 8);
    StringNBT displayName = nbt.getString("Name").length() > 0 ? new StringNBT(nbt.getString("Name")) : new StringNBT(to.getOrCreateChildTag("display").getString("Name"));
    CompoundNBT mergedData = new CompoundNBT();
    mergedData.put("Lore", loreList.copy());
    mergedData.put("Name", displayName.copy());
    to.getOrCreateTag().put("display", mergedData);
    return to;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) StringNBT(net.minecraft.nbt.StringNBT)

Example 9 with StringNBT

use of net.minecraft.nbt.StringNBT in project Enigmatic-Legacy by Aizistral-Studios.

the class OblivionStone method consumeStuff.

public static void consumeStuff(PlayerEntity player, ListNBT list, int mode) {
    HashMap<Integer, ItemStack> stackMap = new HashMap<Integer, ItemStack>();
    int cycleCounter = 0;
    int filledStacks = 0;
    for (int slot = 0; slot < player.inventory.mainInventory.size(); slot++) {
        if (!player.inventory.mainInventory.get(slot).isEmpty()) {
            filledStacks += 1;
            if (player.inventory.mainInventory.get(slot).getItem() != EnigmaticLegacy.oblivionStone)
                stackMap.put(slot, player.inventory.mainInventory.get(slot));
        }
    }
    if (stackMap.size() == 0)
        return;
    if (mode == 0) {
        for (INBT sID : list) {
            String str = ((StringNBT) sID).getString();
            for (int slot : stackMap.keySet()) {
                if (stackMap.get(slot).getItem() == ForgeRegistries.ITEMS.getValue(new ResourceLocation(str)))
                    player.inventory.setInventorySlotContents(slot, ItemStack.EMPTY);
            }
            cycleCounter++;
        }
    } else if (mode == 1) {
        for (INBT sID : list) {
            String str = ((StringNBT) sID).getString();
            HashMap<Integer, ItemStack> localStackMap = new HashMap<Integer, ItemStack>(stackMap);
            Multimap<Integer, Integer> stackSizeMultimap = ArrayListMultimap.create();
            for (int slot : stackMap.keySet()) {
                if (stackMap.get(slot).getItem() != ForgeRegistries.ITEMS.getValue(new ResourceLocation(str)))
                    localStackMap.remove(slot);
            }
            for (int slot : localStackMap.keySet()) {
                stackSizeMultimap.put(localStackMap.get(slot).getCount(), slot);
            }
            while (localStackMap.size() > (player.inventory.offHandInventory.get(0).getItem() == ForgeRegistries.ITEMS.getValue(new ResourceLocation(str)) ? 0 : 1)) {
                int smallestStackSize = Collections.min(stackSizeMultimap.keySet());
                Collection<Integer> smallestStacks = stackSizeMultimap.get(smallestStackSize);
                int slotWithSmallestStack = Collections.max(smallestStacks);
                player.inventory.setInventorySlotContents(slotWithSmallestStack, ItemStack.EMPTY);
                stackSizeMultimap.remove(smallestStackSize, slotWithSmallestStack);
                localStackMap.remove(slotWithSmallestStack);
            }
            cycleCounter++;
        }
    } else if (mode == 2) {
        if (filledStacks >= player.inventory.mainInventory.size()) {
            for (INBT sID : list) {
                String str = ((StringNBT) sID).getString();
                HashMap<Integer, ItemStack> localStackMap = new HashMap<Integer, ItemStack>(stackMap);
                Multimap<Integer, Integer> stackSizeMultimap = ArrayListMultimap.create();
                for (int slot : stackMap.keySet()) {
                    if (stackMap.get(slot).getItem() != ForgeRegistries.ITEMS.getValue(new ResourceLocation(str)))
                        localStackMap.remove(slot);
                }
                for (int slot : localStackMap.keySet()) {
                    stackSizeMultimap.put(localStackMap.get(slot).getCount(), slot);
                }
                if (localStackMap.size() > 0) {
                    int smallestStackSize = Collections.min(stackSizeMultimap.keySet());
                    Collection<Integer> smallestStacks = stackSizeMultimap.get(smallestStackSize);
                    int slotWithSmallestStack = Collections.max(smallestStacks);
                    player.inventory.setInventorySlotContents(slotWithSmallestStack, ItemStack.EMPTY);
                    return;
                }
                cycleCounter++;
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) StringNBT(net.minecraft.nbt.StringNBT) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Multimap(com.google.common.collect.Multimap) INBT(net.minecraft.nbt.INBT) ResourceLocation(net.minecraft.util.ResourceLocation) Collection(java.util.Collection) ItemStack(net.minecraft.item.ItemStack)

Example 10 with StringNBT

use of net.minecraft.nbt.StringNBT in project WarDance by Jackiecrazy.

the class SkillCapability method read.

@Override
public void read(CompoundNBT from) {
    if (!from.getBoolean("fast")) {
        data.clear();
        index = from.getInt("holster");
        // it's the easy way out...
        gatedSkills = from.getBoolean("gamerule");
        Skill[] als = new Skill[10];
        for (int a = 0; a < als.length; a++) if (from.contains("equippedSkill" + a))
            als[a] = (Skill.getSkill(from.getString("equippedSkill" + a)));
        // if (from.getBoolean("skillListDirty")) {
        skillList.clear();
        if (from.contains("randomList", Constants.NBT.TAG_LIST)) {
            ListNBT list = from.getList("randomList", Constants.NBT.TAG_STRING);
            for (Object s : list.toArray()) {
                if (s instanceof StringNBT && Skill.getSkill(((StringNBT) s).getAsString()) != null)
                    skillList.add(Skill.getSkill(((StringNBT) s).getAsString()));
            }
        }
        // }
        equippedSkill.clear();
        equippedSkill.addAll(Arrays.asList(als));
    }
    if (from.contains("skillData", 9)) {
        ListNBT listnbt = from.getList("skillData", 10);
        for (int i = 0; i < listnbt.size(); ++i) {
            CompoundNBT compoundnbt = listnbt.getCompound(i);
            SkillData data = SkillData.read(compoundnbt);
            if (data != null) {
                this.data.put(data.getSkill(), data);
            }
        }
    }
}
Also used : Skill(jackiecrazy.wardance.skill.Skill) ListNBT(net.minecraft.nbt.ListNBT) SkillData(jackiecrazy.wardance.skill.SkillData) CompoundNBT(net.minecraft.nbt.CompoundNBT) StringNBT(net.minecraft.nbt.StringNBT)

Aggregations

StringNBT (net.minecraft.nbt.StringNBT)12 CompoundNBT (net.minecraft.nbt.CompoundNBT)9 ListNBT (net.minecraft.nbt.ListNBT)9 ItemStack (net.minecraft.item.ItemStack)5 INBT (net.minecraft.nbt.INBT)4 ArrayList (java.util.ArrayList)3 StringTextComponent (net.minecraft.util.text.StringTextComponent)3 HashMap (java.util.HashMap)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 ServerWorld (net.minecraft.world.server.ServerWorld)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 Multimap (com.google.common.collect.Multimap)1 StringReader (com.mojang.brigadier.StringReader)1 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)1 JigsawType (de.industria.blocks.BlockJigsaw.JigsawType)1 JigsawTemplateProcessor (de.industria.structureprocessor.JigsawTemplateProcessor)1 JigsawReplacement (de.industria.structureprocessor.JigsawTemplateProcessor.JigsawReplacement)1 Skill (jackiecrazy.wardance.skill.Skill)1 SkillData (jackiecrazy.wardance.skill.SkillData)1 BufferedInputStream (java.io.BufferedInputStream)1