Search in sources :

Example 1 with MonsterEntity

use of net.minecraft.entity.monster.MonsterEntity in project minecolonies by Minecolonies.

the class CommandKillMonster method onExecute.

/**
 * What happens when the command is executed
 *
 * @param context the context of the command execution
 */
@Override
public int onExecute(final CommandContext<CommandSource> context) {
    entitiesKilled = 0;
    context.getSource().getLevel().getEntities().forEach(entity -> {
        if (entity instanceof MonsterEntity) {
            entity.remove();
            entitiesKilled++;
        }
    });
    context.getSource().sendSuccess(new StringTextComponent(entitiesKilled + " entities killed"), true);
    return 1;
}
Also used : MonsterEntity(net.minecraft.entity.monster.MonsterEntity) StringTextComponent(net.minecraft.util.text.StringTextComponent)

Example 2 with MonsterEntity

use of net.minecraft.entity.monster.MonsterEntity in project minecolonies by Minecolonies.

the class ColonyPermissionEventHandler method on.

/**
 * AttackEntityEvent handler.
 * <p>
 * Check, if a player tries to attack an entity.. Deny if: - If the attacking happens in the colony - Player is less than officer to the colony.
 *
 * @param event ItemEntityPickupEvent
 */
@SubscribeEvent
public void on(final AttackEntityEvent event) {
    if (event.getTarget() instanceof MonsterEntity) {
        return;
    }
    @NotNull final PlayerEntity player = EntityUtils.getPlayerOfFakePlayer(event.getPlayer(), event.getPlayer().getCommandSenderWorld());
    if (MineColonies.getConfig().getServer().enableColonyProtection.get() && colony.isCoordInColony(player.getCommandSenderWorld(), new BlockPos(player.position()))) {
        final Permissions perms = colony.getPermissions();
        if (event.getTarget() instanceof EntityCitizen) {
            final AbstractEntityCitizen citizen = (AbstractEntityCitizen) event.getTarget();
            if (citizen.getCitizenJobHandler().getColonyJob() instanceof AbstractJobGuard && perms.hasPermission(event.getPlayer(), Action.GUARDS_ATTACK)) {
                return;
            }
            if (perms.hasPermission(event.getPlayer(), Action.ATTACK_CITIZEN)) {
                return;
            }
            cancelEvent(event, event.getPlayer(), colony, Action.ATTACK_CITIZEN, new BlockPos(event.getTarget().position()));
            return;
        }
        if (!(event.getTarget() instanceof MobEntity) && !perms.hasPermission(event.getPlayer(), Action.ATTACK_ENTITY)) {
            cancelEvent(event, event.getPlayer(), colony, Action.ATTACK_ENTITY, new BlockPos(event.getTarget().position()));
        }
    }
}
Also used : AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) Permissions(com.minecolonies.coremod.colony.permissions.Permissions) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) BlockPos(net.minecraft.util.math.BlockPos) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) NotNull(org.jetbrains.annotations.NotNull) MobEntity(net.minecraft.entity.MobEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 3 with MonsterEntity

use of net.minecraft.entity.monster.MonsterEntity in project Enigmatic-Legacy by Aizistral-Studios.

the class EnigmaticEventHandler method onEntityHurt.

@SubscribeEvent
public void onEntityHurt(LivingHurtEvent event) {
    if (event.getEntityLiving() instanceof PlayerEntity & !event.getEntityLiving().world.isRemote) {
        PlayerEntity player = (PlayerEntity) event.getEntityLiving();
        if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.angelBlessing))
            if (AngelBlessing.resistanceList.containsKey(event.getSource().damageType))
                event.setAmount(event.getAmount() * AngelBlessing.resistanceList.get(event.getSource().damageType));
        if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.oceanStone)) {
            Entity attacker = event.getSource().getTrueSource();
            if (attacker instanceof DrownedEntity || attacker instanceof GuardianEntity || attacker instanceof ElderGuardianEntity)
                event.setAmount(event.getAmount() * ConfigHandler.OCEAN_STONE_UNDERWATER_CREATURES_RESISTANCE.getValue().asModifierInverted());
        }
        if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.eyeOfNebula))
            if (EyeOfNebula.resistanceList.containsKey(event.getSource().damageType))
                event.setAmount(event.getAmount() * EyeOfNebula.resistanceList.get(event.getSource().damageType).get());
        if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.golemHeart))
            if (GolemHeart.resistanceList.containsKey(event.getSource().damageType))
                event.setAmount(event.getAmount() * GolemHeart.resistanceList.get(event.getSource().damageType).get());
        if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.voidPearl))
            if (VoidPearl.resistanceList.containsKey(event.getSource().damageType))
                event.setAmount(event.getAmount() * VoidPearl.resistanceList.get(event.getSource().damageType).get());
        if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.magmaHeart)) {
            // System.out.println("Damage type: " + event.getSource().damageType);
            if (event.getSource().getTrueSource() instanceof LivingEntity && MagmaHeart.nemesisList.contains(event.getSource().damageType)) {
                LivingEntity attacker = (LivingEntity) event.getSource().getTrueSource();
                if (!attacker.isImmuneToFire()) {
                    attacker.attackEntityFrom(new EntityDamageSource(DamageSource.ON_FIRE.damageType, player), (float) ConfigHandler.BLAZING_CORE_DAMAGE_FEEDBACK.getValue());
                    attacker.setFire((int) ConfigHandler.BLAZING_CORE_IGNITION_FEEDBACK.getValue());
                }
            }
        }
        if (EtheriumArmor.hasShield(player)) {
            if (event.getSource().getImmediateSource() instanceof LivingEntity) {
                LivingEntity attacker = ((LivingEntity) event.getSource().getTrueSource());
                Vector3 vec = Vector3.fromEntityCenter(player).subtract(Vector3.fromEntityCenter(event.getSource().getTrueSource())).normalize();
                attacker.knockBack(player, 0.75F, vec.x, vec.y);
                player.world.playSound(null, player.getPosition(), EnigmaticLegacy.SHIELD_TRIGGER, SoundCategory.PLAYERS, 1.0F, 0.9F + (float) (Math.random() * 0.1D));
                player.world.playSound(null, player.getPosition(), EnigmaticLegacy.SHIELD_TRIGGER, SoundCategory.PLAYERS, 1.0F, 0.9F + (float) (Math.random() * 0.1D));
            }
            event.setAmount(event.getAmount() * ConfigHandler.ETHERIUM_ARMOR_SHIELD_REDUCTION.getValue().asModifierInverted());
        }
    } else if (event.getEntityLiving() instanceof MonsterEntity) {
        MonsterEntity monster = (MonsterEntity) event.getEntityLiving();
        if (event.getSource().getTrueSource() instanceof PlayerEntity) {
            PlayerEntity player = (PlayerEntity) event.getSource().getTrueSource();
            if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.monsterCharm)) {
                if (monster.isEntityUndead()) {
                    event.setAmount(event.getAmount() * ConfigHandler.MONSTER_CHARM_UNDEAD_DAMAGE.getValue().asModifier(true));
                } else if (monster.isAggressive() || monster instanceof CreeperEntity) {
                    if (monster instanceof EndermanEntity || monster instanceof ZombiePigmanEntity || monster instanceof BlazeEntity || monster instanceof GuardianEntity || monster instanceof ElderGuardianEntity || !monster.isNonBoss()) {
                    } else {
                        event.setAmount(event.getAmount() * ConfigHandler.MONSTER_CHARM_AGGRESSIVE_DAMAGE.getValue().asModifier(true));
                    }
                }
            }
            if (monster instanceof CreeperEntity)
                monster.setLastAttackedEntity(player);
        // TODO Test if required
        }
    }
    if (event.getSource().getTrueSource() instanceof PlayerEntity) {
        PlayerEntity player = (PlayerEntity) event.getSource().getTrueSource();
        if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.voidPearl)) {
            event.getEntityLiving().addPotionEffect(new EffectInstance(Effects.WITHER, ConfigHandler.VOID_PEARL_WITHERING_EFFECT_TIME.getValue(), ConfigHandler.VOID_PEARL_WITHERING_EFFECT_LEVEL.getValue(), false, true));
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) BlazeEntity(net.minecraft.entity.monster.BlazeEntity) EndermanEntity(net.minecraft.entity.monster.EndermanEntity) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) EnderDragonEntity(net.minecraft.entity.boss.dragon.EnderDragonEntity) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) ZombieEntity(net.minecraft.entity.monster.ZombieEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) PermanentItemEntity(com.integral.enigmaticlegacy.entities.PermanentItemEntity) ZombiePigmanEntity(net.minecraft.entity.monster.ZombiePigmanEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) DrownedEntity(net.minecraft.entity.monster.DrownedEntity) GuardianEntity(net.minecraft.entity.monster.GuardianEntity) Entity(net.minecraft.entity.Entity) CreeperEntity(net.minecraft.entity.monster.CreeperEntity) WitherSkeletonEntity(net.minecraft.entity.monster.WitherSkeletonEntity) SkeletonEntity(net.minecraft.entity.monster.SkeletonEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) ElderGuardianEntity(net.minecraft.entity.monster.ElderGuardianEntity) ZombiePigmanEntity(net.minecraft.entity.monster.ZombiePigmanEntity) BlazeEntity(net.minecraft.entity.monster.BlazeEntity) GuardianEntity(net.minecraft.entity.monster.GuardianEntity) ElderGuardianEntity(net.minecraft.entity.monster.ElderGuardianEntity) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) Vector3(com.integral.enigmaticlegacy.helpers.Vector3) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) EntityDamageSource(net.minecraft.util.EntityDamageSource) LivingEntity(net.minecraft.entity.LivingEntity) EndermanEntity(net.minecraft.entity.monster.EndermanEntity) ElderGuardianEntity(net.minecraft.entity.monster.ElderGuardianEntity) CreeperEntity(net.minecraft.entity.monster.CreeperEntity) DrownedEntity(net.minecraft.entity.monster.DrownedEntity) EffectInstance(net.minecraft.potion.EffectInstance) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 4 with MonsterEntity

