From 6462e0f810e0e56589307212525b1028ed12d213 Mon Sep 17 00:00:00 2001 From: Lucas Vas Date: Tue, 15 Apr 2025 00:30:23 -0400 Subject: [PATCH 1/3] feat: create testing block It's a mess. --- .../uncreativebunch/magicmod/MagicMod.java | 4 + .../magicmod/block/ModBlocks.java | 84 +++++++++++++++++++ .../magicmod/item/ModItemGroups.java | 6 +- .../magicmod/item/ModItems.java | 9 +- .../blockstates/magical_crafting_table.json | 7 ++ .../items/magical_crafting_table.json | 6 ++ .../assets/magic_mod/lang/en_us.json | 1 + .../models/block/magical_crafting_table.json | 12 +++ .../data/magic-mod/recipe/testing_powder.json | 15 ---- .../blocks/magical_crafting_table.json | 19 +++++ 10 files changed, 141 insertions(+), 22 deletions(-) create mode 100644 src/main/java/com/uncreativebunch/magicmod/block/ModBlocks.java create mode 100644 src/main/resources/assets/magic_mod/blockstates/magical_crafting_table.json create mode 100644 src/main/resources/assets/magic_mod/items/magical_crafting_table.json create mode 100644 src/main/resources/assets/magic_mod/models/block/magical_crafting_table.json delete mode 100644 src/main/resources/data/magic-mod/recipe/testing_powder.json create mode 100644 src/main/resources/data/magic_mod/loot_table/blocks/magical_crafting_table.json diff --git a/src/main/java/com/uncreativebunch/magicmod/MagicMod.java b/src/main/java/com/uncreativebunch/magicmod/MagicMod.java index d6bcee0..7eb74e2 100644 --- a/src/main/java/com/uncreativebunch/magicmod/MagicMod.java +++ b/src/main/java/com/uncreativebunch/magicmod/MagicMod.java @@ -1,6 +1,8 @@ package com.uncreativebunch.magicmod; +import com.uncreativebunch.magicmod.block.ModBlocks; import com.uncreativebunch.magicmod.item.ModItemGroups; +import com.uncreativebunch.magicmod.item.ModItems; import net.fabricmc.api.ModInitializer; import org.slf4j.Logger; @@ -24,6 +26,8 @@ public class MagicMod implements ModInitializer { LOGGER.info("Hello Fabric world!"); LOGGER.info("Starting Magic Mod..."); + ModBlocks.init(); + ModItems.init(); ModItemGroups.init(); LOGGER.info("Finished Magic Mod initialization!"); } diff --git a/src/main/java/com/uncreativebunch/magicmod/block/ModBlocks.java b/src/main/java/com/uncreativebunch/magicmod/block/ModBlocks.java new file mode 100644 index 0000000..d221ae9 --- /dev/null +++ b/src/main/java/com/uncreativebunch/magicmod/block/ModBlocks.java @@ -0,0 +1,84 @@ +package com.uncreativebunch.magicmod.block; + +import com.uncreativebunch.magicmod.MagicMod; +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.Block; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.sound.BlockSoundGroup; +import net.minecraft.util.Identifier; + +import java.util.function.Function; + +public class ModBlocks { + //region Block Definitions + + public static final Block MAGICAL_CRAFTING_TABLE = register( + "magical_crafting_table", + Block::new, + AbstractBlock.Settings + .create() + .sounds(BlockSoundGroup.AMETHYST_BLOCK), + true + ); + + //endregion + + /** + * Used to statically initialize this class. Nothing needs to be in it for now. + */ + public static void init() { + MagicMod.LOGGER.info("Block initialization complete"); + } + + /** + * Registers a new {@link Block}. + * @param name The name of the {@link Block} to register. + * @param factory The block factory to use - typically Block::new + * @param settings The {@link AbstractBlock.Settings} to use for creation. + * @param shouldRegisterItem Determines if an item should be created with the block, for use in the inventory. + * @return The newly registered {@link Block}. + */ + public static Block register( + String name, + Function factory, + AbstractBlock.Settings settings, + boolean shouldRegisterItem) { + + RegistryKey blockKey = keyOfBlock(name); + Block block = factory.apply(settings.registryKey(blockKey)); + + // We don't always want to create items for blocks - sometimes the block is in an "active" state, + // which we don't want to create an item instance for, just the block. + if (shouldRegisterItem) { + RegistryKey itemKey = keyOfItem(name); + BlockItem blockItem = new BlockItem(block, new Item.Settings().registryKey(itemKey)); + Registry.register(Registries.ITEM, itemKey, blockItem); + } + + // Finally return the block we want to register. + return Registry.register(Registries.BLOCK, blockKey, block); + } + + /** + * Gets a {@link RegistryKey} for the specified block name. + * @param name The name of the {@link Block} to use. + * @return The {@link RegistryKey} for the specified {@link Block}. + */ + public static RegistryKey keyOfBlock(String name) { + return RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(MagicMod.MOD_ID, name)); + } + + /** + * Gets a {@link RegistryKey} for the specified item name. + * @param name The name of the {@link Item} to use. + * @return The {@link RegistryKey} of the specified {@link Item}. + */ + public static RegistryKey keyOfItem(String name) { + return RegistryKey.of(RegistryKeys.ITEM, Identifier.of(MagicMod.MOD_ID, name)); + } +} diff --git a/src/main/java/com/uncreativebunch/magicmod/item/ModItemGroups.java b/src/main/java/com/uncreativebunch/magicmod/item/ModItemGroups.java index 91d1885..d587622 100644 --- a/src/main/java/com/uncreativebunch/magicmod/item/ModItemGroups.java +++ b/src/main/java/com/uncreativebunch/magicmod/item/ModItemGroups.java @@ -1,6 +1,7 @@ package com.uncreativebunch.magicmod.item; import com.uncreativebunch.magicmod.MagicMod; +import com.uncreativebunch.magicmod.block.ModBlocks; import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; import net.minecraft.item.ItemGroup; @@ -31,7 +32,7 @@ public class ModItemGroups { */ public static final ItemGroup MAGIC_GROUP = FabricItemGroup.builder() .icon(() -> new ItemStack(ModItems.TESTING_POWDER)) // The item to show as the group's icon. Can be anything. - .displayName(Text.translatable("magic-mod.magic_group")) // Gets the name from the translation file in the mod resources. + .displayName(Text.translatable("magic_mod.magic_group")) // Gets the name from the translation file in the mod resources. .build(); @@ -42,12 +43,11 @@ public class ModItemGroups { * custom items. */ public static void init() { - ModItems.init(); - Registry.register(Registries.ITEM_GROUP, MAGIC_GROUP_KEY, MAGIC_GROUP); ItemGroupEvents.modifyEntriesEvent(MAGIC_GROUP_KEY) .register(itemGroup -> { itemGroup.add(ModItems.TESTING_POWDER); + itemGroup.add(ModBlocks.MAGICAL_CRAFTING_TABLE.asItem()); }); MagicMod.LOGGER.info("Item group initialization complete"); diff --git a/src/main/java/com/uncreativebunch/magicmod/item/ModItems.java b/src/main/java/com/uncreativebunch/magicmod/item/ModItems.java index 441843a..34859f0 100644 --- a/src/main/java/com/uncreativebunch/magicmod/item/ModItems.java +++ b/src/main/java/com/uncreativebunch/magicmod/item/ModItems.java @@ -22,17 +22,18 @@ public class ModItems { .food(ModFoodComponents.TESTING_POWDER_COMPONENT, ModConsumableComponents.TESTING_POWDER_NIGHTVIS) ); + public static RegistryKey keyOf(String id) { + return RegistryKey.of(RegistryKeys.ITEM, Identifier.of(MagicMod.MOD_ID, id)); + } public static Item register(String name, @NotNull Function factory, Item.Settings settings) { // Create the item's registry key (get it from the ITEM registry) // Create the item with the specified settings and give it the correct registry key // Register the item with the registry (use the key we found and associate it with the new item) - RegistryKey itemKey = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(MagicMod.MOD_ID, name)); + RegistryKey itemKey = keyOf(name); Item item = factory.apply(settings.registryKey(itemKey)); - Registry.register(Registries.ITEM, itemKey, item); - - return item; + return Registry.register(Registries.ITEM, itemKey, item); } /** diff --git a/src/main/resources/assets/magic_mod/blockstates/magical_crafting_table.json b/src/main/resources/assets/magic_mod/blockstates/magical_crafting_table.json new file mode 100644 index 0000000..3e5ac3f --- /dev/null +++ b/src/main/resources/assets/magic_mod/blockstates/magical_crafting_table.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "magic_mod:block/magical_crafting_table" + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/magic_mod/items/magical_crafting_table.json b/src/main/resources/assets/magic_mod/items/magical_crafting_table.json new file mode 100644 index 0000000..b50e749 --- /dev/null +++ b/src/main/resources/assets/magic_mod/items/magical_crafting_table.json @@ -0,0 +1,6 @@ +{ + "model": { + "type": "minecraft:model", + "model": "magic_mod:block/magical_crafting_table" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/magic_mod/lang/en_us.json b/src/main/resources/assets/magic_mod/lang/en_us.json index bd9c592..54f7066 100644 --- a/src/main/resources/assets/magic_mod/lang/en_us.json +++ b/src/main/resources/assets/magic_mod/lang/en_us.json @@ -1,4 +1,5 @@ { + "block.magic_mod.magical_crafting_table": "Magic Crafter", "item.magic_mod.testing_powder": "Testing Powder (edible)", "magic_mod.magic_group": "Testing Mod Items" } \ No newline at end of file diff --git a/src/main/resources/assets/magic_mod/models/block/magical_crafting_table.json b/src/main/resources/assets/magic_mod/models/block/magical_crafting_table.json new file mode 100644 index 0000000..329901b --- /dev/null +++ b/src/main/resources/assets/magic_mod/models/block/magical_crafting_table.json @@ -0,0 +1,12 @@ +{ + "parent": "minecraft:block/cube", + "textures": { + "up": "minecraft:block/ancient_debris_top", + "down": "minecraft:block/bamboo_block", + "north": "minecraft:block/cobblestone", + "east": "minecraft:block/bedrock", + "south": "minecraft:block/birch_leaves", + "west": "minecraft:block/creaking_heart", + "particle": "minecraft:block/creaking_heart" + } +} \ No newline at end of file diff --git a/src/main/resources/data/magic-mod/recipe/testing_powder.json b/src/main/resources/data/magic-mod/recipe/testing_powder.json deleted file mode 100644 index 4f3e59c..0000000 --- a/src/main/resources/data/magic-mod/recipe/testing_powder.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "type": "minecraft:crafting_shaped", - "pattern": [ - " /", - " / ", - "/ " - ], - "key": { - "/": "minecraft:stick" - }, - "result": { - "id": "magic_mod:testing_powder", - "count": 1 - } -} \ No newline at end of file diff --git a/src/main/resources/data/magic_mod/loot_table/blocks/magical_crafting_table.json b/src/main/resources/data/magic_mod/loot_table/blocks/magical_crafting_table.json new file mode 100644 index 0000000..fcbe76b --- /dev/null +++ b/src/main/resources/data/magic_mod/loot_table/blocks/magical_crafting_table.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "magic_mod:testing_powder" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file -- 2.54.0 From 75a38837a607e0fb7b3f9c538c9ff89c527879f0 Mon Sep 17 00:00:00 2001 From: Lucas Vas Date: Thu, 17 Apr 2025 19:03:38 -0400 Subject: [PATCH 2/3] chore: update recipe for block and alter textures --- .../models/block/magical_crafting_table.json | 30 ++++++++++++------ .../models/block/magical_crafting_table2.json | 12 +++++++ .../textures/block/magical_crafting_table.png | Bin 0 -> 277 bytes .../recipe/magical_crafting_table.json | 16 ++++++++++ .../data/magic_mod/recipe/testing_powder.json | 15 +++++++++ 5 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 src/main/resources/assets/magic_mod/models/block/magical_crafting_table2.json create mode 100644 src/main/resources/assets/magic_mod/textures/block/magical_crafting_table.png create mode 100644 src/main/resources/data/magic_mod/recipe/magical_crafting_table.json create mode 100644 src/main/resources/data/magic_mod/recipe/testing_powder.json diff --git a/src/main/resources/assets/magic_mod/models/block/magical_crafting_table.json b/src/main/resources/assets/magic_mod/models/block/magical_crafting_table.json index 329901b..420aef8 100644 --- a/src/main/resources/assets/magic_mod/models/block/magical_crafting_table.json +++ b/src/main/resources/assets/magic_mod/models/block/magical_crafting_table.json @@ -1,12 +1,22 @@ { - "parent": "minecraft:block/cube", - "textures": { - "up": "minecraft:block/ancient_debris_top", - "down": "minecraft:block/bamboo_block", - "north": "minecraft:block/cobblestone", - "east": "minecraft:block/bedrock", - "south": "minecraft:block/birch_leaves", - "west": "minecraft:block/creaking_heart", - "particle": "minecraft:block/creaking_heart" - } + "credit": "Made with Blockbench", + "texture_size": [32, 32], + "textures": { + "0": "magic_mod:block/magical_crafting_table", + "particle": "magic_mod:block/magical_crafting_table" + }, + "elements": [ + { + "from": [0, 0, 0], + "to": [16, 8, 16], + "faces": { + "north": {"uv": [8, 0, 16, 4], "texture": "#0"}, + "east": {"uv": [8, 4, 16, 8], "texture": "#0"}, + "south": {"uv": [8, 8, 16, 12], "texture": "#0"}, + "west": {"uv": [8, 12, 16, 16], "texture": "#0"}, + "up": {"uv": [8, 8, 0, 0], "texture": "#0"}, + "down": {"uv": [8, 8, 0, 16], "texture": "#0"} + } + } + ] } \ No newline at end of file diff --git a/src/main/resources/assets/magic_mod/models/block/magical_crafting_table2.json b/src/main/resources/assets/magic_mod/models/block/magical_crafting_table2.json new file mode 100644 index 0000000..329901b --- /dev/null +++ b/src/main/resources/assets/magic_mod/models/block/magical_crafting_table2.json @@ -0,0 +1,12 @@ +{ + "parent": "minecraft:block/cube", + "textures": { + "up": "minecraft:block/ancient_debris_top", + "down": "minecraft:block/bamboo_block", + "north": "minecraft:block/cobblestone", + "east": "minecraft:block/bedrock", + "south": "minecraft:block/birch_leaves", + "west": "minecraft:block/creaking_heart", + "particle": "minecraft:block/creaking_heart" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/magic_mod/textures/block/magical_crafting_table.png b/src/main/resources/assets/magic_mod/textures/block/magical_crafting_table.png new file mode 100644 index 0000000000000000000000000000000000000000..5cd4fd5b9ef0eedd8f54a84e38f9bb9e418680fb GIT binary patch literal 277 zcmV+w0qXvVP)Px#&q+iKlra*6AP_|#PR^9ZJ_iYnw}{@tCf>$-r66GlAh0kNneZANX8C_* z{iu~4047G@&Vz3@7QmKSOue_o6ub3s9x=%qUxF%crv$p4B?Xg=<1k(6yLxTZTGlHH+Z>` Date: Sun, 20 Apr 2025 15:03:25 -0400 Subject: [PATCH 3/3] feat: give crafter an example event that calls down lightning --- .../magicmod/block/ModBlocks.java | 6 ++- .../block/crafting/MagicalCrafterBlock.java | 47 +++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/uncreativebunch/magicmod/block/crafting/MagicalCrafterBlock.java diff --git a/src/main/java/com/uncreativebunch/magicmod/block/ModBlocks.java b/src/main/java/com/uncreativebunch/magicmod/block/ModBlocks.java index d221ae9..3eb060c 100644 --- a/src/main/java/com/uncreativebunch/magicmod/block/ModBlocks.java +++ b/src/main/java/com/uncreativebunch/magicmod/block/ModBlocks.java @@ -1,8 +1,10 @@ package com.uncreativebunch.magicmod.block; import com.uncreativebunch.magicmod.MagicMod; +import com.uncreativebunch.magicmod.block.crafting.MagicalCrafterBlock; import net.minecraft.block.AbstractBlock; import net.minecraft.block.Block; +import net.minecraft.block.SlabBlock; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.registry.Registries; @@ -19,7 +21,7 @@ public class ModBlocks { public static final Block MAGICAL_CRAFTING_TABLE = register( "magical_crafting_table", - Block::new, + MagicalCrafterBlock::new, AbstractBlock.Settings .create() .sounds(BlockSoundGroup.AMETHYST_BLOCK), @@ -60,7 +62,7 @@ public class ModBlocks { Registry.register(Registries.ITEM, itemKey, blockItem); } - // Finally return the block we want to register. + // Return the block we want to register. return Registry.register(Registries.BLOCK, blockKey, block); } diff --git a/src/main/java/com/uncreativebunch/magicmod/block/crafting/MagicalCrafterBlock.java b/src/main/java/com/uncreativebunch/magicmod/block/crafting/MagicalCrafterBlock.java new file mode 100644 index 0000000..275a177 --- /dev/null +++ b/src/main/java/com/uncreativebunch/magicmod/block/crafting/MagicalCrafterBlock.java @@ -0,0 +1,47 @@ +package com.uncreativebunch.magicmod.block.crafting; + +import com.uncreativebunch.magicmod.MagicMod; +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.BlockState; +import net.minecraft.block.SlabBlock; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LightningEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.ActionResult; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class MagicalCrafterBlock extends SlabBlock { + + /** + * Creates a new MagicalCrafterBlock. + * @param settings The settings of the block. + */ + public MagicalCrafterBlock(AbstractBlock.Settings settings) { super(settings); } + + /** + * Occurs whenever this block is used. This is intended to open a crafting window in the future. + * @param state The current {@link BlockState} of this block. + * @param world The {@link World} that this block exists in. + * @param pos The {@link BlockPos} that this block is at. + * @param player The {@link PlayerEntity} that used this object. + * @param hit The {@link BlockHitResult} that contains information about this interaction. + * @return Whether the action passed, was canceled, or succeeded. + */ + @Override + protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { + if (world.isClient) return ActionResult.PASS; + + MagicMod.LOGGER.info("Block was used at location {}", pos.toShortString()); + + MagicMod.LOGGER.info("Electrocuting player..."); + BlockPos playerPos = player.getBlockPos(); + LightningEntity lightningEntity = new LightningEntity(EntityType.LIGHTNING_BOLT, world); + lightningEntity.setPosition(playerPos.toCenterPos()); + world.spawnEntity(lightningEntity); + MagicMod.LOGGER.info("Player electrocuted."); + + return ActionResult.SUCCESS; + } +} -- 2.54.0