Jump to content

Recommended Posts

Posted

heya, i cannot get a single block registered.

 

here's what i do:

@Mod.EventBusSubscriber(modid = JSONCraft.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModEventSubscriber {

    @SubscribeEvent
    public static void onRegisterBlocks(final RegistryEvent.Register<Block> event) {
        final IForgeRegistry<Block> registry = event.getRegistry();
        for(Block block: ModBlocks.getAll()){
            registry.register(block);
        }
    }

 

the getAll() method is quite simple atm:

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

public static final Block A_BLOCK = new Block(Block.Properties.create(Material.ROCK).hardnessAndResistance(3.0F, 3.0F));

    public static List<Block> getAll(){
        List<Block> list = new ArrayList<>();
        list.add(A_BLOCK);
        return list;
    }


 

and here's what happens:

[13apr2020 11:25:59.045] [Render thread/ERROR] [net.minecraftforge.fml.javafmlmod.FMLModContainer/]: Exception caught during firing event: ROCK
    Index: 2
    Listeners:
        0: NORMAL
        1: ASM: class network.eden.jsoncraft.ModEventSubscriber onRegisterItems(Lnet/minecraftforge/event/RegistryEvent$Register;)V
        2: ASM: class network.eden.jsoncraft.ModEventSubscriber onRegisterBlocks(Lnet/minecraftforge/event/RegistryEvent$Register;)V
java.lang.NoSuchFieldError: ROCK
    at network.eden.jsoncraft.init.ModBlocks.<clinit>(ModBlocks.java:11)
    at network.eden.jsoncraft.ModEventSubscriber.onRegisterBlocks(ModEventSubscriber.java:20)
    at net.minecraftforge.eventbus.ASMEventHandler_2_ModEventSubscriber_onRegisterBlocks_Register.invoke(.dynamic)


can anybody tell me what am i doing wrong?
thx for your time.

Posted
7 minutes ago, tydeFriz said:

public static final Block A_BLOCK = new Block(Block.Properties.create(Material.ROCK).hardnessAndResistance(3.0F, 3.0F));

You should never statically initialize registry entry values.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
14 minutes ago, tydeFriz said:

heya, i cannot get a single block registered

Look up DeferredRegister, the class has comments that show how to use it, it makes it so much easier to register blocks/items, it's nearly foolproof.

You won't even need to use the actual registry events.

Posted
13 minutes ago, Animefan8888 said:

You should never statically initialize registry entry values.

thanks, mind explaining why?
 

 

6 minutes ago, Ugdhar said:

Look up DeferredRegister, the class has comments that show how to use it, it makes it so much easier to register blocks/items, it's nearly foolproof.

You won't even need to use the actual registry events.

i will, tyvm

Posted
Just now, tydeFriz said:
14 minutes ago, Animefan8888 said:

You should never statically initialize registry entry values.

thanks, mind explaining why?

I believe the simple version is because you have no control over when the static initializer is run in relation to when things are actually being/supposed to be registered, and aside from Blocks and Items being first/second, the registry events do not run in a specific order.

Posted
Just now, tydeFriz said:

thanks, mind explaining why?

When does a statically intialized instance get initialized? It's hard to answer that question because you never know when. As such forge can't assign it the proper MODID for it's registry name.

Also just noticing this now, but in the code snippets you posted you never set that blocks registry name in the first place.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

hello again, i have used the DeferredRegister but the same thing happens.


i have quite literally copypasted the example in the comment:

 

@Mod(JSONCraft.MODID)
public class JSONCraft
{
    public static final String MODID = "jsoncraft";

    public static final DeferredRegister<Block> BLOCKS = new DeferredRegister<Block>(ForgeRegistries.BLOCKS, MODID);
    public static final DeferredRegister<Item> ITEMS = new DeferredRegister<Item>(ForgeRegistries.ITEMS, MODID);

    public static final RegistryObject<Block> EXAMPLE_BLOCK = BLOCKS.register("example_block", () -> new Block(Block.Properties.create(Material.ROCK)));
    public static final RegistryObject<Item> ROCK_ITEM = ITEMS.register("example_block", () -> new BlockItem(EXAMPLE_BLOCK.get(), new Item.Properties().group(ModItemGroups.MOD_ITEM_GROUP)));

    public JSONCraft() {
        ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
        BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());

 

trace:

 

[13apr2020 13:02:49.166] [modloading-worker-2/INFO] [net.minecraftforge.common.MinecraftForge/FORGE]: MinecraftForge v31.1.19 Initialized
[13apr2020 13:02:49.552] [Render thread/ERROR] [net.minecraftforge.fml.javafmlmod.FMLModContainer/]: Exception caught during firing event: ROCK
    Index: 2
    Listeners:
        0: NORMAL
        1: net.minecraftforge.eventbus.EventBus$$Lambda$2081/1783933562@3d5f08d4
        2: net.minecraftforge.eventbus.EventBus$$Lambda$2081/1783933562@3afaa39f
java.lang.NoSuchFieldError: ROCK
    at network.eden.jsoncraft.JSONCraft.lambda$static$0(JSONCraft.java:36)
    at network.eden.jsoncraft.JSONCraft$$Lambda$2220/581639050.get(Unknown Source)
    at net.minecraftforge.registries.DeferredRegister.lambda$register$0(DeferredRegister.java:84)
    at net.minecraftforge.registries.DeferredRegister$$Lambda$2222/1711574174.get(Unknown Source)
    at net.minecraftforge.registries.DeferredRegister.addEntries(DeferredRegister.java:117)
    at net.minecraftforge.registries.DeferredRegister$$Lambda$2251/659577981.accept(Unknown Source)


looks like "nearly foolproof" is not enough for me :D

Posted
2 minutes ago, diesieben07 said:

Looks like you are running the game outside the development environment but without having used the gradle build task to build your jar file.

yes, very much that. thx a lot.

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.