From a6c462f298781a5e20df7da6ddd85b1c5014832b Mon Sep 17 00:00:00 2001 From: Michael Ritter Date: Sun, 14 Oct 2018 11:34:34 +0200 Subject: [PATCH] Fix aspect count being capped at 127 Due to how ItemStack reads/writes the count to NBT (byte value), Some ItemStacks with > 127 of an aspect will get handled wrongly. If the byte representing the count in NBT was negative, then ThaumicJEI didn't display those at all, due to ItemStack#isEmpty() being true. If the byte count was > 0, then it was just a wrong number. This Commit allows for up to Short.MAX_VALUE (32 767) aspects to be still representable, by manually overriding the NBT compound to use item count as short type. I think that this number should be high enough for any (modded) item, but it could be bumped up to use integer count instead, just to be sure. This change will only work for newly generated aspect json files. Old, pre-existing ones will still behave the way they did previously. Fixes #14 --- .../com/buuz135/thaumicjei/ThaumcraftJEIPlugin.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/buuz135/thaumicjei/ThaumcraftJEIPlugin.java b/src/main/java/com/buuz135/thaumicjei/ThaumcraftJEIPlugin.java index 971201c..dc2cf75 100644 --- a/src/main/java/com/buuz135/thaumicjei/ThaumcraftJEIPlugin.java +++ b/src/main/java/com/buuz135/thaumicjei/ThaumcraftJEIPlugin.java @@ -42,6 +42,7 @@ import net.minecraft.item.crafting.CraftingManager; import net.minecraft.nbt.JsonToNBT; import net.minecraft.nbt.NBTException; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; import thaumcraft.api.ThaumcraftApi; import thaumcraft.api.aspects.Aspect; @@ -144,7 +145,11 @@ public void register(IModRegistry registry) { e.printStackTrace(); } return null; - }).filter(Objects::nonNull).map(compound -> new ItemStack(compound)).filter(stack -> !stack.isEmpty()).sorted(Comparator.comparing(ItemStack::getCount).reversed()).collect(Collectors.toList()); + }).filter(Objects::nonNull).map(compound -> { + ItemStack itemStack = new ItemStack(compound); + itemStack.setCount(compound.getShort("Count")); + return itemStack; + }).filter(stack -> !stack.isEmpty()).sorted(Comparator.comparing(ItemStack::getCount).reversed()).collect(Collectors.toList()); int start = 0; while (start < items.size()) { wrappers.add(new AspectFromItemStackCategory.AspectFromItemStackWrapper(new AspectList().add(aspect, 1), items.subList(start, Math.min(start + 36, items.size())))); @@ -204,7 +209,9 @@ public void createAspectsFile(Collection items) { ItemStack clone = stack.copy(); clone.setCount(list.getAmount(aspect)); AspectCache cache = aspectCacheHashMap.getOrDefault(aspect, new AspectCache(aspect.getTag())); - cache.items.add(clone.serializeNBT().toString()); + NBTTagCompound nbtTagCompound = clone.serializeNBT(); + nbtTagCompound.setShort("Count", (short) clone.getCount()); + cache.items.add(nbtTagCompound.toString()); aspectCacheHashMap.put(aspect, cache); } }