Jump to content

codahq

Members
  • Posts

    7
  • Joined

  • Last visited

Everything posted by codahq

  1. That exactly what I did in my workaround. I decided to put the resource location and level in the factory ItemStack so it would be there for easy access in getCraftingResult. This is still a problem though because apparently mods like NEI/JEI look and cache recipes during pre-init or shortly afterwards. If I don't put the wrong, soon-to-be-replaced enchants on the books during factory pre-init they won't show up in those mods. I don't need a workaround. I don't need a solution. I have that already. I'm continuing to post now because I want somebody to realize and validate what I'm saying about the order of these events. Why are the IDs changed AFTER recipe registration instead of before? Or why aren't they adjusted? I have to return ItemStacks with two different IDs for the same enchant for this to work. The order should be changed so that I don't have to do that OR when the IDs are changed by forge forge SHOULD go to all of the places they are used and update them.
  2. Because forge has changed the int IDs of the enchants since the factories were called. If I don't return a different stack, when the recipe is used the first stack is returned with IDs that no longer match any enchants. Since the IDs are not the same anymore it the ItemStack shows as an enchanted book with stored enchants but the stored enchants are missing.
  3. Let me tee it up for you. See the attached code examples: The output: [22:24:34] [main/INFO] [STDOUT]: [me.bendy.pearlmod.recipe.ShapedEnchantingBookRecipeFactory:parse:48]: pre-init :: location: pearlmod:ender_stability id: 11 lvl: 1 And when I use the recipe in a table in-game later on: [22:25:31] [Server thread/INFO] [STDOUT]: [me.bendy.pearlmod.recipe.ShapedEnchantingBookRecipeFactory$ShapedEnchantingBookRecipe:getCraftingResult:91]: in-game :: location: pearlmod:ender_stability id: 90 lvl: 1 PearlmodEnchants.java ShapedEnchantingBookRecipeFactory.java _factories.json book_ender_stability.json
  4. I'm not. You're not getting it yet. I'm using the resource location as is best practice. Minecraft/forge is assigning the int ID. Then it runs the recipe factories and builds the result with the first IDs. Then at some point it changes the IDs. Eventually in game when I use the same resource location I get a different ID back. The recipe output built during pre-init has the wrong IDs. Do you understand?
  5. Yes, thank you to both of you. I understand that I need to implement logic on the result. I'm not able to just implement logic in parse as I was doing previously. The dilemma now is that the result itemstack that I give during parse (and pre-init) is different than the result itemstack that I would give during recipe use and when getCraftingResult is called in-game. For example... the id in the NBT for stored enchant in pre-init is assigned to, let's say 85, and written to the item stack. But if I call Enchantment.getEnchantmentbyId(85) in-game that enchant ID has been moved since pre-init and it fails to find an enchant with 85. If I get the id again with the resource location it returns 95 let's say. So, if I use the old result with the old ID it has bad enchantment data in it. I can recreate the output (which I'm doing in the current implementation in getCraftingResult) by getting the new id from the resource location but that breaks mods like JEI, NEI which must be caching or grabbing data created during pre-init. Doesn't that bother anybody? That I have to return two different stacks? Or is that the way it should be? Shouldn't those stacks be the same? Wouldn't you think the factory event should fire AFTER the enchant IDs are moved so that the result that is saved during the factory's parse stores a recipe result with the current enchant IDs?
  6. So, embarrassingly enough this doesn't work but I didn't notice because I didn't test it very well. At any rate, it works with the OOB enchants but it doesn't work with the custom enchants. In parse it stores an int for the custom enchant's without using resource location for compatibility so it's just an int ID in NBT. But by the time you are in-game and the recipe class's getCraftingResult method is called those enchant IDs have been changed. Since I can't control when EITHER of the registry events happen (recipe factory or enchant registering), what am I supposed to do now?' I guess I could store NBT data in the stack so I can find it later and just build the output stack when getCraftingResult is called but won't that break NEI, JEI, etc?
  7. It took me a little while to figure this out because there aren't really that many examples out there but thanks for getting me on correct path. Here is what I ended up doing. JSON recipe: { "type": "pearlmod:shaped_enchanting_book_recipe", "pattern": [ "fbf", " p " ], "key": { "p": { "item": "minecraft:ender_pearl" }, "b": { "item": "minecraft:book" }, "f": { "item": "minecraft:feather" } }, "result": { "item": "minecraft:enchanted_book", "enchantments": [ { "enchant": "minecraft:infinity", "lvl": 1 } ] } } Parse method on recipe factory: @Override public IRecipe parse(JsonContext context, JsonObject json) { ShapedOreRecipe recipe = ShapedOreRecipe.factory(context, json); ItemStack output = recipe.getRecipeOutput(); final JsonObject result = JsonUtils.getJsonObject(json, "result"); final String item = JsonUtils.getString(result, "item"); assert item == "minecraft:enchanted_book"; final JsonArray enchantments = JsonUtils.getJsonArray(result, "enchantments"); for (JsonElement e : enchantments) { final String enchant = JsonUtils.getString(e.getAsJsonObject(), "enchant"); final int lvl = JsonUtils.getInt(e.getAsJsonObject(), "lvl"); EnchantmentData storedEnchant = new EnchantmentData(Enchantment.getEnchantmentByLocation(enchant), lvl); ItemEnchantedBook.addEnchantment(output, storedEnchant); } ShapedPrimer primer = new ShapedPrimer(); primer.width = recipe.getRecipeWidth(); primer.height = recipe.getRecipeHeight(); primer.mirrored = JsonUtils.getBoolean(json, "mirrored", true); primer.input = recipe.func_192400_c(); return new ShapedEnchantingBookRecipe(new ResourceLocation(Constants.modid, "shaped_enchanting_book_recipe"), output, primer); } I'm not sure if there was a more effective way of parsing the JSON or not. I'm not familiar with teh goog's JSON library and I didn't find any quick examples so I just fudged this together quickly. At any rate, this works. If anybody has a suggestion to make it better please contribute to the example.
  8. I'm trying to update my mod to 1.12.2. Some of my recipes return books with stored enchants. I can't figure out how to do this without using NBT and the int IDs of the enchants. According to @diesieben07 they should never be used. How do I avoid using them in this scenario? For example, I am using this as a recipe. { "type": "minecraft:crafting_shaped", "pattern": [ "pbp", " p " ], "key": { "p": { "item": "minecraft:ender_pearl" }, "b": { "item": "minecraft:book" } }, "result": { "item": "minecraft:enchanted_book", "nbt": { "StoredEnchantments": [ { "id": 32, "lvl": 1 } ] } } } How can this be done without the int ID. This is especially important since I also have custom enchants.
×
×
  • Create New...

Important Information

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