Jump to content

Recommended Posts

Posted (edited)

Hey,

 

I saw mineshaft chests loots are located in chests/abandoned_mineshaft.json.

How do I add chests loots ? Is there a way to keep minecraft's base JSON so my mod still works great with other mods ?

Edited by Dylem
Posted

LootTableLoadEvent. Uses my LootUtils class.

  • Like 1

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.

Posted
14 minutes ago, Dylem said:

Thanks ! Will try to write my own once I understand what you did. 

Essentially:

When a table is loaded and its the table I'm interested in modifying:

 - remove entries I don't want

 - add entries I do want

 

Entries though, are complicated. Two thirds of that code is merely having to rebuild the desired conditional parameters involved with the loot table entries or boilerplate to aid in such.

 

i.e. this is what the loot table for beef from a cow looks like (there's also a leather entry, so this is only half of the cow.json file inside assets.minecraft.loot_tables.entities):

 

        {
            "rolls": 1,
            "entries": [
                {
                    "type": "item",
                    "name": "minecraft:beef",
                    "weight": 1,
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 1,
                                "max": 3
                            }
                        },
                        {
                            "function": "furnace_smelt",
                            "conditions": [
                                {
                                    "condition": "entity_properties",
                                    "entity": "this",
                                    "properties": {
                                        "on_fire": true
                                    }
                                }
                            ]
                        },
                        {
                            "function": "looting_enchant",
                            "count": {
                                "min": 0,
                                "max": 1
                            }
                        }
                    ]
                }
            ]
        }

 

So when I override the quantities involved I've got to recreate all of that.  If you look at this section here, you'll see how that's handled. 318 removes the existing entry, 319 begins the declaration for the new entry. 322-326 handle the "furnace_smelt" functionality. 327-333 handles a custom function (my mod makes animals die of old age, and in such a case, they shouldn't drop any items on death). I did not include a replacement for the looting enchantment; I should go back and add that (an oversight on my part).

 

Fortunately, you're doing something a lot simpler. Downside, I don't know if my LootUtils has all of the features needed. I've only created the methods that do what I need to do. Looks like you would need a way to add an entry to an existing list of entries, assuming its possible.

  • Like 1

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.

Posted

If you want to override a vanilla loot table you can also make your own loot table (wich is a copy of the vanilla one + the items of your mod) and then in that event set your loot table as the table of the event. For example, i do this to override the vanilla mineshaft chest loot table. I create my own mineshaft chest loot table by doing this

public static ResourceLocation CHESTS_ABANDONED_MINESHAFT;
CHESTS_ABANDONED_MINESHAFT =  LootTableList.register(new ResourceLocation(MW.MODID, "abandoned_mineshaft"));


and i call this from the init method in main mod file.

This will assume that in your assets folder you have a folder called "loot_tables" and inside that folder you have the loot table you're looking for (in this case "abandoned_mineshaft"). That will be the replaced loot table (so the game will load this instead of the vanilla one). For example look at this loot table

