I have tried to look for a forum post addressing this topic for a while now and have not found it even though there are similar topics.
So, I have tried to create a cape chestplate item which makes the player fly but they must have redstone in their inventory and it must get removed while the player is in the air.
Though, I can recognize that I'll need !player.onGround() and the player's inventory to do this, I have not found any help on the topic.
There are 2 main ways of doing something special while a player wears armor:
1) override onArmorTick in the armor class. Note that this will be called for every piece of armor (if you have more than just a chestplate)
2) handle the PlayerTickEvent and check for your armor there.
For flight, you almost always have to go the event-handling route. The hard part about armor that gives flight is taking that flight off when the player removes the armor. It's simple enough to set allowFlying to false, but what if there are multiple mods that have flying armor or items? You don't want to break those mods just by taking the easy route.
If you want to have creative-style flight or directly enable the flying capability, you should handle the PlayerTickEvent. For a complicated but inter-mod compatible technique of doing this, see this post. If you want 'jetpack' style flight, where space applies upward motion but the player still falls (though slowly), see this slightly old post.
Rollback Post to RevisionRollBack
Click this banner for a list of illegal mod distributors -- only download from legal sites!
The code below works in making me fly with creative (ish) controls if I have redstone in my inventory, but when I go to creative, it doesn't allow me to fly and the redstone doesn't get damaged every couple of ticks when in flight. Where do I put it in the event?
I'm not sure what you expected this to do. You made a new ItemStack (that doesn't even exist in the player inventory) and you're increasing the metadata of the ItemStack. I thought you wanted to decrease stack size of an actual ItemStack that the player has.
For that, you need to search the inventory of the player for an ItemStack containing redstone, then decrement the stack size of that ItemStack if (player.ticksExisted % (ticksBetweenConsuming) == 0) where ticksBetweenConsuming is how many ticks before a redstone is consumed. Make sure to delete the ItemStack if its size is 0 or less.
Look at ItemBow's findAmmo method for examples of getting an ItemStack from the player inventory. Look at ItemBow's onItemUseFinish method for examples of using up that ItemStack. Although come to think of it, those methods may only have been added in 1.9 with tipped arrows. In that case, look for a method that involves the phrase 'consumeItem' that is called from ItemBow.
As for your problem with gamemode 0 flight not working, I can't tell why that would happen.
Rollback Post to RevisionRollBack
Click this banner for a list of illegal mod distributors -- only download from legal sites!
And also, shouldn't the player.inventory.hasItem(Item item) work in detecting the item in the inventory? It triggers flight for me.
Yes, it detects whether the given item is there. That's not the problem.
Also, I made a mistake, I realized that you do --rs.stackSize to subtract the stack from the inventory.
Yes, that is how you subtract stack size. But 'rs' is still not an actual ItemStack in the player's inventory, it's an ItemStack that you made right then and there. It does not share anything with the actual redstone ItemStack that is in the player's inventory, so any methods or stacksize changes will not affect the player's inventory in any way.
You have to search the player's inventory to get the ItemStack instance that contains the redstone that is in the player's inventory, not the redstone that is randomly in your code.
No, I mean creative mode flight not working.
Oops, I meant gamemode 1 flight. I don't play enough Minecraft to remember commands
And no, I still don't know why your code is interfering with that flight.
Rollback Post to RevisionRollBack
Click this banner for a list of illegal mod distributors -- only download from legal sites!
The Meaning of Life, the Universe, and Everything.
Join Date:
5/28/2014
Posts:
285
Location:
USA
Minecraft:
TheUnderTaker11
Member Details
I mean correct me if I'm wrong but i think sky is trying to say you need to loop through the players inventory to find an instance of redstone(an itemstack) then use that to remove one item every whatever seconds.
Just cause you know the item is there doesn't mean you have an actual itemstack for that item.
Rollback Post to RevisionRollBack
Want a mod with the best magnets available? The download Better Magnets!
And if you like Avaritia then you will love More Avaritia! Adds recipes for creative items from a huge list of mods, and even adds more custom items that fit the Avaritia theme!
Hey guys,
I have tried to look for a forum post addressing this topic for a while now and have not found it even though there are similar topics.
So, I have tried to create a cape chestplate item which makes the player fly but they must have redstone in their inventory and it must get removed while the player is in the air.
Though, I can recognize that I'll need !player.onGround() and the player's inventory to do this, I have not found any help on the topic.
Are there any good ways to do this via an event?
hello?
There are 2 main ways of doing something special while a player wears armor:
1) override onArmorTick in the armor class. Note that this will be called for every piece of armor (if you have more than just a chestplate)
2) handle the PlayerTickEvent and check for your armor there.
For flight, you almost always have to go the event-handling route. The hard part about armor that gives flight is taking that flight off when the player removes the armor. It's simple enough to set allowFlying to false, but what if there are multiple mods that have flying armor or items? You don't want to break those mods just by taking the easy route.
If you want to have creative-style flight or directly enable the flying capability, you should handle the PlayerTickEvent. For a complicated but inter-mod compatible technique of doing this, see this post. If you want 'jetpack' style flight, where space applies upward motion but the player still falls (though slowly), see this slightly old post.
The code below works in making me fly with creative (ish) controls if I have redstone in my inventory, but when I go to creative, it doesn't allow me to fly and the redstone doesn't get damaged every couple of ticks when in flight. Where do I put it in the event?
I'm not sure what you expected this to do. You made a new ItemStack (that doesn't even exist in the player inventory) and you're increasing the metadata of the ItemStack. I thought you wanted to decrease stack size of an actual ItemStack that the player has.
For that, you need to search the inventory of the player for an ItemStack containing redstone, then decrement the stack size of that ItemStack if (player.ticksExisted % (ticksBetweenConsuming) == 0) where ticksBetweenConsuming is how many ticks before a redstone is consumed. Make sure to delete the ItemStack if its size is 0 or less.
Look at ItemBow's findAmmo method for examples of getting an ItemStack from the player inventory. Look at ItemBow's onItemUseFinish method for examples of using up that ItemStack. Although come to think of it, those methods may only have been added in 1.9 with tipped arrows. In that case, look for a method that involves the phrase 'consumeItem' that is called from ItemBow.
As for your problem with gamemode 0 flight not working, I can't tell why that would happen.
No, I mean creative mode flight not working.
And also, shouldn't the player.inventory.hasItem(Item item) work in detecting the item in the inventory? It triggers flight for me.
Also, I made a mistake, I realized that you do --rs.stackSize to subtract the stack from the inventory.
Do you know how to trigger creative (gamemode 1) flight to retrigger again?
Yes, it detects whether the given item is there. That's not the problem.
Yes, that is how you subtract stack size. But 'rs' is still not an actual ItemStack in the player's inventory, it's an ItemStack that you made right then and there. It does not share anything with the actual redstone ItemStack that is in the player's inventory, so any methods or stacksize changes will not affect the player's inventory in any way.
You have to search the player's inventory to get the ItemStack instance that contains the redstone that is in the player's inventory, not the redstone that is randomly in your code.
Oops, I meant gamemode 1 flight. I don't play enough Minecraft to remember commands
And no, I still don't know why your code is interfering with that flight.
I mean correct me if I'm wrong but i think sky is trying to say you need to loop through the players inventory to find an instance of redstone(an itemstack) then use that to remove one item every whatever seconds.
Just cause you know the item is there doesn't mean you have an actual itemstack for that item.
Want a mod with the best magnets available? The download Better Magnets!
And if you like Avaritia then you will love More Avaritia! Adds recipes for creative items from a huge list of mods, and even adds more custom items that fit the Avaritia theme!
I got it, thx guys. I'll see if it works later tonight.