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

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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