I play on a lot of servers, I do play a lot of Survival Games with friends. But one thing that annoys me is when I unintentionally hit my friend (In Minecraft). Is it possible to make a mod that disables PVP according to the players name/entity I am hitting? I'm not too experienced in modding, I do know some stuff. But if someone could give me some basic Idea on how to start or some Code Snippets to help me out it would be greatly appreciated.
The Meaning of Life, the Universe, and Everything.
Location:
Mount Vernon
Join Date:
12/13/2012
Posts:
43
Location:
Mount Vernon
Minecraft:
PhoenixOfWar
Xbox:
Cause Im Ninja
Member Details
I think what he meant was to disable his own character from damaging another player. Not another player from being able to damage him {Unless on their side, they added him to the "Don't harm list"
First you'll need to know your UUID and your friend's UUID. Store these as final fields of some class using UUID.fromString("<uuid>") (probably either some reference/constants class or the class handling the event described below).
When you have an instance of EntityPlayer, you can use EntityPlayer#getUniqueID to get their UUID and use UUID#equals to check for equality.
For the functionality itself, subscribe to LivingAttackEvent.
The entityLiving/entity fields of this event are the Entity being attacked (same value, stored as different different subclasses).
The source field is the DamageSource of the attack. If it's an instance of EntityDamageSource, use DamageSource#getEntity to get the attacking Entity. If this Entity is an instance of EntityArrow, cast to EntityArrow and use the shootingEntity field to get the Entity that fired the arrow.
If both the attacked and attacking Entities are players (i.e. instances of EntityPlayer), get their UUIDs and compare them to you and your friend's UUIDs. To stop the attack from happening, use event.setCanceled(true) to cancel the LivingAttackEvent.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Is it possible to use EntityPlayer.getDisplayName(); instead of the player UUID for 1.7.10 compatibility?
And also where do I use this code? In a PlayerTickEvent?
Everything I posted was for 1.7.10 (though it would probably be similar in 1.8). UUIDs should work without issue since EntityPlayer's constructor sets the entityUniqueID field to the UUID of the player's GameProfile. Display names would probably work, but you may as well properly handle name changes since it's about the same amount of code either way.
The code I described should be in the handler for LivingAttackEvent.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
I play on a lot of servers, I do play a lot of Survival Games with friends. But one thing that annoys me is when I unintentionally hit my friend (In Minecraft). Is it possible to make a mod that disables PVP according to the players name/entity I am hitting? I'm not too experienced in modding, I do know some stuff. But if someone could give me some basic Idea on how to start or some Code Snippets to help me out it would be greatly appreciated.
Thank You!
-Blue Axe
Pretty much, but It could also help me to become a better modder.
You know what i mean..
-Blue Axe
I think what he meant was to disable his own character from damaging another player. Not another player from being able to damage him {Unless on their side, they added him to the "Don't harm list"
Exactly. Can anyone help me out with this? (What PheonixOfWar Said).
First you'll need to know your UUID and your friend's UUID. Store these as final fields of some class using UUID.fromString("<uuid>") (probably either some reference/constants class or the class handling the event described below).
When you have an instance of EntityPlayer, you can use EntityPlayer#getUniqueID to get their UUID and use UUID#equals to check for equality.
For the functionality itself, subscribe to LivingAttackEvent.
The entityLiving/entity fields of this event are the Entity being attacked (same value, stored as different different subclasses).
The source field is the DamageSource of the attack. If it's an instance of EntityDamageSource, use DamageSource#getEntity to get the attacking Entity. If this Entity is an instance of EntityArrow, cast to EntityArrow and use the shootingEntity field to get the Entity that fired the arrow.
If both the attacked and attacking Entities are players (i.e. instances of EntityPlayer), get their UUIDs and compare them to you and your friend's UUIDs. To stop the attack from happening, use event.setCanceled(true) to cancel the LivingAttackEvent.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Thanks a lot Choonster,
I've not understood a few things, but will definitely research.
Is it possible to use EntityPlayer.getDisplayName(); instead of the player UUID for 1.7.10 compatibility?
And also where do I use this code? In a PlayerTickEvent?
Everything I posted was for 1.7.10 (though it would probably be similar in 1.8). UUIDs should work without issue since EntityPlayer's constructor sets the entityUniqueID field to the UUID of the player's GameProfile. Display names would probably work, but you may as well properly handle name changes since it's about the same amount of code either way.
The code I described should be in the handler for LivingAttackEvent.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Yeah, I've got down some code, which i pretty sure won't work, will try it out tomorrow.
Thanks a lot!