2022-11-13 16:33:18 +01:00
|
|
|
package net.citizensnpcs.nms.v1_14_R1.entity;
|
2019-04-24 15:01:22 +02:00
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
|
|
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
|
|
|
|
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPhantom;
|
|
|
|
import org.bukkit.entity.Phantom;
|
|
|
|
import org.bukkit.util.Vector;
|
2023-02-22 17:06:13 +01:00
|
|
|
|
2019-04-24 15:01:22 +02:00
|
|
|
import net.citizensnpcs.api.npc.NPC;
|
2023-02-13 13:32:20 +01:00
|
|
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSBoundingBox;
|
2019-04-24 15:01:22 +02:00
|
|
|
import net.citizensnpcs.nms.v1_14_R1.util.NMSImpl;
|
|
|
|
import net.citizensnpcs.npc.CitizensNPC;
|
|
|
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
2023-02-13 13:32:20 +01:00
|
|
|
import net.citizensnpcs.util.NMS;
|
2019-04-24 15:01:22 +02:00
|
|
|
import net.citizensnpcs.util.Util;
|
2023-02-13 13:32:20 +01:00
|
|
|
import net.minecraft.server.v1_14_R1.AxisAlignedBB;
|
2019-04-24 15:01:22 +02:00
|
|
|
import net.minecraft.server.v1_14_R1.BlockPosition;
|
|
|
|
import net.minecraft.server.v1_14_R1.ControllerLook;
|
|
|
|
import net.minecraft.server.v1_14_R1.ControllerMove;
|
|
|
|
import net.minecraft.server.v1_14_R1.DamageSource;
|
2020-06-12 13:57:45 +02:00
|
|
|
import net.minecraft.server.v1_14_R1.Entity;
|
|
|
|
import net.minecraft.server.v1_14_R1.EntityBoat;
|
|
|
|
import net.minecraft.server.v1_14_R1.EntityMinecartAbstract;
|
2019-04-24 15:01:22 +02:00
|
|
|
import net.minecraft.server.v1_14_R1.EntityPhantom;
|
|
|
|
import net.minecraft.server.v1_14_R1.EntityTypes;
|
|
|
|
import net.minecraft.server.v1_14_R1.EnumDifficulty;
|
2022-11-13 16:33:18 +01:00
|
|
|
import net.minecraft.server.v1_14_R1.FluidType;
|
2019-04-24 15:01:22 +02:00
|
|
|
import net.minecraft.server.v1_14_R1.IBlockData;
|
|
|
|
import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
|
|
|
import net.minecraft.server.v1_14_R1.SoundEffect;
|
2022-11-13 16:33:18 +01:00
|
|
|
import net.minecraft.server.v1_14_R1.Tag;
|
2019-04-24 15:01:22 +02:00
|
|
|
import net.minecraft.server.v1_14_R1.Vec3D;
|
|
|
|
import net.minecraft.server.v1_14_R1.World;
|
|
|
|
|
|
|
|
public class PhantomController extends MobEntityController {
|
|
|
|
public PhantomController() {
|
|
|
|
super(EntityPhantomNPC.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Phantom getBukkitEntity() {
|
|
|
|
return (Phantom) super.getBukkitEntity();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class EntityPhantomNPC extends EntityPhantom implements NPCHolder {
|
|
|
|
private final CitizensNPC npc;
|
|
|
|
|
|
|
|
public EntityPhantomNPC(EntityTypes<? extends EntityPhantom> types, World world) {
|
|
|
|
this(types, world, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public EntityPhantomNPC(EntityTypes<? extends EntityPhantom> types, World world, NPC npc) {
|
|
|
|
super(types, world);
|
|
|
|
this.npc = (CitizensNPC) npc;
|
|
|
|
if (npc != null) {
|
|
|
|
this.moveController = new ControllerMove(this);
|
|
|
|
this.lookController = new ControllerLook(this);
|
|
|
|
// TODO: phantom pitch reversed
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-13 13:32:20 +01:00
|
|
|
@Override
|
|
|
|
public void a(AxisAlignedBB bb) {
|
|
|
|
super.a(NMSBoundingBox.makeBB(npc, bb));
|
|
|
|
}
|
|
|
|
|
2019-04-24 15:01:22 +02:00
|
|
|
@Override
|
|
|
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
|
|
|
if (npc == null || !npc.isFlyable()) {
|
|
|
|
super.a(d0, flag, block, blockposition);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-13 16:33:18 +01:00
|
|
|
@Override
|
|
|
|
public void a(Entity entity, float strength, double dx, double dz) {
|
2023-02-13 13:32:20 +01:00
|
|
|
NMS.callKnockbackEvent(npc, strength, dx, dz, (evt) -> super.a(entity, (float) evt.getStrength(),
|
|
|
|
evt.getKnockbackVector().getX(), evt.getKnockbackVector().getZ()));
|
2022-11-13 16:33:18 +01:00
|
|
|
}
|
|
|
|
|
2019-04-24 15:01:22 +02:00
|
|
|
@Override
|
|
|
|
public void b(float f, float f1) {
|
|
|
|
if (npc == null || !npc.isFlyable()) {
|
|
|
|
super.b(f, f1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-13 16:33:18 +01:00
|
|
|
@Override
|
|
|
|
public boolean b(Tag<FluidType> tag) {
|
2023-06-17 09:46:07 +02:00
|
|
|
if (npc == null) {
|
|
|
|
return super.b(tag);
|
|
|
|
}
|
|
|
|
Vec3D old = getMot().add(0, 0, 0);
|
|
|
|
boolean res = super.b(tag);
|
|
|
|
if (!npc.isPushableByFluids()) {
|
|
|
|
setMot(old);
|
|
|
|
}
|
|
|
|
return res;
|
2022-11-13 16:33:18 +01:00
|
|
|
}
|
|
|
|
|
2023-03-12 15:29:41 +01:00
|
|
|
@Override
|
|
|
|
public int bv() {
|
|
|
|
return NMS.getFallDistance(npc, super.bv());
|
|
|
|
}
|
|
|
|
|
2019-04-24 15:01:22 +02:00
|
|
|
@Override
|
|
|
|
protected void checkDespawn() {
|
|
|
|
if (npc == null) {
|
|
|
|
super.checkDespawn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void collide(net.minecraft.server.v1_14_R1.Entity entity) {
|
|
|
|
// this method is called by both the entities involved - cancelling
|
|
|
|
// it will not stop the NPC from moving.
|
|
|
|
super.collide(entity);
|
|
|
|
if (npc != null)
|
|
|
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean d(NBTTagCompound save) {
|
|
|
|
return npc == null ? super.d(save) : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean dS() {
|
|
|
|
if (npc == null || !npc.isProtected())
|
|
|
|
return super.dS();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void e(Vec3D vec3d) {
|
|
|
|
if (npc == null || !npc.isFlyable()) {
|
|
|
|
super.e(vec3d);
|
|
|
|
} else {
|
|
|
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void f(double x, double y, double z) {
|
2021-01-02 17:09:21 +01:00
|
|
|
Vector vector = Util.callPushEvent(npc, x, y, z);
|
|
|
|
if (vector != null) {
|
2019-04-24 15:01:22 +02:00
|
|
|
super.f(vector.getX(), vector.getY(), vector.getZ());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public CraftEntity getBukkitEntity() {
|
2019-06-02 17:36:47 +02:00
|
|
|
if (npc != null && !(super.getBukkitEntity() instanceof NPCHolder)) {
|
|
|
|
NMSImpl.setBukkitEntity(this, new PhantomNPC(this));
|
|
|
|
}
|
2019-04-24 15:01:22 +02:00
|
|
|
return super.getBukkitEntity();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public NPC getNPC() {
|
|
|
|
return npc;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected SoundEffect getSoundAmbient() {
|
2023-01-01 08:26:35 +01:00
|
|
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.Metadata.AMBIENT_SOUND);
|
2019-04-24 15:01:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected SoundEffect getSoundDeath() {
|
2023-01-01 08:26:35 +01:00
|
|
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.Metadata.DEATH_SOUND);
|
2019-04-24 15:01:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
2023-01-01 08:26:35 +01:00
|
|
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.Metadata.HURT_SOUND);
|
2019-04-24 15:01:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isClimbing() {
|
|
|
|
if (npc == null || !npc.isFlyable()) {
|
|
|
|
return super.isClimbing();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isLeashed() {
|
2023-02-13 17:46:30 +01:00
|
|
|
return NMSImpl.isLeashed(npc, super::isLeashed, this);
|
2019-04-24 15:01:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void movementTick() {
|
2019-04-25 09:43:44 +02:00
|
|
|
super.movementTick();
|
2019-04-24 15:01:22 +02:00
|
|
|
if (npc != null) {
|
|
|
|
if (npc.isProtected()) {
|
|
|
|
this.setOnFire(0);
|
|
|
|
}
|
|
|
|
npc.update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-12 13:57:45 +02:00
|
|
|
@Override
|
|
|
|
protected boolean n(Entity entity) {
|
|
|
|
if (npc != null && (entity instanceof EntityBoat || entity instanceof EntityMinecartAbstract)) {
|
2022-12-10 06:29:05 +01:00
|
|
|
return !npc.isProtected();
|
2020-06-12 13:57:45 +02:00
|
|
|
}
|
|
|
|
return super.n(entity);
|
|
|
|
}
|
|
|
|
|
2019-04-24 15:01:22 +02:00
|
|
|
@Override
|
|
|
|
public void tick() {
|
|
|
|
// avoid suicide
|
|
|
|
boolean resetDifficulty = this.world.getDifficulty() == EnumDifficulty.PEACEFUL;
|
|
|
|
if (npc != null && resetDifficulty) {
|
|
|
|
this.world.getWorldData().setDifficulty(EnumDifficulty.NORMAL);
|
|
|
|
}
|
|
|
|
super.tick();
|
|
|
|
if (npc != null && resetDifficulty) {
|
|
|
|
this.world.getWorldData().setDifficulty(EnumDifficulty.PEACEFUL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class PhantomNPC extends CraftPhantom implements NPCHolder {
|
|
|
|
private final CitizensNPC npc;
|
|
|
|
|
|
|
|
public PhantomNPC(EntityPhantomNPC entity) {
|
|
|
|
super((CraftServer) Bukkit.getServer(), entity);
|
|
|
|
this.npc = entity.npc;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public NPC getNPC() {
|
|
|
|
return npc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|