Jump to content

Recommended Posts

Posted (edited)

I originally created my LootPool by making my LootEntry a LootEntryTable that gets the items from a loot table json, but now I want to do it with code. I figured out how to create a loot entry for a single item by using LootEntryItem instead of LootEntryTable, but how can I make a list of multiple items?

 

 

//loot tables
@SubscribeEvent
public static void lootLoad(LootTableLoadEvent evt) {
   String name = evt.getName().toString();
   
   if (name.contains("chest")) {
      LootEntry entry = new LootEntryItem(Items.COOKIE, 15, 60, new LootFunction[0], new LootCondition[0], "modpoolcustomtest");

      LootPool pool = new LootPool(new LootEntry[] {entry}, new LootCondition[0], new RandomValueRange(1), new RandomValueRange(1), "modpool"); 
      
      evt.getTable().addPool(pool);
   }
}
Edited by skeddles
Posted
  • 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 (edited)

I didn't realize that it could be an array.  This code seems to work now.

 

I haven't used arrays before, how does this look? Would there be any performance loss doing it this way, even if there was hundreds or thousands of items?

 

//loot tables
@SubscribeEvent
public static void lootLoad(LootTableLoadEvent evt) {
   String name = evt.getName().toString();
   
   if (name.contains("chest")) {

      LootEntry[] entry = {
              new LootEntryItem(Items.COOKIE, 1, 60, new LootFunction[0], new LootCondition[0], "test:cookie"),
              new LootEntryItem(Items.SKULL, 1, 60, new LootFunction[0], new LootCondition[0], "test:skull")
      };

      LootPool pool = new LootPool(entry, new LootCondition[0], new RandomValueRange(1), new RandomValueRange(1), "testpool");
      
      evt.getTable().addPool(pool);
   }
}

 

edit: just realized i need to be able to add to the array at will so probably need an arraylist, workin on that

 

edit:

here's what I got now, uses an arraylist and then converts it at the end:

 

ArrayList<LootEntryItem> entries = new ArrayList<LootEntryItem>();

entries.add(new LootEntryItem(Items.COOKIE, 1, 60, new LootFunction[0], new LootCondition[0], "examplemod:cookie"));
entries.add(new LootEntryItem(Items.SKULL, 1, 60, new LootFunction[0], new LootCondition[0], "examplemod:skull"));

LootEntry [] entriesArray = entries.toArray(new LootEntry[entries.size()]);

LootPool pool = new LootPool(entriesArray, new LootCondition[0], new RandomValueRange(1), new RandomValueRange(1), "heroicarmorypool");

evt.getTable().addPool(pool);
Edited by skeddles
Posted

Yeah. Gotta be an array, but lists are easier to work with.

Its why my utils class got so convoluted so quickly.

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.