Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.15.2] GlobalLootModifier not working
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
Sinhika

[1.15.2] GlobalLootModifier not working

By Sinhika, April 6, 2020 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Sinhika    7

Sinhika

Sinhika    7

  • Stone Miner
  • Sinhika
  • Members
  • 7
  • 68 posts
Posted April 6, 2020 (edited)

After explanations from Draco18s (which, with his permission, I have documented for future use here: How to use Global Loot Modifiers ), I have tried to implement a loot_modifier that looks for the modded shears items defined in my SimpleOres mod, and then regenerates the loot table as if they were silk touch items (or real minecraft:shears, I have tried both). The goal is to implement modded shears in a other-mod-friendly fashion; overriding vanilla loot tables, the only way I was able to do it previously, is extremely unfriendly to other mods.

 

The mod source code in question is here: https://github.com/Sinhika/SimpleOres2

The loot modifier stuff is in https://github.com/Sinhika/SimpleOres2/blob/1.15/src/main/java/mod/alexndr/simpleores/helpers/SimpleOresLootModifiers.java

(Don't want to clutter up this post with lots of source code).

It is registered (along with everything else) in https://github.com/Sinhika/SimpleOres2/blob/1.15/src/main/java/mod/alexndr/simpleores/ModEventSubscriber.java

 

I've cut down the loot_modifier/mod_shears_harvest.json to a minimal test case, like so:

{
	"conditions": [
		{
			"condition": "minecraft:match_tool",
			"predicate": {
				"item": "simpleores:copper_shears"
			}
		}
	]
}

Based on the logs, or lack thereof, the function is being registered, but isn't being called when it ought to be.

Can anyone see any reason why, when I whack a leaf block with the copper shears, the loot modifier function isn't being called?

Edited April 6, 2020 by Sinhika
line breaks messed up looks
  • Quote

Stuff I maintain: https://minecraft.curseforge.com/members/sinhika/projects

Repositories: https://github.com/Sinhika?tab=repositories

Share this post


Link to post
Share on other sites

Draco18s    2401

Draco18s

Draco18s    2401

  • Reality Controller
  • Draco18s
  • Members
  • 2401
  • 15919 posts
Posted April 6, 2020 (edited)

Your code looks fine, my guess is that the tool predicate is returning false. Ie. that the item you're using doesn't match "simpleores:copper_shears"

 

Double check your registry names.

 

Scratch that, this file is in the wrong folder:

https://github.com/Sinhika/SimpleOres2/blob/1.15/src/main/resources/data/forge/global_loot_modifiers/global_loot_modifiers.json

Should be forge/loot_modifiers not forge/global_loot_modifiers.

Edited April 6, 2020 by Draco18s
  • Thanks 1
  • Quote

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.

Share this post


Link to post
Share on other sites

Sinhika    7

Sinhika

Sinhika    7

  • Stone Miner
  • Sinhika
  • Members
  • 7
  • 68 posts
Posted April 6, 2020

That does appear to have been the problem! Going on to test with some further refinements. Thank you.

 

  • Quote

Stuff I maintain: https://minecraft.curseforge.com/members/sinhika/projects

Repositories: https://github.com/Sinhika?tab=repositories

Share this post


Link to post
Share on other sites

Kalma    0

Kalma

Kalma    0

  • Tree Puncher
  • Kalma
  • Members
  • 0
  • 13 posts
Posted October 19, 2020

Hi Sinhika! Thanks a lot for taking the time to make this very useful tutorial (https://dragoness-e.dreamwidth.org/136561.html), there isn't much practical info you can find besides that!!!

 

What it is not clear to me is how to inject custom loot pools into existing vanilla chests tables using this method. Did you find out how to, or you have any "pointer" I can follow? I am working on 1.16.3 version now.

 

Thx again!

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7583

diesieben07

diesieben07    7583

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7583
  • 54911 posts
Posted October 19, 2020
57 minutes ago, Kalma said:

What it is not clear to me is how to inject custom loot pools into existing vanilla chests tables using this method. Did you find out how to, or you have any "pointer" I can follow? I am working on 1.16.3 version now.

That's not how this system works. If you want to add custom drops, you add them to the list of already generated ItemStacks in your global loot modifier.

  • Quote

Share this post


Link to post
Share on other sites

Kalma    0

Kalma

Kalma    0

  • Tree Puncher
  • Kalma
  • Members
  • 0
  • 13 posts
Posted October 19, 2020

Thx for your reply!

 

I guess you mean here:

{
  "conditions": [
    {
      "condition": "minecraft:match_tool",
      "predicate": {
        "item": "minecraft:shears"
      }
    },
    {
      "condition": "block_state_property",
      "block":"minecraft:wheat"
    }
  ],
  "seedItem": "minecraft:wheat_seeds",
  "numSeeds": 3,
  "replacement": "minecraft:wheat"
}

I can see there is a "replacement" part which might be the key part (right?), but I don't want to replace it, I would like to add custom items to the vanilla chests loots without replacing it.

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7583

diesieben07

diesieben07    7583

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7583
  • 54911 posts
Posted October 19, 2020

That is not the JSON for a global loot modifier. the JSON structure for global loot modifiers depends mostly on your own implementation (that's why you implement GlobalLootModifierSerializer).

  • Quote

Share this post


Link to post
Share on other sites

Kalma    0

Kalma

Kalma    0

  • Tree Puncher
  • Kalma
  • Members
  • 0
  • 13 posts
Posted October 19, 2020

Thanks again!

 

I see... may be you mean here? 

 

@Nonnull
    @Override
    public List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) {
        //
        // Additional conditions can be checked, though as much as possible should be parameterized via JSON data.
        // It is better to write a new ILootCondition implementation than to do things here.
        //
        int numSeeds = 0;
        for(ItemStack stack : generatedLoot) {
            if(stack.getItem() == itemToCheck)
                numSeeds+=stack.getCount();
        }
        if(numSeeds >= numSeedsToConvert) {
            generatedLoot.removeIf(x -> x.getItem() == itemToCheck);
            generatedLoot.add(new ItemStack(itemReward, (numSeeds/numSeedsToConvert)));
            numSeeds = numSeeds%numSeedsToConvert;
            if(numSeeds > 0)
                generatedLoot.add(new ItemStack(itemToCheck, numSeeds));
        }
        return generatedLoot;
    }

If so, where can I find some info about how to use all this stuff, specially adding or injecting custom loots into existing ones? There isn't anything similar I can search in vanilla classes as far as I know (if there is, sorry, I couldn't find it)

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7583

diesieben07

diesieben07    7583

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7583
  • 54911 posts
Posted October 19, 2020

If you want to add stuff, add it to the list. Not sure if it could be any simpler.

  • Quote

Share this post


Link to post
Share on other sites

Kalma    0

Kalma

Kalma    0

  • Tree Puncher
  • Kalma
  • Members
  • 0
  • 13 posts
Posted October 19, 2020

Still not totally clear, sorry, but I think I have a point to start on. I will make some additional tests to try to figure out the solution or make the questions better ! 

 

Thanks again!

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2401

Draco18s

Draco18s    2401

  • Reality Controller
  • Draco18s
  • Members
  • 2401
  • 15919 posts
Posted October 19, 2020

See these lines?

3 hours ago, Kalma said:

generatedLoot.add(new ItemStack(itemToCheck, numSeeds));

3 hours ago, Kalma said:

generatedLoot.add(new ItemStack(itemReward, (numSeeds/numSeedsToConvert)));

That's how you add stuff.

The items and amounts in question are initialized by values stored in the json:

3 hours ago, Kalma said:

"seedItem": "minecraft:wheat_seeds",

"numSeeds": 3,

"replacement": "minecraft:wheat"

 

  • Quote

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.

Share this post


Link to post
Share on other sites

Kalma    0

Kalma

Kalma    0

  • Tree Puncher
  • Kalma
  • Members
  • 0
  • 13 posts
Posted October 19, 2020

Understood. Much clear to me now. Thanks a lot!!!

 

(I had to port my mod to 1.16.3 from 1.14.4 since my last question regarding this very same issue... it is worth anyway).

  • Quote

Share this post


Link to post
Share on other sites

Kalma    0

Kalma

Kalma    0

  • Tree Puncher
  • Kalma
  • Members
  • 0
  • 13 posts
Posted October 21, 2020

Hi again! I have been searching and testing a lot. I think I have everything in place (global_loot_modifier.json file, my custom .json file, the class which extends LootModifier class, and the registry stuff). What I still don't get to know is how to add my custom items to the vanilla chests.

 

I guess it is something related to the "conditions" or "type" part of my custom loot_modifier.json, right? I have tried to find out the right option, and I think it can be related to "table_bonus" (though inside the class seems to be related to enchantments) or "reference"...  but I am not able to find the "predicate" or whatever is needed to "hook" my items to the chests loot ... Am I missing anything?

 

My global_loot_modifier.json:

{
  "replace": false,
  "entries": [
    "lazybuilder:chests_lazy_builder"
  ]
}

My custom loot_modifier.json

 {
  "type": "lazybuilder:chests_lazy_builder",
  "conditions": [
    {
      "condition": "WHAT SHOULD GO HERE???: e.g. reference???",
      "name":"AND HERE?: e.g. minecraft:chests???"
    }
  ],
  "items": [
    {
      "item": "lazybuilder:start_block",
      "weight": 20
    },
    {
      "item": "lazybuilder:mid_block",
      "weight": 30
    },
    {
      "item": "lazybuilder:end_block",
      "weight": 20
    },
    {
      "item": "lazybuilder:copy_paste_block",
      "weight": 10
    }
  ]
}

My LootModifier class

public class ChestLootModifier extends LootModifier {
	
	@SuppressWarnings("unused")
	private static final Logger LOGGER = LogManager.getLogger();

    private final List<Item> itemToAdd;
    private final List<Integer> weights;
	private final String addTo = "minecraft:chests";
    ILootCondition[] conditions;
    
    public ChestLootModifier(ILootCondition[] conditionsIn, List<Item> itemLoot, List<Integer> itemWeights) {
        super(conditionsIn);
        itemToAdd = itemLoot;
        weights = itemWeights;
    }

    @Nonnull
    @Override
    public List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) {
    	
    	if (false) { // How do I hook to chests loot to add my stuff???
        	for (int i = 0; i < itemToAdd.size() && i < weights.size(); ++i) {
        		int randValue = new Random().nextInt(101);
        		int count = 0;
        		if (randValue <= weights.get(i)) {
        			count = 1;
        		}
        		generatedLoot.add(new ItemStack(itemToAdd.get(i), count));
        	}
    	}
        return generatedLoot;
    }
    
    public static class Serializer extends GlobalLootModifierSerializer<ChestLootModifier> {

        @Override
        public ChestLootModifier read(ResourceLocation name, JsonObject object, ILootCondition[] conditionsIn) {
        	
        	List<Item> blockStack = new ArrayList<Item>();
            List<Integer> weightList = new ArrayList<Integer>();
            
        	for (JsonElement item : JSONUtils.getJsonArray(object, "items")) {
        		blockStack.add(ForgeRegistries.ITEMS.getValue(new ResourceLocation(JSONUtils.getString(item.getAsJsonObject(), "item"))));
        		weightList.add(JSONUtils.getInt(item.getAsJsonObject(), "weight"));
        	}
        	return new ChestLootModifier(conditionsIn, blockStack, weightList);
        }

		@Override
		public JsonObject write(ChestLootModifier instance) {
			// TODO Auto-generated method stub
			return null;
		}
    }
}

 

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7583

