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;
}
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;
}
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;
}
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++;
}
}
}
}
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);
}
}
}
}
Aggregations