Buckets:
| package com.example.examplemod; | |
| import com.mojang.serialization.MapCodec; | |
| import com.mojang.serialization.codecs.RecordCodecBuilder; | |
| import net.minecraft.item.ItemStack; | |
| import net.minecraft.network.RegistryByteBuf; | |
| import net.minecraft.network.codec.PacketCodec; | |
| import net.minecraft.recipe.Ingredient; | |
| import net.minecraft.recipe.Recipe; | |
| import net.minecraft.recipe.RecipeSerializer; | |
| import net.minecraft.recipe.RecipeType; | |
| import net.minecraft.recipe.book.RecipeBookCategory; | |
| import net.minecraft.recipe.input.RecipeInput; | |
| import net.minecraft.registry.Registries; | |
| import net.minecraft.registry.Registry; | |
| import net.minecraft.util.Identifier; | |
| import net.minecraft.world.World; | |
| /** | |
| * A custom recipe type (e.g. for a custom "crusher" machine). | |
| * Recipe registration moved to Registries.RECIPE_TYPE / RECIPE_SERIALIZER | |
| * and is stable across 1.21.7 - 1.21.11. | |
| */ | |
| public record CrushingRecipe(Ingredient input, ItemStack output) implements Recipe<RecipeInput> { | |
| public boolean matches(RecipeInput input, World world) { | |
| return this.input.test(input.getStackInSlot(0)); | |
| } | |
| public ItemStack craft(RecipeInput input, net.minecraft.registry.RegistryWrapper.WrapperLookup lookup) { | |
| return output.copy(); | |
| } | |
| public boolean fits(int width, int height) { | |
| return true; | |
| } | |
| public ItemStack getResult(net.minecraft.registry.RegistryWrapper.WrapperLookup lookup) { | |
| return output; | |
| } | |
| public RecipeType<?> getType() { | |
| return CRUSHING_TYPE; | |
| } | |
| public RecipeBookCategory getRecipeBookCategory() { | |
| return RecipeBookCategory.FURNACE_MISC; | |
| } | |
| // --- Registration --- | |
| public static final RecipeType<CrushingRecipe> CRUSHING_TYPE = Registry.register( | |
| Registries.RECIPE_TYPE, | |
| Identifier.of(ExampleMod.MOD_ID, "crushing"), | |
| new RecipeType<CrushingRecipe>() {} | |
| ); | |
| public static final RecipeSerializer<CrushingRecipe> SERIALIZER = Registry.register( | |
| Registries.RECIPE_SERIALIZER, | |
| Identifier.of(ExampleMod.MOD_ID, "crushing"), | |
| new RecipeSerializer<CrushingRecipe>() { | |
| private final MapCodec<CrushingRecipe> codec = RecordCodecBuilder.mapCodec(instance -> instance.group( | |
| Ingredient.CODEC.fieldOf("input").forGetter(CrushingRecipe::input), | |
| ItemStack.CODEC.fieldOf("output").forGetter(CrushingRecipe::output) | |
| ).apply(instance, CrushingRecipe::new)); | |
| private final PacketCodec<RegistryByteBuf, CrushingRecipe> packetCodec = PacketCodec.tuple( | |
| Ingredient.PACKET_CODEC, CrushingRecipe::input, | |
| ItemStack.PACKET_CODEC, CrushingRecipe::output, | |
| CrushingRecipe::new | |
| ); | |
| public MapCodec<CrushingRecipe> codec() { | |
| return codec; | |
| } | |
| public PacketCodec<RegistryByteBuf, CrushingRecipe> packetCodec() { | |
| return packetCodec; | |
| } | |
| } | |
| ); | |
| } | |
| /* | |
| * Example JSON to place at: | |
| * data/examplemod/recipe/example_crushing.json | |
| * | |
| * { | |
| * "type": "examplemod:crushing", | |
| * "input": { "item": "minecraft:cobblestone" }, | |
| * "output": { "id": "minecraft:gravel", "count": 1 } | |
| * } | |
| */ | |
Xet Storage Details
- Size:
- 3.46 kB
- Xet hash:
- d922091c2e76576aac3278b05f095ef32a4c5b54e5962e3de13b23318bbf88ba
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.