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);
}
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);
}
}
Aggregations