diesieben07

diesieben07    7583

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7583
  • 54911 posts
Posted October 21, 2020
4 minutes ago, Kalma said:

My global_loot_modifier.json:

It needs to be called global_loot_modifiers.json.

 

What you seem to want to achieve is to modify the loot in chests that have a specific loot table (e.g. simple_dungeon), right?

Unfortunately this is not possible from a loot modifier, specifically because LockableLootTileEntity sets it's lootTable to null before generating, so if you try to grab it and check it it will just be null.

  • Quote

Share this post


Link to post
Share on other sites

Kalma    0

Kalma

Kalma    0

  • Tree Puncher
  • Kalma
  • Members
  • 0
  • 13 posts
Posted October 21, 2020

HAHAHAHA! Well... I learned a lot on the way!

 

So, I should stick to the "old" method, right?

    public class onLootTableLoadListener {
		
	@SubscribeEvent
	    public void LootTablesLoad(final LootTableLoadEvent event) {
		
		String prefix = "minecraft:chests/";
		String name = event.getName().toString();
			
		// Test: /loot give @p loot minecraft:chests/pillager_outpost
		if (name.startsWith(prefix)) {
                event.getTable().addPool(LootPool.builder()
    						.addEntry(TableLootEntry.builder(new ResourceLocation(Refs.MODID, "chests/lazy_builder"))
    						.weight(1))
    						.bonusRolls(0, 1)
    						.name(Refs.MODID)
    						.build()
    			);
			}
		}
	}

 

