LaDestitute Posted April 25, 2019 Posted April 25, 2019 So, I just spent hours refactoring my own source code to use Cadiboo's example mod method of registering blocks and items. However, I'm getting an annoying crash, noticed my registry is...setting incorrect names (such as "arrowtrap" instead of "arrow_trap") yet all my code looks okay and I had no errors. I did a search and could only find one thing but I'm still a bit stumped, as I'm not sure that I have that specific thread's issue. My source code: https://gitlab.com/LaDestitute/Spelunkcraft/tree/unstable/src/main/java/ladestitute/spelunkcraft (the main dev branch is the unstable branch) My crash: https://pastebin.com/TYb787JY My EventHandler class: package ladestitute.spelunkcraft; import java.util.Arrays; import javax.annotation.Nonnull; import com.google.common.base.Preconditions; import ladestitute.spelunkcraft.blocks.TileEntityArrowTrap; import ladestitute.spelunkcraft.blocks.decor.RubyBlock; import ladestitute.spelunkcraft.blocks.decor.SapphireBlock; import ladestitute.spelunkcraft.blocks.decor.VaultCeilingBlock; import ladestitute.spelunkcraft.blocks.decor.VaultCornerBlock; import ladestitute.spelunkcraft.blocks.decor.VaultMiddleBlock; import ladestitute.spelunkcraft.blocks.ore.RubyOre; import ladestitute.spelunkcraft.blocks.ore.SapphireOre; import ladestitute.spelunkcraft.blocks.traps.ArrowTrap; import ladestitute.spelunkcraft.blocks.traps.PowderBox; import ladestitute.spelunkcraft.blocks.traps.PushBlock; import ladestitute.spelunkcraft.blocks.traps.Spikes; import ladestitute.spelunkcraft.init.ModBlocks; import ladestitute.spelunkcraft.items.materials.ConcentratedGunpowder; import ladestitute.spelunkcraft.items.treasure.GoldenIdol; import ladestitute.spelunkcraft.items.treasure.LargeRuby; import ladestitute.spelunkcraft.items.treasure.LargeSapphire; import ladestitute.spelunkcraft.items.treasure.SmallRuby; import ladestitute.spelunkcraft.items.treasure.SmallSapphire; import ladestitute.spelunkcraft.items.treasure.TreasureBag; import ladestitute.spelunkcraft.util.ModReference; import ladestitute.spelunkcraft.util.ModUtil; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.crash.CrashReport; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ReportedException; import net.minecraft.util.ResourceLocation; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.registry.EntityEntry; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.registries.IForgeRegistry; @Mod.EventBusSubscriber(modid = ModReference.MOD_ID) public final class EventSubscriber { private static int entityId = 0; /* register blocks */ @SubscribeEvent public static void onRegisterBlocksEvent(@Nonnull final RegistryEvent.Register<Block> event) { final IForgeRegistry<Block> registry = event.getRegistry(); registry.register(new SapphireOre("oreSapphire")); registry.register(new RubyOre("oreRuby")); registry.register(new SapphireBlock("blockSapphire")); registry.register(new RubyBlock("blockRuby")); registry.register(new VaultCeilingBlock("vault_ceiling_block")); registry.register(new VaultMiddleBlock("vault_middle_block")); registry.register(new VaultCornerBlock("vault_corner_block")); registry.register(new Spikes("spikes")); registry.register(new PushBlock("push_block")); registry.register(new ArrowTrap("arrow_trap")); registry.register(new PowderBox("powder_box")); Main.SPELUNKCRAFT_MOD_LOG.debug("Registered blocks"); registerTileEntities(); Main.SPELUNKCRAFT_MOD_LOG.debug("Registered tile entities"); } private static void registerTileEntities() { GameRegistry.registerTileEntity(TileEntityArrowTrap.class, ModReference.MOD_ID + ":arrow_trap"); } private static void registerTileEntity(@Nonnull final Class<? extends TileEntity> clazz, String name) { try { GameRegistry.registerTileEntity(clazz, new ResourceLocation(ModReference.MOD_ID, name)); } catch (final Exception exception) { CrashReport crashReport = new CrashReport("Error registering Tile Entity " + clazz.getSimpleName(), exception); crashReport.makeCategory("Registering Tile Entity"); throw new ReportedException(crashReport); } } /* register items */ @SubscribeEvent public static void onRegisterItemsEvent(@Nonnull final RegistryEvent.Register<Item> event) { final IForgeRegistry<Item> registry = event.getRegistry(); // item blocks // make an array of all the blocks we want to have items Arrays.stream(new Block[]{ ModBlocks.SAPPHIREORE, ModBlocks.RUBYORE, ModBlocks.SAPPHIREBLOCK, ModBlocks.RUBYBLOCK, ModBlocks.VAULTCEILINGBLOCK, ModBlocks.VAULTMIDDLEBLOCK, ModBlocks.VAULTCORNERBLOCK, ModBlocks.SPIKES, ModBlocks.PUSHBLOCK, ModBlocks.ARROWTRAP, ModBlocks.POWDERBOX }).forEach(block -> { Preconditions.checkNotNull(block.getRegistryName(), "Registry name cannot be null!"); registry.register( ModUtil.setCreativeTab( // set it's creative tab to our creativetab (Optional) ModUtil.setRegistryNames( //set its name new ItemBlock(block), //make the itemblock block.getRegistryName()) ) ); }); // items // you can also instantiate items like this, however its not often used for a number of reasons registry.register(ModUtil.setCreativeTab(ModUtil.setRegistryNames(new Item(), "small_sapphire"))); registry.register(new SmallSapphire("small_sapphire")); registry.register(ModUtil.setCreativeTab(ModUtil.setRegistryNames(new Item(), "gemSapphire"))); registry.register(new LargeSapphire("gemSapphire")); registry.register(ModUtil.setCreativeTab(ModUtil.setRegistryNames(new Item(), "small_ruby"))); registry.register(new SmallRuby("small_ruby")); registry.register(ModUtil.setCreativeTab(ModUtil.setRegistryNames(new Item(), "gemRuby"))); registry.register(new LargeRuby("gemRuby")); registry.register(ModUtil.setCreativeTab(ModUtil.setRegistryNames(new Item(), "golden_idol"))); registry.register(new GoldenIdol("golden_idol")); registry.register(ModUtil.setCreativeTab(ModUtil.setRegistryNames(new Item(), "treasure_bag"))); registry.register(new TreasureBag("treasure_bag")); registry.register(ModUtil.setCreativeTab(ModUtil.setRegistryNames(new Item(), "concentrated_gunpowder"))); registry.register(new ConcentratedGunpowder("concentrated_gunpowder")); Main.SPELUNKCRAFT_MOD_LOG.debug("Registered items"); } /* register entities */ @SubscribeEvent public static void onRegisterEntitiesEvent(@Nonnull final RegistryEvent.Register<EntityEntry> event) { final IForgeRegistry<EntityEntry> registry = event.getRegistry(); { // final Class clazz = Entity____.class; // final ResourceLocation registryName = new ResourceLocation(MOD_ID, ModUtil.getRegistryNameForClass(clazz, "Entity")); // registry.register( // EntityEntryBuilder.create() // .entity(clazz) // .id(registryName, entityId++) // .name(registryName.getPath()) // .tracker(range, updateFrequency, sendVelocityUpdates) // .egg(primaryColor, secondaryColor) // .build() // ); } Main.SPELUNKCRAFT_MOD_LOG.debug("Registered entities"); } } The snippet of the central error: Quote [01:41:04] [main/DEBUG] [FML]: Unable to lookup spelunkcraft:sapphireore for public static ladestitute.spelunkcraft.blocks.ore.SapphireOre ladestitute.spelunkcraft.init.ModBlocks.SAPPHIREORE. This means the object wasn't registered. It's likely just mod options. [01:41:04] [main/DEBUG] [FML]: Unable to lookup spelunkcraft:rubyore for public static ladestitute.spelunkcraft.blocks.ore.RubyOre ladestitute.spelunkcraft.init.ModBlocks.RUBYORE. This means the object wasn't registered. It's likely just mod options. [01:41:04] [main/DEBUG] [FML]: Unable to lookup spelunkcraft:sapphireblock for public static ladestitute.spelunkcraft.blocks.decor.SapphireBlock ladestitute.spelunkcraft.init.ModBlocks.SAPPHIREBLOCK. This means the object wasn't registered. It's likely just mod options. [01:41:04] [main/DEBUG] [FML]: Unable to lookup spelunkcraft:rubyblock for public static ladestitute.spelunkcraft.blocks.decor.RubyBlock ladestitute.spelunkcraft.init.ModBlocks.RUBYBLOCK. This means the object wasn't registered. It's likely just mod options. [01:41:04] [main/DEBUG] [FML]: Unable to lookup spelunkcraft:vaultceilingblock for public static ladestitute.spelunkcraft.blocks.decor.VaultCeilingBlock ladestitute.spelunkcraft.init.ModBlocks.VAULTCEILINGBLOCK. This means the object wasn't registered. It's likely just mod options. [01:41:04] [main/DEBUG] [FML]: Unable to lookup spelunkcraft:vaultmiddleblock for public static ladestitute.spelunkcraft.blocks.decor.VaultMiddleBlock ladestitute.spelunkcraft.init.ModBlocks.VAULTMIDDLEBLOCK. This means the object wasn't registered. It's likely just mod options. [01:41:04] [main/DEBUG] [FML]: Unable to lookup spelunkcraft:vaultcornerblock for public static ladestitute.spelunkcraft.blocks.decor.VaultCornerBlock ladestitute.spelunkcraft.init.ModBlocks.VAULTCORNERBLOCK. This means the object wasn't registered. It's likely just mod options. [01:41:04] [main/DEBUG] [FML]: Unable to lookup spelunkcraft:pushblock for public static ladestitute.spelunkcraft.blocks.traps.PushBlock ladestitute.spelunkcraft.init.ModBlocks.PUSHBLOCK. This means the object wasn't registered. It's likely just mod options. [01:41:04] [main/DEBUG] [FML]: Unable to lookup spelunkcraft:arrowtrap for public static ladestitute.spelunkcraft.blocks.traps.ArrowTrap ladestitute.spelunkcraft.init.ModBlocks.ARROWTRAP. This means the object wasn't registered. It's likely just mod options. [01:41:04] [main/DEBUG] [FML]: Unable to lookup spelunkcraft:powderbox for public static ladestitute.spelunkcraft.blocks.traps.PowderBox ladestitute.spelunkcraft.init.ModBlocks.POWDERBOX. This means the object wasn't registered. It's likely just mod options. [01:41:04] [main/DEBUG] [FML]: Unable to lookup spelunkcraft:smallsapphire for public static ladestitute.spelunkcraft.items.treasure.SmallSapphire ladestitute.spelunkcraft.init.ModItems.SMALLSAPPHIRE. This means the object wasn't registered. It's likely just mod options. [01:41:04] [main/DEBUG] [FML]: Unable to lookup spelunkcraft:largesapphire for public static ladestitute.spelunkcraft.items.treasure.LargeSapphire ladestitute.spelunkcraft.init.ModItems.LARGESAPPHIRE. This means the object wasn't registered. It's likely just mod options. [01:41:04] [main/DEBUG] [FML]: Unable to lookup spelunkcraft:smallruby for public static ladestitute.spelunkcraft.items.treasure.SmallRuby ladestitute.spelunkcraft.init.ModItems.SMALLRUBY. This means the object wasn't registered. It's likely just mod options. [01:41:04] [main/DEBUG] [FML]: Unable to lookup spelunkcraft:largeruby for public static ladestitute.spelunkcraft.items.treasure.LargeRuby ladestitute.spelunkcraft.init.ModItems.LARGERUBY. This means the object wasn't registered. It's likely just mod options. [01:41:04] [main/DEBUG] [FML]: Unable to lookup spelunkcraft:goldenidol for public static ladestitute.spelunkcraft.items.treasure.GoldenIdol ladestitute.spelunkcraft.init.ModItems.GOLDENIDOL. This means the object wasn't registered. It's likely just mod options. [01:41:04] [main/DEBUG] [FML]: Unable to lookup spelunkcraft:treasurebag for public static ladestitute.spelunkcraft.items.treasure.TreasureBag ladestitute.spelunkcraft.init.ModItems.TREASUREBAG. This means the object wasn't registered. It's likely just mod options. [01:41:04] [main/DEBUG] [FML]: Unable to lookup spelunkcraft:concentratedgunpowder for public static ladestitute.spelunkcraft.items.materials.ConcentratedGunpowder ladestitute.spelunkcraft.init.ModItems.CONCENTRATEDGUNPOWDER. This means the object wasn't registered. It's likely just mod options. Quote
V0idWa1k3r Posted April 25, 2019 Posted April 25, 2019 SAPPHIREORE != oreSapphire. ObjectHolders aren't magical, they match the field name(or the value passed in the annotation) to the registry name. Also registry names must be entirely lowercase. Quote
LaDestitute Posted April 25, 2019 Author Posted April 25, 2019 okay yeah, I'm dumb, thanks, I'll see if that fixes it. I spent hours refactoring and editing so it's silly I missed a mistake like that. Quote
LaDestitute Posted April 25, 2019 Author Posted April 25, 2019 Okay, yeah that fixed it. Thanks for the pointer man. One thing learned every day. Quote
Draco18s Posted April 26, 2019 Posted April 26, 2019 (edited) Unrelated things: https://gitlab.com/LaDestitute/Spelunkcraft/blob/unstable/src/main/java/ladestitute/spelunkcraft/util/ModUtil.java#L64-73 ...You do know that setRegistryName and setTranslationKey both return the object, right? You can totally do this: Block b = new BlockWhatever().setRegistryName(...).setTranslationKey(...) Ditto items. Or you could do it right in the constructor where you're already calling setRegistryNames...The only real value this has is setting the translation key to the registry name, but because of where you're calling this, there is no reason why you need these generic overloaded helper functions, except here where, where it's still unneeded because of the above. You also return the entry object despite doing nothing with it, so what was the point? Ditto setCreateiveTab. https://gitlab.com/LaDestitute/Spelunkcraft/blob/unstable/src/main/java/ladestitute/spelunkcraft/util/ModUtil.java#L135-141 Why. Seriously, why did this need a method call? https://gitlab.com/LaDestitute/Spelunkcraft/blob/unstable/src/main/java/ladestitute/spelunkcraft/items/treasure/SmallRuby.java#L12 Classes like this....don't need classes. Seriously, you gained fuck and all with this class. And what's this? Didn't like your mod util class this time? Just use new Item() https://gitlab.com/LaDestitute/Spelunkcraft/blob/unstable/src/main/java/ladestitute/spelunkcraft/proxy/CommonProxy.java CommonProxy is stupid. Anything that would go here should go in your main mod class. Not that you even call these methods anyway. Speaking of the proxy, and sided things, you have a client folder. And a server folder. Why are your proxies not in these folders but instead in a special "proxy" folder? Organize by groups, that's what its for. Everything that's client side goes in the client folder the client proxy is client sided! It goes in the client folder. Edited April 26, 2019 by Draco18s 1 Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
DavidM Posted April 26, 2019 Posted April 26, 2019 Make sure you are consistent with the way you are achieving stuff. Either set all register names in the constructor, or set them when the object is instantiated and registered. The same applies to setting creative tab. I can see that you are trying to create a clean, neat method of registering everything with ModUtil; unfortunately, your ModUtil is currently achieving the exact opposite effect. The main problem of your ModUtil is that it is lacking a solid structure; registries don't follow a clear routine, and will result in redundant registering and other undesired effects. Quote Some tips: Spoiler Modder Support: Spoiler 1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code. 2. Always post your code. 3. Never copy and paste code. You won't learn anything from doing that. 4. Quote Programming via Eclipse's hotfixes will get you nowhere 5. Learn to use your IDE, especially the debugger. 6. Quote The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it. Support & Bug Reports: Spoiler 1. Read the EAQ before asking for help. Remember to provide the appropriate log(s). 2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.