Jump to content

Can anyone pls explain me this error? :D


eriknoe

Recommended Posts

Can anyone explain me this error? :D

Im at registering an Block btw.

 

 An error occurred trying to load an EventBusSubscriber amethyst for modid java.lang.IllegalArgumentException: Method public static void erik.mod.init.RegistrationHandler.registerBlocks(net.minecraftforge.event.RegistryEvent$Register,net.minecraft.block.Block) has @SubscribeEvent annotation, but requires 2 arguments.  Event handler methods must require a single argument.

 

and

 

Fatal errors were detected during the transition from CONSTRUCTING to PREINITIALIZATION. Loading cannot continue+

 

Thanks <3

 

 

Link to comment
Share on other sites

this

public static void registerBlocks(final RegistryEvent.Register<Block> event, Block BlockModAmethystOre) {

to this

public static void registerBlocks(final RegistryEvent.Register<Block> event) {

?

 

Edited by eriknoe
Formatting
Link to comment
Share on other sites

mhhh... I tried this:     public static void registerBlocks (RegistryEvent.Register<Block> event) {

 

but i get this error O.o:    Exception caught during firing event net.minecraftforge.event.RegistryEvent$Register@3e8a1137:java.lang.NullPointerException: null

 

pls help me, im still pretty inexperienced :D

Link to comment
Share on other sites

When you run into an error, make sure you have the latest code posted, as well as the complete error, preferably the fml-client-latest.log.

 

And just to warn you, if you don't really understand Java, you're going to have a very hard time modding without someone holding your hand, which will be tough on the forums, because people are not always here waiting to help people, and if it becomes apparent you are repeatedly having troubles with basic Java issues, you'll likely be asked to go learn the basics before coming here for help.

Link to comment
Share on other sites

Just now, Ugdhar said:

When you run into an error, make sure you have the latest code posted, as well as the complete error, preferably the fml-client-latest.log.

 

And just to warn you, if you don't really understand Java, you're going to have a very hard time modding without someone holding your hand, which will be tough on the forums, because people are not always here waiting to help people, and if it becomes apparent you are repeatedly having troubles with basic Java issues, you'll likely be asked to go learn the basics before coming here for help.

LearningByDoing xD

Link to comment
Share on other sites

main class: https://pastebin.com/mSKcvTLJ

Block class: https://pastebin.com/dnT14Xiv

init class:  https://pastebin.com/uGXeCdz8

client proxy: 

https://pastebin.com/dExAbDer

serverproxy: https://pastebin.com/vt8p5GCh

last crash report: https://pastebin.com/9uTmRMdu

hope u can help me...I am new at programming, so I dont have so uch experience, but daily I learn more..so please dont slap me therfore :D

 

 

 

 

 

Link to comment
Share on other sites

You register the Wrong Element...

Currentl you are Creating a new Instance of your AmethystOre when you register your Blocks. But when you then register your Items you access your static reference.

Just Change your Block registration, so that you store your Instance in  your static final variable and then register that.

 

(I hope you know, that your Java Code is a Mess, so I won't point all your mistakes out to you (that would take too much time))

(Pls learn too Code...) 

Link to comment
Share on other sites

1 minute ago, Major Tuvok said:

You register the Wrong Element...

Currentl you are Creating a new Instance of your AmethystOre when you register your Blocks. But when you then register your Items you access your static reference.

Just Change your Block registration, so that you store your Instance in  your static final variable and then register that.

 

(I hope you know, that your Java Code is a Mess, so I won't point all your mistakes out to you (that would take too much time))

(Pls learn too Code...) 

can u show me one of ur codes, so i can see what is a mess?

Link to comment
Share on other sites

public class SpellcraftBlocks extends BaseContainer<Block> {

    private static final int GENERATOR_WEIGHT = 2;
    public static BlockWandCraftingTable WAND_CRAFTING_TABLE;
    private RegistryUtils<Item> itemRegistryUtils;

    public SpellcraftBlocks() {
        super();
        itemRegistryUtils = new RegistryUtils<>();
    }

    @Override
    @SubscribeEvent
    public void onRegistryEvent(RegistryEvent.Register<Block> e) {
        createBlocks();
        super.onRegistryEvent(e);
        Log.info("Registering SpellcraftBlocks");
        register(WAND_CRAFTING_TABLE);
        Log.info("Adding SpellcraftItemBlocks");
        registerBlockItem(WAND_CRAFTING_TABLE);
    }


    @SubscribeEvent
    public void onItemRegistryEvent(RegistryEvent.Register<Item> e) {
        Log.info("Registering SpellcraftItemBlocks");
        itemRegistryUtils.setRegistry(e.getRegistry());
        for (Item item :
                getUtils().getRegisteredItems()) {
            itemRegistryUtils.register(item);
        }
    }

    @Override
    public void commonPreInit() {
        super.commonPreInit();
    }

    @Override
    @SideOnly(Side.CLIENT)
    public void clientInit() {
        super.clientInit();
    }

    public void registerWorldGen() {
        Log.info("Registering Ore Generation");
    }

    public void registerBlockItem(Block entry) {
        if (entry != null) {
            RenderableBlockItem blockItem = new RenderableBlockItem(entry);
            addToItemMap(entry, blockItem);
            addToRenderable(entry);
        } else {
            Log.error("Cannot registerBlockItem with null Block!");
        }
    }

    private static void createBlocks() {
        Log.info("Creating Blocks");
        WAND_CRAFTING_TABLE = new BlockWandCraftingTable();
    }


    private static final class RenderableBlockItem extends ItemBlock implements INamed, IRenderable {
        public RenderableBlockItem(Block block) {
            super(block);
            if (block.getRegistryName() != null) {
                setRegistryName(block.getRegistryName());
            }
        }

        @Override
        public String getName() {
            if (block instanceof INamed) {
                return ((INamed) block).getName();
            } else {
                return block.getUnlocalizedName().substring(5);
            }
        }

        @Nullable
        @Override
        public ResourceLocation getLocation() {
            return getRegistryName();
        }

        @Override
        public boolean registerRenderer() {
            return true;
        }
    }
}

In conjuction with:

public class BaseContainer<T extends IForgeRegistryEntry<T>> implements ILoggable {
    private final RegistryUtils<T> utils;

    public BaseContainer() {
        this.utils = new RegistryUtils<T>();
        MinecraftForge.EVENT_BUS.register(this);
    }

    protected RegistryUtils<T> getUtils() {
        return utils;
    }

    @SubscribeEvent
    public void onRegistryEvent(RegistryEvent.Register<T> e) {
        getUtils().setRegistry(e.getRegistry());
    }

    public void commonPreInit() {

    }

    public void postInit() {
        getUtils().postInit();
    }

    public @Nullable
    Item getItem(T thing) {
        return getUtils().getItem(thing);
    }

    @SideOnly(Side.CLIENT)
    public void clientInit() {
        getUtils().clientInit();
    }

    protected void register(T thing) {
        getUtils().register(thing);
    }

    @SideOnly(Side.CLIENT)
    protected void registerRenderer(@Nonnull T thing) {
        getUtils().registerRenderer(thing);
    }

    @SideOnly(Side.CLIENT)
    protected void registerItemRenderer(@Nonnull Item thing) {
        getUtils().registerItemRenderer(thing);
    }

    @SideOnly(Side.CLIENT)
    protected void registerItemRenderer(@Nonnull Item item, @Nonnegative int meta) {
        getUtils().registerItemRenderer(item, meta);
    }

    protected Object registerOreDict(@Nonnull Object thing, String name) {
        return getUtils().registerOreDict(thing, name);
    }


    @SubscribeEvent
    public void registerRender(ModelRegistryEvent registryEvent) {
        getUtils().registerRenders(registryEvent);
    }

    protected IOreDictNamed registerOreDict(@Nonnull IOreDictNamed thing) {
        return getUtils().registerOreDict(thing);
    }

    protected void addToRenderable(T t) {
        getUtils().addToRenderable(t);
    }

    protected void addToItemMap(T thing, Item item) {
        getUtils().addToItemMap(thing, item);
    }
}
public class RegistryUtils<T extends IForgeRegistryEntry<T>> implements ILoggable {
    private List<T> renderable;
    private List<Item> itemRenderables;
    private List<Tuple<Object, String>> postponedOredictEntries;
    private HashMap<T, Item> thingItemMap;
    private IForgeRegistry<T> registry;
    private boolean initWasCalled;

    public RegistryUtils() {
        renderable = new LinkedList<>();
        thingItemMap = new HashMap<>();
        itemRenderables = new LinkedList<>();
        registry = null;
        postponedOredictEntries = new LinkedList<>();
        initWasCalled = false;
    }

    public void clientInit() {
        initWasCalled = true;
        for (Tuple<Object, String> tuple :
                postponedOredictEntries) {
            registerOreDict(tuple.getFirst(), tuple.getSecond());
        }
    }

    public void postInit() {
        renderable.clear();
        itemRenderables.clear();
        postponedOredictEntries.clear();
        thingItemMap.clear();
        renderable = null;
        itemRenderables = null;
        postponedOredictEntries = null;
        thingItemMap = null;
        registry = null;
        initWasCalled = false;
    }

    public void setRegistry(IForgeRegistry<T> registry) {
        this.registry = registry;
    }

    public void registerRenders(ModelRegistryEvent registryEvent) {
        for (T thing :
                renderable) {
            if (thing instanceof Item) {
                itemRenderables.add((Item) thing);
            } else {
                Item item = getItem(thing);
                if (item != null) {
                    itemRenderables.add(item);
                } else {
                    Log.warn("Failed to registerGameOverlayListener Renderer for " + getName(item) + "!");
                }
            }
        }
        for (Item item :
                itemRenderables) {
            registerItemRenderer(item);
        }
    }

    public void register(RegistryEvent.Register<T> e, T toRegister) {
        setRegistry(e.getRegistry());
        checkAdditionalRegistration(toRegister);
    }

    public void registerAll(RegistryEvent.Register<T> e, T... toRegister) {
        setRegistry(e.getRegistry());
        registerAll(toRegister);
    }

    public void register(T toRegister) {
        if (this.registry != null && toRegister != null) {
            this.registry.register(toRegister);
            checkAdditionalRegistration(toRegister);
        } else {
            Log.error("Failed to registerGameOverlayListener thing(" + (toRegister != null ? getName(toRegister) + ") because there was no registry available!" : "null) because thing was null"));
        }
    }

    public void registerAll(T... toRegister) {
        if (this.registry != null && toRegister != null && toRegister.length > 0) {
            this.registry.registerAll(toRegister);
            for (T thing :
                    toRegister) {
                checkAdditionalRegistration(thing);
            }
        } else {
            Log.error("Failed to registerGameOverlayListener thing(" + (toRegister != null ? (toRegister.length > 0 ? Arrays.toString(toRegister) + ") because there was no registry available!" : "void vaargs list)") : "null vaargs list)"));
        }
    }

    @SuppressWarnings("unchecked")
    private void checkAdditionalRegistration(T toRegister) {
        if (toRegister instanceof IOreDictNamed) {
            registerOreDict((IOreDictNamed) toRegister);
        }
        if (toRegister instanceof TileEntityContainer) {
            GameRegistry.registerTileEntity(((TileEntityContainer) toRegister).getTileEntityClass(), MODID + getName(toRegister));
        }
        addToRenderable(toRegister);
    }

    public @Nullable
    Item getItem(T thing) {
        if (thing instanceof Item) {
            return (Item) thing;
        } else if (thingItemMap.containsKey(thing)) {
            return thingItemMap.get(thing);
        }
        return null;
    }

    protected Object registerOreDict(Object thing, String name) {
        if (name != null && thing != null) {
            if (initWasCalled) {
                if (thing instanceof Block) {
                    OreDictionary.registerOre(name, (Block) thing);
                } else if (thing instanceof Item) {
                    OreDictionary.registerOre(name, (Item) thing);
                } else if (thing instanceof ItemStack) {
                    OreDictionary.registerOre(name, (ItemStack) thing);
                } else {
                    Log.error("Cannot registerGameOverlayListener " + name + " in the GameRegistry because it is neither a Block, Item or ItemStack!");
                }
            } else {
                postponedOredictEntries.add(new Tuple<>(thing, name));
            }
        } else if (name == null) {
            Log.warn("Attempted to registerGameOverlayListener Object to OreDict with null OreDict Name!");
        } else {
            Log.warn("Cannot registerGameOverlayListener null Object(" + name + ") to the OreDictionary!");
        }
        return thing;
    }

    public IOreDictNamed registerOreDict(@Nonnull IOreDictNamed thing) {
        if (thing.getOreDictName() != null) {
            registerOreDict(thing, thing.getOreDictName());
        } else {
            Log.warn("Attempted to registerGameOverlayListener IOreDictNamed to OreDictionary with null OreDict Name!");
        }
        return thing;
    }

    @SideOnly(Side.CLIENT)
    public void registerRenderer(@Nonnull T thing) {
        if (thing instanceof Item) {
            itemRenderables.add((Item) thing);
        } else {
            Item item = thingItemMap.get(thing);
            if (item != null) {
                itemRenderables.add(item);
            } else if (thing instanceof Renderable) {
                addToRenderable(thing);
            } else {
                Log.warn("Could no registerGameOverlayListener Renderer for non-item and non-renderable");
            }
        }
    }

    @SideOnly(Side.CLIENT)
    public void registerItemRenderer(@Nonnull Item thing) {
        if (thing.getHasSubtypes()) {
            Log.trace("Registering item with subtypes " + getName(thing));
            CreativeTabs tabs;
            if (thing instanceof IRenderSubTabProvider) {
                tabs = ((IRenderSubTabProvider) thing).getSubTab();
            } else {
                tabs = CTabs.TAB_MAIN;
            }
            NonNullList<ItemStack> itemStacks = NonNullList.create();
            thing.getSubItems(tabs, itemStacks);
            for (ItemStack stack :
                    itemStacks) {
                registerItemRenderer(stack.getItem(), stack.getMetadata());
            }
        } else {
            registerItemRenderer(thing, 0);
        }
    }

    @SideOnly(Side.CLIENT)
    protected void registerItemRenderer(@Nonnull Item item, @Nonnegative int meta) {
        if (item.getRegistryName() != null) {
            ResourceLocation location = item.getRegistryName();
            if (item instanceof IRenderable && ((IRenderable) item).getLocation() != null) {
                location = ((IRenderable) item).getLocation();
            }
            String path = StringHelper.createResourceLocation(MODID, location.getResourcePath());
            if (!(item instanceof IRenderable) || ((IRenderable) item).registerRenderer()) {
                ModelLoader.setCustomModelResourceLocation(item, meta,
                        new ModelResourceLocation(path, "inventory"));
                Log.trace("Registered renderer for " + getName(item) + " with meta " + meta + ".");
            }
        } else {
            Log.warn("Could not registerItemRenderer for " + getName(item) + " because Registry Name hasn't been set!");
        }
    }

    public void addToRenderable(T t) {
        if (t instanceof IRenderable) {
            if (thingItemMap.containsKey(t) && thingItemMap.get(t) != null) {
                itemRenderables.add(thingItemMap.get(t));
            } else {
                renderable.add(t);
            }
        }
    }

    protected void addToItemMap(T thing, Item item) {
        if (!thingItemMap.containsKey(thing)) {
            thingItemMap.put(thing, item);
        }
    }

    public Collection<Item> getRegisteredItems() {
        return thingItemMap.values();
    }

}

As you can see: I Split up Code in multiple Files and don't create obsolete Arrays (use your varargs solution it is pretty elegant as long as you DON'T create a seperate array).

 

I know that most peoble will call this overconstructed, but I am not that far with the Mod I copied that from, so there aren't enough Blocks to justify that much Code yet.

In your case it would be more suitable to use a solution with less and much simpler Code, which doesn' declare all of your Variables as final

Link to comment
Share on other sites

Apperetnly I can't recall typing the 

GameOverlayListener 

things, I seem to have used auto-completion at that time.

 

=> This can server as an example how NOT to write a Log. Because it makes your Logs undescriptive and therefore hard to  read. I'll quickly change this to simply register...

 

More specifically it should be the Method name... (like registerRenderer)

Edited by Major Tuvok
Incomplete
Link to comment
Share on other sites

You have this:

final ResourceLocation registryName = Preconditions.checkNotNull(block.getRegistryName(), "Block %s has null registry name", block);

That precondition is useless. Why? Because if the block's registry name was null, you'd have gotten an error when registering it.

What you should do is check to see if the block is null.

 

Because it will be:

private static final Block AMETHYST_ORE = null;

You never assign a value to this field. If you are intending to use Object Holders to fill it (good idea) you need to add the Object Holder annotation.

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

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.