Jump to content

[1.12.2] Use loot table from config folder


Meldexun

Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
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.
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.