Traveler's Backpack

Traveler's Backpack

32M Downloads

Traveller's Backpacks breaks serialisation of loot tables it edits

Daomephsta opened this issue ยท 0 comments

commented

LootEntry serialisation is hardcoded using instanceof checks, so it's not possible to use non-vanilla loot entry types without breaking loot table serialisation. Loot table serialisation is used by users of mods like LootTweaker to inspect loot tables.
This function will achieve the same thing as this mod's LootEntryItemStack. I suggest using a quality of 0, as it is only relevant in vanilla fishing loot tables.

    private static final LootCondition[] NO_CONDITIONS = new LootCondition[0];
    private static final LootFunction[] NO_FUNCTIONS = new LootFunction[0];

    public static LootEntryItem createItemEntry(ItemStack stack, int weight, int quality, String entryName)
    {
        Collection<LootFunction> functions = new ArrayList<>(3);
        if (stack.hasTagCompound())
            functions.add(new SetNBT(NO_CONDITIONS, stack.getTagCompound()));
        if (stack.getCount() > 1)
            functions.add(new SetCount(NO_CONDITIONS, new RandomValueRange(stack.getCount())));
        if (stack.getMetadata() != 0)
        {
            functions.add(stack.isItemStackDamageable()
                // SetDamage takes a percentage, not a number
                ? new SetDamage(NO_CONDITIONS, new RandomValueRange((float) stack.getItemDamage() / (float) stack.getMaxDamage()))
                : new SetMetadata(NO_CONDITIONS, new RandomValueRange(stack.getMetadata())));
        }
        return new LootEntryItem(stack.getItem(), weight, quality, functions.toArray(NO_FUNCTIONS), NO_CONDITIONS, entryName);
    }