{
    "pools": [
        {
            "name": "abandoned_mineshaft_1",
            "rolls": 1,
            "entries": [
                {
                    "type": "item",
                    "entryName": "golden_apple",
                    "name": "minecraft:golden_apple",
                    "weight": 20
                },
                {
                    "type": "item",
                    "entryName": "enchanted_golden_apple",
                    "name": "minecraft:golden_apple",
                    "weight": 1,
                    "functions": [
                        {
                            "function": "set_data",
                            "data": 1
                        }
                    ]
                },
                {
                    "type": "item",
                    "name": "minecraft:name_tag",
                    "weight": 30
                },
                {
                    "type": "item",
                    "name": "minecraft:book",
                    "weight": 10,
                    "functions": [
                        {
                            "function": "enchant_randomly"
                        }
                    ]
                },
                {
                    "type": "item",
                    "name": "minecraft:iron_pickaxe",
                    "weight": 5
                },
                {
                    "type": "item",
                    "name": "mw:ruby",
                    "weight": 20,
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 1,
                                "max": 4
                            }
                        }
                    ]
                },
                {
                    "type": "item",
                    "name": "mw:sapphire",
                    "weight": 20,
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 1,
                                "max": 4
                            }
                        }
                    ]
                },
                {
                    "type": "empty",
                    "weight": 5
                }
            ]
        },
        {
            "name": "abandoned_mineshaft_2",
            "rolls": {
                "min": 2,
                "max": 4
            },
            "entries": [
                {
                    "type": "item",
                    "name": "minecraft:iron_ingot",
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 1,
                                "max": 5
                            }
                        }
                    ],
                    "weight": 10
                },
                {
                    "type": "item",
                    "name": "minecraft:gold_ingot",
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 1,
                                "max": 3
                            }
                        }
                    ],
                    "weight": 5
                },
                {
                    "type": "item",
                    "name": "minecraft:redstone",
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 4,
                                "max": 9
                            }
                        }
                    ],
                    "weight": 5
                },
                {
                    "type": "item",
                    "name": "minecraft:dye",
                    "functions": [
                        {
                            "function": "set_data",
                            "data": 4
                        },
                        {
                            "function": "set_count",
                            "count": {
                                "min": 4,
                                "max": 9
                            }
                        }
                    ],
                    "weight": 5
                },
                {
                    "type": "item",
                    "name": "minecraft:diamond",
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 1,
                                "max": 2
                            }
                        }
                    ],
                    "weight": 3
                },
                {
                    "type": "item",
                    "name": "minecraft:coal",
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 3,
                                "max": 8
                            }
                        }
                    ],
                    "weight": 10
                },
                {
                    "type": "item",
                    "name": "minecraft:bread",
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 1,
                                "max": 3
                            }
                        }
                    ],
                    "weight": 15
                },
                {
                    "type": "item",
                    "name": "minecraft:melon_seeds",
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 2,
                                "max": 4
                            }
                        }
                    ],
                    "weight": 10
                },
                {
                    "type": "item",
                    "name": "minecraft:pumpkin_seeds",
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 2,
                                "max": 4
                            }
                        }
                    ],
                    "weight": 10
                },
                {
                    "type": "item",
                    "name": "minecraft:beetroot_seeds",
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 2,
                                "max": 4
                            }
                        }
                    ],
                    "weight": 10
                }
            ]
        },
        {
            "name": "abandoned_mineshaft_3",
            "rolls": 3,
            "entries": [
                {
                    "type": "item",
                    "name": "minecraft:rail",
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 4,
                                "max": 8
                            }
                        }
                    ],
                    "weight": 20
                },
                {
                    "type": "item",
                    "name": "minecraft:golden_rail",
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 1,
                                "max": 4
                            }
                        }
                    ],
                    "weight": 5
                },
                {
                    "type": "item",
                    "name": "minecraft:detector_rail",
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 1,
                                "max": 4
                            }
                        }
                    ],
                    "weight": 5
                },
                {
                    "type": "item",
                    "name": "minecraft:activator_rail",
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 1,
                                "max": 4
                            }
                        }
                    ],
                    "weight": 5
                },
                {
                    "type": "item",
                    "name": "minecraft:torch",
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 1,
                                "max": 16
                            }
                        }
                    ],
                    "weight": 15
                }
            ]
        }
    ]
}



This is the vanilla abandoned_mineshaft loot table plus some rolls for my mod items, so in game in mineshafts i can find mod items too in chests. Finally, to load this table instead of the vanilla one you'll have to catch the LootTableLoadEvent and set the table to your own table.

public void onLootTableLoad(LootTableLoadEvent event) {
        if(event.getName().equals(LootTableList.CHESTS_ABANDONED_MINESHAFT)) {
            event.setTable(event.getLootTableManager().getLootTableFromLocation(MWLootTables.CHESTS_ABANDONED_MINESHAFT));
        }
}



In game, when you'll open a mineshaft chest it will load your loot table (the one showed up) instead of the vanilla one and so yuour mod items will have a chance to be in that cehst. Hope this is clear :)

  • Like 1

Don't blame me if i always ask for your help. I just want to learn to be better :)

Posted (edited)

Thanks guys a lot, you were both very helpful. Made it, that wasn't that hard finally :)

Note : I put a random attribute so I don't override all minecraft loot tables and it's still compatible with other mods !

Edited by Dylem
Posted (edited)

Just adding a comment to say that I found a very easy way to do it.

Simply :

public static LootEntry entry = new LootEntryItem(
			StyxItems.ANCIENT_COMPASS, 100, 50, new LootFunction[0], new LootCondition[0], "styx:loot_ancient_compass");
	
	@SubscribeEvent
	public void onLootTableLoad(final LootTableLoadEvent event) {
		
            if(event.getName().equals(LootTableList.CHESTS_ABANDONED_MINESHAFT)) {
        	
                event.getTable().getPool("main").addEntry(entry);
            }
	}

 

That works surprisingly well and I don't have to override anything from Minecraft files.

Edited by Dylem
Posted

Nice. I figured there was a way like that, I just didn't feel like diving into the loot table code to see what was public and modifiable. 

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

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