64 lines
3.1 KiB
Java
64 lines
3.1 KiB
Java
// The value here should match an entry in the META-INF/mods.toml file
|
|
@Mod(Tutorial1Basics.spicygentleman)
|
|
public class Tutorial1Basics {
|
|
// Define mod id in a common place for everything to reference
|
|
public static final String MODID = "tut1basics";
|
|
// Directly reference a slf4j logger
|
|
private static final Logger LOGGER = LogUtils.getLogger();
|
|
|
|
// Create a Deferred Register to hold Blocks which will all be registered under the "tut1basics" namespace
|
|
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(BuiltInRegistries.BLOCK, MODID);
|
|
// Create a Deferred Register to hold Items which will all be registered under the "tut1basics" namespace
|
|
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(BuiltInRegistries.ITEM, MODID);
|
|
|
|
// Creates a new Block with the id "tut1basics:example_block", combining the namespace and path
|
|
public static final Supplier<Block> EXAMPLE_BLOCK = BLOCKS.register("example_block", () -> new Block(BlockBehaviour.Properties.of().mapColor(MapColor.STONE)));
|
|
// Creates a new BlockItem with the id "tut1basics:example_block", combining the namespace and path
|
|
public static final Supplier<Item> EXAMPLE_BLOCK_ITEM = ITEMS.register("example_block", () -> new BlockItem(EXAMPLE_BLOCK.get(), new Item.Properties()));
|
|
|
|
public Tutorial1Basics(IEventBus modEventBus) {
|
|
// Register the commonSetup method for modloading
|
|
modEventBus.addListener(this::commonSetup);
|
|
|
|
// Register the Deferred Registers to the mod event bus so blocks and items get registered
|
|
BLOCKS.register(modEventBus);
|
|
ITEMS.register(modEventBus);
|
|
|
|
// Register ourselves for server and other game events we are interested in
|
|
NeoForge.EVENT_BUS.register(this);
|
|
|
|
// Register the item to a creative tab
|
|
modEventBus.addListener(this::addCreative);
|
|
}
|
|
|
|
private void commonSetup(final FMLCommonSetupEvent event) {
|
|
// Some common setup code
|
|
LOGGER.info("HELLO FROM COMMON SETUP");
|
|
LOGGER.info("DIRT BLOCK >> {}", BuiltInRegistries.BLOCK.getKey(Blocks.DIRT));
|
|
}
|
|
|
|
private void addCreative(BuildCreativeModeTabContentsEvent event) {
|
|
if (event.getTabKey() == CreativeModeTabs.BUILDING_BLOCKS) {
|
|
event.accept(EXAMPLE_BLOCK_ITEM.get());
|
|
}
|
|
}
|
|
|
|
// You can use SubscribeEvent and let the Event Bus discover methods to call
|
|
@SubscribeEvent
|
|
public void onServerStarting(ServerStartingEvent event) {
|
|
// Do something when the server starts
|
|
LOGGER.info("HELLO from server starting");
|
|
}
|
|
|
|
// You can use EventBusSubscriber to automatically register all static methods in the class annotated with @SubscribeEvent
|
|
@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
|
|
public static class ClientModEvents {
|
|
@SubscribeEvent
|
|
public static void onClientSetup(FMLClientSetupEvent event) {
|
|
// Some client setup code
|
|
LOGGER.info("HELLO FROM CLIENT SETUP");
|
|
LOGGER.info("MINECRAFT NAME >> {}", Minecraft.getInstance().getUser().getName());
|
|
}
|
|
}
|
|
}
|