Jump to content

[1.11.2] Block registered twice?


xXJamie_Xx

Recommended Posts

Your repository is terribly arranged. Why is the Init package not inside the com.xXJamie_Xx.myTweaks package?

 

Also, do you own xXJamie_Xx.com?

 

Now then, lets look at this method

 

This method is called twice.

 

Can you find the problem?

 

I'll give you a hint.
 

private static void registerBlock(Block block) {
GameRegistry.register(townCentre); //COUGH, COUGH

 

Edited by Draco18s

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.

Link to comment
Share on other sites

1 hour ago, Draco18s said:

 


private static void registerBlock(Block block) {
GameRegistry.register(townCentre); //COUGH, COUGH

 

Excuse my lack of knowledge (I'm fairly new to modding), I can't see the issue here.

Edited by xXJamie_Xx
Link to comment
Share on other sites

No?

You can't?

 

How about I in-line that method.

//copy 1, was registerBlock(townCentre);
		GameRegistry.register(townCentre); //COUGH #1
		ItemBlock itemtowncentre = new ItemBlock(townCentre);
		itemtowncentre.setRegistryName(townCentre.getRegistryName());
		GameRegistry.register(itemtowncentre);

		GameRegistry.register(house);
		ItemBlock itemhouse = new ItemBlock(townCentre);
		itemhouse.setRegistryName(townCentre.getRegistryName());
		GameRegistry.register(itemhouse);
//copy 2, was registerBlock(house);
		GameRegistry.register(townCentre); //COUGH #2
		ItemBlock itemtowncentre = new ItemBlock(house);
		itemtowncentre.setRegistryName(house.getRegistryName());
		GameRegistry.register(itemtowncentre);

		GameRegistry.register(house);
		ItemBlock itemhouse = new ItemBlock(house);
		itemhouse.setRegistryName(house.getRegistryName());
		GameRegistry.register(itemhouse);

Can you find where a block is being registered twice, now?

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.

Link to comment
Share on other sites

1 hour ago, Draco18s said:

No?

You can't?

 

How about I in-line that method.


//copy 1, was registerBlock(townCentre);
		GameRegistry.register(townCentre); //COUGH #1
		ItemBlock itemtowncentre = new ItemBlock(townCentre);
		itemtowncentre.setRegistryName(townCentre.getRegistryName());
		GameRegistry.register(itemtowncentre);

		GameRegistry.register(house);
		ItemBlock itemhouse = new ItemBlock(townCentre);
		itemhouse.setRegistryName(townCentre.getRegistryName());
		GameRegistry.register(itemhouse);
//copy 2, was registerBlock(house);
		GameRegistry.register(townCentre); //COUGH #2
		ItemBlock itemtowncentre = new ItemBlock(house);
		itemtowncentre.setRegistryName(house.getRegistryName());
		GameRegistry.register(itemtowncentre);

		GameRegistry.register(house);
		ItemBlock itemhouse = new ItemBlock(house);
		itemhouse.setRegistryName(house.getRegistryName());
		GameRegistry.register(itemhouse);

Can you find where a block is being registered twice, now?

So you are saying that there is 2 of these:

		GameRegistry.register(townCentre); //COUGH #1
		ItemBlock itemtowncentre = new ItemBlock(townCentre);
		itemtowncentre.setRegistryName(townCentre.getRegistryName());
		GameRegistry.register(itemtowncentre);
		GameRegistry.register(townCentre); //COUGH #2
		ItemBlock itemtowncentre = new ItemBlock(house);
		itemtowncentre.setRegistryName(house.getRegistryName());
		GameRegistry.register(itemtowncentre);

Yet I only see one.

Link to comment
Share on other sites

1 hour ago, Jay Avery said:

Within your private registerBlock method, you register your townCentre block and your house block. You call the registerBlock method twice. Both times you call it, it tries to register townCentre and house.

No. I only use this line once:

private static void registerBlock(Block block) {

 

Link to comment
Share on other sites

No, you still don't realise what I'm saying. The method registerBlock, within itself, already registers both blocks. You've written it that way. Inside registerBlock, you have lines GameRegistry.register(townCentre) and GameRegistry.register(house). That means that every time you call the registerBlock method, no matter what parameters are passed to it, both of those lines get executed. When you call registerBlock(townCentre), those two lines get executed. When you call registerBlock(house), those two lines get executed.

Link to comment
Share on other sites

1 hour ago, Jay Avery said:

No, you still don't realise what I'm saying. The method registerBlock, within itself, already registers both blocks. You've written it that way. Inside registerBlock, you have lines GameRegistry.register(townCentre) and GameRegistry.register(house). That means that every time you call the registerBlock method, no matter what parameters are passed to it, both of those lines get executed. When you call registerBlock(townCentre), those two lines get executed. When you call registerBlock(house), those two lines get executed.

I see. So I commented out these lines:

//GameRegistry.register(townCentre);
//GameRegistry.register(house);

But the game crashes still. (with the same error)

Link to comment
Share on other sites

That error says that the ItemBlock is being registered twice. That's because you have a slightly different version of the same mistake in registering your items in registerBlock. Within that method, you twice create a new ItemBlock  from the passed Block parameter, and register it under the Block parameter's name. You give the variables different names but that doesn't change the fact that you're doing the same thing twice.

Edited by Jay Avery
Link to comment
Share on other sites

1 hour ago, Jay Avery said:

That error says that the ItemBlock is being registered twice. That's because you have a slightly different version of the same mistake in registering your items in registerBlock. Within that method, you twice create a new ItemBlock  from the passed Block parameter, and register it under the Block parameter's name. You give the variables different names but that doesn't change the fact that you're doing the same thing twice.

ModBlocks.java:

package com.xXJamie_Xx.myTweaks.init;

import com.xXJamie_Xx.myTweaks.blocks.Blockhouse;
import com.xXJamie_Xx.myTweaks.blocks.BlocktownCentre;
import com.xXJamie_Xx.myTweaks.items.ItemScroll;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class ModBlocks {

	//Passive/Economical Buildings
	public static Block townCentre;
	public static Block house;
	public static Block farm;
	public static Block market;
	public static Block mine;
	
	//Aggressive/Military Buildings
	public static Block barracks;
	public static Block stable;
	public static Block artilleryFoundry;
	
	public static void init() {
		townCentre = new BlocktownCentre(); 
		house = new Blockhouse();
	}
	
	public static void register() {
		registerBlock(townCentre);
		registerBlock(house);
	}
	
	private static void registerBlock(Block block) {
		//GameRegistry.register(townCentre);
		ItemBlock itemtowncentre = new ItemBlock(townCentre);
		itemtowncentre.setRegistryName(block.getRegistryName());
		GameRegistry.register(itemtowncentre);

		//GameRegistry.register(house);
		ItemBlock itemhouse = new ItemBlock(house);
		itemhouse.setRegistryName(block.getRegistryName());
		GameRegistry.register(itemhouse);
	}
	
	public static void registerRenders() {
		registerRender(townCentre);
		registerRender(house);
	}
	
	private static void registerRender(Block block) {
		
	}
}

 

Crash Report: https://pastebin.com/yJPwrsE8

Link to comment
Share on other sites

Go learn Java. If you had the most basic Java knowledge (or any programming language for that matter), your mistake would be painfully obvious.

 

In your registerBlock method, you call GameRegistry.register for 1) your town center block 2) your town center item 3) your house block 4) your house item. So in this method, you're registering all four objects.

 

