Jump to content

How do I set the crafting size of a custom ShapedRecipe? [1.19.2]


Myxtro

Recommended Posts

I want to create a custom recipe with a 5 by 5 grid. I extended the ShapedRecipe class as this seems to be the obivous route to take. (Or should I take a different approach perhaps?) The ShapedRecipe class has a setCraftingSize method. This is however a static method so I can't call it in the constructor of my custom recipe. Where and how should this method be called instead?

Edited by Myxtro
Link to comment
Share on other sites

4 hours ago, ChampionAsh5357 said:

In FMLCommonSetupEvent within the deferred work queue (#enqueueWork).

 

Like this?

    private void setup(final FMLCommonSetupEvent event)
    {
        event.enqueueWork(() -> {
            LargeCraftingRecipe.setCraftingSize(5, 5);
        });
    }

 

Edited by Myxtro
Link to comment
Share on other sites

19 hours ago, ChampionAsh5357 said:

Assuming you're attaching the event to the mod event bus. Though, if you are just using the unmodified crafting grid in terms of logic, you don't need a custom recipe, you just need to increase the base crafting table size.

The reason I'm doing this is because I don't want regular recipes to work on my custom 5 by 5 table. Only the recipes I create should be able to be crafted. Is there an easy way to achieve this?

Link to comment
Share on other sites

20 hours ago, ChampionAsh5357 said:

Technically, you can reuse the crafting recipe classes as long as you change the RecipeType since that's what determines whether the recipes can be used by a given system or not.

Could you elaborate on what you mean by "reuse"? As there's a couple ways to interpret it.

Do you mean registering it with ShapedRecipe as the registry object? like so:
 

    public static final RegistryObject<RecipeSerializer<ShapedRecipe>> LARGE_GRID_SERIALIZER =
            SERIALIZERS.register("large_grid", () -> ShapedRecipe.Serializer.SHAPED_RECIPE);
//Do you mean to change ShapedRecipe.Serializer.SHAPED_RECIPE to something else?

Or do you mean copying the ShapedRecipe class and renaming it, then using that to register?

The way I currently do it is by having a custom class extend the ShapedRecipe class, but this comes with it's own set of problems which I rather avoid building crappy solutions for.

Link to comment
Share on other sites

2 hours ago, Myxtro said:

Could you elaborate on what you mean by "reuse"? As there's a couple ways to interpret it.

Extend the class and override getRecipeType to return your own. Everything else can be exactly the same as vanilla, even the serializer (though you will have to register a second one so it deserializes to your recipe).

Link to comment
Share on other sites

6 minutes ago, ChampionAsh5357 said:

Extend the class and override getRecipeType to return your own. Everything else can be exactly the same as vanilla, even the serializer (though you will have to register a second one so it deserializes to your recipe).

So this should work?

public class LargeGridRecipe extends ShapedRecipe {

	@Override
    public RecipeType<?> getType() {
        return Type.INSTANCE;
    }

    public static class Type implements RecipeType<LargeGridRecipe> {
        private Type() { }
        public static final Type INSTANCE = new Type();
        public static final String ID = "large_grid";
    }

}

 

As a side question, do you perhaps know where I can find an example of how to check if a recipe is present in the BlockEntity? I know how to do this for shapeless recipes but it doesn't seem to work for a shaped recipe.

Link to comment
Share on other sites

5 hours ago, Myxtro said:
public static class Type implements RecipeType<LargeGridRecipe> {
        private Type() { }
        public static final Type INSTANCE = new Type();
        public static final String ID = "large_grid";
    }

You can just make an anonymous class and use the DeferredRegister to register the type the same way. Don't ever do static initialization.

5 hours ago, Myxtro said:

As a side question, do you perhaps know where I can find an example of how to check if a recipe is present in the BlockEntity? I know how to do this for shapeless recipes but it doesn't seem to work for a shaped recipe.

Look at the RecipeManager. Also, it has nothing to do with the difference of recipes. If your type doesn't have serializers for the recipe you want to handle, then no recipes of that type will be present. For example, shapeless recipes are tied to the crafting recipe type. The only way to get around that is to grab all the craft recipes and then check if the recipe is an instance of ShapelessRecipe.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • every time I try to load forge version 1. 12. 2 with the blockbuster mod the mclib and the metamorphs mod The game crashed and this is the crash m whilst there was a severe problem during mod loading that has caused the game to fail Error: net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Blockbuster (blockbuster)
    • Join the Ultimate EarthSMP - [RiftMC SMP] play.riftmc.net https://riftmc.net/ Join Our Discord     Are you ready to embark on a Minecraft adventure like no other? Look no further than RiftMC! With our server, you'll be transported to a world of endless possibilities, where your imagination can run wild.   Have you ever dreamed of building your own kingdom, or exploring vast landscapes with your friends? At RiftMC, you can do just that and more. With multiple gameplay options, including survival, earthsmp, and PvP gameplay, you'll never run out of things to do.   Are you looking for a challenge? Our survival mode will test your skills as you brave the dangers of the wilderness. Or, if you're feeling creative, our custom world is the perfect canvas for you to unleash your imagination and build whatever your heart desires.   Do you thrive on competition? Our PvP arenas are the perfect place for you to battle it out with other players for supremacy. Or, if you prefer a more cooperative experience, join up with other players to form communities and build sprawling cities.   But that's not all - we also have a thriving economic system, where you can buy and sell goods with other players and even start your own businesses. And with our friendly and dedicated staff, you can rest assured that you'll always have the help and support you need.   So, what are you waiting for? Are you ready to experience the adventure of a lifetime? Join the thousands of players who have already discovered the magic of RiftMC! Simply connect to play.riftmc.net and let the journey begin. Are you ready to dive in?  
    • I want a sword that will kill all hostile mobs with one hit, so is there any way to do that?
    • I have that error when i started my forge server, can anyone help me? C:\Users\orden\Desktop\Servidor MC>REM Forge requires a configured set of both JVM and program arguments. C:\Users\orden\Desktop\Servidor MC>REM Add custom JVM arguments to the user_jvm_args.txt C:\Users\orden\Desktop\Servidor MC>REM Add custom program arguments {such as nogui} to this file in the next line before the  or C:\Users\orden\Desktop\Servidor MC>REM  pass them to this script directly C:\Users\orden\Desktop\Servidor MC>java @user_jvm_args.txt @libraries/net/minecraftforge/forge/1.18.2-40.1.57/win_args.txt 2023-04-01 21:15:43,376 main WARN Advanced terminal features are not available in this environment [21:15:43] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--launchTarget, forgeserver, --fml.forgeVersion, 40.1.57, --fml.mcVersion, 1.18.2, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20220404.173914, -nogui] [21:15:43] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher 9.1.3+9.1.3+main.9b69c82a starting: java version 20 by Oracle Corporation [21:15:43] [main/INFO] [op.OptiFineTransformationService/]: OptiFineTransformationService.onLoad [21:15:43] [main/INFO] [op.OptiFineTransformationService/]: OptiFine ZIP file URL: union:/C:/Users/orden/Desktop/Servidor%20MC/mods/OptiFine-1.18.2_HD_U_H7.jar%2338!/ [21:15:43] [main/INFO] [op.OptiFineTransformationService/]: OptiFine ZIP file: C:\Users\orden\Desktop\Servidor MC\mods\OptiFine-1.18.2_HD_U_H7.jar [21:15:43] [main/INFO] [op.OptiFineTransformer/]: Target.PRE_CLASS is available [21:15:43] [main/INFO] [mixin/]: SpongePowered MIXIN Subsystem Version=0.8.5 Source=union:/C:/Users/orden/Desktop/Servidor%20MC/libraries/org/spongepowered/mixin/0.8.5/mixin-0.8.5.jar%2314!/ Service=ModLauncher Env=SERVER [21:15:43] [main/INFO] [op.OptiFineTransformationService/]: OptiFineTransformationService.initialize [21:15:45] [main/INFO] [op.OptiFineTransformationService/]: OptiFineTransformationService.transformers [21:15:45] [main/INFO] [op.OptiFineTransformer/]: Targets: 350 [21:15:45] [main/INFO] [op.OptiFineTransformationService/]: additionalClassesLocator: [optifine., net.optifine.] [21:15:47] [main/INFO] [mixin/]: Compatibility level set to JAVA_17 [21:15:47] [main/INFO] [mixin/]: Successfully loaded Mixin Connector [de.maxhenkel.camera.MixinConnector] [21:15:47] [main/INFO] [mixin/]: Successfully loaded Mixin Connector [tictim.paraglider.MixinConnector] [21:15:47] [main/INFO] [cp.mo.mo.LaunchServiceHandler/MODLAUNCHER]: Launching target 'forgeserver' with arguments [-nogui] [21:15:47] [main/WARN] [mixin/]: Error loading class: net/minecraft/server/level/ChunkMap (java.lang.IllegalArgumentException: Unsupported class file major version 64) [21:15:47] [main/WARN] [mixin/]: @Mixin target net.minecraft.server.level.ChunkMap was not found securitycraft.mixins.json:camera.ChunkMapMixin [21:15:47] [main/WARN] [mixin/]: Error loading class: de/maxhenkel/gravestone/events/DeathEvents (java.lang.ClassNotFoundException: de.maxhenkel.gravestone.events.DeathEvents) [21:15:47] [main/WARN] [mixin/]: Error loading class: net/minecraft/world/item/ItemStack (java.lang.IllegalArgumentException: Unsupported class file major version 64) [21:15:47] [main/WARN] [mixin/]: @Mixin target net.minecraft.world.item.ItemStack was not found tombstone.mixins.json:ItemStackMixin [21:15:47] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 64) [21:15:47] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 64) [21:15:47] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 64) [21:15:47] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 64) [21:15:47] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 64) [21:15:47] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 64) [21:15:47] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 64) [21:15:47] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 64) [21:15:47] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 64) [21:15:47] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 64) [21:15:47] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 64) [21:15:47] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 64) [21:15:47] [main/WARN] [mixin/]: Error loading class: java/lang/invoke/MethodHandles$Lookup (java.lang.IllegalArgumentException: Unsupported class file major version 64) [21:15:47] [main/WARN] [mixin/]: Error loading class: java/util/concurrent/CompletableFuture (java.lang.IllegalArgumentException: Unsupported class file major version 64) Exception in thread "main" org.spongepowered.asm.mixin.transformer.throwables.MixinTransformerError: An unexpected critical error was encountered         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinProcessor.applyMixins(MixinProcessor.java:392)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinTransformer.transformClass(MixinTransformer.java:250)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.service.modlauncher.MixinTransformationHandler.processClass(MixinTransformationHandler.java:131)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.launch.MixinLaunchPluginLegacy.processClass(MixinLaunchPluginLegacy.java:131)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.serviceapi.ILaunchPluginService.processClassWithFlags(ILaunchPluginService.java:156)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.LaunchPluginHandler.offerClassNodeToPlugins(LaunchPluginHandler.java:88)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.ClassTransformer.transform(ClassTransformer.java:120)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.TransformingClassLoader.maybeTransformClassBytes(TransformingClassLoader.java:50)         at cpw.mods.securejarhandler@1.0.3/cpw.mods.cl.ModuleClassLoader.readerToClass(ModuleClassLoader.java:110)         at cpw.mods.securejarhandler@1.0.3/cpw.mods.cl.ModuleClassLoader.lambda$findClass$16(ModuleClassLoader.java:216)         at cpw.mods.securejarhandler@1.0.3/cpw.mods.cl.ModuleClassLoader.loadFromModule(ModuleClassLoader.java:226)         at cpw.mods.securejarhandler@1.0.3/cpw.mods.cl.ModuleClassLoader.findClass(ModuleClassLoader.java:216)         at cpw.mods.securejarhandler@1.0.3/cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:132)         at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)         at java.base/java.lang.Class.getDeclaredMethods0(Native Method)         at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3502)         at java.base/java.lang.Class.getMethodsRecursive(Class.java:3643)         at java.base/java.lang.Class.getMethod0(Class.java:3629)         at java.base/java.lang.Class.getMethod(Class.java:2319)         at MC-BOOTSTRAP/fmlloader@1.18.2-40.1.57/net.minecraftforge.fml.loading.targets.CommonServerLaunchHandler.lambda$launchService$0(CommonServerLaunchHandler.java:32)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.Launcher.run(Launcher.java:106)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.Launcher.main(Launcher.java:77)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26)         at MC-BOOTSTRAP/cpw.mods.modlauncher@9.1.3/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23)         at cpw.mods.bootstraplauncher@1.0.0/cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:149) Caused by: org.spongepowered.asm.mixin.throwables.ClassMetadataNotFoundException: java.util.concurrent.CompletableFuture         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinPreProcessorStandard.transformMethod(MixinPreProcessorStandard.java:754)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinPreProcessorStandard.transform(MixinPreProcessorStandard.java:739)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinPreProcessorStandard.attach(MixinPreProcessorStandard.java:310)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinPreProcessorStandard.createContextFor(MixinPreProcessorStandard.java:280)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinInfo.createContextFor(MixinInfo.java:1288)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard.apply(MixinApplicatorStandard.java:292)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.TargetClassContext.apply(TargetClassContext.java:383)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.TargetClassContext.applyMixins(TargetClassContext.java:365)         at MC-BOOTSTRAP/org.spongepowered.mixin/org.spongepowered.asm.mixin.transformer.MixinProcessor.applyMixins(MixinProcessor.java:363)         ... 27 more C:\Users\orden\Desktop\Servidor MC>pause Presione una tecla para continuar . . .
  • Topics

×
×
  • Create New...

Important Information

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