WildHeart Posted December 7, 2017 Share Posted December 7, 2017 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? Quote Link to comment Share on other sites More sharing options...
Draco18s Posted December 7, 2017 Share Posted December 7, 2017 What's the crash? Quote 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 More sharing options...
loordgek Posted December 7, 2017 Share Posted December 7, 2017 dont know it is the problem stack in 1.11 and up are not null check for isEmpty() Quote Link to comment Share on other sites More sharing options...
WildHeart Posted December 7, 2017 Author Share Posted December 7, 2017 15 minutes ago, loordgek said: dont know it is the problem stack in 1.11 and up are not null check for isEmpty() Amended Quote Link to comment Share on other sites More sharing options...
WildHeart Posted December 7, 2017 Author Share Posted December 7, 2017 49 minutes ago, Draco18s said: What's the crash? So, isEmpty corrects this, but items is not saving:/ Quote Link to comment Share on other sites More sharing options...
WildHeart Posted December 8, 2017 Author Share Posted December 8, 2017 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. Quote Link to comment Share on other sites More sharing options...
jabelar Posted December 8, 2017 Share Posted December 8, 2017 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. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/ Link to comment Share on other sites More sharing options...
WildHeart Posted December 8, 2017 Author Share Posted December 8, 2017 (edited) 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, 2017 by WildHeart Quote Link to comment Share on other sites More sharing options...
WildHeart Posted December 8, 2017 Author Share Posted December 8, 2017 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)); } } } } ? Quote Link to comment Share on other sites More sharing options...
Draco18s Posted December 8, 2017 Share Posted December 8, 2017 Why are you getting from and setting to the same inventory? Quote 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 More sharing options...
WildHeart Posted December 8, 2017 Author Share Posted December 8, 2017 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)); } } } } Quote Link to comment Share on other sites More sharing options...
WildHeart Posted December 9, 2017 Author Share Posted December 9, 2017 Solved! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.