mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-22 08:02:31 +01:00
AbstractProjectile and arrows now call EntityAttackEvent, without damaging entities
This commit is contained in:
parent
dbd0e472c2
commit
bcdd1bb70a
@ -55,4 +55,6 @@ public interface Projectile {
|
||||
);
|
||||
}
|
||||
|
||||
Entity getShooter();
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package net.minestom.server.entity.type.projectile;
|
||||
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.ObjectEntity;
|
||||
import net.minestom.server.entity.type.Projectile;
|
||||
import net.minestom.server.utils.Position;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class AbstractProjectile extends ObjectEntity implements Projectile {
|
||||
|
||||
private final Entity shooter;
|
||||
|
||||
public AbstractProjectile(@Nullable Entity shooter, @NotNull EntityType entityType, @NotNull Position spawnPosition) {
|
||||
super(entityType, spawnPosition);
|
||||
this.shooter = shooter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity getShooter() {
|
||||
return this.shooter;
|
||||
}
|
||||
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
package net.minestom.server.entity.type.projectile;
|
||||
|
||||
import net.minestom.server.entity.*;
|
||||
import net.minestom.server.entity.damage.DamageType;
|
||||
import net.minestom.server.entity.type.Projectile;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.LivingEntity;
|
||||
import net.minestom.server.entity.Metadata;
|
||||
import net.minestom.server.event.entity.EntityAttackEvent;
|
||||
import net.minestom.server.instance.Chunk;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
@ -16,16 +18,13 @@ import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EntityAbstractArrow extends ObjectEntity implements Projectile {
|
||||
public class EntityAbstractArrow extends AbstractProjectile {
|
||||
|
||||
private final static byte CRITICAL_BIT = 0x01;
|
||||
private final static byte NO_CLIP_BIT = 0x02;
|
||||
|
||||
private final Entity shooter;
|
||||
|
||||
EntityAbstractArrow(@Nullable Entity shooter, @NotNull EntityType entityType, @NotNull Position spawnPosition) {
|
||||
super(entityType, spawnPosition);
|
||||
this.shooter = shooter;
|
||||
super(shooter, entityType, spawnPosition);
|
||||
super.hasPhysics = false;
|
||||
|
||||
setBoundingBox(.5F, .5F, .5F);
|
||||
@ -115,7 +114,7 @@ public class EntityAbstractArrow extends ObjectEntity implements Projectile {
|
||||
if (victimOptional.isPresent()) {
|
||||
LivingEntity victim = (LivingEntity) victimOptional.get();
|
||||
victim.setArrowCount(victim.getArrowCount() + 1);
|
||||
victim.damage(DamageType.fromProjectile(this.shooter, this), 2F);
|
||||
callEvent(EntityAttackEvent.class, new EntityAttackEvent(this, victim));
|
||||
remove();
|
||||
return super.onGround;
|
||||
}
|
||||
@ -171,7 +170,8 @@ public class EntityAbstractArrow extends ObjectEntity implements Projectile {
|
||||
|
||||
@Override
|
||||
public int getObjectData() {
|
||||
return this.shooter == null ? 0 : this.shooter.getEntityId() + 1;
|
||||
Entity shooter = getShooter();
|
||||
return shooter == null ? 0 : shooter.getEntityId() + 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.entity.type.projectile;
|
||||
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.Metadata;
|
||||
import net.minestom.server.entity.ObjectEntity;
|
||||
@ -7,11 +8,13 @@ import net.minestom.server.entity.type.Projectile;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import net.minestom.server.utils.Position;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class EntityEyeOfEnder extends ObjectEntity implements Projectile {
|
||||
public class EntityEyeOfEnder extends AbstractProjectile {
|
||||
|
||||
public EntityEyeOfEnder(Position spawnPosition) {
|
||||
super(EntityType.EYE_OF_ENDER, spawnPosition);
|
||||
public EntityEyeOfEnder(@Nullable Entity shooter, @NotNull Position spawnPosition) {
|
||||
super(shooter, EntityType.EYE_OF_ENDER, spawnPosition);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.entity.type.projectile;
|
||||
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.Metadata;
|
||||
import net.minestom.server.entity.ObjectEntity;
|
||||
@ -7,11 +8,12 @@ import net.minestom.server.entity.type.Projectile;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.utils.Position;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class EntityPotion extends ObjectEntity implements Projectile {
|
||||
public class EntityPotion extends AbstractProjectile {
|
||||
|
||||
public EntityPotion(Position spawnPosition, @NotNull ItemStack potion) {
|
||||
super(EntityType.POTION, spawnPosition);
|
||||
public EntityPotion(@Nullable Entity shooter, @NotNull Position spawnPosition, @NotNull ItemStack potion) {
|
||||
super(shooter, EntityType.POTION, spawnPosition);
|
||||
setBoundingBox(0.25f, 0.25f, 0.25f);
|
||||
setPotion(potion);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user