2020-11-04 00:51:54 +01:00
|
|
|
package net.citizensnpcs.nms.v1_16_R3.entity;
|
2020-06-25 11:24:32 +02:00
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
2020-11-04 00:51:54 +01:00
|
|
|
import org.bukkit.craftbukkit.v1_16_R3.CraftServer;
|
|
|
|
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity;
|
|
|
|
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftTurtle;
|
2020-06-25 11:24:32 +02:00
|
|
|
import org.bukkit.entity.Turtle;
|
|
|
|
import org.bukkit.util.Vector;
|
|
|
|
|
|
|
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
|
|
|
import net.citizensnpcs.api.npc.NPC;
|
2021-01-02 17:09:21 +01:00
|
|
|
import net.citizensnpcs.nms.v1_16_R3.util.ForwardingNPCHolder;
|
2020-11-04 00:51:54 +01:00
|
|
|
import net.citizensnpcs.nms.v1_16_R3.util.NMSImpl;
|
|
|
|
import net.citizensnpcs.nms.v1_16_R3.util.PlayerControllerMove;
|
2020-06-25 11:24:32 +02:00
|
|
|
import net.citizensnpcs.npc.CitizensNPC;
|
|
|
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
|
|
|
import net.citizensnpcs.util.Util;
|
2020-11-04 00:51:54 +01:00
|
|
|
import net.minecraft.server.v1_16_R3.BlockPosition;
|
|
|
|
import net.minecraft.server.v1_16_R3.ControllerJump;
|
|
|
|
import net.minecraft.server.v1_16_R3.ControllerMove;
|
|
|
|
import net.minecraft.server.v1_16_R3.DamageSource;
|
|
|
|
import net.minecraft.server.v1_16_R3.Entity;
|
|
|
|
import net.minecraft.server.v1_16_R3.EntityBoat;
|
|
|
|
import net.minecraft.server.v1_16_R3.EntityInsentient;
|
|
|
|
import net.minecraft.server.v1_16_R3.EntityMinecartAbstract;
|
|
|
|
import net.minecraft.server.v1_16_R3.EntityTurtle;
|
|
|
|
import net.minecraft.server.v1_16_R3.EntityTypes;
|
|
|
|
import net.minecraft.server.v1_16_R3.IBlockData;
|
|
|
|
import net.minecraft.server.v1_16_R3.NBTTagCompound;
|
|
|
|
import net.minecraft.server.v1_16_R3.SoundEffect;
|
|
|
|
import net.minecraft.server.v1_16_R3.Vec3D;
|
|
|
|
import net.minecraft.server.v1_16_R3.World;
|
2020-06-25 11:24:32 +02:00
|
|
|
|
|
|
|
public class TurtleController extends MobEntityController {
|
|
|
|
public TurtleController() {
|
|
|
|
super(EntityTurtleNPC.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Turtle getBukkitEntity() {
|
|
|
|
return (Turtle) super.getBukkitEntity();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class EntityTurtleNPC extends EntityTurtle implements NPCHolder {
|
|
|
|
private final CitizensNPC npc;
|
|
|
|
private ControllerJump oldJumpController;
|
|
|
|
private ControllerMove oldMoveController;
|
|
|
|
|
|
|
|
public EntityTurtleNPC(EntityTypes<? extends EntityTurtle> types, World world) {
|
|
|
|
this(types, world, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public EntityTurtleNPC(EntityTypes<? extends EntityTurtle> types, World world, NPC npc) {
|
|
|
|
super(types, world);
|
|
|
|
this.npc = (CitizensNPC) npc;
|
|
|
|
if (npc != null) {
|
|
|
|
this.oldMoveController = this.moveController;
|
2020-08-12 16:21:12 +02:00
|
|
|
this.oldJumpController = this.bi;
|
2020-06-25 11:24:32 +02:00
|
|
|
this.moveController = new ControllerMove(this);
|
2020-08-12 16:21:12 +02:00
|
|
|
this.bi = new EmptyControllerJump(this);
|
2020-06-25 11:24:32 +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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean b(float f, float f1) {
|
|
|
|
if (npc == null || !npc.isFlyable()) {
|
|
|
|
return super.b(f, f1);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void checkDespawn() {
|
|
|
|
if (npc == null) {
|
|
|
|
super.checkDespawn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-11-04 00:51:54 +01:00
|
|
|
public void collide(net.minecraft.server.v1_16_R3.Entity entity) {
|
2020-06-25 11:24:32 +02:00
|
|
|
// 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 void enderTeleportTo(double d0, double d1, double d2) {
|
|
|
|
if (npc == null) {
|
|
|
|
super.enderTeleportTo(d0, d1, d2);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
|
|
|
Bukkit.getPluginManager().callEvent(event);
|
|
|
|
if (!event.isCancelled()) {
|
|
|
|
super.enderTeleportTo(d0, d1, d2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-08-12 16:21:12 +02:00
|
|
|
public void g(Vec3D vec3d) {
|
2020-06-25 11:24:32 +02:00
|
|
|
if (npc == null || !npc.isFlyable()) {
|
2022-02-19 11:26:37 +01:00
|
|
|
if (!NMSImpl.moveFish(npc, this, vec3d)) {
|
2022-02-16 10:36:03 +01:00
|
|
|
super.g(vec3d);
|
|
|
|
}
|
2020-06-25 11:24:32 +02:00
|
|
|
} else {
|
|
|
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public CraftEntity getBukkitEntity() {
|
|
|
|
if (npc != null && !(super.getBukkitEntity() instanceof NPCHolder)) {
|
|
|
|
NMSImpl.setBukkitEntity(this, new TurtleNPC(this));
|
|
|
|
}
|
|
|
|
return super.getBukkitEntity();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public NPC getNPC() {
|
|
|
|
return npc;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected SoundEffect getSoundAmbient() {
|
|
|
|
return NMSImpl.getSoundEffect(npc, super.getSoundAmbient(), NPC.AMBIENT_SOUND_METADATA);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected SoundEffect getSoundDeath() {
|
|
|
|
return NMSImpl.getSoundEffect(npc, super.getSoundDeath(), NPC.DEATH_SOUND_METADATA);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected SoundEffect getSoundHurt(DamageSource damagesource) {
|
|
|
|
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-08-12 16:21:12 +02:00
|
|
|
public void i(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) {
|
2020-08-12 16:21:12 +02:00
|
|
|
super.i(vector.getX(), vector.getY(), vector.getZ());
|
2020-06-25 11:24:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isClimbing() {
|
|
|
|
if (npc == null || !npc.isFlyable()) {
|
|
|
|
return super.isClimbing();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isLeashed() {
|
|
|
|
if (npc == null)
|
|
|
|
return super.isLeashed();
|
|
|
|
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
|
|
|
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
|
|
|
return super.isLeashed();
|
|
|
|
if (super.isLeashed()) {
|
|
|
|
unleash(true, false); // clearLeash with client update
|
|
|
|
}
|
|
|
|
return false; // shouldLeash
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mobTick() {
|
|
|
|
super.mobTick();
|
|
|
|
if (npc != null) {
|
|
|
|
NMSImpl.updateMinecraftAIState(npc, this);
|
|
|
|
if (npc.useMinecraftAI() && this.moveController != this.oldMoveController) {
|
|
|
|
this.moveController = this.oldMoveController;
|
2020-08-12 16:21:12 +02:00
|
|
|
this.bi = this.oldJumpController;
|
2020-06-25 11:24:32 +02:00
|
|
|
}
|
|
|
|
if (!npc.useMinecraftAI() && this.moveController == this.oldMoveController) {
|
|
|
|
this.moveController = new PlayerControllerMove(this);
|
2020-08-12 16:21:12 +02:00
|
|
|
this.bi = new EmptyControllerJump(this);
|
2020-06-25 11:24:32 +02:00
|
|
|
}
|
|
|
|
npc.update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean n(Entity entity) {
|
|
|
|
if (npc != null && (entity instanceof EntityBoat || entity instanceof EntityMinecartAbstract)) {
|
|
|
|
return !npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
|
|
|
}
|
|
|
|
return super.n(entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
static class EmptyControllerJump extends ControllerJump {
|
|
|
|
public EmptyControllerJump(EntityInsentient var1) {
|
|
|
|
super(var1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void b() {
|
|
|
|
this.a = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-02 17:09:21 +01:00
|
|
|
public static class TurtleNPC extends CraftTurtle implements ForwardingNPCHolder {
|
2020-06-25 11:24:32 +02:00
|
|
|
public TurtleNPC(EntityTurtleNPC entity) {
|
|
|
|
super((CraftServer) Bukkit.getServer(), entity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|