Jump to content

Recommended Posts

Posted

I already tried looking at the documentation for injecting loot tables into vanilla ones, and I still can't figure it out, even after looking through Botania's code that uses it. I have a basic ModLootTables file with

Spoiler

public class ModLootTables {
    
    @SubscribeEvent
    public void onEvent(LootTableLoadEvent event) {
        
        System.out.println("Almost Regsiter loot table?");
            
        LootTableList.register(new ResourceLocation(Reference.MOD_ID, "inject/ocelot"));
        if (event.getName().toString().equals("minecraft:entities/ocelot")) {
            
            System.out.println("Regsiter loot table?");
            
            event.getTable().addPool(new LootPool(new LootEntry[] {new LootEntryTable(new ResourceLocation(Reference.MOD_ID, "inject/ocelot"), 1, 0, new LootCondition[0], "rtapeentry")}, new LootCondition[0], new RandomValueRange(1), new RandomValueRange(0, 1), "rtapentry"));
            
        }

    }

}

I just want to add a drop to the ocelot's death loot table. However, the System.out.println parts never actually send anything to the console, making me feel like the class is never running. I don't think I need to reference the class in any other place out side of itself, but I still don't quite know how the event system works. The loot table json itself is valid and located in loot_tables/inject/ocelot.json

Professional Hot Garbage Programmer.

https://github.com/Bedrockbreaker/

Posted

This might help:

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/hardlib/util/LootUtils.java

 

If you have questions about specific lines, I'd be more than happy to answer them.

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
10 hours ago, Alexiy said:

Have you registered this class to Forge event bus?

*facepalms* No I have not. However, typing MinecraftForge.EVENT_BUS.register(ModLootTables.class); Into any of  "init stages" of my main mod class, doesn't seem to do anything (I have a different event bus register for entity interact). Nothing is still printed to the console.

As for @Draco18s's comment, If I am to understand the file correctly, the many addItemToTable s essentially do the same thing, but with added arguments for each one. The actual part where the item is added is line 116, which takes newPool from line 106 which takes a ton of arguments, which would be originally defined in the loot table json, but is instead defined with lines 88-104. I think that is how that works. I still do have a question as to what "name" does when adding a loot pool. Is it a unique identifier for the pool? If I am injecting a json into a table, does it have to be the "name" specified from inside the json? Also at line 104, can I replace LootEntryItem with LootEntryTable to substitute an Item for a json?

Professional Hot Garbage Programmer.

https://github.com/Bedrockbreaker/

Posted (edited)
3 hours ago, _Bedrockbreaker_ said:

I still do have a question as to what "name" does when adding a loot pool. Is it a unique identifier for the pool?

Required by Forge that all non-vanilla loot pools have a name. This is so they can be identified. None of my code deals with finding a pool by name (I don't need it and vanilla pools aren't named helpfully--they get an autogenerated name). Not necessarily unique, but I think it needs to be unique relative to that table.

 

3 hours ago, _Bedrockbreaker_ said:

If I am injecting a json into a table, does it have to be the "name" specified from inside the json?

I'd say "don't inject raw json data." But yes, it would.

 

3 hours ago, _Bedrockbreaker_ said:

Also at line 104, can I replace LootEntryItem with LootEntryTable to substitute an Item for a json?

I don't think so. I'm not sure where LootEntryTable falls in the grand scheme of things off the top of my head.

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.

Posted

Alright, thanks for the help so far. I didn't know my class had to be static, so thanks for that. However, now that the loot table class actually runs, I get an error on trying to enter a world. The only thing is, the error never references a part of my mod's code, and only says this:

Spoiler

java.util.ConcurrentModificationException: null
    at java.util.HashMap$HashIterator.nextNode(HashMap.java:1429) ~[?:1.8.0_91]
    at java.util.HashMap$KeyIterator.next(HashMap.java:1453) ~[?:1.8.0_91]
    at java.util.Collections$UnmodifiableCollection$1.next(Collections.java:1042) ~[?:1.8.0_91]
    at net.minecraft.world.storage.loot.LootTableManager.reloadLootTables(LootTableManager.java:47) ~[LootTableManager.class:?]
    at net.minecraft.world.storage.loot.LootTableManager.<init>(LootTableManager.java:35) ~[LootTableManager.class:?]
    at net.minecraft.world.WorldServer.init(WorldServer.java:161) ~[WorldServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:123) ~[IntegratedServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.init(IntegratedServer.java:160) ~[IntegratedServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:550) [MinecraftServer.class:?]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_91]

 

So..... I honestly have no idea what went wrong. I haven't changed the class, So the spoiler in the first post is still accurate.

Professional Hot Garbage Programmer.

https://github.com/Bedrockbreaker/

Posted
13 hours ago, _Bedrockbreaker_ said:

Alright, thanks for the help so far. I didn't know my class had to be static, so thanks for that.

Erm, a correction - by registering the class I didn't mean the actual class, but an instance of it only.

Posted
3 hours ago, Alexiy said:

Erm, a correction - by registering the class I didn't mean the actual class, but an instance of it only.

You can do both. But registering the class object means the methods have to be static. (You can also register via an annotation this way)

Registering an instance, they must not be.

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 (edited)

Alright, I am pretty sure registering loot tables doesn't need be not static, so I am just going to leave it like that. However, I still don't understand what the new error means. Can anyone help me figure out what went wrong, and would there be any more information that I would need to give to help solve this?

 

EDIT: After some testing, it turns out the forge seems to hate registering the loot table inside the LootTableLoadEvent. So, I got the problem fixed. Thanks for your help!

Edited by _Bedrockbreaker_
Problem Solved!

Professional Hot Garbage Programmer.

https://github.com/Bedrockbreaker/

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.