From ef8a3bc6fd2c9abdf6625d8aabc44382c6456cb4 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Wed, 20 Nov 2024 19:48:59 +0100 Subject: Add crafting recipe --- .../nea/funnyteleporters/ColouredChestState.java | 4 +--- .../nea/funnyteleporters/FunnyDataGenerator.java | 13 +++++++++++ .../nea/funnyteleporters/FunnyRecipeProvider.java | 27 ++++++++++++++++++++++ .../moe/nea/funnyteleporters/FunnyRegistry.java | 20 +++++++++------- .../moe/nea/funnyteleporters/FunnyTeleporters.java | 5 ++++ 5 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 src/main/java/moe/nea/funnyteleporters/FunnyDataGenerator.java create mode 100644 src/main/java/moe/nea/funnyteleporters/FunnyRecipeProvider.java (limited to 'src/main/java/moe') diff --git a/src/main/java/moe/nea/funnyteleporters/ColouredChestState.java b/src/main/java/moe/nea/funnyteleporters/ColouredChestState.java index 9e18b16..74f0207 100644 --- a/src/main/java/moe/nea/funnyteleporters/ColouredChestState.java +++ b/src/main/java/moe/nea/funnyteleporters/ColouredChestState.java @@ -22,8 +22,6 @@ import java.util.Map; import java.util.Objects; import java.util.StringJoiner; -import static moe.nea.funnyteleporters.FunnyRegistry.MODID; - public class ColouredChestState extends PersistentState { public Map, DefaultedList> inventories = new HashMap<>(); @@ -72,7 +70,7 @@ public class ColouredChestState extends PersistentState { public static Type TYPE = new Type<>(ColouredChestState::new, ColouredChestState::createFromNbt, null); - public static Identifier identifier = Identifier.of(MODID, "coloured_chests"); + public static Identifier identifier = FunnyTeleporters.id("coloured_chests"); public static ColouredChestState getServerState(MinecraftServer server) { var persistentStateWorld = Objects.requireNonNull(server.getWorld(World.OVERWORLD)).getPersistentStateManager(); // Force all data saving to be done in the overworld diff --git a/src/main/java/moe/nea/funnyteleporters/FunnyDataGenerator.java b/src/main/java/moe/nea/funnyteleporters/FunnyDataGenerator.java new file mode 100644 index 0000000..195723e --- /dev/null +++ b/src/main/java/moe/nea/funnyteleporters/FunnyDataGenerator.java @@ -0,0 +1,13 @@ +package moe.nea.funnyteleporters; + +import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; +import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; + +public class FunnyDataGenerator implements DataGeneratorEntrypoint { + @Override + public void onInitializeDataGenerator(FabricDataGenerator dataGenerator) { + var pack = dataGenerator.createPack(); + pack.addProvider(FunnyRecipeProvider::new); + } + +} diff --git a/src/main/java/moe/nea/funnyteleporters/FunnyRecipeProvider.java b/src/main/java/moe/nea/funnyteleporters/FunnyRecipeProvider.java new file mode 100644 index 0000000..5b7ee14 --- /dev/null +++ b/src/main/java/moe/nea/funnyteleporters/FunnyRecipeProvider.java @@ -0,0 +1,27 @@ +package moe.nea.funnyteleporters; + +import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; +import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider; +import net.minecraft.data.server.recipe.RecipeExporter; +import net.minecraft.data.server.recipe.ShapelessRecipeJsonBuilder; +import net.minecraft.item.Items; +import net.minecraft.recipe.book.RecipeCategory; +import net.minecraft.registry.RegistryWrapper; + +import java.util.concurrent.CompletableFuture; + +public class FunnyRecipeProvider extends FabricRecipeProvider { + + public FunnyRecipeProvider(FabricDataOutput output, CompletableFuture registriesFuture) { + super(output, registriesFuture); + } + + @Override + public void generate(RecipeExporter recipeExporter) { + ShapelessRecipeJsonBuilder.create(RecipeCategory.TRANSPORTATION, FunnyRegistry.COLOURED_CHEST) + .input(Items.ENDER_CHEST).input(Items.REDSTONE_BLOCK).input(Items.HOPPER) + .criterion(hasItem(Items.ENDER_CHEST), conditionsFromItem(Items.ENDER_CHEST)) + .offerTo(recipeExporter); + + } +} diff --git a/src/main/java/moe/nea/funnyteleporters/FunnyRegistry.java b/src/main/java/moe/nea/funnyteleporters/FunnyRegistry.java index 87f2c4f..7b3e3c2 100644 --- a/src/main/java/moe/nea/funnyteleporters/FunnyRegistry.java +++ b/src/main/java/moe/nea/funnyteleporters/FunnyRegistry.java @@ -1,31 +1,35 @@ package moe.nea.funnyteleporters; +import eu.pb4.polymer.core.api.block.PolymerBlockUtils; +import eu.pb4.polymer.core.api.item.PolymerBlockItem; import net.minecraft.block.AbstractBlock; import net.minecraft.block.Block; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; +import net.minecraft.item.Items; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; import net.minecraft.util.Identifier; public class FunnyRegistry { - public static final String MODID = "funny_teleporters"; - public static Block COLOURED_CHEST = registerBlock("coloured_chest", new ColouredChestBlock(AbstractBlock.Settings.create())); + public static Block COLOURED_CHEST = registerBlock("coloured_chest", new ColouredChestBlock(AbstractBlock.Settings.create()), Items.RED_WOOL); public static BlockEntityType COLOURED_CHEST_ENTITY = registerBlockEntity("coloured_chest", BlockEntityType.Builder.create(ColouredChestBlockEntity::new, COLOURED_CHEST)); private static BlockEntityType registerBlockEntity(String name, BlockEntityType.Builder builder, Block... blocks) { - return Registry.register(Registries.BLOCK_ENTITY_TYPE, - Identifier.of(MODID, name), - builder.build() + var be = Registry.register(Registries.BLOCK_ENTITY_TYPE, + Identifier.of(FunnyTeleporters.MOD_ID, name), + builder.build() ); + PolymerBlockUtils.registerBlockEntity(be); + return be; } - private static T registerBlock(String name, T block) { - var id = Identifier.of(MODID, name); - Registry.register(Registries.ITEM, id, new BlockItem(block, new Item.Settings())); + private static T registerBlock(String name, T block, Item blockItem) { + var id = Identifier.of(FunnyTeleporters.MOD_ID, name); + Registry.register(Registries.ITEM, id, new PolymerBlockItem(block, new Item.Settings(), blockItem)); return Registry.register(Registries.BLOCK, id, block); } diff --git a/src/main/java/moe/nea/funnyteleporters/FunnyTeleporters.java b/src/main/java/moe/nea/funnyteleporters/FunnyTeleporters.java index eb4accb..a81c63c 100644 --- a/src/main/java/moe/nea/funnyteleporters/FunnyTeleporters.java +++ b/src/main/java/moe/nea/funnyteleporters/FunnyTeleporters.java @@ -2,6 +2,7 @@ package moe.nea.funnyteleporters; import net.fabricmc.api.ModInitializer; +import net.minecraft.util.Identifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -10,6 +11,10 @@ public class FunnyTeleporters implements ModInitializer { public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); + public static Identifier id(String name) { + return Identifier.of(MOD_ID, name); + } + @Override public void onInitialize() { FunnyRegistry.init(); -- cgit