Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/11/17 in all areas

  1. I'm brand new to modding and a noob programmer. I learned the old way to register blocks and items using GameRegistry.register() then I found out there is actually a new, better way to register blocks, items, and even models. The new way is to use RegistryEvents and I'm a sucker for new and better things so I tried to figure out how it works. My goal with this post is to see if anything I did can be done better and whether or not this is correct. Just because it works doesn't mean it's correct. I want to have a solid base before I build on it too much. Here is what I came up with: RegistryEventHandler.java @Mod.EventBusSubscriber public class RegistryEventHandler { @SubscribeEvent public static void registerBlocks(RegistryEvent.Register<Block> event) { event.getRegistry().registerAll(ModBlocks.BLOCKS); Utils.getLogger().info("Registered blocks"); } @SubscribeEvent public static void registerItems(RegistryEvent.Register<Item> event) { event.getRegistry().registerAll(ModItems.ITEMS); for (Block block : ModBlocks.BLOCKS) { event.getRegistry().register(new ItemBlock(block).setRegistryName(block.getRegistryName())); } Utils.getLogger().info("Registered items"); } @SubscribeEvent public static void registerModels(ModelRegistryEvent event) { for (Block block: ModBlocks.BLOCKS) { ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(), "inventory")); } for (Item item: ModItems.ITEMS) { ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory")); } Utils.getLogger().info("Registered models"); } } ModBlocks.java public class ModBlocks { public static final Block[] BLOCKS = { new BlockTinOre("tin_ore", Material.ROCK), new BlockTinBlock("tin_block", Material.ROCK) }; } ModItems.java public class ModItems { public static final Item[] ITEMS = { new ItemTinIngot("tin_ingot") }; } BlockTinOre.java public class BlockTinOre extends BlockBase { public BlockTinOre(String name, Material material) { super(name, material); } } BlockTinBlock.java public class BlockTinBlock extends BlockBase { public BlockTinBlock(String name, Material material) { super(name, material); } } BlockBase.java public class BlockBase extends Block { BlockBase(String name, Material material) { super(material); this.setRegistryName(Reference.MODID, name); this.setUnlocalizedName(this.getRegistryName().toString()); } } ItemTinIngot.java public class ItemTinIngot extends ItemBase { public ItemTinIngot(String name) { super(name); } } ItemBase.java public class ItemBase extends Item { ItemBase(String name) { this.setRegistryName(new ResourceLocation(Reference.MODID, name)); this.setUnlocalizedName(this.getRegistryName().toString()); } }
    1 point
  2. I will make it simple. To save changes made from GUI, subscribe to ConfigChangedEvent.OnConfigChangedEvent. Check if event's modid is the modid of your mod, then call ConfigManager#sync(). I don't have access to sources right now, but the code looks like this: @EventBusSubscriber public class ConfigEventHandler { /* I prefer to make it inner class of my config class, but it doesn't have to be, it just needs to be registered. Read docs about events if you don't understand. */ @SubscribeEvent public static void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) { if (event.getModid().equals(modid) { ConfigManager.sync(modid, Config.Type.INSTANCE); } } } I believe,ConfigManager#sync() also saves changes made to fields to your config file, but as I said, I don't know much about configs .
    1 point
  3. It was replaced by RegistryEvent.MissingMappings<T extends IForgeRegistryEntry<T>> in the 1.12 registry overhaul. T is the registry type you want to handle the missing mappings for.
    1 point
  4. Well, tecnically it did... The registry name is used as the file name... Changing one to match the other will fix it regardless of which one you changed.
    1 point
  5. This is actually a good way to register blocks and items! I will probably switch to this in the future. Also, is this 1.11 exclusive?
    1 point
  6. Use a different number, Specifically, a number of megabytes inbetween. I think I had to use some odd number like 1368mb; finding a value that was less than my ram available (mind, I have 3.25gb total) and more than it needed. (It would with crash having exceeded the amount I gave it, or would stall tyring to allocate more than I actually had, so I'd have to go in and spilt the difference)
    1 point
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.