Search in sources :

Example 1 with AbstractEntityCitizen

use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.

the class CitizenData method serializeViewNetworkData.

@Override
public void serializeViewNetworkData(@NotNull final PacketBuffer buf) {
    buf.writeUtf(name);
    buf.writeBoolean(female);
    buf.writeInt(getEntity().map(AbstractEntityCitizen::getId).orElse(-1));
    buf.writeBoolean(paused);
    buf.writeBoolean(isChild);
    buf.writeBoolean(homeBuilding != null);
    if (homeBuilding != null) {
        buf.writeBlockPos(homeBuilding.getID());
    }
    buf.writeBoolean(workBuilding != null);
    if (workBuilding != null) {
        buf.writeBlockPos(workBuilding.getID());
    }
    // If the entity is not present we assumes standard values.
    buf.writeFloat(getEntity().map(AbstractEntityCitizen::getHealth).orElse(MAX_HEALTH));
    buf.writeFloat(getEntity().map(AbstractEntityCitizen::getMaxHealth).orElse(MAX_HEALTH));
    buf.writeDouble(getSaturation());
    buf.writeDouble(citizenHappinessHandler.getHappiness(getColony()));
    buf.writeNbt(citizenSkillHandler.write());
    buf.writeUtf((job != null) ? job.getJobRegistryEntry().getTranslationKey() : "");
    buf.writeInt(colony.getID());
    final CompoundNBT compound = new CompoundNBT();
    compound.put("inventory", inventory.write(new ListNBT()));
    buf.writeNbt(compound);
    buf.writeBlockPos(lastPosition);
    if (colony.getWorld() != null) {
        final List<IInteractionResponseHandler> subInteractions = citizenChatOptions.values().stream().filter(e -> e.isVisible(colony.getWorld())).collect(Collectors.toList());
        buf.writeInt(subInteractions.size());
        for (final IInteractionResponseHandler interactionHandler : subInteractions) {
            buf.writeNbt(interactionHandler.serializeNBT());
        }
    } else {
        buf.writeInt(0);
    }
    final CompoundNBT happinessCompound = new CompoundNBT();
    citizenHappinessHandler.write(happinessCompound);
    buf.writeNbt(happinessCompound);
    buf.writeInt(status != null ? status.getId() : -1);
    buf.writeBoolean(job != null);
    if (job != null) {
        job.serializeToView(buf);
    }
    if (colony.getCitizenManager().getCivilian(partner) == null) {
        partner = 0;
    }
    siblings.removeIf(s -> colony.getCitizenManager().getCivilian(s) == null);
    children.removeIf(c -> colony.getCitizenManager().getCivilian(c) == null);
    buf.writeInt(partner);
    buf.writeInt(siblings.size());
    for (int sibling : siblings) {
        buf.writeInt(sibling);
    }
    buf.writeInt(children.size());
    for (int child : children) {
        buf.writeInt(child);
    }
    buf.writeUtf(parents.getA());
    buf.writeUtf(parents.getB());
}
Also used : LanguageHandler(com.ldtteam.structurize.util.LanguageHandler) Constants(net.minecraftforge.common.util.Constants) WALKING(com.minecolonies.api.research.util.ResearchConstants.WALKING) CompoundNBT(net.minecraft.nbt.CompoundNBT) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) MinecoloniesAPIProxy(com.minecolonies.api.MinecoloniesAPIProxy) ICitizenSkillHandler(com.minecolonies.api.entity.citizen.citizenhandlers.ICitizenSkillHandler) AttributeModifierUtils(com.minecolonies.coremod.util.AttributeModifierUtils) StringTextComponent(net.minecraft.util.text.StringTextComponent) CAN_EAT(com.minecolonies.api.util.ItemStackUtils.CAN_EAT) CitizenConstants(com.minecolonies.api.util.constant.CitizenConstants) CitizenSkillHandler(com.minecolonies.coremod.entity.citizen.citizenhandlers.CitizenSkillHandler) ListNBT(net.minecraft.nbt.ListNBT) HEALTH_BOOST(com.minecolonies.api.research.util.ResearchConstants.HEALTH_BOOST) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Skill(com.minecolonies.api.entity.citizen.Skill) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) Collectors(java.util.stream.Collectors) AbstractCivilianEntity(com.minecolonies.api.entity.citizen.AbstractCivilianEntity) IntNBT(net.minecraft.nbt.IntNBT) Nullable(org.jetbrains.annotations.Nullable) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) MineColonies(com.minecolonies.coremod.MineColonies) ServerCitizenInteraction(com.minecolonies.coremod.colony.interactionhandling.ServerCitizenInteraction) NotNull(org.jetbrains.annotations.NotNull) CitizenHappinessHandler(com.minecolonies.coremod.entity.citizen.citizenhandlers.CitizenHappinessHandler) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) CITIZEN_NOT_GUARD_NEAR_WORK(com.minecolonies.api.util.constant.TranslationConstants.CITIZEN_NOT_GUARD_NEAR_WORK) java.util(java.util) Suppression(com.minecolonies.api.util.constant.Suppression) TAG_ACTIVE(com.minecolonies.api.util.constant.BuildingConstants.TAG_ACTIVE) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) ICitizenData(com.minecolonies.api.colony.ICitizenData) ITextComponent(net.minecraft.util.text.ITextComponent) ItemStack(net.minecraft.item.ItemStack) Attributes(net.minecraft.entity.ai.attributes.Attributes) CitizenMournHandler(com.minecolonies.coremod.entity.citizen.citizenhandlers.CitizenMournHandler) AbstractAISkeleton(com.minecolonies.coremod.entity.ai.basic.AbstractAISkeleton) IJobDataManager(com.minecolonies.api.colony.jobs.registry.IJobDataManager) IInteractionResponseHandler(com.minecolonies.api.colony.interactionhandling.IInteractionResponseHandler) LivingBuildingModule(com.minecolonies.coremod.colony.buildings.modules.LivingBuildingModule) Hand(net.minecraft.util.Hand) com.minecolonies.api.util(com.minecolonies.api.util) WeakReference(java.lang.ref.WeakReference) INBT(net.minecraft.nbt.INBT) Entity(net.minecraft.entity.Entity) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) BlockPos(net.minecraft.util.math.BlockPos) CITIZEN_NOT_GUARD_NEAR_HOME(com.minecolonies.api.util.constant.TranslationConstants.CITIZEN_NOT_GUARD_NEAR_HOME) IRequestable(com.minecolonies.api.colony.requestsystem.requestable.IRequestable) InventoryCitizen(com.minecolonies.api.inventory.InventoryCitizen) EquipmentSlotType(net.minecraft.inventory.EquipmentSlotType) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) NbtTagConstants(com.minecolonies.api.util.constant.NbtTagConstants) IColony(com.minecolonies.api.colony.IColony) PacketBuffer(net.minecraft.network.PacketBuffer) IJob(com.minecolonies.api.colony.jobs.IJob) IInteractionResponseHandler(com.minecolonies.api.colony.interactionhandling.IInteractionResponseHandler) ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen)

Example 2 with AbstractEntityCitizen

use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen 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(COM_MINECOLONIES_JMAP_PREFIX + "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 ? COM_MINECOLONIES_JMAP_PREFIX + "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());
        }
    }
}
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) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 3 with AbstractEntityCitizen

use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.

the class DruidPotionEntity method applySplash.

@Override
public void applySplash(@NotNull List<EffectInstance> effects, @Nullable Entity entity) {
    final AbstractEntityCitizen citizen = this.getOwner();
    if (citizen != null && citizen.getCitizenData().getJob() instanceof JobDruid) {
        final AxisAlignedBB axisalignedbb = this.getBoundingBox().inflate(SPLASH_SIZE, SPLASH_HEIGTH, SPLASH_SIZE);
        final List<LivingEntity> list = this.level.getEntitiesOfClass(LivingEntity.class, axisalignedbb);
        if (!list.isEmpty()) {
            for (final LivingEntity livingentity : list) {
                if (livingentity.isAffectedByPotions()) {
                    final double distanceSq = this.distanceToSqr(livingentity);
                    if (distanceSq < MAX_DISTANCE) {
                        double d1 = 1.0D - Math.sqrt(distanceSq) / 4.0D;
                        if (livingentity == entity) {
                            d1 = 1.0D;
                        }
                        for (final EffectInstance effectinstance : effects) {
                            final Effect effect = effectinstance.getEffect();
                            if (entitySelectionPredicate == null || entitySelectionPredicate.test(livingentity, effect)) {
                                if (effect.isInstantenous()) {
                                    effect.applyInstantenousEffect(this, this.getOwner(), livingentity, effectinstance.getAmplifier(), d1);
                                } else {
                                    final int duration = (int) (d1 * (double) effectinstance.getDuration());
                                    livingentity.addEffect(new EffectInstance(effect, duration, effectinstance.getAmplifier(), effectinstance.isAmbient(), effectinstance.isVisible()));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) LivingEntity(net.minecraft.entity.LivingEntity) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) Effect(net.minecraft.potion.Effect) JobDruid(com.minecolonies.coremod.colony.jobs.JobDruid) EffectInstance(net.minecraft.potion.EffectInstance)

Example 4 with AbstractEntityCitizen

use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.

the class CommandCitizenTrack method onExecute.

/**
 * What happens when the command is executed after preConditions are successful.
 *
 * @param context the context of the command execution
 */
@Override
public int onExecute(final CommandContext<CommandSource> context) {
    final Entity sender = context.getSource().getEntity();
    if (!(sender instanceof PlayerEntity)) {
        return 1;
    }
    // Colony
    final int colonyID = IntegerArgumentType.getInteger(context, COLONYID_ARG);
    final IColony colony = IColonyManager.getInstance().getColonyByDimension(colonyID, sender == null ? World.OVERWORLD : context.getSource().getLevel().dimension());
    if (colony == null) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.colonyidnotfound", colonyID), true);
        return 0;
    }
    final ICitizenData citizenData = colony.getCitizenManager().getCivilian(IntegerArgumentType.getInteger(context, CITIZENID_ARG));
    if (citizenData == null) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notfound"), true);
        return 0;
    }
    final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
    if (!optionalEntityCitizen.isPresent()) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notloaded"), true);
        return 0;
    }
    final AbstractEntityCitizen entityCitizen = optionalEntityCitizen.get();
    if (AbstractPathJob.trackingMap.getOrDefault((PlayerEntity) sender, UUID.randomUUID()).equals(entityCitizen.getUUID())) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizentrack.success.disable"), true);
        AbstractPathJob.trackingMap.remove((PlayerEntity) sender);
        Network.getNetwork().sendToPlayer(new SyncPathMessage(new HashSet<>(), new HashSet<>(), new HashSet<>()), (ServerPlayerEntity) sender);
    } else {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizentrack.success.enable"), true);
        AbstractPathJob.trackingMap.put((PlayerEntity) sender, entityCitizen.getUUID());
    }
    return 1;
}
Also used : Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SyncPathMessage(com.minecolonies.coremod.network.messages.client.SyncPathMessage) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) IColony(com.minecolonies.api.colony.IColony) ICitizenData(com.minecolonies.api.colony.ICitizenData) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) HashSet(java.util.HashSet)

Example 5 with AbstractEntityCitizen

use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.

the class RecallCitizenMessage method onExecute.

@Override
protected void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony, final IBuilding building) {
    final List<ICitizenData> citizens = new ArrayList<>(building.getAllAssignedCitizen());
    for (int i = 0; i < building.getAllAssignedCitizen().size(); i++) {
        Optional<AbstractEntityCitizen> optionalEntityCitizen = citizens.get(i).getEntity();
        final ICitizenData citizenData = citizens.get(i);
        if (!optionalEntityCitizen.isPresent()) {
            if (citizenData != null) {
                Log.getLogger().warn(String.format("Citizen #%d:%d has gone AWOL, respawning them!", colony.getID(), citizenData.getId()));
                citizenData.setNextRespawnPosition(EntityUtils.getSpawnPoint(colony.getWorld(), building.getPosition()));
                citizenData.updateEntityIfNecessary();
            } else {
                Log.getLogger().warn("Citizen is AWOL and citizenData is null!");
                return;
            }
        } else if (optionalEntityCitizen.get().getTicksExisted() == 0) {
            citizenData.getEntity().ifPresent(Entity::remove);
            citizenData.updateEntityIfNecessary();
        }
        final BlockPos loc = building.getPosition();
        if (optionalEntityCitizen.isPresent() && !TeleportHelper.teleportCitizen(optionalEntityCitizen.get(), colony.getWorld(), loc)) {
            final PlayerEntity player = ctxIn.getSender();
            if (player == null) {
                return;
            }
            LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.workerhuts.recallFail");
        }
    }
}
Also used : ArrayList(java.util.ArrayList) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)70 ICitizenData (com.minecolonies.api.colony.ICitizenData)32 BlockPos (net.minecraft.util.math.BlockPos)32 PlayerEntity (net.minecraft.entity.player.PlayerEntity)22 ItemStack (net.minecraft.item.ItemStack)20 NotNull (org.jetbrains.annotations.NotNull)18 IColony (com.minecolonies.api.colony.IColony)16 AttributeModifier (net.minecraft.entity.ai.attributes.AttributeModifier)14 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)10 Entity (net.minecraft.entity.Entity)10 CompoundNBT (net.minecraft.nbt.CompoundNBT)10 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)10 com.minecolonies.api.util (com.minecolonies.api.util)8 EntityCitizen (com.minecolonies.coremod.entity.citizen.EntityCitizen)8 java.util (java.util)8 ArrayList (java.util.ArrayList)8 Collectors (java.util.stream.Collectors)8 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)8 World (net.minecraft.world.World)8 IItemHandler (net.minecraftforge.items.IItemHandler)8