Jump to content

Recommended Posts

Posted (edited)

So I'm following some tutorials, and I'm trying to use them is ways other than exactly what they're doing (which helps me learn faster), but I may have caused problems by doing that... So the first problem started when I had a block and an item for that block. I could /setblock the block just fine, no errors. But when I /give-d myself the item, it says "an internal error occurred when running this command" and immediately crashed. I didn't understand what was wrong, but after some messing around I managed to make it stop doing that... With the slight side effect that the game wont even load. It just throws a bunch of errors, and comes up with a screen saying "1 error occurred". I have no clue how to fix this (the error seems blatantly unconnected), so I decided to ask about it here. I am using 1.14.4.

This is my main file (Noodles)

package com.happyhippo77.noodles;

import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

// The value here should match an entry in the META-INF/mods.toml file
@Mod("noodles")
public class Noodles {
    public static final String MODID = "noodles";

    // Directly reference a log4j logger.
    public static final Logger LOGGER = LogManager.getLogger();

    public Noodles() {
        // Register the setup method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);

    }

    private void setup(final FMLCommonSetupEvent event) {

    }
}

 

This is the file for the block (NoodleOre) don't ask why the obsession with noodles, I don't know
 

package com.happyhippo77.noodles.blocks.properties;

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

public class NoodleOre extends Block {
    public NoodleOre() {
        super(Properties.create(Material.ROCK)
                .sound(SoundType.STONE)
                .hardnessAndResistance(2.0f)
        );
        setRegistryName("noodle_ore");
    }
}


Here's the file for the blocks (ModBlocks)
 

package com.happyhippo77.noodles.blocks;

import com.happyhippo77.noodles.Noodles;
import com.happyhippo77.noodles.blocks.properties.NoodleOre;
import net.minecraft.block.Block;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.ObjectHolder;

@Mod.EventBusSubscriber(modid = Noodles.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
@ObjectHolder(Noodles.MODID)
public class ModBlocks {
        @SubscribeEvent
        public static void onBlocksRegistry(final RegistryEvent.Register<Block> event) {
            // register a new block here
            event.getRegistry().register(new NoodleOre());
            Noodles.LOGGER.info("Registered Blocks");
        }

    public static NoodleOre NOODLE_ORE = null;
}

 

And here's the file for the items (ModItems)
 

package com.happyhippo77.noodles.items;

import com.happyhippo77.noodles.Noodles;
import com.happyhippo77.noodles.blocks.ModBlocks;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

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

    @SubscribeEvent
    public static void onItemsRegistry(final RegistryEvent.Register<Item> event) {
        // register a new block here
        event.getRegistry().register(new BlockItem(ModBlocks.NOODLE_ORE, new Item.Properties()).setRegistryName(ModBlocks.NOODLE_ORE.getRegistryName()));
        Noodles.LOGGER.info("Registered Items");
    }
}


 

Overall the code is just kind of erratic, so there's probably some really idiotic mistake in there that I can't see. Nonetheless, I really can't figure it out, so any help is appreciated!

Oh yeah, and here's the console from around the time the errors start to where they end.
 

  Reveal hidden contents

 

Edited by HappyHippo77
Posted (edited)

ModBlocks::NOODLE_ORE is always null. You've never give it a value.

Edited by DavidM

Some tips:

  Reveal hidden contents

 

Posted

From the looks, nothing that you're doing in your block's constructor should be there, also why are you registering your block to receive events?

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

  Reveal hidden contents

 

Posted
  On 2/22/2020 at 12:56 AM, DaemonUmbra said:

From the looks, nothing that you're doing in your block's constructor should be there, also why are you registering your block to receive events?

Expand  

I'm not entirely sure what this means, nor how I should fix it. What is a constructor, and what is a receive event, and what should I be doing instead?

Posted
  On 2/22/2020 at 8:07 PM, HappyHippo77 said:

What is a constructor, and what is a receive event, and what should I be doing instead?

Expand  

Not what you want to hear, but you honestly should probably be learning basic Java/OOP. Not knowing what a constructor is is a bad thing.

  • Like 1
Posted
  On 2/22/2020 at 10:11 PM, Ugdhar said:

Not what you want to hear, but you honestly should probably be learning basic Java/OOP. Not knowing what a constructor is is a bad thing.

Expand  

I already have a basic understanding of how Java functions. I can get around alright in a Java environment. I guess I just never heard "constructor" before.

One problem that I may have is that I can't learn Java well with anything except Forge. I only learn well when I'm doing something I find interesting, and the boring, drawling, here's-this-now-go-use-it tutorials you usually find never teach me anything I'll remember. I'll end up learning Forge faster if I just learn to use Forge than if I spend forever scurrying around trying to find the smallest shred of a good resource for Java.

  • Like 1
Posted (edited)

- NoodleOre (Block) needs a registry name (noodle_ore)

- The public static field NOODLE_ORE (ModBlocks class) will always be null because afaik ObjectHolder pupulates only PSF fields, not PS (so make it final)

 

Not sure about the 2nd point though, check the ObjectHolder class, I think its explained in there

 

EDIT: NVM just seen that you set the registry name inside the constructor.

Edited by CAS_ual_TY
Posted
  On 2/22/2020 at 11:06 PM, HappyHippo77 said:

I already have a basic understanding of how Java functions. I can get around alright in a Java environment. I guess I just never heard "constructor" before.

One problem that I may have is that I can't learn Java well with anything except Forge. I only learn well when I'm doing something I find interesting, and the boring, drawling, here's-this-now-go-use-it tutorials you usually find never teach me anything I'll remember. I'll end up learning Forge faster if I just learn to use Forge than if I spend forever scurrying around trying to find the smallest shred of a good resource for Java.

Expand  

Forge has a very good API/ Docs for Minecraft 1.14.x - 1.15.x. You simply need to see on the Docs and: https://mcforge.readthedocs.io/en/latest/concepts/registries/#injecting-registry-values-into-fields

New in Modding? == Still learning!

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.