feat: create testing block

It's a mess.
This commit is contained in:
alphafetus committed 2025-04-15 00:30:23 -04:00
1 parent 901749b3a5
commit 6462e0f810
10 files changed
+141 -22

No files matched your search

@@ -1,6 +1,8 @@
package com.uncreativebunch.magicmod; package com.uncreativebunch.magicmod;
import com.uncreativebunch.magicmod.block.ModBlocks;
import com.uncreativebunch.magicmod.item.ModItemGroups; import com.uncreativebunch.magicmod.item.ModItemGroups;
import com.uncreativebunch.magicmod.item.ModItems;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -24,6 +26,8 @@ public class MagicMod implements ModInitializer {
LOGGER.info("Hello Fabric world!"); LOGGER.info("Hello Fabric world!");
LOGGER.info("Starting Magic Mod..."); LOGGER.info("Starting Magic Mod...");
ModBlocks.init();
ModItems.init();
ModItemGroups.init(); ModItemGroups.init();
LOGGER.info("Finished Magic Mod initialization!"); LOGGER.info("Finished Magic Mod initialization!");
} }
@@ -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<AbstractBlock.Settings,Block> factory,
AbstractBlock.Settings settings,
boolean shouldRegisterItem) {
RegistryKey<Block> 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<Item> 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<Block> 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<Item> keyOfItem(String name) {
return RegistryKey.of(RegistryKeys.ITEM, Identifier.of(MagicMod.MOD_ID, name));
}
}
@@ -1,6 +1,7 @@
package com.uncreativebunch.magicmod.item; package com.uncreativebunch.magicmod.item;
import com.uncreativebunch.magicmod.MagicMod; 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.FabricItemGroup;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroup;
@@ -31,7 +32,7 @@ public class ModItemGroups {
*/ */
public static final ItemGroup MAGIC_GROUP = FabricItemGroup.builder() 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. .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(); .build();
@@ -42,12 +43,11 @@ public class ModItemGroups {
* custom items. * custom items.
*/ */
public static void init() { public static void init() {
ModItems.init();
Registry.register(Registries.ITEM_GROUP, MAGIC_GROUP_KEY, MAGIC_GROUP); Registry.register(Registries.ITEM_GROUP, MAGIC_GROUP_KEY, MAGIC_GROUP);
ItemGroupEvents.modifyEntriesEvent(MAGIC_GROUP_KEY) ItemGroupEvents.modifyEntriesEvent(MAGIC_GROUP_KEY)
.register(itemGroup -> { .register(itemGroup -> {
itemGroup.add(ModItems.TESTING_POWDER); itemGroup.add(ModItems.TESTING_POWDER);
itemGroup.add(ModBlocks.MAGICAL_CRAFTING_TABLE.asItem());
}); });
MagicMod.LOGGER.info("Item group initialization complete"); MagicMod.LOGGER.info("Item group initialization complete");
@@ -22,17 +22,18 @@ public class ModItems {
.food(ModFoodComponents.TESTING_POWDER_COMPONENT, ModConsumableComponents.TESTING_POWDER_NIGHTVIS) .food(ModFoodComponents.TESTING_POWDER_COMPONENT, ModConsumableComponents.TESTING_POWDER_NIGHTVIS)
); );
public static RegistryKey<Item> keyOf(String id) {
return RegistryKey.of(RegistryKeys.ITEM, Identifier.of(MagicMod.MOD_ID, id));
}
public static Item register(String name, @NotNull Function<Item.Settings, Item> factory, Item.Settings settings) { public static Item register(String name, @NotNull Function<Item.Settings, Item> factory, Item.Settings settings) {
// Create the item's registry key (get it from the ITEM registry) // 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 // 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) // Register the item with the registry (use the key we found and associate it with the new item)
RegistryKey<Item> itemKey = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(MagicMod.MOD_ID, name)); RegistryKey<Item> itemKey = keyOf(name);
Item item = factory.apply(settings.registryKey(itemKey)); Item item = factory.apply(settings.registryKey(itemKey));
Registry.register(Registries.ITEM, itemKey, item); return Registry.register(Registries.ITEM, itemKey, item);
return item;
} }
/** /**
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "magic_mod:block/magical_crafting_table"
}
}
}
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "magic_mod:block/magical_crafting_table"
}
}
@@ -1,4 +1,5 @@
{ {
"block.magic_mod.magical_crafting_table": "Magic Crafter",
"item.magic_mod.testing_powder": "Testing Powder (edible)", "item.magic_mod.testing_powder": "Testing Powder (edible)",
"magic_mod.magic_group": "Testing Mod Items" "magic_mod.magic_group": "Testing Mod Items"
} }
@@ -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"
}
}
@@ -1,15 +0,0 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
" /",
" / ",
"/ "
],
"key": {
"/": "minecraft:stick"
},
"result": {
"id": "magic_mod:testing_powder",
"count": 1
}
}
@@ -0,0 +1,19 @@
{
"type": "minecraft:block",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"name": "magic_mod:testing_powder"
}
],
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
]
}
]
}