Jump to content

Custom crafting table output visually messed up


torresmon235

Recommended Posts

Hello people

I am working on a mod and it adds a new crafting table with its own recipes and it works, but the output slot doesnt show the item the recipe is resulting, even though if you click on the slot with no items, it crafts the item like it should.

I have tried a lot of changes on the code and it still doesnt show the right output, anyone has an ideia of what is happening?

 

Crafting Manager

 

package torresmon235.crystalgun.crafting;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraft.world.World;
import torresmon235.crystalgun.common.CrystalGunMain;

public class AlchemyManager
{
    /** The static instance of this class */
    private static final AlchemyManager instance = new AlchemyManager();

    /** A list of all the recipes added */
    private List recipes = new ArrayList();

    /**
     * Returns the static instance of this class
     */
    public static final AlchemyManager getInstance()
    {
        return instance;
    }

    private AlchemyManager()
    {
        this.addRecipe(new ItemStack(CrystalGunMain.PoisonCrystal, 3), new Object[] {"F", "W", "F", 'F', CrystalGunMain.FireCrystal, 'W', CrystalGunMain.WaterCrystal});
        this.addRecipe(new ItemStack(CrystalGunMain.PoisonCrystal, 2), new Object[] {"G", "F", 'F', CrystalGunMain.FireCrystal, 'G', CrystalGunMain.GrassCrystal});
        this.addRecipe(new ItemStack(CrystalGunMain.GrassCrystal, 2), new Object[] {"F", "W", 'F', CrystalGunMain.FireCrystal, 'W', CrystalGunMain.WaterCrystal});
        this.addRecipe(new ItemStack(CrystalGunMain.IceCrystal, 2), new Object[] {"A", "W", 'A', CrystalGunMain.AirCrystal, 'W', CrystalGunMain.WaterCrystal});
        this.addRecipe(new ItemStack(CrystalGunMain.SandCrystal, 2), new Object[] {"F", "A", 'F', CrystalGunMain.FireCrystal, 'A', CrystalGunMain.AirCrystal});
        this.addRecipe(new ItemStack(CrystalGunMain.LifeCrystal, 6), new Object[] {"FWA", "PPP", "GIS", 'F', CrystalGunMain.FireCrystal, 'W', CrystalGunMain.WaterCrystal, 'A', CrystalGunMain.AirCrystal, 'G', CrystalGunMain.GrassCrystal, 'I', CrystalGunMain.IceCrystal, 'S', CrystalGunMain.SandCrystal, 'P', Item.gunpowder});
        System.out.println(this.recipes.size() + " Achemy Recipes");
    }

    void addRecipe(ItemStack itemstack, Object ... inputArray)
    {
             String var3 = "";
             int var4 = 0;
             int var5 = 0;
             int var6 = 0;
             int var9;
             if (inputArray[var4] instanceof String[])
             {
                     String[] var7 = (String[])((String[])inputArray[var4++]);
                     String[] var8 = var7;
                     var9 = var7.length;
                     for (int var10 = 0; var10 < var9; ++var10)
                     {
                             String var11 = var8[var10];
                             ++var6;
                             var5 = var11.length();
                             var3 = var3 + var11;
                     }
             }
             else
             {
                     while (inputArray[var4] instanceof String)
                     {
                             String var13 = (String)inputArray[var4++];
                             ++var6;
                             var5 = var13.length();
                             var3 = var3 + var13;
                     }
             }
             HashMap var14;
             for (var14 = new HashMap(); var4 < inputArray.length; var4 += 2)
             {
                     Character var16 = (Character)inputArray[var4];
                     ItemStack var17 = null;
                     if (inputArray[var4 + 1] instanceof Item)
                     {
                             var17 = new ItemStack((Item)inputArray[var4 + 1]);
                     }
                     else if (inputArray[var4 + 1] instanceof Block)
                     {
                             var17 = new ItemStack((Block)inputArray[var4 + 1], 1, -1);
                     }
                     else if (inputArray[var4 + 1] instanceof ItemStack)
                     {
                             var17 = (ItemStack)inputArray[var4 + 1];
                     }
                     var14.put(var16, var17);
             }
             ItemStack[] var15 = new ItemStack[var5 * var6];
             for (var9 = 0; var9 < var5 * var6; ++var9)
             {
                     char var18 = var3.charAt(var9);
                     if (var14.containsKey(Character.valueOf(var18)))
                     {
                             var15[var9] = ((ItemStack)var14.get(Character.valueOf(var18))).copy();
                     }
                     else
                     {
                             var15[var9] = null;
                     }
             }
             this.recipes.add(new ShapedRecipes(var5, var6, var15, itemstack));
    }
    
    void addShapelessRecipe(ItemStack itemstack, Object ... inputArray)
    {
             ArrayList var3 = new ArrayList();
             Object[] var4 = inputArray;
             int var5 = inputArray.length;
             for (int var6 = 0; var6 < var5; ++var6)
             {
                     Object var7 = var4[var6];
                     if (var7 instanceof ItemStack)
                     {
                             var3.add(((ItemStack)var7).copy());
                     }
                     else if (var7 instanceof Item)
                     {
                             var3.add(new ItemStack((Item)var7));
                     }
                     else
                     {
                             if (!(var7 instanceof Block))
                             {
                                     throw new RuntimeException("Invalid shapeless recipy!");
                             }
                             var3.add(new ItemStack((Block)var7));
                     }
             }
             this.recipes.add(new ShapelessRecipes(itemstack, var3));
    }