Thank you anyway!

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7583

diesieben07

diesieben07    7583

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7583
  • 54911 posts
Posted October 21, 2020

I guess you have to. Someone should make a pull request to mitigate this situation.

  • Quote

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • DaemonUmbra
      Any good exploration mods for 1.16.3?

      By DaemonUmbra · Posted 1 minute ago

      Why limit yourself to 1.16.3? Especially since 1.16.5 just came out and fixes crash bugs that could be abused to render a server unusuable.
    • PotatoEz1
      Any good exploration mods for 1.16.3?

      By PotatoEz1 · Posted 13 minutes ago

      Does anybody know any cool mods for 1.16.3 that adds biomes and dungeons? Thanks!
    • XenoPyax
      GUI Button has weird image

      By XenoPyax · Posted 33 minutes ago

      SO I have the following code I've been looking through the gui of the Minecraft menus and replicated them but somehow my buttons don't seem to take the correct texture. Code: https://paste.md-5.net/figovuzufa.java Image:
    • Draco18s
      [1.16.4] setBlockState with out send update event.

      By Draco18s · Posted 37 minutes ago

      Still don't know why you added the 1 if you didn't want block updates.
    • DrakenXI
      [1.16.4] setBlockState with out send update event.

      By DrakenXI · Posted 51 minutes ago

      Thanks for your reply. You gave me another idea for a solution.   19 :  1 will cause a block update. 2 will send the change to clients. 16 will prevent neighbor reactions (e.g. fences connecting, observers pulsing). That what I found in Minecraft source for "setBlockState" Function. 🤨    
  • Topics

    • PotatoEz1
      1
      Any good exploration mods for 1.16.3?

      By PotatoEz1
      Started 13 minutes ago

    • XenoPyax
      0
      GUI Button has weird image

      By XenoPyax
      Started 33 minutes ago

    • DrakenXI
      3
      [1.16.4] setBlockState with out send update event.

      By DrakenXI
      Started 20 hours ago

    • Somonestolemyusername
      16
      [1.15.2] How Would I make a custom bow?

      By Somonestolemyusername
      Started Tuesday at 09:30 PM

    • Ipsissimus418
      2
      [1.16.4] WorldTickEvent Concurrent Access Exception

      By Ipsissimus418
      Started 4 hours ago

  • Who's Online (See full list)

    • DaemonUmbra
    • MetalMetagross
    • lawra771
    • PotatoEz1
    • MineModder2000
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.15.2] GlobalLootModifier not working
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community