Jump to content

Recommended Posts

Posted

I use forge 8.0.76.1375 for Minecraft 1.8

 

When I try to use GameRegistry.findBlock("minecraft","chest"); it returns null;

So I wrote this little testing code to see where it goes wrong. And it goes wrong in the containsKey method of the FMLControlledNamespacedRegistry

 

I'm not sure why it won't find the map, but I did find some hits on stackoverflow that if a map is altered after its initialised the hashCode checks may fail in the buckets allowing for an "early" nothing found return. Maybe that helps a bit finding out why this thing does what it does.

 

The testing code I used:

 

Block chest = GameRegistry.findBlock("minecraft","chest");
WhoTookMyCookies.log.warn("Trying to do it how it should:" + chest);
if(chest == null) {
WhoTookMyCookies.log.warn("Failed to find it the legit way.");
Class x = GameData.class;
try {
	Method method = x.getDeclaredMethod("getMain");
	method.setAccessible(true);
	GameData gamedata = (GameData)method.invoke(null);
	FMLControlledNamespacedRegistry<Block> b = gamedata.getBlockRegistry();
	WhoTookMyCookies.log.warn("All keys currently in the registry. the minecraft:chest is actually in there. " + b.getKeys());
	WhoTookMyCookies.log.warn("Testing for a false object that should not exist. should return air: " + b.getObject("minecraft:chestxxx"));

	WhoTookMyCookies.log.warn("Testing if chest exists with containsKey");
	if(b.containsKey("minecraft:chest")) {
		WhoTookMyCookies.log.warn("registry.containsKey returned true on minecraft:chest");
	}
	else {
		WhoTookMyCookies.log.warn("registry.containsKey returned false on minecraft:chest continue the hackish way");
		WhoTookMyCookies.log.warn("Testing containsKey on the list itself by getting it and testing if its not air");
		chest = b.getObject("minecraft:chest");
		if(chest != Blocks.air) {
			WhoTookMyCookies.log.warn("Chest found: "+GameRegistry.findUniqueIdentifierFor(b.getObject("minecraft:chest")).name);
		}
		else {
			WhoTookMyCookies.log.warn("chest not found... this is the time to cry :`(");
		}
	}
}
catch(Exception ex) {
	ex.printStackTrace();
}
if(this.item!=null) {
	BlocksBroken.restore(item, event.world);
	this.item = null;
}
}

 

The complete latest log file. You can find the output of the above code at the end.

 

 

  Reveal hidden contents

 

How much wood could a woodchuck chuck if a wood chuck could chuck wood - Guybrush Treepwood

 

I wrote my own mod ish... still a few bugs to fix. http://thaumcraft.duckdns.org/downloads/MagicCookies-1.0.6.4.jar

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



×
×
  • Create New...

Important Information

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