Jump to content

Just refactored my code for non-static registries, need help with a crash


Recommended Posts

Posted

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.

 

Posted

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.

Posted (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 by Draco18s
  • Like 1

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.

Posted

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.

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.

 

 

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } }  
    • All versions of Minecraft Forge suddenly black screen even without mods (tried reinstalling original Minecraft, Java, updating drivers doesn't work)
    • When i join minecraft all ok, when i join world all working fine, but when i open indentity menu, i get this The game crashed whilst unexpected error Error: java.lang.NullPointerException: Cannot invoke "top.ribs.scguns.common.Gun$Projectile.getDamage()" because "this.projectile" is null crash report here https://paste.ee/p/0vKaf
  • Topics

×
×
  • Create New...

Important Information

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