Search in sources :

Example 1 with AbstractEntityMinecoloniesMob

use of com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesMob in project minecolonies by Minecolonies.

the class EntityAIBreakDoor method tick.

@Override
public void tick() {
    if (mob.getCommandSenderWorld().getDifficulty().getId() < 2 || !MineColonies.getConfig().getServer().shouldRaidersBreakDoors.get()) {
        breakTime = 0;
    }
    // Only advances breaking time in relation to hardness
    if (this.mob.getRandom().nextInt(breakChance) != 0) {
        this.breakTime--;
    } else {
        int fasterBreakPerXNearby = 5;
        if (mob instanceof AbstractEntityMinecoloniesMob && !mob.level.isClientSide()) {
            final IColony colony = ((AbstractEntityMinecoloniesMob) mob).getColony();
            fasterBreakPerXNearby += colony.getResearchManager().getResearchEffects().getEffectStrength(MECHANIC_ENHANCED_GATES);
        }
        breakChance = Math.max(1, hardness / (1 + (mob.level.getLoadedEntitiesOfClass(AbstractEntityMinecoloniesMob.class, mob.getBoundingBox().inflate(5)).size() / fasterBreakPerXNearby)));
    }
    if (this.breakTime == this.getDoorBreakTime() - 1) {
        final BlockState toBreak = mob.level.getBlockState(doorPos);
        if (toBreak.getBlock() instanceof AbstractBlockGate) {
            ((AbstractBlockGate) toBreak.getBlock()).removeGate(mob.level, doorPos, toBreak.getValue(BlockStateProperties.HORIZONTAL_FACING).getClockWise());
        }
    }
    super.tick();
}
Also used : BlockState(net.minecraft.block.BlockState) AbstractBlockGate(com.minecolonies.api.blocks.decorative.AbstractBlockGate) IColony(com.minecolonies.api.colony.IColony) AbstractEntityMinecoloniesMob(com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesMob)

Example 2 with AbstractEntityMinecoloniesMob

use of com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesMob in project minecolonies by Minecolonies.

the class EventListener method onUpdateEntityRadar.

@SubscribeEvent
public void onUpdateEntityRadar(@NotNull final EntityRadarUpdateEvent event) {
    final WrappedEntity wrapper = event.getWrappedEntity();
    final LivingEntity entity = wrapper.getEntityLivingRef().get();
    if (entity instanceof AbstractEntityCitizen) {
        final boolean isVisitor = entity instanceof VisitorCitizen;
        TextComponent jobName;
        if (isVisitor) {
            if (!JourneymapOptions.getShowVisitors(this.jmap.getOptions())) {
                wrapper.setDisable(true);
                return;
            }
            jobName = new TranslationTextComponent(PARTIAL_JOURNEY_MAP_INFO + "visitor");
        } else {
            final String jobId = entity.getEntityData().get(DATA_JOB);
            final JobEntry jobEntry = IJobRegistry.getInstance().getValue(new ResourceLocation(jobId));
            final IJob<?> job = jobEntry == null ? null : jobEntry.produceJob(null);
            if (job instanceof AbstractJobGuard ? !JourneymapOptions.getShowGuards(this.jmap.getOptions()) : !JourneymapOptions.getShowCitizens(this.jmap.getOptions())) {
                wrapper.setDisable(true);
                return;
            }
            jobName = new TranslationTextComponent(jobEntry == null ? PARTIAL_JOURNEY_MAP_INFO + "unemployed" : jobEntry.getTranslationKey());
        }
        if (JourneymapOptions.getShowColonistTooltip(this.jmap.getOptions())) {
            ITextComponent name = entity.getCustomName();
            if (name != null) {
                wrapper.setEntityToolTips(Arrays.asList(name, jobName.setStyle(JOB_TOOLTIP)));
            }
        }
        final boolean showName = event.getActiveUiState().ui.equals(Context.UI.Minimap) ? JourneymapOptions.getShowColonistNameMinimap(this.jmap.getOptions()) : JourneymapOptions.getShowColonistNameFullscreen(this.jmap.getOptions());
        if (!showName) {
            wrapper.setCustomName("");
        }
        if (!isVisitor && JourneymapOptions.getShowColonistTeamColour(this.jmap.getOptions())) {
            wrapper.setColor(entity.getTeamColor());
        }
    } else if (entity instanceof AbstractEntityMinecoloniesMob) {
        final JourneymapOptions.RaiderColor color = JourneymapOptions.getRaiderColor(this.jmap.getOptions());
        if (JourneymapOptions.RaiderColor.NONE.equals(color)) {
            wrapper.setDisable(true);
        } else if (!JourneymapOptions.RaiderColor.HOSTILE.equals(color)) {
            wrapper.setColor(color.getColor().getValue());
        }
    }
}
Also used : AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) WrappedEntity(journeymap.client.api.model.WrappedEntity) VisitorCitizen(com.minecolonies.coremod.entity.citizen.VisitorCitizen) LivingEntity(net.minecraft.entity.LivingEntity) JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) ResourceLocation(net.minecraft.util.ResourceLocation) AbstractEntityMinecoloniesMob(com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesMob) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 3 with AbstractEntityMinecoloniesMob

