Created Test Block & DataGen

This commit is contained in:
2025-04-23 01:48:58 +02:00
parent d9bd79a22a
commit 24eaf236e3
23 changed files with 282 additions and 11 deletions

View File

@ -4,21 +4,15 @@ import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import wtf.hak.blocks.ModBlocks;
public class SurvivalEnhanced implements ModInitializer {
public static final String MOD_ID = "survivalenhanced";
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
@Override
public void onInitialize() {
// This code runs as soon as Minecraft is in a mod-load-ready state.
// However, some things (like resources) may still be uninitialized.
// Proceed with mild caution.
LOGGER.info("Hello Fabric world!");
ModBlocks.registerBlocks();
}
}

View File

@ -0,0 +1,62 @@
package wtf.hak.blocks;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.ChestBlock;
import net.minecraft.block.TestBlock;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroups;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
import wtf.hak.SurvivalEnhanced;
import java.util.function.Function;
public class ModBlocks {
public static Block TEST_BLOCK;
private static Block register(String name, Function<AbstractBlock.Settings, Block> blockFactory, AbstractBlock.Settings settings, boolean shouldRegisterItem) {
// Create a registry key for the block
RegistryKey<Block> blockKey = keyOfBlock(name);
// Create the block instance
Block block = blockFactory.apply(settings.registryKey(blockKey));
// Sometimes, you may not want to register an item for the block.
// Eg: if it's a technical block like `minecraft:moving_piston` or `minecraft:end_gateway`
if (shouldRegisterItem) {
// Items need to be registered with a different type of registry key, but the ID
// can be the same.
RegistryKey<Item> itemKey = keyOfItem(name);
BlockItem blockItem = new BlockItem(block, new Item.Settings().registryKey(itemKey));
Registry.register(Registries.ITEM, itemKey, blockItem);
}
return Registry.register(Registries.BLOCK, blockKey, block);
}
private static RegistryKey<Block> keyOfBlock(String name) {
return RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(SurvivalEnhanced.MOD_ID, name));
}
private static RegistryKey<Item> keyOfItem(String name) {
return RegistryKey.of(RegistryKeys.ITEM, Identifier.of(SurvivalEnhanced.MOD_ID, name));
}
public static void registerBlocks(){
TEST_BLOCK = register("test_block",
TestBlock::new,
AbstractBlock.Settings.create().strength(1f).requiresTool(),
true);
ItemGroupEvents.modifyEntriesEvent(ItemGroups.BUILDING_BLOCKS).register(entries -> entries.add(TEST_BLOCK));
}
}

View File

@ -0,0 +1,10 @@
package wtf.hak.blocks;
import net.minecraft.block.Block;
public class TestBlock extends Block {
public TestBlock(Settings settings) {
super(settings);
}
}