Search in sources :

Example 1 with IRangedAttackMob

use of net.minecraft.entity.IRangedAttackMob in project SpongeCommon by SpongePowered.

the class SpongeRangeAgentAIBuilder method build.

@Override
public RangeAgentAITask build(Ranger owner) {
    checkNotNull(owner);
    checkArgument(owner instanceof IRangedAttackMob, "Ranger must be an IRangedAttackMob!");
    return (RangeAgentAITask) new EntityAIAttackRanged((IRangedAttackMob) owner, this.maxSpeed, this.delayBetweenAttacks, this.attackRadius);
}
Also used : EntityAIAttackRanged(net.minecraft.entity.ai.EntityAIAttackRanged) RangeAgentAITask(org.spongepowered.api.entity.ai.task.builtin.creature.RangeAgentAITask) IRangedAttackMob(net.minecraft.entity.IRangedAttackMob)

Example 2 with IRangedAttackMob

use of net.minecraft.entity.IRangedAttackMob in project Charset by CharsetMC.

the class CharsetTweakMobEqualizer method upgradeMob.

@SubscribeEvent(priority = EventPriority.LOW)
public void upgradeMob(LivingSpawnEvent.SpecialSpawn event) {
    EnumDifficulty difficulty = event.getWorld().getDifficulty();
    if (difficulty == null || difficulty.getDifficultyId() <= 1) {
        return;
    }
    if (!(event.getEntityLiving() instanceof EntityMob)) {
        return;
    }
    EntityMob ent = (EntityMob) event.getEntityLiving();
    // 2) Should we add more granular setups (like only some elements of armor, but at a higher frequency)?
    if (event.getWorld().rand.nextInt(400) > difficulty.getDifficultyId()) {
        return;
    }
    if (!ent.canPickUpLoot())
        return;
    EntityPlayer template = pickNearPlayer(event);
    if (template == null) {
        return;
    }
    int equipmentCount = 0;
    ItemStack[] equipmentCopies = new ItemStack[6];
    boolean copyArmor = event.getEntity() instanceof IRangedAttackMob || event.getWorld().rand.nextBoolean();
    boolean copyWeapon = !(event.getEntity() instanceof IRangedAttackMob) || event.getWorld().rand.nextBoolean();
    for (EntityEquipmentSlot slot : EntityEquipmentSlot.values()) {
        if (slot.getSlotType() == EntityEquipmentSlot.Type.ARMOR && copyArmor) {
            ItemStack is = template.getItemStackFromSlot(slot);
            if (!is.isEmpty() && is.getItem().isValidArmor(is, slot, ent)) {
                equipmentCopies[slot.ordinal()] = is.copy();
                equipmentCount++;
            } else {
                equipmentCopies[slot.ordinal()] = ItemStack.EMPTY;
            }
        }
    }
    List<ItemStack> carriedWeapons = new ArrayList<ItemStack>();
    if (copyWeapon) {
        ItemStack currentWeapon = ent.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND);
        double currentWeaponDmg = ItemUtils.getAttributeValue(EntityEquipmentSlot.MAINHAND, currentWeapon, SharedMonsterAttributes.ATTACK_DAMAGE);
        for (int i = 0; i < 9; i++) {
            ItemStack playerWeapon = template.inventory.getStackInSlot(i);
            if (playerWeapon.isEmpty() || playerWeapon.getCount() != 1 || playerWeapon.getMaxStackSize() != 1) {
                continue;
            }
            EnumAction act = playerWeapon.getItemUseAction();
            if (act != EnumAction.BLOCK && act != EnumAction.NONE && act != EnumAction.BOW) {
                continue;
            }
            double playerWeaponDmg = ItemUtils.getAttributeValue(EntityEquipmentSlot.MAINHAND, playerWeapon, SharedMonsterAttributes.ATTACK_DAMAGE);
            if (playerWeaponDmg > currentWeaponDmg) {
                carriedWeapons.add(playerWeapon.copy());
            }
        }
    }
    if (!carriedWeapons.isEmpty()) {
        equipmentCopies[0] = carriedWeapons.get(event.getWorld().rand.nextInt(carriedWeapons.size())).copy();
        equipmentCount++;
    }
    if (equipmentCount <= 0) {
        return;
    }
    event.setCanceled(true);
    ent.onInitialSpawn(ent.world.getDifficultyForLocation(new BlockPos(event.getEntity())), null);
    // We need to cancel the event so that we can call this before the below happens
    ent.setCanPickUpLoot(false);
    for (EntityEquipmentSlot slot : EntityEquipmentSlot.values()) {
        if (equipmentCopies[slot.ordinal()] != null) {
            ent.setItemStackToSlot(slot, equipmentCopies[slot.ordinal()]);
        }
        ent.setDropChance(slot, 0);
    }
}
Also used : EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) ArrayList(java.util.ArrayList) IRangedAttackMob(net.minecraft.entity.IRangedAttackMob) EnumAction(net.minecraft.item.EnumAction) EntityMob(net.minecraft.entity.monster.EntityMob) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) EnumDifficulty(net.minecraft.world.EnumDifficulty) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

IRangedAttackMob (net.minecraft.entity.IRangedAttackMob)2 ArrayList (java.util.ArrayList)1 EntityAIAttackRanged (net.minecraft.entity.ai.EntityAIAttackRanged)1 EntityMob (net.minecraft.entity.monster.EntityMob)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EntityEquipmentSlot (net.minecraft.inventory.EntityEquipmentSlot)1 EnumAction (net.minecraft.item.EnumAction)1 ItemStack (net.minecraft.item.ItemStack)1 BlockPos (net.minecraft.util.math.BlockPos)1 EnumDifficulty (net.minecraft.world.EnumDifficulty)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 RangeAgentAITask (org.spongepowered.api.entity.ai.task.builtin.creature.RangeAgentAITask)1