Skip to content

Commit

Permalink
Minions should not attack team players or players at all if PVP is di…
Browse files Browse the repository at this point in the history
…sabled

Close #1268
  • Loading branch information
maxanier committed Oct 14, 2023
1 parent 30c88dd commit 9a484bb
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import de.teamlapen.vampirism.inventory.MinionContainer;
import de.teamlapen.vampirism.util.DamageHandler;
import de.teamlapen.vampirism.util.IPlayerOverlay;
import de.teamlapen.vampirism.util.Permissions;
import de.teamlapen.vampirism.util.PlayerSkinHelper;
import de.teamlapen.vampirism.world.MinionWorldData;
import net.minecraft.core.NonNullList;
Expand Down Expand Up @@ -118,7 +119,8 @@ protected MinionEntity(EntityType<? extends VampirismEntity> type, Level world,
this.hardAttackPredicate = livingEntity -> {
boolean flag1 = getLordOpt().map(ILordPlayer::getPlayer).filter(entity -> entity == livingEntity).isPresent(); //Don't attack lord
boolean flag2 = livingEntity instanceof MinionEntity && ((MinionEntity<?>) livingEntity).getLordID().filter(id -> getLordID().map(id2 -> id == id2).orElse(false)).isPresent(); //Don't attack other minions of lord
return !flag1 && !flag2;
boolean flag3 = livingEntity instanceof Player otherPlayer && getLordOpt().map(ILordPlayer::getPlayer).map(player -> !player.canHarmPlayer(otherPlayer)).orElse(!Permissions.isPvpEnabled(otherPlayer));
return !flag1 && !flag2 && !flag3;
};
setDontDropEquipment();
this.peaceful = true;
Expand Down Expand Up @@ -184,7 +186,7 @@ public void die(@NotNull DamageSource cause) {
/**
* Copy of {@link net.minecraft.world.entity.Mob} but with modified DamageSource
* Check if code still up-to-date
* TODO 1.20
* TODO 1.21
*/
@Override
public boolean doHurtTarget(@NotNull Entity entityIn) {
Expand All @@ -211,6 +213,8 @@ public boolean doHurtTarget(@NotNull Entity entityIn) {
if (entityIn instanceof Player player) {
this.maybeDisableShield(player, this.getMainHandItem(), player.isUsingItem() ? player.getUseItem() : ItemStack.EMPTY);
}

//Usually only players call the hurt enemy method on the itemstack
if (!this.level().isClientSide && !itemstack.isEmpty() && entityIn instanceof LivingEntity) {
itemstack.getItem().hurtEnemy(itemstack, (LivingEntity) entityIn, this);
if (itemstack.isEmpty()) {
Expand Down

0 comments on commit 9a484bb

Please sign in to comment.