use of net.citizensnpcs.npc.ai.NPCHolder in project Citizens2 by CitizensDev.
the class MountTrait method run.
@Override
public void run() {
if (!npc.isSpawned())
return;
if (!triggered && uuid != null) {
try {
mountedOn = UUID.fromString(uuid);
} catch (IllegalArgumentException e) {
mountedOn = null;
}
checkMount(null);
}
Entity e = NMS.getVehicle(npc.getEntity());
if (e == null && !triggered) {
mountedOn = null;
} else if (e instanceof NPCHolder) {
mountedOn = ((NPCHolder) e).getNPC().getUniqueId();
uuid = mountedOn.toString();
}
checkMount(e);
}
use of net.citizensnpcs.npc.ai.NPCHolder in project Citizens2 by CitizensDev.
the class CitizensBlockBreaker method run.
@Override
public BehaviorStatus run() {
if (entity.dead) {
return BehaviorStatus.FAILURE;
}
if (!isDigging) {
return BehaviorStatus.SUCCESS;
}
// CraftBukkit
currentTick = (int) (System.currentTimeMillis() / 50);
if (configuration.radiusSquared() > 0 && distanceSquared() >= configuration.radiusSquared()) {
startDigTick = currentTick;
if (entity instanceof NPCHolder) {
NPC npc = ((NPCHolder) entity).getNPC();
if (npc != null && !npc.getNavigator().isNavigating()) {
npc.getNavigator().setTarget(entity.world.getWorld().getBlockAt(x, y, z).getLocation().add(0, 1, 0));
}
}
return BehaviorStatus.RUNNING;
}
Util.faceLocation(entity.getBukkitEntity(), location);
if (entity instanceof EntityPlayer) {
PlayerAnimation.ARM_SWING.play((Player) entity.getBukkitEntity());
}
IBlockData block = entity.world.getType(new BlockPosition(x, y, z));
if (block == null || block == Blocks.AIR) {
return BehaviorStatus.SUCCESS;
} else {
int tickDifference = currentTick - startDigTick;
float damage = getStrength(block) * (tickDifference + 1) * configuration.blockStrengthModifier();
if (damage >= 1F) {
entity.world.getWorld().getBlockAt(x, y, z).breakNaturally(CraftItemStack.asCraftMirror(getCurrentItem()));
return BehaviorStatus.SUCCESS;
}
int modifiedDamage = (int) (damage * 10.0F);
if (modifiedDamage != currentDamage) {
setBlockDamage(modifiedDamage);
currentDamage = modifiedDamage;
}
}
return BehaviorStatus.RUNNING;
}
use of net.citizensnpcs.npc.ai.NPCHolder in project Citizens2 by CitizensDev.
the class NMSImpl method tick.
@Override
public boolean tick(org.bukkit.entity.Entity next) {
Entity entity = NMSImpl.getHandle(next);
Entity entity1 = entity.bB();
if (entity1 != null) {
if ((entity1.dead) || (!entity1.w(entity))) {
entity.stopRiding();
}
} else {
if (!entity.dead) {
try {
entity.world.g(entity);
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Ticking player");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Player being ticked");
entity.appendEntityCrashDetails(crashreportsystemdetails);
throw new ReportedException(crashreport);
}
}
boolean removeFromPlayerList = ((NPCHolder) entity).getNPC().data().get("removefromplayerlist", Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
if (entity.dead) {
entity.world.removeEntity(entity);
return true;
} else if (!removeFromPlayerList) {
if (!entity.world.players.contains(entity)) {
entity.world.players.add((EntityHuman) entity);
}
return true;
} else {
entity.world.players.remove(entity);
}
}
return false;
}
use of net.citizensnpcs.npc.ai.NPCHolder in project Citizens2 by CitizensDev.
the class NMSImpl method minecartItemLogic.
@SuppressWarnings("deprecation")
public static void minecartItemLogic(EntityMinecartAbstract minecart) {
NPC npc = ((NPCHolder) minecart).getNPC();
if (npc == null)
return;
Material mat = Material.getMaterial(npc.data().get(NPC.MINECART_ITEM_METADATA, ""));
int data = npc.data().get(NPC.MINECART_ITEM_DATA_METADATA, 0);
int offset = npc.data().get(NPC.MINECART_OFFSET_METADATA, 0);
minecart.a(mat != null);
if (mat != null) {
minecart.setDisplayBlock(Block.getById(mat.getId()).fromLegacyData(data));
}
minecart.setDisplayBlockOffset(offset);
}
use of net.citizensnpcs.npc.ai.NPCHolder in project Citizens2 by CitizensDev.
the class NMSImpl method minecartItemLogic.
@SuppressWarnings("deprecation")
public static void minecartItemLogic(EntityMinecartAbstract minecart) {
NPC npc = ((NPCHolder) minecart).getNPC();
if (npc == null)
return;
Material mat = Material.getMaterial(npc.data().get(NPC.MINECART_ITEM_METADATA, ""));
int data = npc.data().get(NPC.MINECART_ITEM_DATA_METADATA, 0);
int offset = npc.data().get(NPC.MINECART_OFFSET_METADATA, 0);
minecart.a(mat != null);
if (mat != null) {
minecart.setDisplayBlock(Block.getById(mat.getId()).fromLegacyData(data));
}
minecart.SetDisplayBlockOffset(offset);
}
Aggregations