Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I want to generate a chest with my loot table. This works fine when i use a loot table from my assets. But is there a way to spawn a chest with a loot table from the config folder?

 

Edit: I just found the LootTableLoadEvent. Could i just pass the loot table from the config folder when the loot table from my mod is loaded?

Edited by Meldexun

  • Author

The event seems to work but i don't know how i can get a LootTable from a String. I mean i have the content of the loot_table.json file in the config folder as String but how can i generate a LootTable out of it?

I haven't touched loot tables yet in any of my mods, but I just found this inside the LootTable class:
 

    public static class Serializer implements JsonDeserializer<LootTable>, JsonSerializer<LootTable>
        {
            public LootTable deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
            {
                JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "loot table");
                LootPool[] alootpool = (LootPool[])JsonUtils.deserializeClass(jsonobject, "pools", new LootPool[0], p_deserialize_3_, LootPool[].class);
                return new LootTable(alootpool);
            }

            public JsonElement serialize(LootTable p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_)
            {
                JsonObject jsonobject = new JsonObject();
                jsonobject.add("pools", p_serialize_3_.serialize(p_serialize_1_.pools));
                return jsonobject;
            }
        }

Just don't ask me how to use it :P

If you find existing usages of the deserialize method, you might be able to figure out how to use it correctly.

  • Author

Now i got this:

	private static final Gson GSON_INSTANCE = (new GsonBuilder()).registerTypeAdapter(RandomValueRange.class, new RandomValueRange.Serializer()).registerTypeAdapter(LootPool.class, new LootPool.Serializer()).registerTypeAdapter(LootTable.class, new LootTable.Serializer()).registerTypeHierarchyAdapter(LootEntry.class, new LootEntry.Serializer()).registerTypeHierarchyAdapter(LootFunction.class, new LootFunctionManager.Serializer()).registerTypeHierarchyAdapter(LootCondition.class, new LootConditionManager.Serializer()).registerTypeHierarchyAdapter(LootContext.EntityTarget.class, new LootContext.EntityTarget.Serializer()).create();
	
	@SubscribeEvent
	public static void loadLootTable(LootTableLoadEvent event) {
		if (event.getName() == TileEntityChestArmor.LOOT_TABLE) {
			File f = new File(CrystalicVoid.configFolderLoot + "/chest_armor.json");
			if (f.exists() && f.isFile()) {
				String s = null;
				try {
					s = Files.toString(f, StandardCharsets.UTF_8);
				} catch (IOException e) {
					e.printStackTrace();
				}
				event.setTable(GSON_INSTANCE.fromJson(s, LootTable.class));
		}
	}

But it just says

Invalid call stack, could not grab json context!

The json loot table that i try to load is fine. So someone has any idea?

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

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.