Guest User

Example Mod getting textures to load

a guest
Sep 6th, 2019
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.96 KB | None | 0 0
  1. package com.example.examplemod;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.block.Blocks;
  5. import net.minecraft.block.material.Material;
  6. import net.minecraft.client.main.Main;
  7. import net.minecraft.client.renderer.model.ModelResourceLocation;
  8. import net.minecraft.item.BlockItem;
  9. import net.minecraft.item.Item;
  10. import net.minecraft.item.ItemGroup;
  11. import net.minecraft.item.Rarity;
  12. import net.minecraft.util.ResourceLocation;
  13. import net.minecraftforge.client.event.ModelRegistryEvent;
  14. import net.minecraftforge.client.model.IModel;
  15. import net.minecraftforge.client.model.ModelLoader;
  16. import net.minecraftforge.client.model.ModelLoaderRegistry;
  17. import net.minecraftforge.common.MinecraftForge;
  18. import net.minecraftforge.event.RegistryEvent;
  19. import net.minecraftforge.eventbus.api.SubscribeEvent;
  20. import net.minecraftforge.fml.InterModComms;
  21. import net.minecraftforge.fml.common.Mod;
  22. import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
  23. import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
  24. import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
  25. import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
  26. import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
  27. import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
  28. import org.apache.logging.log4j.LogManager;
  29. import org.apache.logging.log4j.Logger;
  30.  
  31. import java.util.stream.Collectors;
  32.  
  33. // The value here should match an entry in the META-INF/mods.toml file
  34. @Mod("examplemod")
  35. public class ExampleMod
  36. {
  37.     // Directly reference a log4j logger.
  38.     private static final Logger LOGGER = LogManager.getLogger();
  39.  
  40.     private static Block sampleiteOre = new Block(Block.Properties.create(Material.IRON)).setRegistryName("sampleite_ore");
  41.     private static BlockItem itemblock = new BlockItem(sampleiteOre, new Item.Properties().rarity(Rarity.RARE).group(ItemGroup.BUILDING_BLOCKS));
  42.  
  43.     public ExampleMod() {
  44.         // Register the setup method for modloading
  45.         FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
  46.         // Register the enqueueIMC method for modloading
  47.         FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
  48.         // Register the processIMC method for modloading
  49.         FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
  50.         // Register the doClientStuff method for modloading
  51.         FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
  52.  
  53.         // Register ourselves for server and other game events we are interested in
  54.         MinecraftForge.EVENT_BUS.register(this);
  55.     }
  56.  
  57.     private void setup(final FMLCommonSetupEvent event)
  58.     {
  59.         // some preinit code
  60.         LOGGER.info("HELLO FROM PREINIT");
  61.         LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
  62.     }
  63.  
  64.     private void doClientStuff(final FMLClientSetupEvent event) {
  65.         // do something that can only be done on the client
  66.         LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);
  67.     }
  68.  
  69.     private void enqueueIMC(final InterModEnqueueEvent event)
  70.     {
  71.         // some example code to dispatch IMC to another mod
  72.         InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";});
  73.     }
  74.  
  75.     private void processIMC(final InterModProcessEvent event)
  76.     {
  77.         // some example code to receive and process InterModComms from other mods
  78.         LOGGER.info("Got IMC {}", event.getIMCStream().
  79.                 map(m->m.getMessageSupplier().get()).
  80.                 collect(Collectors.toList()));
  81.     }
  82.     // You can use SubscribeEvent and let the Event Bus discover methods to call
  83.     @SubscribeEvent
  84.     public void onServerStarting(FMLServerStartingEvent event) {
  85.         // do something when the server starts
  86.         LOGGER.info("HELLO from server starting");
  87.     }
  88.  
  89.     // You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
  90.     // Event bus for receiving Registry Events)
  91.     @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
  92.     public static class RegistryEvents {
  93.         @SubscribeEvent
  94.         public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
  95.             // register a new block here
  96.             blockRegistryEvent.getRegistry().register(sampleiteOre);
  97.             LOGGER.info("HELLO from Register Block");
  98.         }
  99.         @SubscribeEvent
  100.         public static void onItemsRegistry(final RegistryEvent.Register<Item> blockRegistryEvent) {
  101.             // register a new block here
  102.             blockRegistryEvent.getRegistry().register(itemblock.setRegistryName("sampleite_ore"));
  103.             LOGGER.info("HELLO from Register Block");
  104.         }
  105.  
  106.         @SubscribeEvent
  107.         public static void onModelRegistry(ModelRegistryEvent event) {
  108.  
  109.         }
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment