Scaffolded mod structure for now

This commit is contained in:
Andrew 2022-08-05 15:24:11 +07:00
parent 0df2997010
commit 38ee524bf9
5 changed files with 143 additions and 62 deletions

View file

@ -1,77 +1,29 @@
package xyz.nuark.enchantrium; package xyz.nuark.enchantrium;
import com.mojang.logging.LogUtils; import com.mojang.logging.LogUtils;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.event.server.ServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import xyz.nuark.enchantrium.block.ModBlocks;
import xyz.nuark.enchantrium.block.entity.ModBlockEntities;
import xyz.nuark.enchantrium.item.ModItems;
import xyz.nuark.enchantrium.screen.ModMenuTypes;
import java.util.stream.Collectors; @Mod(Enchantrium.MOD_ID)
// The value here should match an entry in the META-INF/mods.toml file
@Mod("enchantrium")
public class Enchantrium { public class Enchantrium {
public static final String MOD_ID = "enchantrium";
// Directly reference a slf4j logger public static final Logger LOGGER = LogUtils.getLogger();
private static final Logger LOGGER = LogUtils.getLogger();
public Enchantrium() { public Enchantrium() {
// Register the setup method for modloading IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
// Register the enqueueIMC method for modloading ModItems.register(eventBus);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC); ModBlocks.register(eventBus);
// Register the processIMC method for modloading ModBlockEntities.register(eventBus);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC); ModMenuTypes.register(eventBus);
// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
} }
private void setup(final FMLCommonSetupEvent event) {
// Some preinit code
LOGGER.info("HELLO FROM PREINIT");
LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
}
private void enqueueIMC(final InterModEnqueueEvent event) {
// Some example code to dispatch IMC to another mod
InterModComms.sendTo("enchantrium", "helloworld", () -> {
LOGGER.info("Hello world from the MDK");
return "Hello world";
});
}
private void processIMC(final InterModProcessEvent event) {
// Some example code to receive and process InterModComms from other mods
LOGGER.info("Got IMC {}", event.getIMCStream().
map(m -> m.messageSupplier().get()).
collect(Collectors.toList()));
}
// 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 subscribe events on the contained class (this is subscribing to the MOD
// Event bus for receiving Registry Events)
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public static class RegistryEvents {
@SubscribeEvent
public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
// Register a new block here
LOGGER.info("HELLO from Register Block");
}
}
} }

View file

@ -0,0 +1,61 @@
package xyz.nuark.enchantrium.block;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.nuark.enchantrium.Enchantrium;
import xyz.nuark.enchantrium.item.ModItems;
import java.util.List;
import java.util.function.Supplier;
public class ModBlocks {
public static final DeferredRegister<Block> BLOCKS =
DeferredRegister.create(ForgeRegistries.BLOCKS, Enchantrium.MOD_ID);
private static <T extends Block> RegistryObject<T> registerBlockWithoutBlockItem(String name, Supplier<T> block) {
return BLOCKS.register(name, block);
}
private static <T extends Block> RegistryObject<T> registerBlock(String name, Supplier<T> block, String tooltipKey) {
RegistryObject<T> toReturn = BLOCKS.register(name, block);
registerBlockItem(name, toReturn, tooltipKey);
return toReturn;
}
private static <T extends Block> RegistryObject<Item> registerBlockItem(String name, RegistryObject<T> block, String tooltipKey) {
return ModItems.ITEMS.register(name, () -> new BlockItem(block.get(),
new Item.Properties().tab(ModItems.ITEM_GROUP)) {
@Override
public void appendHoverText(@NotNull ItemStack pStack, @Nullable Level pLevel, @NotNull List<Component> pTooltip, @NotNull TooltipFlag pFlag) {
pTooltip.add(new TranslatableComponent(tooltipKey));
}
});
}
private static <T extends Block> RegistryObject<T> registerBlock(String name, Supplier<T> block) {
RegistryObject<T> toReturn = BLOCKS.register(name, block);
registerBlockItem(name, toReturn);
return toReturn;
}
private static <T extends Block> RegistryObject<Item> registerBlockItem(String name, RegistryObject<T> block) {
return ModItems.ITEMS.register(name, () -> new BlockItem(block.get(),
new Item.Properties().tab(ModItems.ITEM_GROUP)));
}
public static void register(IEventBus eventBus) {
BLOCKS.register(eventBus);
}
}

View file

@ -0,0 +1,16 @@
package xyz.nuark.enchantrium.block.entity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import xyz.nuark.enchantrium.Enchantrium;
public class ModBlockEntities {
public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES =
DeferredRegister.create(ForgeRegistries.BLOCK_ENTITIES, Enchantrium.MOD_ID);
public static void register(IEventBus eventBus) {
BLOCK_ENTITIES.register(eventBus);
}
}

View file

@ -0,0 +1,28 @@
package xyz.nuark.enchantrium.item;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import org.jetbrains.annotations.NotNull;
import xyz.nuark.enchantrium.Enchantrium;
public class ModItems {
public static final CreativeModeTab ITEM_GROUP = new CreativeModeTab(Enchantrium.MOD_ID) {
@Override
public @NotNull ItemStack makeIcon() {
return new ItemStack(TEST_ITEM.get());
}
};
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, Enchantrium.MOD_ID);
public static final RegistryObject<Item> TEST_ITEM = ITEMS.register("test_item", () -> new Item(new Item.Properties().tab(ITEM_GROUP)));
public static void register(IEventBus eventBus) {
ITEMS.register(eventBus);
}
}

View file

@ -0,0 +1,24 @@
package xyz.nuark.enchantrium.screen;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.MenuType;
import net.minecraftforge.common.extensions.IForgeMenuType;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.network.IContainerFactory;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import xyz.nuark.enchantrium.Enchantrium;
public class ModMenuTypes {
public static final DeferredRegister<MenuType<?>> MENUS =
DeferredRegister.create(ForgeRegistries.CONTAINERS, Enchantrium.MOD_ID);
private static <T extends AbstractContainerMenu> RegistryObject<MenuType<T>> registerMenuType(IContainerFactory<T> factory, String name) {
return MENUS.register(name, () -> IForgeMenuType.create(factory));
}
public static void register(IEventBus eventBus) {
MENUS.register(eventBus);
}
}