Last active
December 24, 2020 18:18
-
-
Save Commoble/d8f005d7bbaba8784f7a11edac77448f to your computer and use it in GitHub Desktop.
Forge Mod Skeleton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Mod(YourMod.MODID) // tells forge to construct this during modloading | |
public class YourMod | |
{ | |
public static final String MODID = "yourmod"; // use this same string everywhere you need a modid | |
// Deferred Registers are forge's latest abstraction layer over the registries | |
// you give them suppliers and they create and register your things when the registry event happens | |
// don't forget to subscribe them to the mod bus in your mod constructor! this is important for making them work | |
// in 1.14 or old forge builds of 1.15 use `new DeferredRegister` instead of .create | |
private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, YourMod.MODID); | |
// registry objects let you static-init a reference to the block without actually creating the block right away | |
// the deferred register will create and register the block during the block registry event and then store your block here | |
public static final RegistryObject<YourBlock> YOUR_BLOCK = BLOCKS.register("yourblock", | |
() -> new YourBlock(AbstractBlock.Properties.from(Blocks.SPONGE))); // re-use existing block properties or create your own, | |
// see Blocks for examples of block instantiation | |
public YourMod() // invoked by forge due to @Mod | |
{ | |
// mod bus has modloading init events and registry events | |
IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus(); | |
// forge bus is for server starting events and in-game events | |
IEventBus forgeBus = MinecraftForge.EVENT_BUS; | |
// add listeners to mod bus and forge bus, register deferred registers to mod bus | |
BLOCKS.register(modBus); | |
// add listeners to clientjar events separately | |
if (FMLEnvironment.dist == Dist.CLIENT) | |
{ | |
ClientEvents.subscribeClientEvents(modBus, forgeBus); | |
} | |
} | |
} | |
// separate class in a different file | |
public class ClientEvents | |
{ | |
public static void subscribeClientEvents(IEventBus modBus, IEventBus forgeBus) | |
{ | |
// subscribe client-only events | |
// client-only classes like Minecraft can be safely referred to in this class | |
modBus.addListener(ClientEvents::onClientSetup); | |
} | |
public static void onClientSetup(FMLClientSetupEvent event) | |
{ | |
// renderers can be registered here | |
// register an entity renderer | |
RenderingRegistry.registerEntityRenderingHandler(your entity type, renderer factory); | |
// register a tile entity renderer | |
ClientRegistry.bindTileEntityRenderer(your tile entity type, YourTileEntityRenderer::new); | |
// set block render layer to cutout or translucent if block doesn't use a solid texture | |
RenderTypeLookup.setRenderLayer(your block, RenderType.getCutout()); | |
// register Screen factory for synced container guis | |
Screenmanager.registerFactory(your container type, screen factory); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment