Jump to content

Recommended Posts

Posted (edited)

I feel really nooby(Is that even a word?) asking this, but I cannot seem to get a block to register. I followed forge documentation then looked at choonster's TestMod3 and tried that method, but no luck.

Main Class:

@Mod(modid = "modid", version = "v1.0.0 - Mc 1.12", name = "mod")
public class Mod {

}

Registry class:

public static final SaltOre saltOre = new SaltOre();
	
	public static void registerBlocks(final RegistryEvent.Register<Block> event) {
		final IForgeRegistry<Block> registry = event.getRegistry();

		final Block[] blocks = {
				saltOre,
		};
		registry.registerAll(blocks);
	}
		@SubscribeEvent
		public static void registerItemBlocks(final RegistryEvent.Register<Item> event) {
			final ItemBlock[] items = {
					new ItemBlock(saltOre),
			};
		}

Block class:

     super(Material.ROCK);
        setUnlocalizedName("saltOre");
        setRegistryName("SaltOre");
        setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
    }

Idk what I am forgetting, it's probably something obvious though.

EDIT: I have tried it with the way in the forge Docs and without the registerItemBlocks

Edited by Big_Bad_E
Posted
1 hour ago, Big_Bad_E said:

setRegistryName("SaltOre");

Registry name needs to be all lower case.

 

1 hour ago, Big_Bad_E said:

setUnlocalizedName("saltOre");

Unlocalized name should contain your mod ID, most people do this by setting the registry name and then calling setUnlocalizedName(getRegistryName().toString())

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

i'm not even going to try to find an excuse for forgetting to use lower cases...

 

Also, Still not working, I think it is the registry. I don't know how it works at all. I changed the registry code a bit, here's my new classes:

Registry:

package Big_Bad_E;

import net.minecraft.block.Block;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import Big_Bad_E.Blocks.SaltOre;

public class Registery {

	public static final SaltOre saltore = new SaltOre();
	
	@SubscribeEvent
	public void registerBlocks(RegistryEvent.Register<Block> event) {
		event.getRegistry().registerAll(saltore);
	}
}

Block Class:

package Big_Bad_E.Blocks;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;

public class SaltOre extends Block {

	public SaltOre() {
        super(Material.ROCK);
        setUnlocalizedName(getRegistryName().toString());
        setRegistryName("saltore");
        setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
    }
}

 

Posted
1 hour ago, Draco18s said:

Registry name needs to be all lower case.

 

Unlocalized name should contain your mod ID, most people do this by setting the registry name and then calling setUnlocalizedName(getRegistryName().toString())

Any other problems you notice?

Posted

You don't have a ModelRegistryEvent, meaning your block in the inventory will be black and purple.

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

1) dont statically inialize your blocks thats bad

2) You need to set the unlocalized name AFTER the registry name if they depend on it

3) You should pass in your modid to the registry name.

 

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted
7 hours ago, LexManos said:

3) You should pass in your modid to the registry name.

Uh, Lex. You don't have to. setRegistryName already handles it. Line 9:

 

1.        public final T setRegistryName(String name)
2.        {
3.            if (getRegistryName() != null)
4.                throw new IllegalStateException("Attempted to set registry name with existing registry name! New: " + name + " Old: " + getRegistryName());
5.            int index = name.lastIndexOf(':');
6.            String oldPrefix = index == -1 ? "" : name.substring(0, index);
7.            name = index == -1 ? name : name.substring(index + 1);
8.            ModContainer mc = Loader.instance().activeModContainer();
9.            String prefix = mc == null || (mc instanceof InjectedModContainer && ((InjectedModContainer)mc).wrappedContainer instanceof FMLContainer) ? "minecraft" : mc.getModId().toLowerCase();
10.            if (!oldPrefix.equals(prefix) && oldPrefix.length() > 0)
11.            {
12.                FMLLog.bigWarning("Dangerous alternative prefix `{}` for name `{}`, expected `{}` invalid registry invocation/invalid name?", oldPrefix, name, prefix);
13.                prefix = oldPrefix;
14.            }
15.            this.registryName = new ResourceLocation(prefix, name);
16.            return (T)this;
17.        }

Unless you're telling us that you're going to make it not do that, throw warnings, or similar.

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
1 hour ago, Draco18s said:

Uh, Lex. You don't have to. setRegistryName already handles it. Line 9:

I know I wrote the code. There is a difference between what the code supports, and what you SHOULD do.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted (edited)
11 minutes ago, LexManos said:

There is a difference between what the code supports, and what you SHOULD do.

If a modder should do something, then it should throw warnings when they don't. If there's no error or warning, then it's assumed to be correct.

 

I'm not going to bother with the string concatenation that isn't required just because you said I should even though it'll just get split into two strings again.

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.

Posted

Thats one train of thought, for a sane programming environment.

Minecraft is full of kids who complain if you even think of trying to apply a standard.

Not to mention nobody cares about warnings {See Every Mod Pack Ever having 10,000+ warning at startup}

So this is what we have.

Just take it on the word of the guy who wrote the damn thing what the intention was. 

 

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

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.