2012-02-03 10:20:48 +01:00
|
|
|
package net.citizensnpcs.npc.entity;
|
|
|
|
|
2016-01-01 07:59:49 +01:00
|
|
|
import org.bukkit.Bukkit;
|
2016-06-09 12:25:27 +02:00
|
|
|
import org.bukkit.craftbukkit.v1_10_R1.CraftServer;
|
|
|
|
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity;
|
|
|
|
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftSilverfish;
|
2016-01-01 07:59:49 +01:00
|
|
|
import org.bukkit.entity.Silverfish;
|
|
|
|
import org.bukkit.util.Vector;
|
|
|
|
|
2016-02-02 14:10:15 +01:00
|
|
|
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
2012-07-28 09:02:57 +02:00
|
|
|
import net.citizensnpcs.api.event.NPCPushEvent;
|
2012-03-12 11:45:36 +01:00
|
|
|
import net.citizensnpcs.api.npc.NPC;
|
2012-04-19 05:52:07 +02:00
|
|
|
import net.citizensnpcs.npc.CitizensNPC;
|
2012-12-14 15:07:25 +01:00
|
|
|
import net.citizensnpcs.npc.MobEntityController;
|
2012-07-19 17:10:30 +02:00
|
|
|
import net.citizensnpcs.npc.ai.NPCHolder;
|
2012-09-01 12:05:22 +02:00
|
|
|
import net.citizensnpcs.util.NMS;
|
2012-07-27 18:01:52 +02:00
|
|
|
import net.citizensnpcs.util.Util;
|
2016-06-09 12:25:27 +02:00
|
|
|
import net.minecraft.server.v1_10_R1.BlockPosition;
|
|
|
|
import net.minecraft.server.v1_10_R1.EntitySilverfish;
|
|
|
|
import net.minecraft.server.v1_10_R1.IBlockData;
|
|
|
|
import net.minecraft.server.v1_10_R1.MinecraftKey;
|
|
|
|
import net.minecraft.server.v1_10_R1.NBTTagCompound;
|
|
|
|
import net.minecraft.server.v1_10_R1.SoundEffect;
|
|
|
|
import net.minecraft.server.v1_10_R1.World;
|
2012-02-03 10:20:48 +01:00
|
|
|
|
2012-12-08 13:08:58 +01:00
|
|
|
public class SilverfishController extends MobEntityController {
|
|
|
|
public SilverfishController() {
|
|
|
|
super(EntitySilverfishNPC.class);
|
2012-02-03 10:20:48 +01:00
|
|
|
}
|
2012-02-04 07:48:23 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Silverfish getBukkitEntity() {
|
2012-08-12 08:39:44 +02:00
|
|
|
return (Silverfish) super.getBukkitEntity();
|
2012-02-04 07:48:23 +01:00
|
|
|
}
|
|
|
|
|
2012-07-19 17:10:30 +02:00
|
|
|
public static class EntitySilverfishNPC extends EntitySilverfish implements NPCHolder {
|
2012-04-19 05:52:07 +02:00
|
|
|
private final CitizensNPC npc;
|
2012-03-12 11:45:36 +01:00
|
|
|
|
2012-05-03 23:38:23 +02:00
|
|
|
public EntitySilverfishNPC(World world) {
|
|
|
|
this(world, null);
|
|
|
|
}
|
|
|
|
|
2012-04-20 16:45:09 +02:00
|
|
|
public EntitySilverfishNPC(World world, NPC npc) {
|
2012-02-04 07:48:23 +01:00
|
|
|
super(world);
|
2012-04-20 16:45:09 +02:00
|
|
|
this.npc = (CitizensNPC) npc;
|
2012-07-19 17:10:30 +02:00
|
|
|
if (npc != null) {
|
2012-09-01 12:05:22 +02:00
|
|
|
NMS.clearGoals(goalSelector, targetSelector);
|
2012-07-19 17:10:30 +02:00
|
|
|
}
|
2012-02-04 07:48:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-01 04:12:13 +01:00
|
|
|
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
2013-11-05 14:35:26 +01:00
|
|
|
if (npc == null || !npc.isFlyable()) {
|
2014-11-28 16:22:11 +01:00
|
|
|
super.a(d0, flag, block, blockposition);
|
2013-11-05 14:35:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-29 14:37:27 +01:00
|
|
|
@Override
|
2016-06-09 12:25:27 +02:00
|
|
|
protected SoundEffect bW() {
|
|
|
|
return npc == null || !npc.data().has(NPC.HURT_SOUND_METADATA) ? super.bW()
|
2016-03-01 06:44:14 +01:00
|
|
|
: SoundEffect.a.get(new MinecraftKey(
|
2016-06-09 12:25:27 +02:00
|
|
|
npc.data().get(NPC.HURT_SOUND_METADATA, SoundEffect.a.b(super.bW()).toString())));
|
2014-01-29 14:37:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-06-09 12:25:27 +02:00
|
|
|
protected SoundEffect bV() {
|
|
|
|
return npc == null || !npc.data().has(NPC.DEATH_SOUND_METADATA) ? super.bV()
|
2016-03-01 06:44:14 +01:00
|
|
|
: SoundEffect.a.get(new MinecraftKey(
|
2016-06-09 12:25:27 +02:00
|
|
|
npc.data().get(NPC.DEATH_SOUND_METADATA, SoundEffect.a.b(super.bV()).toString())));
|
2014-01-29 14:37:27 +01:00
|
|
|
}
|
|
|
|
|
2013-11-05 14:35:26 +01:00
|
|
|
@Override
|
2016-06-09 12:25:27 +02:00
|
|
|
public void collide(net.minecraft.server.v1_10_R1.Entity entity) {
|
2012-07-28 09:02:57 +02:00
|
|
|
// this method is called by both the entities involved - cancelling
|
|
|
|
// it will not stop the NPC from moving.
|
|
|
|
super.collide(entity);
|
2012-09-07 12:25:54 +02:00
|
|
|
if (npc != null)
|
2012-12-14 15:07:25 +01:00
|
|
|
Util.callCollisionEvent(npc, entity.getBukkitEntity());
|
2012-02-04 07:48:23 +01:00
|
|
|
}
|
2012-07-09 15:35:57 +02:00
|
|
|
|
2014-11-16 16:43:01 +01:00
|
|
|
@Override
|
|
|
|
public boolean d(NBTTagCompound save) {
|
|
|
|
return npc == null ? super.d(save) : false;
|
|
|
|
}
|
|
|
|
|
2013-11-05 14:35:26 +01:00
|
|
|
@Override
|
|
|
|
public void e(float f, float f1) {
|
|
|
|
if (npc == null || !npc.isFlyable()) {
|
|
|
|
super.e(f, f1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-02 14:10:15 +01:00
|
|
|
@Override
|
|
|
|
public void enderTeleportTo(double d0, double d1, double d2) {
|
|
|
|
if (npc == null)
|
|
|
|
super.enderTeleportTo(d0, d1, d2);
|
|
|
|
NPCEnderTeleportEvent event = new NPCEnderTeleportEvent(npc);
|
|
|
|
Bukkit.getPluginManager().callEvent(event);
|
|
|
|
if (!event.isCancelled()) {
|
|
|
|
super.enderTeleportTo(d0, d1, d2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-28 10:15:12 +02:00
|
|
|
@Override
|
2012-08-02 15:44:59 +02:00
|
|
|
public void g(double x, double y, double z) {
|
|
|
|
if (npc == null) {
|
|
|
|
super.g(x, y, z);
|
|
|
|
return;
|
|
|
|
}
|
2012-09-07 12:25:54 +02:00
|
|
|
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
|
|
|
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
|
|
|
super.g(x, y, z);
|
2012-08-02 15:44:59 +02:00
|
|
|
return;
|
2012-09-07 12:25:54 +02:00
|
|
|
}
|
2012-08-04 07:39:04 +02:00
|
|
|
Vector vector = new Vector(x, y, z);
|
|
|
|
NPCPushEvent event = Util.callPushEvent(npc, vector);
|
|
|
|
if (!event.isCancelled()) {
|
|
|
|
vector = event.getCollisionVector();
|
|
|
|
super.g(vector.getX(), vector.getY(), vector.getZ());
|
|
|
|
}
|
2012-08-02 15:44:59 +02:00
|
|
|
// when another entity collides, this method is called to push the
|
|
|
|
// NPC so we prevent it from doing anything if the event is
|
|
|
|
// cancelled.
|
2012-07-28 10:15:12 +02:00
|
|
|
}
|
|
|
|
|
2014-11-28 16:22:11 +01:00
|
|
|
@Override
|
|
|
|
public void g(float f, float f1) {
|
|
|
|
if (npc == null || !npc.isFlyable()) {
|
|
|
|
super.g(f, f1);
|
|
|
|
} else {
|
|
|
|
NMS.flyingMoveLogic(this, f, f1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-01 04:12:13 +01:00
|
|
|
@Override
|
|
|
|
protected SoundEffect G() {
|
2016-03-01 06:44:14 +01:00
|
|
|
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.G()
|
|
|
|
: SoundEffect.a.get(new MinecraftKey(
|
|
|
|
npc.data().get(NPC.AMBIENT_SOUND_METADATA, SoundEffect.a.b(super.G()).toString())));
|
2016-03-01 04:12:13 +01:00
|
|
|
}
|
|
|
|
|
2012-10-12 06:16:44 +02:00
|
|
|
@Override
|
2013-01-19 13:42:03 +01:00
|
|
|
public CraftEntity getBukkitEntity() {
|
2012-10-12 06:16:44 +02:00
|
|
|
if (bukkitEntity == null && npc != null)
|
|
|
|
bukkitEntity = new SilverfishNPC(this);
|
|
|
|
return super.getBukkitEntity();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public NPC getNPC() {
|
|
|
|
return npc;
|
|
|
|
}
|
2014-01-21 05:25:14 +01:00
|
|
|
|
|
|
|
@Override
|
2016-03-01 04:12:13 +01:00
|
|
|
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
|
|
|
|
protected void L() {
|
|
|
|
if (npc == null) {
|
|
|
|
super.L();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void M() {
|
|
|
|
super.M();
|
|
|
|
if (npc != null)
|
|
|
|
npc.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-06-09 12:25:27 +02:00
|
|
|
public boolean m_() {
|
2014-01-21 05:25:14 +01:00
|
|
|
if (npc == null || !npc.isFlyable()) {
|
2016-06-09 12:25:27 +02:00
|
|
|
return super.m_();
|
2014-01-21 05:25:14 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-01 07:59:49 +01:00
|
|
|
@Override
|
|
|
|
public void setSize(float f, float f1) {
|
|
|
|
if (npc == null) {
|
|
|
|
super.setSize(f, f1);
|
|
|
|
} else {
|
|
|
|
NMS.setSize(this, f, f1, justCreated);
|
|
|
|
}
|
|
|
|
}
|
2012-10-12 06:16:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static class SilverfishNPC extends CraftSilverfish implements NPCHolder {
|
|
|
|
private final CitizensNPC npc;
|
|
|
|
|
|
|
|
public SilverfishNPC(EntitySilverfishNPC entity) {
|
|
|
|
super((CraftServer) Bukkit.getServer(), entity);
|
|
|
|
this.npc = entity.npc;
|
|
|
|
}
|
|
|
|
|
2012-07-09 15:35:57 +02:00
|
|
|
@Override
|
|
|
|
public NPC getNPC() {
|
|
|
|
return npc;
|
|
|
|
}
|
2012-02-04 07:48:23 +01:00
|
|
|
}
|
2012-02-03 10:20:48 +01:00
|
|
|
}
|