    public ItemStack findMatchingRecipe(InventoryCrafting par1InventoryCrafting, World par2World)
    {
        int var3 = 0;
        ItemStack var4 = null;
        ItemStack var5 = null;
        int var6;

        for (var6 = 0; var6 < par1InventoryCrafting.getSizeInventory(); ++var6)
        {
            ItemStack var7 = par1InventoryCrafting.getStackInSlot(var6);

            if (var7 != null)
            {
                if (var3 == 0)
                {
                    var4 = var7;
                }

                if (var3 == 1)
                {
                    var5 = var7;
                }

                ++var3;
            }
        }

        if (var3 == 2 && var4.itemID == var5.itemID && var4.stackSize == 1 && var5.stackSize == 1 && Item.itemsList[var4.itemID].isRepairable())
        {
            Item var11 = Item.itemsList[var4.itemID];
            int var13 = var11.getMaxDamage() - var4.getItemDamageForDisplay();
            int var8 = var11.getMaxDamage() - var5.getItemDamageForDisplay();
            int var9 = var13 + var8 + var11.getMaxDamage() * 5 / 100;
            int var10 = var11.getMaxDamage() - var9;

            if (var10 < 0)
            {
                var10 = 0;
            }

            return new ItemStack(var4.itemID, 1, var10);
        }
        else
        {
            for (var6 = 0; var6 < this.recipes.size(); ++var6)
            {
                IRecipe var12 = (IRecipe)this.recipes.get(var6);

                if (var12.matches(par1InventoryCrafting, par2World))
                {
                    return var12.getCraftingResult(par1InventoryCrafting);
                }
            }

            return null;
        }
    }

    /**
     * returns the List<> of all recipes
     */
    public List getRecipeList()
    {
        return this.recipes;
    }
}

 

Link to comment
Share on other sites

After some testing, it seems like the output shows icons for the normal crafting table recipes, if i try to make a fence, it shows on the output but it wont let me grab the fences. And if i try a recipe from the custom table the icon wont show up, but if i try to grab it will craft the item.

I have been looking for the code that shows the output icon, but with no luck, anyone knows where can i find and change it?

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hey folks. I am working on a custom "Mecha" entity (extended from LivingEntity) that the player builds up from blocks that should get modular stats depending on the used blocks. e.g. depending on what will be used for the legs, the entity will have a different jump strength. However, something unexpected is happening when trying to override a few of LivingEntity's functions and using my new own "Mecha" specific fields: instead of their actual instance-specific value, the default value is used (0f for a float, null for an object...) This is especially strange as when executing with the same entity from a point in the code specific to the mecha entity, the correct value is used. Here are some code snippets to better illustrate what I mean: /* The main Mecha class, cut down for brevity */ public class Mecha extends LivingEntity { protected float jumpMultiplier; //somewhere later during the code when spawning the entity, jumpMultiplier is set to something like 1.5f //changing the access to public didn't help @Override //Overridden from LivingEntity, this function is only used in the jumpFromGround() function, used in the aiStep() function, used in the LivingEntity tick() function protected float getJumpPower() { //something is wrong with this function //for some reason I can't correctly access the fields and methods from the instanciated entity when I am in one of those overridden protected functions. this is very annoying LogUtils.getLogger().info(String.valueOf(this.jumpMultiplier))) //will print 0f return this.jumpMultiplier * super.getJumpPower(); } //The code above does not operate properly. Written as is, the entity will not jump, and adding debug logs shows that when executing the code, the value of this.jumpMultiplier is 0f //in contrast, it will be the correct value when done here: @Override public void tick() { super.tick(); //inherited LivingEntity logic //Custom logic LogUtils.getLogger().info(String.valueOf(this.jumpMultiplier))) //will print 1.5f } } My actual code is slightly different, as the jumpMuliplier is stored in another object (so I am calling "this.legModule.getJumpPower()" instead of the float), but even using a simple float exactly like in the code above didn't help. When running my usual code, the object I try to use is found to be null instead, leading to a crash from a nullPointerException. Here is the stacktrace of said crash: The full code can be viewed here. I have found a workaround in the case of jump strength, but have already found the same problem for another parameter I want to do, and I do not understand why the code is behaving as such, and I would very much like to be able to override those methods as intended - they seemed to work just fine like that for vanilla mobs... Any clues as to what may be happening here?
    • Please delete post. Had not noticed the newest edition for 1.20.6 which resolves the issue.
    • https://paste.ee/p/GTgAV Here's my debug log, I'm on 1.18.2 with forge 40.2.4 and I just want to get it to work!! I cant find any mod names in the error part and I would like some help from the pros!! I have 203 mods at the moment.
    • In 1.20.6 any potion brewed in the brewing stand disappears upon completion.
    • My game crashes whenever I click on Singleplayer then it crashes after the "Saving world". I'm playing on fabric 1.20.1 on forge for the easy instance loading. My game is using 12GB of RAM, I tried deleting the options.txt, and also renaming the saves file but neither worked. Here's the crash report link: https://mclo.gs/qByOqVK
  • Topics

×
×
  • Create New...

Important Information

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