Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Help Adding Loot to Chests [1.11.2]


Recommended Posts

TileEntityChest chest = (TileEntityChest) world.getTileEntity(new BlockPos(i + 6, j + 11, k + 6));
					
					chest.setLootTable(new ResourceLocation("nm:loot/loot_chest"), new Random().nextLong());

Hello, I have made a custom structure and have been trying to add loot tables to the chests inside my structure. I have this code. The resource path is correct I have checked that many times. The only error I get is: Couldn't find resource table nm:loot/loot_chest when I open the chest. I don't know why this is happening because the path is assets.nm.loot and in that package I have loot_chest.json with the loot table in it. Any help is appreciated, Thanks!

Edited by funsize888
Link to post
Share on other sites

Try adding .json to your resource location. Not entirely sure if necessary but I know you need for instance .png in resource locations for entity textures

IGN: matte006

Played Minecraft since summer 2011.

Modding is my life now.

Please check out my mod :)

https://minecraft.curseforge.com/projects/gadgets-n-goodies-mod?gameCategorySlug=mc-mods&projectID=230028

Link to post
Share on other sites
2 minutes ago, TheMattyBoy said:

Try adding .json to your resource location. Not entirely sure if necessary but I know you need for instance .png in resource locations for entity textures

I have tried that and the same thing happened

Link to post
Share on other sites

OK then. Why don't you register it like Minecraft has done it in LootTableList::register(ResourceLocation) (which is a public static method)? That does mean that you have to rename your "loot" folder to "loot_tables", and you probably want to create a sub folder called "chests" where you put your "loot_chest.json" file, but that shouldn't be too big of an issue.

 

I would try doing something like public static ResourceLocation LOOT_CHEST; in your main mod class, then say LOOT_CHEST = LootTableList.register(new ResourceLocation("nm", "chests/loot_chest")); in your pre-initialization event (maybe another event) and then call this field in your chest.setLootTable method.

IGN: matte006

Played Minecraft since summer 2011.

Modding is my life now.

Please check out my mod :)

https://minecraft.curseforge.com/projects/gadgets-n-goodies-mod?gameCategorySlug=mc-mods&projectID=230028

Link to post
Share on other sites
1 hour ago, TheMattyBoy said:

OK then. Why don't you register it like Minecraft has done it in LootTableList::register(ResourceLocation) (which is a public static method)? That does mean that you have to rename your "loot" folder to "loot_tables", and you probably want to create a sub folder called "chests" where you put your "loot_chest.json" file, but that shouldn't be too big of an issue.

 

I would try doing something like public static ResourceLocation LOOT_CHEST; in your main mod class, then say LOOT_CHEST = LootTableList.register(new ResourceLocation("nm", "chests/loot_chest")); in your pre-initialization event (maybe another event) and then call this field in your chest.setLootTable method.

Ok, I have this in my main class:

 public static ResourceLocation LOOT_CHEST;

and this also in my main class but under the preInit method:

LOOT_CHEST = LootTableList.register(new ResourceLocation("nm", "chests/loot_chest")); 

And I have this in my structure class:

TileEntityChest chest = (TileEntityChest) world.getTileEntity(new BlockPos(i + 6, j + 11, k + 6));
				
				chest.setLootTable((MyMod.LOOT_CHEST), new Random().nextLong());

I have also changed the resource locations. I don't get any errors but nothing is inside the chests. Which happens everytime I register it.

Link to post
Share on other sites
16 hours ago, funsize888 said:

Nevermind, I changed:  ("nm", "chests/loot_chest")); to "nm:loot_tables/chests/loot_chest" and it worked!, Thank you so much for your help, would have never got it otherwise!

Ok nevermind, items spawned in the chest once and now I'm getting the same error couldn't find resource table. I didn't change anything. I am still stuck

Link to post
Share on other sites

Now I'm getting the error:  Loot Table "nm:chests/loot_chest" Missing `name` entry for pool #0. I did set a name though, here is my json file:

{
    "pools": [
        {
            "name": "loot",
            "rolls": {
                "min": 2,
                "max": 4
            },
            "entries": [
                {
                    "type": "item",
                    "name": "minecraft:diamond",
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 1,
                                "max": 3
                            }
                        }
                    ],
                    "weight": 5
                },
                {
                    "type": "item",
                    "name": "minecraft:iron_ingot",
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 1,
                                "max": 5
                            }
                        }
                    ],
                    "weight": 15
                },
                {
                    "type": "item",
                    "name": "minecraft:gold_ingot",
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 2,
                                "max": 7
                            }
                        }
                    ],
                    "weight": 15
                },
                {
                    "type": "item",
                    "name": "minecraft:emerald",
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 1,
                                "max": 3
                            }
                        }
                    ],
                    "weight": 15
                },
                {
                    "type": "item",
                    "name": "minecraft:bone",
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 4,
                                "max": 6
                            }
                        }
                    ],
                    "weight": 25
                },
                {
                    "type": "item",
                    "name": "minecraft:spider_eye",
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 1,
                                "max": 3
                            }
                        }
                    ],
                    "weight": 25
                },
                {
                    "type": "item",
                    "name": "minecraft:rotten_flesh",
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 3,
                                "max": 7
                            }
                        }
                    ],
                    "weight": 25
                },
                {
                    "type": "item",
                    "name": "minecraft:saddle",
                    "weight": 20
                },
                {
                    "type": "item",
                    "name": "minecraft:iron_horse_armor",
                    "weight": 15
                },
                {
                    "type": "item",
                    "name": "minecraft:golden_horse_armor",
                    "weight": 10
                },
                {
                    "type": "item",
                    "name": "minecraft:diamond_horse_armor",
                    "weight": 5
                },
                {
                    "type": "item",
                    "name": "minecraft:book",
                    "weight": 20,
                    "functions": [
                        {
                            "function": "enchant_randomly"
                        }
                    ]
                },
                {
                    "type": "item",
                    "name": "minecraft:gunpowder",
                    "weight": 20
                },
                {
                    "type": "item",
                    "name": "minecraft:golden_apple",
                    "weight": 2,
                    "functions": [
                        {
                            "function": "set_data",
                            "data": 1
                        }
                    ]
                },
                {
                    "type": "empty",
                    "weight": 15
                }
            ]
        },
        {
            "rolls": 4,
            "entries": [
                {
                    "type": "item",
                    "name": "minecraft:bone",
                    "weight": 10,
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 1,
                                "max": 8
                            }
                        }
                    ]
                },
                {
                    "type": "item",
                    "name": "minecraft:gunpowder",
                    "weight": 10,
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 1,
                                "max": 8
                            }
                        }
                    ]
                },
                {
                    "type": "item",
                    "name": "minecraft:rotten_flesh",
                    "weight": 10,
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 1,
                                "max": 8
                            }
                        }
                    ]
                },
                {
                    "type": "item",
                    "name": "minecraft:string",
                    "weight": 10,
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 1,
                                "max": 8
                            }
                        }
                    ]
                },
                {
                    "type": "item",
                    "name": "minecraft:sand",
                    "weight": 10,
                    "functions": [
                        {
                            "function": "set_count",
                            "count": {
                                "min": 1,
                                "max": 8
                            }
                        }
                    ]
                }
            ]
        }
    ]
}

 

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



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.