So, a new problem has surfaced in my code. Basically what's happening is, because the armor suit saves and then overwrites the contents of the other armor slots with the rest of the suit when you put it on, it causes issues if you die in the suit. Dying in the suit causes it to drop the chestplate, leggings, and boots from the suit, which should be unobtainable and, because of the way they work, trying to pick them up causes a game crash.
In order to fix this, I'm trying to catch the player death drops event so that I can force it to drop the helmet before anything else. This should cause the rest of the suit to run through its normal reversion routine (also removing added effects like flight, etc.), thereby fixing this issue. This is the code I have so far (it's so small I didn't put it up in gist, but I can do that if you want...)
@SubscribeEvent
public void playerDropsEvent(PlayerDropsEvent event)
{
event.setCanceled(true);
EntityPlayer player = event.entityPlayer;
if (player.inventory.armorItemInSlot(3) != null && player.inventory.armorItemInSlot(3).getItem() == NovaMod.NovaHelmet)
{
ItemStack helmetDrop = new ItemStack(player.inventory.armorItemInSlot(3).getItem(), 1);
EntityItem helmetitem = new EntityItem(player.worldObj, player.posX, player.posY+1, player.posZ, helmetDrop);
}
}
I was attempting to use the method in reply #6 of this thread, but for some reason it doesn't like it and gives me errors. I'm not sure if it's because the code has changed between 1.7 and 1.8, but I'm concerned that could be the case.
Does anyone else know how I could force the helmet to drop and then wait for the rest of the armor to revert before I allow the rest of the drop sequence to go through? Is canceling the event even necessary? (I am going to uncancel it after I run my code... unless canceling it isn't necessary)
Bonus: I'm working on making the helmet placeable as a block. It's still buggy, but for when it's done, how could I place the helmet as a block instead of just dropping the item from the inventory?
-- if they are, drop it as an item (using player.worldObj.spawnEntityInWorld(entityitem) )
-- set the helmet to null
-- then check if the other armor is NovaMod armor and set it to null if it is. That is, manually tell the other armor pieces to not exist BEFORE the game even considers dropping them.
However, sometimes armor should not drop on death (creative mode, other mods, etc.). Try JUST setting the other armor pieces to null and see if the helmet drops as usual before it gets a chance to "make" more armor.
Rollback Post to RevisionRollBack
Click this banner for a list of illegal mod distributors -- only download from legal sites!
-- if they are, drop it as an item (using ",monospace">player.worldObj.spawnEntityInWorld(entityitem) )
-- set the helmet to null
-- then check if the other armor is NovaMod armor and set it to null if it is. That is, manually tell the other armor pieces to not exist BEFORE the game even considers dropping them.
However, sometimes armor should not drop on death (creative mode, other mods, etc.). Try JUST setting the other armor pieces to null and see if the helmet drops as usual before it gets a chance to "make" more armor.
Ah, okay- thanks! I'll try this!
I think I'll go with the first method to see if that works, because the rest of the armor has more complicated functions like saving former armor and stuff, so just setting it to null would automatically mess some of that up. But I think this will give me a good starting place. Thanks!
Hey, it's me again.
So, a new problem has surfaced in my code. Basically what's happening is, because the armor suit saves and then overwrites the contents of the other armor slots with the rest of the suit when you put it on, it causes issues if you die in the suit. Dying in the suit causes it to drop the chestplate, leggings, and boots from the suit, which should be unobtainable and, because of the way they work, trying to pick them up causes a game crash.
In order to fix this, I'm trying to catch the player death drops event so that I can force it to drop the helmet before anything else. This should cause the rest of the suit to run through its normal reversion routine (also removing added effects like flight, etc.), thereby fixing this issue. This is the code I have so far (it's so small I didn't put it up in gist, but I can do that if you want...)
I was attempting to use the method in reply #6 of this thread, but for some reason it doesn't like it and gives me errors. I'm not sure if it's because the code has changed between 1.7 and 1.8, but I'm concerned that could be the case.
Does anyone else know how I could force the helmet to drop and then wait for the rest of the armor to revert before I allow the rest of the drop sequence to go through? Is canceling the event even necessary? (I am going to uncancel it after I run my code... unless canceling it isn't necessary)
Bonus: I'm working on making the helmet placeable as a block. It's still buggy, but for when it's done, how could I place the helmet as a block instead of just dropping the item from the inventory?
Thanks!
Here's a messy way to do it:
- on death, do the following:
-- check if player is wearing NovaMod helmet
-- if they are, drop it as an item (using player.worldObj.spawnEntityInWorld(entityitem) )
-- set the helmet to null
-- then check if the other armor is NovaMod armor and set it to null if it is. That is, manually tell the other armor pieces to not exist BEFORE the game even considers dropping them.
However, sometimes armor should not drop on death (creative mode, other mods, etc.). Try JUST setting the other armor pieces to null and see if the helmet drops as usual before it gets a chance to "make" more armor.
Ah, okay- thanks! I'll try this!
I think I'll go with the first method to see if that works, because the rest of the armor has more complicated functions like saving former armor and stuff, so just setting it to null would automatically mess some of that up. But I think this will give me a good starting place. Thanks!