Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello, i use event PlayerEvent.Clone for saving items with death, but if i use that code, my mc has been crashed.

@SubscribeEvent
    public void onClone(PlayerEvent.Clone e)
    {
        if (e.wasDeath)
        {
            ItemStack backStack = null;

            for (ItemStack stack : e.original.inventory.mainInventory)
            {
                if (stack != null && (stack.getItem() instanceof ModGun || stack.getItem() instanceof ModTool))
                {
                    backStack = stack;
                }
            }

            if (backStack != null)
            {
                e.entityPlayer.inventory.addItemStackToInventory(backStack);
            }
        }
    }

What's the problem?

What's the crash?

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.

  • Author
15 minutes ago, loordgek said:

dont know it is the problem

stack in 1.11 and up are not null check for isEmpty()

Amended

  • Author
49 minutes ago, Draco18s said:

What's the crash?

So, isEmpty corrects this, but items is not saving:/

  • Author
10 hours ago, diesieben07 said:

Look at EntityPlayerMP::copyFrom to see how data is copied over in case of a non-death copy. Then apply that to the death copy.

Yes, but this copy inventory, not a specific item.

  • Author
20 minutes ago, jabelar said:

Just compare each item in the inventory with the one you want and if it is in the inventory copy it.

So, if (st.getItem() instanceof MyItem)

{

 e.entityPlayer.inventory.copyInv(e.original.inventory);

}

Edited by WildHeart

  • Author
3 hours ago, diesieben07 said:

No. Look at what copyInventory does and adapt it for your needs.

@SubscribeEvent
    public void onClone(PlayerEvent.Clone e)
    {
        if (e.wasDeath)
        {
            InventoryPlayer inv = e.entityPlayer.inventory; 
            
            for (int i = 0; i < inv.getSizeInventory(); ++i)
            {
                if (inv.getStackInSlot(i).getItem() instanceof CustomArmor || 
                        inv.getStackInSlot(i).getItem() instanceof CustomWeapon)
                {
                    inv.setInventorySlotContents(i, e.original.inventory.getStackInSlot(i));
                }
            }
        }
    }

?

Why are you getting from and setting to the same inventory?

Capture.PNG

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.

  • Author
3 minutes ago, Draco18s said:

Why are you getting from and setting to the same inventory?

Capture.PNG

Ups, my fail. Corrected.

@SubscribeEvent
    public void onClone(PlayerEvent.Clone e)
    {
        if (e.wasDeath)
        {
            InventoryPlayer orig = e.original.inventory;

            for (int i = 0; i < orig.getSizeInventory(); ++i)
            {
                if (orig.getStackInSlot(i).getItem() instanceof CustomArmor ||
                        orig.getStackInSlot(i).getItem() instanceof CustomWeapon)
                {
                    e.entityPlayer.inventory.setInventorySlotContents(i, orig.getStackInSlot(i));
                }
            }
        }
    }

 

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.