Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

How does one add items to vanilla mob loot tables with global loot modifiers? I already managed to make it work with blocks, but mobs don't seem to work.

Here's my code:

LootAdditionModifier:

public class LootAdditionModifier extends LootModifier {
	private final Item addition;

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

    @Nonnull
    @Override
    protected List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) {
        // generatedLoot is the loot that would be dropped, if we wouldn't add or replace
        // anything!
        generatedLoot.add(new ItemStack(addition, 1));
        return generatedLoot;
    }

    public static class Serializer extends GlobalLootModifierSerializer<LootAdditionModifier> {

        @Override
        public LootAdditionModifier read(ResourceLocation name, JsonObject object, ILootCondition[] conditionsIn) {
            Item addition = ForgeRegistries.ITEMS.getValue(
                    new ResourceLocation(JSONUtils.getString(object, "addition")));
            return new LootAdditionModifier(conditionsIn, addition);
        }

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

LootStructureAdditionModifier:

public class LootStructureAdditionModifier extends LootModifier{
	 private final Item addition;

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

	    @Nonnull
	    @Override
	    protected List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) {
	        // generatedLoot is the loot that would be dropped, if we wouldn't add or replace
	        // anything!
	        if(context.getRandom().nextFloat() > 1.0) {
	            generatedLoot.add(new ItemStack(addition, 1));
	        }
	        return generatedLoot;
	    }

	    public static class Serializer extends GlobalLootModifierSerializer<LootStructureAdditionModifier> {

	        @Override
	        public LootStructureAdditionModifier read(ResourceLocation name, JsonObject object, ILootCondition[] conditionsIn) {
	            Item addition = ForgeRegistries.ITEMS.getValue(
	                    new ResourceLocation(JSONUtils.getString(object, "addition")));
	            return new LootStructureAdditionModifier(conditionsIn, addition);
	        }

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

The global_loot_modifiers.json:

{
  "replace": false,
  "entries": [
    "mikesfancycontent:test"
  ]
}

And the test.json:

{
  "conditions": [
    {
      "condition": "minecraft:entity_properties",
      "entity": "this",
      "predicate": {
        "type": "minecraft:stray"
      }
    }
  ],
  "addition": "mikesfancycontent:frost_berries"
}

What do I have to change to make it work for mob drops. Thanks in advance.

this is not possible with GlobalLootModifiers, you can replace the LootTable of the Entity via a Datapack overwrite
wrong information, ignore this post please

Edited by Luis_ST

4 hours ago, ChonkoTheGreat said:
mikesfancycontent:test

This is not the registry name of your loot modifier serializser(s) is it?

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

3 hours ago, diesieben07 said:

What are you talking about?

just replacing the vanilla lootTable file via a Datapack, i mean data/minecraft/loot_tables/entities/entity_loot_table.json

They sure do, I made sure of it.
Kinda surprised it isn't part of the test mod that went along with it in the Forge repo source, but whatever.

I wrote it and tested it. So I know it works.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.