Jump to content

[1.16.5] Global Loot Modifiers replace the drop table instead of supplement it


Recommended Posts

Posted (edited)

i wanted the blaze to still be able to drop rods but when i added this the blazes started only dropping what i typed in
how to fix it?

global_loot_modifiers.json

{
  "replace": false,
  "entries": [
    "cosrpg:blaze_rinkril"
  ]
}

blaze_rinkril.json

{
  "type": "cosrpg:blaze_rinkril",
  "conditions": [
    {
      "condition": "forge:loot_table_id",
      "loot_table_id": "minecraft:entities/blaze"
    }
  ],
  "addition": "cosrpg:rinkril"
}

 

Edited by auriny
  • auriny changed the title to [1.16.5] Global Loot Modifiers replace the drop table instead of supplement it
Posted
7 minutes ago, diesieben07 said:

Show your loot modifier code.

package com.auriny.cosrpg.events.loot;

import com.google.gson.JsonObject;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.LootContext;
import net.minecraft.loot.conditions.ILootCondition;
import net.minecraft.util.JSONUtils;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.loot.GlobalLootModifierSerializer;
import net.minecraftforge.common.loot.LootModifier;
import net.minecraftforge.registries.ForgeRegistries;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;


public class RinkrilAdditionModifier extends LootModifier {
    private Item addition;

    public RinkrilAdditionModifier(ILootCondition[] conditionsIn, Item addition) {
        super(conditionsIn);
        this.addition = addition;
    }

    @Nonnull
    @Override
    public List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) {
        List<ItemStack> stack = new ArrayList<ItemStack>();
        stack.add(new ItemStack(addition));
        return stack;
    }

    public static class Serializer extends GlobalLootModifierSerializer<RinkrilAdditionModifier> {
        @Override
        public RinkrilAdditionModifier read(ResourceLocation name, JsonObject object, ILootCondition[] conditionsIn) {
            Item addition = ForgeRegistries.ITEMS.getValue(new ResourceLocation(JSONUtils.getString(object, "addition")));
            return new RinkrilAdditionModifier(conditionsIn, addition);
        }

        @Override
        public JsonObject write(RinkrilAdditionModifier instance) {
            JsonObject json = makeConditions(instance.conditions);
            json.addProperty("addition", ForgeRegistries.ITEMS.getKey(instance.addition).toString());
            return json;
        }
    }
}

 

Posted
22 minutes ago, diesieben07 said:

You are entirely ignoring the already generated loot and just creating a new, empty list. What did you expect?

fixed, thank you

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.