In your register method, you call the reigsterBlock method twice, once with the argument townCentre and the other time with the argument house. This would result in each of the GameRegistry.register calls occurring twice, so every object would be registered twice.

 

As for how to fix it, learn Java.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

Link to comment
Share on other sites

30 minutes ago, xXJamie_Xx said:

ModBlocks.java:


package com.xXJamie_Xx.myTweaks.init;

import com.xXJamie_Xx.myTweaks.blocks.Blockhouse;
import com.xXJamie_Xx.myTweaks.blocks.BlocktownCentre;
import com.xXJamie_Xx.myTweaks.items.ItemScroll;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class ModBlocks {

	//Passive/Economical Buildings
	public static Block townCentre;
	public static Block house;
	public static Block farm;
	public static Block market;
	public static Block mine;
	
	//Aggressive/Military Buildings
	public static Block barracks;
	public static Block stable;
	public static Block artilleryFoundry;
	
	public static void init() {
		townCentre = new BlocktownCentre(); 
		house = new Blockhouse();
	}
	
	public static void register() {
		registerBlock(townCentre);
		registerBlock(house);
	}
	
	private static void registerBlock(Block block) {
		//GameRegistry.register(townCentre);
		ItemBlock itemtowncentre = new ItemBlock(townCentre);
		itemtowncentre.setRegistryName(block.getRegistryName());
		GameRegistry.register(itemtowncentre);

		//GameRegistry.register(house);
		ItemBlock itemhouse = new ItemBlock(house);
		itemhouse.setRegistryName(block.getRegistryName());
		GameRegistry.register(itemhouse);
	}
	
	public static void registerRenders() {
		registerRender(townCentre);
		registerRender(house);
	}
	
	private static void registerRender(Block block) {
		
	}
}

 

Crash Report: https://pastebin.com/yJPwrsE8

I explained the problem, it hasn't changed. shadowfacts has explained (again) what is wrong, but you don't seem to be understanding it. It seems like you are struggling with some fairly fundamental aspects of object-oriented programming, and how methods and parameters work. There's not much more I can think of to say that will explain what's wrong other than re-writing your code for you - which I'm not going to do (because you'll immediately be back here as soon as you need to change something, if you don't understand the code you're using).

Edited by Jay Avery
Link to comment
Share on other sites

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.

×
×
  • Create New...

Important Information

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