use of com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesMob in project minecolonies by Minecolonies.

the class CombatUtils method notifyGuardsOfTarget.

/**
 * Actions on changing to a new target entity
 */
public static void notifyGuardsOfTarget(final AbstractEntityCitizen user, final LivingEntity target, final int callRange) {
    for (final ICitizenData citizen : user.getCitizenData().getWorkBuilding().getAllAssignedCitizen()) {
        if (citizen.getEntity().isPresent() && citizen.getEntity().get().getLastHurtByMob() == null) {
            ((EntityCitizen) citizen.getEntity().get()).getThreatTable().addThreat(target, 0);
        }
    }
    if (target instanceof AbstractEntityMinecoloniesMob) {
        for (final Map.Entry<BlockPos, IBuilding> entry : user.getCitizenColonyHandler().getColony().getBuildingManager().getBuildings().entrySet()) {
            if (entry.getValue() instanceof AbstractBuildingGuards && user.blockPosition().distSqr(entry.getKey()) < callRange) {
                final AbstractBuildingGuards building = (AbstractBuildingGuards) entry.getValue();
                building.setTempNextPatrolPoint(target.blockPosition());
            }
        }
    }
}
Also used : AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos) Map(java.util.Map) AbstractEntityMinecoloniesMob(com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesMob)

Example 4 with AbstractEntityMinecoloniesMob

use of com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesMob in project minecolonies by Minecolonies.

the class CommandKillRaider 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 AbstractEntityMinecoloniesMob) {
            final AbstractEntityMinecoloniesMob mob = (AbstractEntityMinecoloniesMob) entity;
            mob.die(new DamageSource("despawn"));
            mob.remove();
            final IColonyEvent event = mob.getColony().getEventManager().getEventByID(mob.getEventID());
            if (event != null) {
                event.setStatus(EventStatus.DONE);
            }
            entitiesKilled++;
        }
    });
    context.getSource().sendSuccess(new StringTextComponent(entitiesKilled + " entities killed"), true);
    return 1;
}
Also used : IColonyEvent(com.minecolonies.api.colony.colonyEvents.IColonyEvent) DamageSource(net.minecraft.util.DamageSource) StringTextComponent(net.minecraft.util.text.StringTextComponent) AbstractEntityMinecoloniesMob(com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesMob)

Example 5 with AbstractEntityMinecoloniesMob

use of com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesMob in project minecolonies by ldtteam.

the class CombatUtils method notifyGuardsOfTarget.

/**
 * Actions on changing to a new target entity
 */
public static void notifyGuardsOfTarget(final AbstractEntityCitizen user, final LivingEntity target, final int callRange) {
    for (final ICitizenData citizen : user.getCitizenData().getWorkBuilding().getAllAssignedCitizen()) {
        if (citizen.getEntity().isPresent() && citizen.getEntity().get().getLastHurtByMob() == null) {
            ((EntityCitizen) citizen.getEntity().get()).getThreatTable().addThreat(target, 0);
        }
    }
    if (target instanceof AbstractEntityMinecoloniesMob) {
        for (final Map.Entry<BlockPos, IBuilding> entry : user.getCitizenColonyHandler().getColony().getBuildingManager().getBuildings().entrySet()) {
            if (entry.getValue() instanceof AbstractBuildingGuards && user.blockPosition().distSqr(entry.getKey()) < callRange) {
                final AbstractBuildingGuards building = (AbstractBuildingGuards) entry.getValue();
                building.setTempNextPatrolPoint(target.blockPosition());
            }
        }
    }
}
Also used : AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos) Map(java.util.Map) AbstractEntityMinecoloniesMob(com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesMob)

Aggregations

AbstractEntityMinecoloniesMob (com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesMob)7 AbstractBlockGate (com.minecolonies.api.blocks.decorative.AbstractBlockGate)2 ICitizenData (com.minecolonies.api.colony.ICitizenData)2 IColony (com.minecolonies.api.colony.IColony)2 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 IColonyEvent (com.minecolonies.api.colony.colonyEvents.IColonyEvent)2 AbstractBuildingGuards (com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards)2 Map (java.util.Map)2 BlockState (net.minecraft.block.BlockState)2 DamageSource (net.minecraft.util.DamageSource)2 BlockPos (net.minecraft.util.math.BlockPos)2 StringTextComponent (net.minecraft.util.text.StringTextComponent)2 JobEntry (com.minecolonies.api.colony.jobs.registry.JobEntry)1 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)1 AbstractJobGuard (com.minecolonies.coremod.colony.jobs.AbstractJobGuard)1 VisitorCitizen (com.minecolonies.coremod.entity.citizen.VisitorCitizen)1 WrappedEntity (journeymap.client.api.model.WrappedEntity)1 LivingEntity (net.minecraft.entity.LivingEntity)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1