Search in sources :

Example 1 with NPCHolder

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);
}
Also used : Entity(org.bukkit.entity.Entity) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder)

Example 2 with NPCHolder

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;
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) IBlockData(net.minecraft.server.v1_10_R1.IBlockData) BlockPosition(net.minecraft.server.v1_10_R1.BlockPosition) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) EntityPlayer(net.minecraft.server.v1_10_R1.EntityPlayer)

Example 3 with NPCHolder

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;
}
Also used : PathEntity(net.minecraft.server.v1_10_R1.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) CraftEntity(org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity) Entity(net.minecraft.server.v1_10_R1.Entity) EntityHuman(net.minecraft.server.v1_10_R1.EntityHuman) CrashReportSystemDetails(net.minecraft.server.v1_10_R1.CrashReportSystemDetails) CrashReport(net.minecraft.server.v1_10_R1.CrashReport) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) ReportedException(net.minecraft.server.v1_10_R1.ReportedException)

Example 4 with NPCHolder

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);
}
Also used : EntityHumanNPC(net.citizensnpcs.nms.v1_10_R1.entity.EntityHumanNPC) NPC(net.citizensnpcs.api.npc.NPC) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) Material(org.bukkit.Material) PathPoint(net.minecraft.server.v1_10_R1.PathPoint)

Example 5 with NPCHolder

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);
}
Also used : EntityHumanNPC(net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC) NPC(net.citizensnpcs.api.npc.NPC) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) Material(org.bukkit.Material) PathPoint(net.minecraft.server.v1_8_R3.PathPoint)

Aggregations

NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)21 NPC (net.citizensnpcs.api.npc.NPC)12 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)8 LivingEntity (org.bukkit.entity.LivingEntity)8 CancelReason (net.citizensnpcs.api.ai.event.CancelReason)4 MCNavigator (net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator)4 ArmorStandTrait (net.citizensnpcs.trait.ArmorStandTrait)4 Material (org.bukkit.Material)4 EntityPlayer (net.minecraft.server.v1_11_R1.EntityPlayer)3 EntityPlayer (net.minecraft.server.v1_12_R1.EntityPlayer)3 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 Vector (org.bukkit.util.Vector)3 BlockPosition (net.minecraft.server.v1_10_R1.BlockPosition)2 Entity (net.minecraft.server.v1_10_R1.Entity)2 EntityPlayer (net.minecraft.server.v1_10_R1.EntityPlayer)2 PathEntity (net.minecraft.server.v1_10_R1.PathEntity)2 BlockPosition (net.minecraft.server.v1_11_R1.BlockPosition)2 Entity (net.minecraft.server.v1_11_R1.Entity)2 PathEntity (net.minecraft.server.v1_11_R1.PathEntity)2