mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-09-28 07:07:39 +02:00
Add new entity controllers
This commit is contained in:
parent
81872b6799
commit
1b02573b9c
@ -454,5 +454,5 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static final String COMPATIBLE_MC_VERSION = "1.7.10";
|
||||
private static final String COMPATIBLE_MC_VERSION = "1.8";
|
||||
}
|
||||
|
@ -10,8 +10,10 @@ import net.citizensnpcs.npc.entity.CowController;
|
||||
import net.citizensnpcs.npc.entity.CreeperController;
|
||||
import net.citizensnpcs.npc.entity.EnderDragonController;
|
||||
import net.citizensnpcs.npc.entity.EndermanController;
|
||||
import net.citizensnpcs.npc.entity.EndermiteController;
|
||||
import net.citizensnpcs.npc.entity.GhastController;
|
||||
import net.citizensnpcs.npc.entity.GiantController;
|
||||
import net.citizensnpcs.npc.entity.GuardianController;
|
||||
import net.citizensnpcs.npc.entity.HorseController;
|
||||
import net.citizensnpcs.npc.entity.HumanController;
|
||||
import net.citizensnpcs.npc.entity.IronGolemController;
|
||||
@ -20,6 +22,7 @@ import net.citizensnpcs.npc.entity.MushroomCowController;
|
||||
import net.citizensnpcs.npc.entity.OcelotController;
|
||||
import net.citizensnpcs.npc.entity.PigController;
|
||||
import net.citizensnpcs.npc.entity.PigZombieController;
|
||||
import net.citizensnpcs.npc.entity.RabbitController;
|
||||
import net.citizensnpcs.npc.entity.SheepController;
|
||||
import net.citizensnpcs.npc.entity.SilverfishController;
|
||||
import net.citizensnpcs.npc.entity.SkeletonController;
|
||||
@ -32,6 +35,7 @@ import net.citizensnpcs.npc.entity.WitchController;
|
||||
import net.citizensnpcs.npc.entity.WitherController;
|
||||
import net.citizensnpcs.npc.entity.WolfController;
|
||||
import net.citizensnpcs.npc.entity.ZombieController;
|
||||
import net.citizensnpcs.npc.entity.nonliving.ArmorStandController;
|
||||
import net.citizensnpcs.npc.entity.nonliving.ArrowController;
|
||||
import net.citizensnpcs.npc.entity.nonliving.BoatController;
|
||||
import net.citizensnpcs.npc.entity.nonliving.EggController;
|
||||
@ -89,6 +93,7 @@ public class EntityControllers {
|
||||
|
||||
static {
|
||||
TYPES.put(EntityType.ARROW, ArrowController.class);
|
||||
TYPES.put(EntityType.ARMOR_STAND, ArmorStandController.class);
|
||||
TYPES.put(EntityType.BAT, BatController.class);
|
||||
TYPES.put(EntityType.BLAZE, BlazeController.class);
|
||||
TYPES.put(EntityType.BOAT, BoatController.class);
|
||||
@ -103,12 +108,14 @@ public class EntityControllers {
|
||||
TYPES.put(EntityType.ENDER_PEARL, EnderPearlController.class);
|
||||
TYPES.put(EntityType.ENDER_SIGNAL, EnderSignalController.class);
|
||||
TYPES.put(EntityType.ENDERMAN, EndermanController.class);
|
||||
TYPES.put(EntityType.ENDERMITE, EndermiteController.class);
|
||||
TYPES.put(EntityType.FALLING_BLOCK, FallingBlockController.class);
|
||||
TYPES.put(EntityType.FIREWORK, FireworkController.class);
|
||||
TYPES.put(EntityType.FIREBALL, LargeFireballController.class);
|
||||
TYPES.put(EntityType.FISHING_HOOK, FishingHookController.class);
|
||||
TYPES.put(EntityType.GHAST, GhastController.class);
|
||||
TYPES.put(EntityType.GIANT, GiantController.class);
|
||||
TYPES.put(EntityType.GUARDIAN, GuardianController.class);
|
||||
TYPES.put(EntityType.HORSE, HorseController.class);
|
||||
TYPES.put(EntityType.IRON_GOLEM, IronGolemController.class);
|
||||
TYPES.put(EntityType.ITEM_FRAME, ItemFrameController.class);
|
||||
@ -126,6 +133,7 @@ public class EntityControllers {
|
||||
TYPES.put(EntityType.PIG, PigController.class);
|
||||
TYPES.put(EntityType.PIG_ZOMBIE, PigZombieController.class);
|
||||
TYPES.put(EntityType.PLAYER, HumanController.class);
|
||||
TYPES.put(EntityType.RABBIT, RabbitController.class);
|
||||
TYPES.put(EntityType.SHEEP, SheepController.class);
|
||||
TYPES.put(EntityType.SILVERFISH, SilverfishController.class);
|
||||
TYPES.put(EntityType.SKELETON, SkeletonController.class);
|
||||
|
@ -45,7 +45,6 @@ public class EndermanController extends MobEntityController {
|
||||
}
|
||||
|
||||
public static class EntityEndermanNPC extends EntityEnderman implements NPCHolder {
|
||||
private int jumpTicks;
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public EntityEndermanNPC(World world) {
|
||||
|
@ -0,0 +1,185 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.MobEntityController;
|
||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.minecraft.server.v1_8_R1.Block;
|
||||
import net.minecraft.server.v1_8_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_8_R1.EntityEndermite;
|
||||
import net.minecraft.server.v1_8_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_8_R1.World;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftEndermite;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity;
|
||||
import org.bukkit.entity.Endermite;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class EndermiteController extends MobEntityController {
|
||||
public EndermiteController() {
|
||||
super(EntityEndermiteNPC.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Endermite getBukkitEntity() {
|
||||
return (Endermite) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
public static class EndermiteNPC extends CraftEndermite implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public EndermiteNPC(EntityEndermiteNPC entity) {
|
||||
super((CraftServer) Bukkit.getServer(), entity);
|
||||
this.npc = entity.npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return npc;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EntityEndermiteNPC extends EntityEndermite implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public EntityEndermiteNPC(World world) {
|
||||
this(world, null);
|
||||
}
|
||||
|
||||
public EntityEndermiteNPC(World world, NPC npc) {
|
||||
super(world);
|
||||
this.npc = (CitizensNPC) npc;
|
||||
if (npc != null) {
|
||||
NMS.clearGoals(goalSelector, targetSelector);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
super.a(d0, flag, block, blockposition);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String bn() {
|
||||
return npc == null ? super.bn() : npc.data().get(NPC.HURT_SOUND_METADATA, super.bn());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String bo() {
|
||||
return npc == null ? super.bo() : npc.data().get(NPC.DEATH_SOUND_METADATA, super.bo());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cb() {
|
||||
if (npc == null)
|
||||
return super.cb();
|
||||
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||
return super.cb();
|
||||
if (super.cb()) {
|
||||
unleash(true, false); // clearLeash with client update
|
||||
}
|
||||
return false; // shouldLeash
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collide(net.minecraft.server.v1_8_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
|
||||
protected void D() {
|
||||
if (npc == null) {
|
||||
super.D();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doTick() {
|
||||
super.doTick();
|
||||
if (npc != null)
|
||||
npc.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void e(float f, float f1) {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
super.e(f, f1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void g(double x, double y, double z) {
|
||||
if (npc == null) {
|
||||
super.g(x, y, z);
|
||||
return;
|
||||
}
|
||||
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||
super.g(x, y, z);
|
||||
return;
|
||||
}
|
||||
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());
|
||||
}
|
||||
// when another entity collides, this method is called to push the
|
||||
// NPC so we prevent it from doing anything if the event is
|
||||
// cancelled.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void g(float f, float f1) {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
super.g(f, f1);
|
||||
} else {
|
||||
NMS.flyingMoveLogic(this, f, f1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftEntity getBukkitEntity() {
|
||||
if (bukkitEntity == null && npc != null)
|
||||
bukkitEntity = new EndermiteNPC(this);
|
||||
return super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean j_() {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
return super.j_();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String z() {
|
||||
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get(
|
||||
NPC.AMBIENT_SOUND_METADATA, super.z());
|
||||
}
|
||||
}
|
||||
}
|
@ -64,10 +64,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
||||
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
|
||||
PlayerInteractManager playerInteractManager, NPC npc) {
|
||||
super(minecraftServer, world, gameProfile, playerInteractManager);
|
||||
playerInteractManager.setGameMode(EnumGamemode.SURVIVAL);
|
||||
|
||||
this.npc = (CitizensNPC) npc;
|
||||
if (npc != null) {
|
||||
playerInteractManager.setGameMode(EnumGamemode.SURVIVAL);
|
||||
initialise(minecraftServer);
|
||||
}
|
||||
}
|
||||
@ -103,8 +103,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
||||
return;
|
||||
}
|
||||
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) {
|
||||
super.g(x, y, z);
|
||||
}
|
||||
return;
|
||||
}
|
||||
Vector vector = new Vector(x, y, z);
|
||||
@ -129,8 +130,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
||||
|
||||
@Override
|
||||
public CraftPlayer getBukkitEntity() {
|
||||
if (npc != null && bukkitEntity == null)
|
||||
if (npc != null && bukkitEntity == null) {
|
||||
bukkitEntity = new PlayerNPC(this);
|
||||
}
|
||||
return super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@ -176,15 +178,8 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
||||
conn = new EmptyNetworkManager(EnumProtocolDirection.CLIENTBOUND);
|
||||
playerConnection = new EmptyNetHandler(minecraftServer, conn, this);
|
||||
conn.a(playerConnection);
|
||||
} catch (IOException e) {
|
||||
// swallow
|
||||
}
|
||||
|
||||
NMS.setStepHeight(this, 1); // the default (0) breaks step climbing
|
||||
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException ex) {
|
||||
} catch (IOException e) {
|
||||
// swallow
|
||||
}
|
||||
|
||||
@ -193,10 +188,12 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
||||
range = this.getAttributeMap().b(GenericAttributes.b);
|
||||
}
|
||||
range.setValue(Setting.DEFAULT_PATHFINDING_RANGE.asDouble());
|
||||
|
||||
controllerJump = new PlayerControllerJump(this);
|
||||
controllerLook = new PlayerControllerLook(this);
|
||||
controllerMove = new PlayerControllerMove(this);
|
||||
navigation = new PlayerNavigation(this, world);
|
||||
NMS.setStepHeight(this, 1); // the default (0) breaks step climbing
|
||||
}
|
||||
|
||||
public boolean isNavigating() {
|
||||
@ -246,15 +243,17 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
||||
// (onGround is normally updated by the client)
|
||||
}
|
||||
|
||||
if (Math.abs(motX) < EPSILON && Math.abs(motY) < EPSILON && Math.abs(motZ) < EPSILON)
|
||||
if (Math.abs(motX) < EPSILON && Math.abs(motY) < EPSILON && Math.abs(motZ) < EPSILON) {
|
||||
motX = motY = motZ = 0;
|
||||
}
|
||||
if (navigating) {
|
||||
if (!NMS.isNavigationFinished(navigation)) {
|
||||
NMS.updateNavigation(navigation);
|
||||
}
|
||||
moveOnCurrentHeading();
|
||||
} else if (motX != 0 || motZ != 0 || motY != 0) {
|
||||
e(0, 0); // is this necessary? it does controllable but sometimes
|
||||
g(0, 0); // is this necessary? it does controllable but
|
||||
// sometimes
|
||||
// players sink into the ground
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,199 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.MobEntityController;
|
||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.minecraft.server.v1_8_R1.Block;
|
||||
import net.minecraft.server.v1_8_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_8_R1.EntityGuardian;
|
||||
import net.minecraft.server.v1_8_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_8_R1.World;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftGuardian;
|
||||
import org.bukkit.entity.Guardian;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class GuardianController extends MobEntityController {
|
||||
public GuardianController() {
|
||||
super(EntityGuardianNPC.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Guardian getBukkitEntity() {
|
||||
return (Guardian) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
public static class EntityGuardianNPC extends EntityGuardian implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public EntityGuardianNPC(World world) {
|
||||
this(world, null);
|
||||
}
|
||||
|
||||
public EntityGuardianNPC(World world, NPC npc) {
|
||||
super(world);
|
||||
this.npc = (CitizensNPC) npc;
|
||||
if (npc != null) {
|
||||
NMS.clearGoals(goalSelector, targetSelector);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void a(boolean flag) {
|
||||
float oldw = width;
|
||||
float oldl = length;
|
||||
super.a(flag);
|
||||
if (oldw != width || oldl != length) {
|
||||
this.setPosition(locX - 0.01, locY, locZ - 0.01);
|
||||
this.setPosition(locX + 0.01, locY, locZ + 0.01);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
super.a(d0, flag, block, blockposition);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String bn() {
|
||||
return npc == null ? super.bn() : npc.data().get(NPC.HURT_SOUND_METADATA, super.bn());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String bo() {
|
||||
return npc == null ? super.bo() : npc.data().get(NPC.DEATH_SOUND_METADATA, super.bo());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cb() {
|
||||
if (npc == null)
|
||||
return super.cb();
|
||||
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||
return super.cb();
|
||||
if (super.cb()) {
|
||||
unleash(true, false); // clearLeash with client update
|
||||
}
|
||||
return false; // shouldLeash
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collide(net.minecraft.server.v1_8_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
|
||||
protected void D() {
|
||||
if (npc == null) {
|
||||
super.D();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doTick() {
|
||||
super.doTick();
|
||||
if (npc != null) {
|
||||
npc.update();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void e(float f, float f1) {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
super.e(f, f1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void g(double x, double y, double z) {
|
||||
if (npc == null) {
|
||||
super.g(x, y, z);
|
||||
return;
|
||||
}
|
||||
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||
super.g(x, y, z);
|
||||
return;
|
||||
}
|
||||
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());
|
||||
}
|
||||
// when another entity collides, this method is called to push the
|
||||
// NPC so we prevent it from doing anything if the event is
|
||||
// cancelled.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void g(float f, float f1) {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
super.g(f, f1);
|
||||
} else {
|
||||
NMS.flyingMoveLogic(this, f, f1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftEntity getBukkitEntity() {
|
||||
if (bukkitEntity == null && npc != null)
|
||||
bukkitEntity = new GuardianNPC(this);
|
||||
return super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean j_() {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
return super.j_();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String z() {
|
||||
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get(
|
||||
NPC.AMBIENT_SOUND_METADATA, super.z());
|
||||
}
|
||||
}
|
||||
|
||||
public static class GuardianNPC extends CraftGuardian implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public GuardianNPC(EntityGuardianNPC entity) {
|
||||
super((CraftServer) Bukkit.getServer(), entity);
|
||||
this.npc = entity.npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return npc;
|
||||
}
|
||||
}
|
||||
}
|
199
src/main/java/net/citizensnpcs/npc/entity/RabbitController.java
Normal file
199
src/main/java/net/citizensnpcs/npc/entity/RabbitController.java
Normal file
@ -0,0 +1,199 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.MobEntityController;
|
||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.minecraft.server.v1_8_R1.Block;
|
||||
import net.minecraft.server.v1_8_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_8_R1.EntityRabbit;
|
||||
import net.minecraft.server.v1_8_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_8_R1.World;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftRabbit;
|
||||
import org.bukkit.entity.Rabbit;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class RabbitController extends MobEntityController {
|
||||
public RabbitController() {
|
||||
super(EntityRabbitNPC.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rabbit getBukkitEntity() {
|
||||
return (Rabbit) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
public static class EntityRabbitNPC extends EntityRabbit implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public EntityRabbitNPC(World world) {
|
||||
this(world, null);
|
||||
}
|
||||
|
||||
public EntityRabbitNPC(World world, NPC npc) {
|
||||
super(world);
|
||||
this.npc = (CitizensNPC) npc;
|
||||
if (npc != null) {
|
||||
NMS.clearGoals(goalSelector, targetSelector);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void a(boolean flag) {
|
||||
float oldw = width;
|
||||
float oldl = length;
|
||||
super.a(flag);
|
||||
if (oldw != width || oldl != length) {
|
||||
this.setPosition(locX - 0.01, locY, locZ - 0.01);
|
||||
this.setPosition(locX + 0.01, locY, locZ + 0.01);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
super.a(d0, flag, block, blockposition);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String bn() {
|
||||
return npc == null ? super.bn() : npc.data().get(NPC.HURT_SOUND_METADATA, super.bn());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String bo() {
|
||||
return npc == null ? super.bo() : npc.data().get(NPC.DEATH_SOUND_METADATA, super.bo());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cb() {
|
||||
if (npc == null)
|
||||
return super.cb();
|
||||
boolean protectedDefault = npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||
if (!protectedDefault || !npc.data().get(NPC.LEASH_PROTECTED_METADATA, protectedDefault))
|
||||
return super.cb();
|
||||
if (super.cb()) {
|
||||
unleash(true, false); // clearLeash with client update
|
||||
}
|
||||
return false; // shouldLeash
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collide(net.minecraft.server.v1_8_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
|
||||
protected void D() {
|
||||
if (npc == null) {
|
||||
super.D();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doTick() {
|
||||
super.doTick();
|
||||
if (npc != null) {
|
||||
npc.update();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void e(float f, float f1) {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
super.e(f, f1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void g(double x, double y, double z) {
|
||||
if (npc == null) {
|
||||
super.g(x, y, z);
|
||||
return;
|
||||
}
|
||||
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||
super.g(x, y, z);
|
||||
return;
|
||||
}
|
||||
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());
|
||||
}
|
||||
// when another entity collides, this method is called to push the
|
||||
// NPC so we prevent it from doing anything if the event is
|
||||
// cancelled.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void g(float f, float f1) {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
super.g(f, f1);
|
||||
} else {
|
||||
NMS.flyingMoveLogic(this, f, f1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftEntity getBukkitEntity() {
|
||||
if (bukkitEntity == null && npc != null)
|
||||
bukkitEntity = new RabbitNPC(this);
|
||||
return super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean j_() {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
return super.j_();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String z() {
|
||||
return npc == null || !npc.data().has(NPC.AMBIENT_SOUND_METADATA) ? super.z() : npc.data().get(
|
||||
NPC.AMBIENT_SOUND_METADATA, super.z());
|
||||
}
|
||||
}
|
||||
|
||||
public static class RabbitNPC extends CraftRabbit implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public RabbitNPC(EntityRabbitNPC entity) {
|
||||
super((CraftServer) Bukkit.getServer(), entity);
|
||||
this.npc = entity.npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return npc;
|
||||
}
|
||||
}
|
||||
}
|
@ -29,7 +29,6 @@ public class WitherController extends MobEntityController {
|
||||
}
|
||||
|
||||
public static class EntityWitherNPC extends EntityWither implements NPCHolder {
|
||||
private int jumpTicks;
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public EntityWitherNPC(World world) {
|
||||
|
@ -0,0 +1,121 @@
|
||||
package net.citizensnpcs.npc.entity.nonliving;
|
||||
|
||||
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.MobEntityController;
|
||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.util.Util;
|
||||
import net.minecraft.server.v1_8_R1.EntityArmorStand;
|
||||
import net.minecraft.server.v1_8_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_8_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_8_R1.Vec3D;
|
||||
import net.minecraft.server.v1_8_R1.World;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftArmorStand;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class ArmorStandController extends MobEntityController {
|
||||
public ArmorStandController() {
|
||||
super(EntityArmorStandNPC.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArmorStand getBukkitEntity() {
|
||||
return (ArmorStand) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
public static class ArmorStandNPC extends CraftArmorStand implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public ArmorStandNPC(EntityArmorStandNPC entity) {
|
||||
super((CraftServer) Bukkit.getServer(), entity);
|
||||
this.npc = entity.npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return npc;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EntityArmorStandNPC extends EntityArmorStand implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public EntityArmorStandNPC(World world) {
|
||||
this(world, null);
|
||||
}
|
||||
|
||||
public EntityArmorStandNPC(World world, NPC npc) {
|
||||
super(world);
|
||||
this.npc = (CitizensNPC) npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean a(EntityHuman paramEntityHuman, Vec3D paramVec3D) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collide(net.minecraft.server.v1_8_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 void g(double x, double y, double z) {
|
||||
if (npc == null) {
|
||||
super.g(x, y, z);
|
||||
return;
|
||||
}
|
||||
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
|
||||
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
|
||||
super.g(x, y, z);
|
||||
return;
|
||||
}
|
||||
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());
|
||||
}
|
||||
// when another entity collides, this method is called to push the
|
||||
// NPC so we prevent it from doing anything if the event is
|
||||
// cancelled.
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftEntity getBukkitEntity() {
|
||||
if (bukkitEntity == null && npc != null) {
|
||||
bukkitEntity = new ArmorStandNPC(this);
|
||||
}
|
||||
return super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void s_() {
|
||||
super.s_();
|
||||
if (npc != null) {
|
||||
npc.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -39,11 +39,6 @@ public class FishingHookController extends MobEntityController {
|
||||
this.npc = (CitizensNPC) npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean d(NBTTagCompound save) {
|
||||
return npc == null ? super.d(save) : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collide(net.minecraft.server.v1_8_R1.Entity entity) {
|
||||
// this method is called by both the entities involved - cancelling
|
||||
@ -54,6 +49,11 @@ public class FishingHookController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean d(NBTTagCompound save) {
|
||||
return npc == null ? super.d(save) : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void g(double x, double y, double z) {
|
||||
if (npc == null) {
|
||||
|
Loading…
Reference in New Issue
Block a user