Posted December 7, 20177 yr 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?
December 7, 20177 yr 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.
December 7, 20177 yr dont know it is the problem stack in 1.11 and up are not null check for isEmpty()
December 7, 20177 yr 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
December 7, 20177 yr Author 49 minutes ago, Draco18s said: What's the crash? So, isEmpty corrects this, but items is not saving:/
December 8, 20177 yr 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.
December 8, 20177 yr 52 minutes ago, WildHeart said: Yes, but this copy inventory, not a specific item. Just compare each item in the inventory with the one you want and if it is in the inventory copy it. Check out my tutorials here: http://jabelarminecraft.blogspot.com/
December 8, 20177 yr 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 December 8, 20177 yr by WildHeart
December 8, 20177 yr 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)); } } } } ?
December 8, 20177 yr Why are you getting from and setting to the same inventory? 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.
December 8, 20177 yr Author 3 minutes ago, Draco18s said: Why are you getting from and setting to the same inventory? 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.