mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-04 22:41:25 +01:00
Add new entity types
This commit is contained in:
parent
3d73e68e81
commit
60a99643cc
@ -29,6 +29,7 @@ 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.ShulkerController;
|
||||
import net.citizensnpcs.npc.entity.SilverfishController;
|
||||
import net.citizensnpcs.npc.entity.SkeletonController;
|
||||
import net.citizensnpcs.npc.entity.SlimeController;
|
||||
@ -40,8 +41,10 @@ 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.AreaEffectCloudController;
|
||||
import net.citizensnpcs.npc.entity.nonliving.ArmorStandController;
|
||||
import net.citizensnpcs.npc.entity.nonliving.BoatController;
|
||||
import net.citizensnpcs.npc.entity.nonliving.DragonFireballController;
|
||||
import net.citizensnpcs.npc.entity.nonliving.EggController;
|
||||
import net.citizensnpcs.npc.entity.nonliving.EnderCrystalController;
|
||||
import net.citizensnpcs.npc.entity.nonliving.EnderPearlController;
|
||||
@ -60,8 +63,10 @@ import net.citizensnpcs.npc.entity.nonliving.MinecartHopperController;
|
||||
import net.citizensnpcs.npc.entity.nonliving.MinecartRideableController;
|
||||
import net.citizensnpcs.npc.entity.nonliving.MinecartTNTController;
|
||||
import net.citizensnpcs.npc.entity.nonliving.PaintingController;
|
||||
import net.citizensnpcs.npc.entity.nonliving.ShulkerBulletController;
|
||||
import net.citizensnpcs.npc.entity.nonliving.SmallFireballController;
|
||||
import net.citizensnpcs.npc.entity.nonliving.SnowballController;
|
||||
import net.citizensnpcs.npc.entity.nonliving.SpectralArrowController;
|
||||
import net.citizensnpcs.npc.entity.nonliving.TNTPrimedController;
|
||||
import net.citizensnpcs.npc.entity.nonliving.ThrownExpBottleController;
|
||||
import net.citizensnpcs.npc.entity.nonliving.ThrownPotionController;
|
||||
@ -92,6 +97,7 @@ public class EntityControllers {
|
||||
private static final Map<EntityType, Class<? extends EntityController>> TYPES = Maps.newEnumMap(EntityType.class);
|
||||
|
||||
static {
|
||||
TYPES.put(EntityType.AREA_EFFECT_CLOUD, AreaEffectCloudController.class);
|
||||
TYPES.put(EntityType.ARROW, TippedArrowController.class);
|
||||
TYPES.put(EntityType.ARMOR_STAND, ArmorStandController.class);
|
||||
TYPES.put(EntityType.BAT, BatController.class);
|
||||
@ -101,6 +107,7 @@ public class EntityControllers {
|
||||
TYPES.put(EntityType.CHICKEN, ChickenController.class);
|
||||
TYPES.put(EntityType.COW, CowController.class);
|
||||
TYPES.put(EntityType.CREEPER, CreeperController.class);
|
||||
TYPES.put(EntityType.DRAGON_FIREBALL, DragonFireballController.class);
|
||||
TYPES.put(EntityType.DROPPED_ITEM, ItemController.class);
|
||||
TYPES.put(EntityType.EGG, EggController.class);
|
||||
TYPES.put(EntityType.ENDER_CRYSTAL, EnderCrystalController.class);
|
||||
@ -135,15 +142,19 @@ public class EntityControllers {
|
||||
TYPES.put(EntityType.PLAYER, HumanController.class);
|
||||
TYPES.put(EntityType.RABBIT, RabbitController.class);
|
||||
TYPES.put(EntityType.SHEEP, SheepController.class);
|
||||
TYPES.put(EntityType.SHULKER, ShulkerController.class);
|
||||
TYPES.put(EntityType.SHULKER_BULLET, ShulkerBulletController.class);
|
||||
TYPES.put(EntityType.SILVERFISH, SilverfishController.class);
|
||||
TYPES.put(EntityType.SKELETON, SkeletonController.class);
|
||||
TYPES.put(EntityType.SLIME, SlimeController.class);
|
||||
TYPES.put(EntityType.SMALL_FIREBALL, SmallFireballController.class);
|
||||
TYPES.put(EntityType.SNOWBALL, SnowballController.class);
|
||||
TYPES.put(EntityType.SNOWMAN, SnowmanController.class);
|
||||
TYPES.put(EntityType.SPECTRAL_ARROW, SpectralArrowController.class);
|
||||
TYPES.put(EntityType.SPIDER, SpiderController.class);
|
||||
TYPES.put(EntityType.SPLASH_POTION, ThrownPotionController.class);
|
||||
TYPES.put(EntityType.SQUID, SquidController.class);
|
||||
TYPES.put(EntityType.TIPPED_ARROW, TippedArrowController.class);
|
||||
TYPES.put(EntityType.THROWN_EXP_BOTTLE, ThrownExpBottleController.class);
|
||||
TYPES.put(EntityType.PRIMED_TNT, TNTPrimedController.class);
|
||||
TYPES.put(EntityType.VILLAGER, VillagerController.class);
|
||||
|
215
src/main/java/net/citizensnpcs/npc/entity/ShulkerController.java
Normal file
215
src/main/java/net/citizensnpcs/npc/entity/ShulkerController.java
Normal file
@ -0,0 +1,215 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftShulker;
|
||||
import org.bukkit.entity.Shulker;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import net.citizensnpcs.api.event.NPCEnderTeleportEvent;
|
||||
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_9_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_9_R1.EntityShulker;
|
||||
import net.minecraft.server.v1_9_R1.IBlockData;
|
||||
import net.minecraft.server.v1_9_R1.MinecraftKey;
|
||||
import net.minecraft.server.v1_9_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_9_R1.SoundEffect;
|
||||
import net.minecraft.server.v1_9_R1.World;
|
||||
|
||||
public class ShulkerController extends MobEntityController {
|
||||
public ShulkerController() {
|
||||
super(EntityShulkerNPC.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Shulker getBukkitEntity() {
|
||||
return (Shulker) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
public static class EntityShulkerNPC extends EntityShulker implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public EntityShulkerNPC(World world) {
|
||||
this(world, null);
|
||||
}
|
||||
|
||||
public EntityShulkerNPC(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, IBlockData block, BlockPosition blockposition) {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
super.a(d0, flag, block, blockposition);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SoundEffect bR() {
|
||||
return npc == null || !npc.data().has(NPC.HURT_SOUND_METADATA) ? super.bR()
|
||||
: SoundEffect.a.get(new MinecraftKey(
|
||||
npc.data().get(NPC.HURT_SOUND_METADATA, SoundEffect.a.b(super.bR()).toString())));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SoundEffect bS() {
|
||||
return npc == null || !npc.data().has(NPC.DEATH_SOUND_METADATA) ? super.bS()
|
||||
: SoundEffect.a.get(new MinecraftKey(
|
||||
npc.data().get(NPC.DEATH_SOUND_METADATA, SoundEffect.a.b(super.bR()).toString())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collide(net.minecraft.server.v1_9_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 e(float f, float f1) {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
super.e(f, f1);
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
@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
|
||||
protected SoundEffect G() {
|
||||
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())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftEntity getBukkitEntity() {
|
||||
if (bukkitEntity == null && npc != null)
|
||||
bukkitEntity = new ShulkerNPC(this);
|
||||
return super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return npc;
|
||||
}
|
||||
|
||||
@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
|
||||
protected void L() {
|
||||
if (npc == null) {
|
||||
super.L();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void m() {
|
||||
if (npc != null) {
|
||||
npc.update();
|
||||
} else {
|
||||
super.m();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean n_() {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
return super.n_();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSize(float f, float f1) {
|
||||
if (npc == null) {
|
||||
super.setSize(f, f1);
|
||||
} else {
|
||||
NMS.setSize(this, f, f1, justCreated);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ShulkerNPC extends CraftShulker implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public ShulkerNPC(EntityShulkerNPC entity) {
|
||||
super((CraftServer) Bukkit.getServer(), entity);
|
||||
this.npc = entity.npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return npc;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
package net.citizensnpcs.npc.entity.nonliving;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftAreaEffectCloud;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftEntity;
|
||||
import org.bukkit.entity.AreaEffectCloud;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
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_9_R1.EntityAreaEffectCloud;
|
||||
import net.minecraft.server.v1_9_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_9_R1.World;
|
||||
|
||||
public class AreaEffectCloudController extends MobEntityController {
|
||||
public AreaEffectCloudController() {
|
||||
super(EntityAreaEffectCloudNPC.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AreaEffectCloud getBukkitEntity() {
|
||||
return (AreaEffectCloud) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
public static class AreaEffectCloudNPC extends CraftAreaEffectCloud implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public AreaEffectCloudNPC(EntityAreaEffectCloudNPC entity) {
|
||||
super((CraftServer) Bukkit.getServer(), entity);
|
||||
this.npc = entity.npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return npc;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EntityAreaEffectCloudNPC extends EntityAreaEffectCloud implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public EntityAreaEffectCloudNPC(World world) {
|
||||
this(world, null);
|
||||
}
|
||||
|
||||
public EntityAreaEffectCloudNPC(World world, NPC npc) {
|
||||
super(world);
|
||||
this.npc = (CitizensNPC) npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collide(net.minecraft.server.v1_9_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 AreaEffectCloudNPC(this);
|
||||
}
|
||||
return super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void m() {
|
||||
if (npc != null) {
|
||||
npc.update();
|
||||
} else {
|
||||
super.m();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
package net.citizensnpcs.npc.entity.nonliving;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftDragonFireball;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftEntity;
|
||||
import org.bukkit.entity.DragonFireball;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
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_9_R1.EntityDragonFireball;
|
||||
import net.minecraft.server.v1_9_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_9_R1.World;
|
||||
|
||||
public class DragonFireballController extends MobEntityController {
|
||||
public DragonFireballController() {
|
||||
super(EntityDragonFireballNPC.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DragonFireball getBukkitEntity() {
|
||||
return (DragonFireball) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
public static class DragonFireballNPC extends CraftDragonFireball implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public DragonFireballNPC(EntityDragonFireballNPC entity) {
|
||||
super((CraftServer) Bukkit.getServer(), entity);
|
||||
this.npc = entity.npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return npc;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EntityDragonFireballNPC extends EntityDragonFireball implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public EntityDragonFireballNPC(World world) {
|
||||
this(world, null);
|
||||
}
|
||||
|
||||
public EntityDragonFireballNPC(World world, NPC npc) {
|
||||
super(world);
|
||||
this.npc = (CitizensNPC) npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collide(net.minecraft.server.v1_9_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 DragonFireballNPC(this);
|
||||
}
|
||||
return super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void m() {
|
||||
if (npc != null) {
|
||||
npc.update();
|
||||
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)) {
|
||||
super.m();
|
||||
}
|
||||
} else {
|
||||
super.m();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSize(float f, float f1) {
|
||||
if (npc == null) {
|
||||
super.setSize(f, f1);
|
||||
} else {
|
||||
NMS.setSize(this, f, f1, justCreated);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
package net.citizensnpcs.npc.entity.nonliving;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftShulkerBullet;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
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_9_R1.EntityShulkerBullet;
|
||||
import net.minecraft.server.v1_9_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_9_R1.World;
|
||||
|
||||
public class ShulkerBulletController extends MobEntityController {
|
||||
public ShulkerBulletController() {
|
||||
super(EntityShulkerBulletNPC.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Arrow getBukkitEntity() {
|
||||
return (Arrow) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
public static class EntityShulkerBulletNPC extends EntityShulkerBullet implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public EntityShulkerBulletNPC(World world) {
|
||||
this(world, null);
|
||||
}
|
||||
|
||||
public EntityShulkerBulletNPC(World world, NPC npc) {
|
||||
super(world);
|
||||
this.npc = (CitizensNPC) npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collide(net.minecraft.server.v1_9_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 ShulkerBulletNPC(this);
|
||||
}
|
||||
return super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void m() {
|
||||
if (npc != null) {
|
||||
npc.update();
|
||||
} else {
|
||||
super.m();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ShulkerBulletNPC extends CraftShulkerBullet implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public ShulkerBulletNPC(EntityShulkerBulletNPC entity) {
|
||||
super((CraftServer) Bukkit.getServer(), entity);
|
||||
this.npc = entity.npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return npc;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
package net.citizensnpcs.npc.entity.nonliving;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftArrow;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftEntity;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
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_9_R1.EntitySpectralArrow;
|
||||
import net.minecraft.server.v1_9_R1.NBTTagCompound;
|
||||
import net.minecraft.server.v1_9_R1.World;
|
||||
|
||||
public class SpectralArrowController extends MobEntityController {
|
||||
public SpectralArrowController() {
|
||||
super(EntitySpectralArrowNPC.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Arrow getBukkitEntity() {
|
||||
return (Arrow) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
public static class EntitySpectralArrowNPC extends EntitySpectralArrow implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public EntitySpectralArrowNPC(World world) {
|
||||
this(world, null);
|
||||
}
|
||||
|
||||
public EntitySpectralArrowNPC(World world, NPC npc) {
|
||||
super(world);
|
||||
this.npc = (CitizensNPC) npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collide(net.minecraft.server.v1_9_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 SpectralArrowNPC(this);
|
||||
}
|
||||
return super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void m() {
|
||||
if (npc != null) {
|
||||
npc.update();
|
||||
} else {
|
||||
super.m();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class SpectralArrowNPC extends CraftArrow implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public SpectralArrowNPC(EntitySpectralArrowNPC entity) {
|
||||
super((CraftServer) Bukkit.getServer(), entity);
|
||||
this.npc = entity.npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return npc;
|
||||
}
|
||||
}
|
||||
}
|
@ -27,20 +27,6 @@ public class TippedArrowController extends MobEntityController {
|
||||
return (Arrow) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
public static class TippedArrowNPC extends CraftArrow implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public TippedArrowNPC(EntityTippedArrowNPC entity) {
|
||||
super((CraftServer) Bukkit.getServer(), entity);
|
||||
this.npc = entity.npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return npc;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EntityTippedArrowNPC extends EntityTippedArrow implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
@ -112,4 +98,18 @@ public class TippedArrowController extends MobEntityController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class TippedArrowNPC extends CraftArrow implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
public TippedArrowNPC(EntityTippedArrowNPC entity) {
|
||||
super((CraftServer) Bukkit.getServer(), entity);
|
||||
this.npc = entity.npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return npc;
|
||||
}
|
||||
}
|
||||
}
|
@ -22,17 +22,17 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
* <p>
|
||||
* Very fast pseudo random number generator. See
|
||||
* <a href= "http://school.anhb.uwa.edu.au/personalpages/kwessen/shared/Marsaglia03.html" >this page</a> for a
|
||||
* description. This RNG has a period of about 2^160, which is not as long as the MersenneTwisterRNG but it is
|
||||
* description. This RNG has a period of about 2^160, which is not as long as the {@link MersenneTwisterRNG} but it is
|
||||
* faster.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* <em>NOTE: Because instances of this class require 160-bit seeds, it is not
|
||||
* possible to seed this RNG using the {@link #setSeed(long)} method inherited
|
||||
* from {@link Random}. Calls to this method will have no effect.
|
||||
* Instead the seed must be set by a constructor.</em>
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @author Daniel Dyer
|
||||
* @since 1.2
|
||||
*/
|
||||
@ -52,6 +52,9 @@ public class XORShiftRNG extends Random {
|
||||
|
||||
/**
|
||||
* Creates an RNG and seeds it with the specified seed data.
|
||||
*
|
||||
* @param seed
|
||||
* The seed data used to initialise the RNG.
|
||||
*/
|
||||
public XORShiftRNG() {
|
||||
this.seed = new byte[SEED_SIZE_BYTES];
|
||||
@ -102,7 +105,7 @@ public class XORShiftRNG extends Random {
|
||||
/**
|
||||
* Take four bytes from the specified position in the specified block and convert them into a 32-bit int, using the
|
||||
* big-endian convention.
|
||||
*
|
||||
*
|
||||
* @param bytes
|
||||
* The data to read from.
|
||||
* @param offset
|
||||
@ -117,7 +120,7 @@ public class XORShiftRNG extends Random {
|
||||
/**
|
||||
* Convert an array of bytes into an array of ints. 4 bytes from the input data map to a single int in the output
|
||||
* data.
|
||||
*
|
||||
*
|
||||
* @param bytes
|
||||
* The data to read from.
|
||||
* @return An array of 32-bit integers constructed from the data.
|
||||
@ -133,4 +136,4 @@ public class XORShiftRNG extends Random {
|
||||
}
|
||||
return ints;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user