Jump to content

Subscribing to item crafted event crashes the game


ilan321

Recommended Posts

Hello, I am working on something that lets me change an item's NBT when it is being crafted with (A transmutation stone).

I have this method:

    @SubscribeEvent
    public void ItemCraftedEvent(PlayerEvent.ItemCraftedEvent e)
    {
        // If the item crafted is the transmutation stone
        if (e.crafting.getItem() instanceof BasicTransmutationStone)
        {
            e.crafting.stackTagCompound = new NBTTagCompound();
            e.crafting.stackTagCompound.setString("owner", e.player.getDisplayName());
            e.crafting.stackTagCompound.setInteger("uses", 128);
            return;
        }
        // If the item being used in crafting is the transmutation stone
        for (int i = 0; i < e.craftMatrix.getSizeInventory(); i++)
        {
            if (e.craftMatrix.getStackInSlot(i).getItem() instanceof BasicTransmutationStone)
            {
                if (e.craftMatrix.getStackInSlot(i).stackTagCompound != null)
                {
                    e.craftMatrix.getStackInSlot(i).stackTagCompound.setInteger("uses", e.craftMatrix.getStackInSlot(i).stackTagCompound.getInteger("uses") - 1);
                    if (e.craftMatrix.getStackInSlot(i).stackTagCompound.getInteger("uses") < 1)
                    {
                        e.craftMatrix.setInventorySlotContents(i, null);
                        return;
                    }
                }
            }
        }
    }

When I try to craft the transmutation stone, it does not crash!

When I try to craft with a transmutation stone, it crashes.

The crash log is identical:

---- Minecraft Crash Report ----
// You should try our sister game, Minceraft!

Time: 10/1/14 1:58 PM
Description: Updating screen events

java.lang.NullPointerException: Updating screen events
at com.ilan321.transmutation.ref.CraftingHandler.ItemCraftedEvent(CraftingHandler.java:29)
at cpw.mods.fml.common.eventhandler.ASMEventHandler_5_CraftingHandler_ItemCraftedEvent_ItemCraftedEvent.invoke(.dynamic)
at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:51)
at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:122)
at cpw.mods.fml.common.FMLCommonHandler.firePlayerCraftingEvent(FMLCommonHandler.java:569)
at net.minecraft.inventory.SlotCrafting.onPickupFromSlot(SlotCrafting.java:128)
at net.minecraft.inventory.Container.slotClick(Container.java:349)
at net.minecraft.client.multiplayer.PlayerControllerMP.windowClick(PlayerControllerMP.java:482)
at net.minecraft.client.gui.inventory.GuiContainer.handleMouseClick(GuiContainer.java:678)
at net.minecraft.client.gui.inventory.GuiContainer.mouseClicked(GuiContainer.java:420)
at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:346)
at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:315)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1730)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1038)
at net.minecraft.client.Minecraft.run(Minecraft.java:961)
at net.minecraft.client.main.Main.main(Main.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at GradleStart.bounce(GradleStart.java:107)
at GradleStart.startClient(GradleStart.java:100)
at GradleStart.main(GradleStart.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

 

What am I doing wrong here?

 

Link to comment
Share on other sites

That is not the problem. The

e.crafting

block is for when the player is crafting a transmutation stone. My problem is when the player crafts with the transmutation stone, for example 'stone + 1 iron = 4 ender pearl'. That is when it crashes.

 

Edit: ah nvm, it works now. I added the null check for the second block and it works. Thanks! :)

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.