Jump to content

Recommended Posts

Posted

Good Morning People,

 

maybe someone can help me with a Mod I'm triying to program right now. The mod also includes a grindstone which applies Sharpness every time used.

The class looks like this till now:

 

 

public class katanasharpening implements IRecipe {

    @Override
    public boolean matches(InventoryCrafting inv, World worldIn) {

        Boolean meitouexistend = false;
        Boolean grindstoneexistend = false;

        for(int slot = 0; slot < inv.getSizeInventory(); slot++)
        {
            if(inv.getStackInSlot(slot).getItem().getUnlocalizedName() == "meitoukokuhikari")
            {
                meitouexistend = true;
            }
            if(inv.getStackInSlot(slot).getItem().getUnlocalizedName() == "grindstone")
            {
                grindstoneexistend = true;
            }
        }
        if(grindstoneexistend && meitouexistend)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    @Override
    public ItemStack getCraftingResult(InventoryCrafting inv) {

        int meitouposition = 0;
        int currentlevel = 0;

        for(int slot = 0; slot < inv.getSizeInventory(); slot++)
        {
                if(inv.getStackInSlot(slot).getItem().getUnlocalizedName() == "meitoukokuhikari")
                {
                    meitouposition = slot;
                }
        }

        NBTTagList tags = inv.getStackInSlot(meitouposition).getEnchantmentTagList();

        if(tags != null)
        {
            for (int i = 0; i < tags.tagCount(); ++i)
            {
                int j = tags.getCompoundTagAt(i).getShort("id");
                int k = tags.getCompoundTagAt(i).getShort("lvl");
                if(j == 16)
                {
                    currentlevel = k;
                }
            }
        }

        inv.removeStackFromSlot(meitouposition);
        ItemStack kokumeitou = new ItemStack(HikariTouMod.meitoukokuhikari);
        kokumeitou.addEnchantment(Enchantments.SHARPNESS, currentlevel +1);

        return kokumeitou;
    }

 

Questions:

 

Is inv.getStackInSlot(slot).getItem().getUnlocalizedName() == "something" a good way to check if the right items inside?

Through debugging it seems 16 is the id for sharpness?

 

How would I now register the recipe?

GameRegistry.addShaplessRecipe(katanasharpening);  ??

 

addShapelessRecipe has a optional ResourceLocation parameter, is that it?

 

Happy for anyone who can give me some hints.

 

Posted
2 minutes ago, El_Ludolf said:

Is inv.getStackInSlot(slot).getItem().getUnlocalizedName() == "something" a good way to check if the right items inside?

 

No, unlocalised names should only be used for display/translation purposes. They're not unique and can change at any time.

 

Instead, compare the Item instances directly (e.g. stack.getItem() == MyModItems.FOO_BAR) or check if the Item is an instance of the appropriate class (e.g. stack.getItem() instanceof ItemFooBar). This also applies to other registry entries like Blocks and Enchantments.

 

 

5 minutes ago, El_Ludolf said:

Through debugging it seems 16 is the id for sharpness?

 

Don't use numeric IDs, they can be different in every save. Use EnchantmentHelper.getEnchantments to get the Enchantments on an ItemStack. The Vanilla Enchantment instances are stored in the Enchantments class.

 

 

12 minutes ago, El_Ludolf said:

How would I now register the recipe?

GameRegistry.addShaplessRecipe(katanasharpening);  ??

 

Recipes are managed by a Forge registry, register them in the appropriate registry event; just like you do for Blocks, Items, etc.

 

 

16 minutes ago, El_Ludolf said:

addShapelessRecipe has a optional ResourceLocation parameter, is that it?

 

The name argument of addShapelessRecipe is the registry name of the recipe and the group argument is the recipe's group name. Recipes with the same group name are displayed in the same button in the recipe book.

 

 

You should move your recipes to the JSON system rather than hardcoding them.

  • Like 1

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
Just now, El_Ludolf said:

Thanks a lot. I haven't found a way to meddle with the NBT values inside a JSON file. All the other recipes are JSONs.

 

You can use your own recipe classes with the JSON system by creating an IRecipeFactory and specifying it in your _factories.json file.

 

You can see some example IRecipe and IRecipeFactory implementations here and the corresponding _factories.json file here.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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

    • So I started an MC server with some friends. It worked perfectly last night, but this morning I get the error that my PlayerData is invalid. I tried deleting my player data along with my cobblemon player pokemon storage data (for the cobblemon mod). I am still having the issue. https://pastes.io/log-38182 is my latest log, though I am not great at deciphering it. Any help would be appreciated. I have already tried using Packet Fixer aswell. I really would prefer to not have to delete the world.  
    • Looks like an issue with one of the create addons - remove these one by one
    • I have no idea - maybe it is directly an issue with mohist
    • I made a custom pack, but i can't even load it, it just crashes at launcher, giving me Error 1. I looked at the log, and it just doesn't seem to tell me what the issue actually is. Here's the report.   Edit- Trying to get report, but copy paste being weird [22:59:59] [main/ERROR]:Error replacing mixin module source java.lang.ClassNotFoundException: cpw.mods.cl.JarModuleFinder$JarModuleReference at java.base/jdk.internal.loader.Loader.loadClass(Loader.java:571) ~[?:?] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526) ~[?:?] at cpw.mods.securejarhandler/net.minecraftforge.securemodules.SecureModuleClassLoader.loadClass(SecureModuleClassLoader.java:429) ~[securemodules-2.2.21.jar!/:?] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526) ~[?:?] at java.base/java.lang.Class.forName0(Native Method) ~[?:?] at java.base/java.lang.Class.forName(Class.java:421) ~[?:?] at java.base/java.lang.Class.forName(Class.java:412) ~[?:?] at LAYER SERVICE/[email protected]+1.20.1/io.github.steelwoolmc.mixintransmog.InstrumentationHack.inject(InstrumentationHack.java:46) ~[?:?] at LAYER SERVICE/[email protected]+1.20.1/io.github.steelwoolmc.mixintransmog.MixinTransformationService.<init>(MixinTransformationService.java:59) ~[?:?] at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62) [?:?] at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502) [?:?] at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486) [?:?] at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:789) [?:?] at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:729) [?:?] at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1403) [?:?] at SECURE-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.TransformationServicesHandler.discoverServices(TransformationServicesHandler.java:156) [modlauncher-10.2.4.jar!/:?] at SECURE-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.Launcher.run(Launcher.java:84) [modlauncher-10.2.4.jar!/:?] at SECURE-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.Launcher.main(Launcher.java:75) [modlauncher-10.2.4.jar!/:?] at SECURE-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.BootstrapEntry.main(BootstrapEntry.java:17) [modlauncher-10.2.4.jar!/:?] at [email protected]/net.minecraftforge.bootstrap.Bootstrap.moduleMain(Bootstrap.java:188) [bootstrap-2.1.8.jar!/:?] at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[?:?] at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[?:?] at net.minecraftforge.bootstrap.Bootstrap.bootstrapMain(Bootstrap.java:133) [bootstrap-2.1.8.jar:2.1.8] at net.minecraftforge.bootstrap.Bootstrap.start(Bootstrap.java:53) [bootstrap-2.1.8.jar:2.1.8] at net.minecraftforge.bootstrap.ForgeBootstrap.main(ForgeBootstrap.java:19) [bootstrap-2.1.8.jar:2.1.8] [22:59:59] [main/FATAL]:Encountered serious error loading transformation service, expect problems java.util.ServiceConfigurationError: cpw.mods.modlauncher.api.ITransformationService: Provider io.github.steelwoolmc.mixintransmog.MixinTransformationService could not be instantiated at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:586) ~[?:?] at SECURE-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.TransformationServicesHandler.discoverServices(TransformationServicesHandler.java:156) [modlauncher-10.2.4.jar!/:?] at SECURE-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.Launcher.run(Launcher.java:84) [modlauncher-10.2.4.jar!/:?] at SECURE-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.Launcher.main(Launcher.java:75) [modlauncher-10.2.4.jar!/:?] at SECURE-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.BootstrapEntry.main(BootstrapEntry.java:17) [modlauncher-10.2.4.jar!/:?] at [email protected]/net.minecraftforge.bootstrap.Bootstrap.moduleMain(Bootstrap.java:188) [bootstrap-2.1.8.jar!/:?] at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[?:?] at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[?:?] at net.minecraftforge.bootstrap.Bootstrap.bootstrapMain(Bootstrap.java:133) [bootstrap-2.1.8.jar:2.1.8] at net.minecraftforge.bootstrap.Bootstrap.start(Bootstrap.java:53) [bootstrap-2.1.8.jar:2.1.8] at net.minecraftforge.bootstrap.ForgeBootstrap.main(ForgeBootstrap.java:19) [bootstrap-2.1.8.jar:2.1.8] Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: cpw.mods.cl.JarModuleFinder$JarModuleReference at LAYER SERVICE/[email protected]+1.20.1/io.github.steelwoolmc.mixintransmog.MixinTransformationService.<init>(MixinTransformationService.java:62) ~[?:?] at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62) ~[?:?] at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502) ~[?:?] at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486) ~[?:?] at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:789) ~[?:?] ... 12 more Caused by: java.lang.ClassNotFoundException: cpw.mods.cl.JarModuleFinder$JarModuleReference at java.base/jdk.internal.loader.Loader.loadClass(Loader.java:571) ~[?:?] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526) ~[?:?] at cpw.mods.securejarhandler/net.minecraftforge.securemodules.SecureModuleClassLoader.loadClass(SecureModuleClassLoader.java:429) ~[securemodules-2.2.21.jar!/:?] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526) ~[?:?] at java.base/java.lang.Class.forName0(Native Method) ~[?:?] at java.base/java.lang.Class.forName(Class.java:421) ~[?:?] at java.base/java.lang.Class.forName(Class.java:412) ~[?:?] at LAYER SERVICE/[email protected]+1.20.1/io.github.steelwoolmc.mixintransmog.InstrumentationHack.inject(InstrumentationHack.java:46) ~[?:?] at LAYER SERVICE/[email protected]+1.20.1/io.github.steelwoolmc.mixintransmog.MixinTransformationService.<init>(MixinTransformationService.java:59) ~[?:?] at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62) ~[?:?] at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502) ~[?:?] at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486) ~[?:?] at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:789) ~[?:?] ... 12 more [22:59:59] [main/INFO]:SpongePowered MIXIN Subsystem Version=0.8.7 Source=jar:file:///C:/Users/mxz/curseforge/minecraft/Install/libraries/org/spongepowered/mixin/0.8.7/mixin-0.8.7.jar!/ Service=ModLauncher Env=CLIENT at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:813) ~[?:?] at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:729) ~[?:?] at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1403) ~[?:?]
    • here is a different world https://ibb.co/Q3VWj9gW and the server console https://ibb.co/dwQf0qrR
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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