use of net.minecraft.entity.monster.MonsterEntity in project ChocolateQuestRepoured by TeamChocoQuest.

the class TargetUtil method isEnemyCheckingLeaders.

public static boolean isEnemyCheckingLeaders(LivingEntity entity, LivingEntity target) {
    LivingEntity leader = getLeaderOrOwnerRecursive(entity);
    if (leader instanceof PlayerEntity) {
        entity = leader;
    }
    LivingEntity targetLeader = getLeaderOrOwnerRecursive(target);
    if (targetLeader instanceof PlayerEntity) {
        target = targetLeader;
    }
    if (entity == target) {
        return false;
    }
    if (entity instanceof PlayerEntity) {
        if (target instanceof PlayerEntity) {
            // TODO add coop/pvp mode?
            return false;
        } else {
            LivingEntity temp = entity;
            entity = target;
            target = temp;
        }
    }
    Faction faction = FactionRegistry.instance(entity).getFactionOf(entity);
    if (target instanceof PlayerEntity && faction == FactionRegistry.DUMMY_FACTION) {
        if (!(entity instanceof MonsterEntity)) {
            return false;
        }
    } else {
        if (!faction.isEnemy(target)) {
            return false;
        }
    }
    return true;
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Faction(team.cqr.cqrepoured.faction.Faction)

Example 5 with MonsterEntity

use of net.minecraft.entity.monster.MonsterEntity in project minecolonies by ldtteam.

the class ColonyPermissionEventHandler method on.

/**
 * AttackEntityEvent handler.
 * <p>
 * Check, if a player tries to attack an entity.. Deny if: - If the attacking happens in the colony - Player is less than officer to the colony.
 *
 * @param event ItemEntityPickupEvent
 */
@SubscribeEvent
public void on(final AttackEntityEvent event) {
    if (event.getTarget() instanceof MonsterEntity) {
        return;
    }
    @NotNull final PlayerEntity player = EntityUtils.getPlayerOfFakePlayer(event.getPlayer(), event.getPlayer().getCommandSenderWorld());
    if (MineColonies.getConfig().getServer().enableColonyProtection.get() && colony.isCoordInColony(player.getCommandSenderWorld(), new BlockPos(player.position()))) {
        final Permissions perms = colony.getPermissions();
        if (event.getTarget() instanceof EntityCitizen) {
            final AbstractEntityCitizen citizen = (AbstractEntityCitizen) event.getTarget();
            if (citizen.getCitizenJobHandler().getColonyJob() instanceof AbstractJobGuard && perms.hasPermission(event.getPlayer(), Action.GUARDS_ATTACK)) {
                return;
            }
            if (perms.hasPermission(event.getPlayer(), Action.ATTACK_CITIZEN)) {
                return;
            }
            cancelEvent(event, event.getPlayer(), colony, Action.ATTACK_CITIZEN, new BlockPos(event.getTarget().position()));
            return;
        }
        if (!(event.getTarget() instanceof MobEntity) && !perms.hasPermission(event.getPlayer(), Action.ATTACK_ENTITY)) {
            cancelEvent(event, event.getPlayer(), colony, Action.ATTACK_ENTITY, new BlockPos(event.getTarget().position()));
        }
    }
}
Also used : AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) Permissions(com.minecolonies.coremod.colony.permissions.Permissions) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) BlockPos(net.minecraft.util.math.BlockPos) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) NotNull(org.jetbrains.annotations.NotNull) MobEntity(net.minecraft.entity.MobEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

MonsterEntity (net.minecraft.entity.monster.MonsterEntity)7 PlayerEntity (net.minecraft.entity.player.PlayerEntity)4 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)3 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)3 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)2 AbstractJobGuard (com.minecolonies.coremod.colony.jobs.AbstractJobGuard)2 Permissions (com.minecolonies.coremod.colony.permissions.Permissions)2 EntityCitizen (com.minecolonies.coremod.entity.citizen.EntityCitizen)2 LivingEntity (net.minecraft.entity.LivingEntity)2 MobEntity (net.minecraft.entity.MobEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 StringTextComponent (net.minecraft.util.text.StringTextComponent)2 NotNull (org.jetbrains.annotations.NotNull)2 PermanentItemEntity (com.integral.enigmaticlegacy.entities.PermanentItemEntity)1 Vector3 (com.integral.enigmaticlegacy.helpers.Vector3)1 Entity (net.minecraft.entity.Entity)1 EnderDragonEntity (net.minecraft.entity.boss.dragon.EnderDragonEntity)1 ItemEntity (net.minecraft.entity.item.ItemEntity)1 BlazeEntity (net.minecraft.entity.monster.BlazeEntity)1 CreeperEntity (net.minecraft.entity.monster.CreeperEntity)1