2021-06-12 21:20:18 +02:00
|
|
|
package net.citizensnpcs.nms.v1_17_R1.entity;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
|
|
|
|
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity;
|
|
|
|
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftZombie;
|
|
|
|
import org.bukkit.util.Vector;
|
2023-02-22 17:06:13 +01:00
|
|
|
|
2021-06-12 21:20:18 +02:00
|
|
|
import net.citizensnpcs.api.npc.NPC;
|
|
|
|
import net.citizensnpcs.nms.v1_17_R1.util.ForwardingNPCHolder;
|
2023-02-13 13:32:20 +01:00
|
|
|
import net.citizensnpcs.nms.v1_17_R1.util.NMSBoundingBox;
|
2021-06-12 21:20:18 +02:00
|
|
|
import net.citizensnpcs.nms.v1_17_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;
|
2021-06-12 21:20:18 +02:00
|
|
|
import net.citizensnpcs.util.Util;
|
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.nbt.CompoundTag;
|
|
|
|
import net.minecraft.sounds.SoundEvent;
|
2022-11-13 13:54:06 +01:00
|
|
|
import net.minecraft.tags.Tag;
|
2021-06-12 21:20:18 +02:00
|
|
|
import net.minecraft.world.damagesource.DamageSource;
|
|
|
|
import net.minecraft.world.entity.Entity;
|
|
|
|
import net.minecraft.world.entity.EntityType;
|
|
|
|
import net.minecraft.world.entity.monster.Zombie;
|
|
|
|
import net.minecraft.world.entity.vehicle.AbstractMinecart;
|
|
|
|
import net.minecraft.world.entity.vehicle.Boat;
|
|
|
|
import net.minecraft.world.level.Level;
|
|
|
|
import net.minecraft.world.level.block.state.BlockState;
|
2022-11-13 13:54:06 +01:00
|
|
|
import net.minecraft.world.level.material.Fluid;
|
2023-02-13 13:32:20 +01:00
|
|
|
import net.minecraft.world.phys.AABB;
|
2021-06-12 21:20:18 +02:00
|
|
|
import net.minecraft.world.phys.Vec3;
|
|
|
|
|
|
|
|
public class ZombieController extends MobEntityController {
|
|
|
|
public ZombieController() {
|
|
|
|
super(EntityZombieNPC.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public org.bukkit.entity.Zombie getBukkitEntity() {
|
|
|
|
return (org.bukkit.entity.Zombie) super.getBukkitEntity();
|
|
|
|
}
|
|
|
|
|
2023-02-20 16:34:12 +01:00
|
|
|
public static class EntityZombieNPC extends Zombie implements NPCHolder {
|
2021-06-12 21:20:18 +02:00
|
|
|
private final CitizensNPC npc;
|
|
|
|
|
|
|
|
public EntityZombieNPC(EntityType<? extends Zombie> types, Level level) {
|
|
|
|
this(types, level, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public EntityZombieNPC(EntityType<? extends Zombie> types, Level level, NPC npc) {
|
|
|
|
super(types, level);
|
|
|
|
this.npc = (CitizensNPC) npc;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean canRide(Entity entity) {
|
|
|
|
if (npc != null && (entity instanceof Boat || entity instanceof AbstractMinecart)) {
|
2022-12-10 06:29:05 +01:00
|
|
|
return !npc.isProtected();
|
2021-06-12 21:20:18 +02:00
|
|
|
}
|
|
|
|
return super.canRide(entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean causeFallDamage(float f, float f1, DamageSource damagesource) {
|
|
|
|
if (npc == null || !npc.isFlyable()) {
|
|
|
|
return super.causeFallDamage(f, f1, damagesource);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void checkDespawn() {
|
|
|
|
if (npc == null) {
|
|
|
|
super.checkDespawn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void checkFallDamage(double d0, boolean flag, BlockState iblockdata, BlockPos blockposition) {
|
|
|
|
if (npc == null || !npc.isFlyable()) {
|
|
|
|
super.checkFallDamage(d0, flag, iblockdata, blockposition);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void customServerAiStep() {
|
|
|
|
super.customServerAiStep();
|
|
|
|
if (npc != null) {
|
|
|
|
NMSImpl.updateMinecraftAIState(npc, this);
|
|
|
|
npc.update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-14 18:41:24 +01:00
|
|
|
|
2021-06-12 21:20:18 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected SoundEvent getAmbientSound() {
|
2023-01-01 08:26:35 +01:00
|
|
|
return NMSImpl.getSoundEffect(npc, super.getAmbientSound(), NPC.Metadata.AMBIENT_SOUND);
|
2021-06-12 21:20:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public CraftEntity getBukkitEntity() {
|
|
|
|
if (npc != null && !(super.getBukkitEntity() instanceof NPCHolder)) {
|
|
|
|
NMSImpl.setBukkitEntity(this, new ZombieNPC(this));
|
|
|
|
}
|
|
|
|
return super.getBukkitEntity();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected SoundEvent getDeathSound() {
|
2023-01-01 08:26:35 +01:00
|
|
|
return NMSImpl.getSoundEffect(npc, super.getDeathSound(), NPC.Metadata.DEATH_SOUND);
|
2021-06-12 21:20:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected SoundEvent getHurtSound(DamageSource damagesource) {
|
2023-01-01 08:26:35 +01:00
|
|
|
return NMSImpl.getSoundEffect(npc, super.getHurtSound(damagesource), NPC.Metadata.HURT_SOUND);
|
2021-06-12 21:20:18 +02:00
|
|
|
}
|
|
|
|
|
2023-03-12 15:29:41 +01:00
|
|
|
@Override
|
|
|
|
public int getMaxFallDistance() {
|
|
|
|
return NMS.getFallDistance(npc, super.getMaxFallDistance());
|
|
|
|
}
|
|
|
|
|
2021-06-12 21:20:18 +02:00
|
|
|
@Override
|
|
|
|
public NPC getNPC() {
|
|
|
|
return npc;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isLeashed() {
|
2023-02-13 17:46:30 +01:00
|
|
|
return NMSImpl.isLeashed(npc, super::isLeashed, this);
|
2021-06-12 21:20:18 +02:00
|
|
|
}
|
|
|
|
|
2023-02-21 15:56:50 +01:00
|
|
|
@Override
|
|
|
|
public boolean isPushable() {
|
|
|
|
return npc == null ? super.isPushable()
|
|
|
|
: npc.data().<Boolean> get(NPC.Metadata.COLLIDABLE, !npc.isProtected());
|
|
|
|
}
|
|
|
|
|
2022-11-13 16:33:18 +01:00
|
|
|
@Override
|
|
|
|
public void knockback(double strength, double dx, double dz) {
|
2023-02-13 13:32:20 +01:00
|
|
|
NMS.callKnockbackEvent(npc, (float) strength, dx, dz, (evt) -> super.knockback((float) evt.getStrength(),
|
|
|
|
evt.getKnockbackVector().getX(), evt.getKnockbackVector().getZ()));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected AABB makeBoundingBox() {
|
|
|
|
return NMSBoundingBox.makeBB(npc, super.makeBoundingBox());
|
2022-11-13 16:33:18 +01:00
|
|
|
}
|
|
|
|
|
2021-06-12 21:20:18 +02:00
|
|
|
@Override
|
|
|
|
public boolean onClimbable() {
|
|
|
|
if (npc == null || !npc.isFlyable()) {
|
|
|
|
return super.onClimbable();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void push(double x, double y, double z) {
|
|
|
|
Vector vector = Util.callPushEvent(npc, x, y, z);
|
|
|
|
if (vector != null) {
|
|
|
|
super.push(vector.getX(), vector.getY(), vector.getZ());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void push(Entity entity) {
|
|
|
|
// this method is called by both the entities involved - cancelling
|
|
|
|
// it will not stop the NPC from moving.
|
|
|
|
super.push(entity);
|
|
|
|
if (npc != null)
|
|
|
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean save(CompoundTag save) {
|
|
|
|
return npc == null ? super.save(save) : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void travel(Vec3 vec3d) {
|
|
|
|
if (npc == null || !npc.isFlyable()) {
|
|
|
|
super.travel(vec3d);
|
|
|
|
} else {
|
|
|
|
NMSImpl.flyingMoveLogic(this, vec3d);
|
|
|
|
}
|
|
|
|
}
|
2022-11-13 16:33:18 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean updateFluidHeightAndDoFluidPushing(Tag<Fluid> Tag, double d0) {
|
2023-02-13 17:19:45 +01:00
|
|
|
return NMSImpl.fluidPush(npc, this, () -> super.updateFluidHeightAndDoFluidPushing(Tag, d0));
|
2022-11-13 16:33:18 +01:00
|
|
|
}
|
2021-06-12 21:20:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static class ZombieNPC extends CraftZombie implements ForwardingNPCHolder {
|
|
|
|
public ZombieNPC(EntityZombieNPC entity) {
|
|
|
|
super((CraftServer) Bukkit.getServer(), entity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|