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() != 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()));
}
}
}
}
}
}
}
}
}
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(new TranslationTextComponent(CommandTranslationConstants.COMMAND_COLONY_ID_NOT_FOUND, colonyID), true);
return 0;
}
final ICitizenData citizenData = colony.getCitizenManager().getCivilian(IntegerArgumentType.getInteger(context, CITIZENID_ARG));
if (citizenData == null) {
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_NOT_FOUND), true);
return 0;
}
final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
if (!optionalEntityCitizen.isPresent()) {
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_NOT_LOADED), true);
return 0;
}
final AbstractEntityCitizen entityCitizen = optionalEntityCitizen.get();
if (AbstractPathJob.trackingMap.getOrDefault((PlayerEntity) sender, UUID.randomUUID()).equals(entityCitizen.getUUID())) {
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_ENTITY_TRACK_DISABLED), true);
AbstractPathJob.trackingMap.remove((PlayerEntity) sender);
Network.getNetwork().sendToPlayer(new SyncPathMessage(new HashSet<>(), new HashSet<>(), new HashSet<>()), (ServerPlayerEntity) sender);
} else {
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_ENTITY_TRACK_ENABLED), true);
AbstractPathJob.trackingMap.put((PlayerEntity) sender, entityCitizen.getUUID());
}
return 1;
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.
the class CommandCitizenTriggerWalkTo 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();
// 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(new TranslationTextComponent(CommandTranslationConstants.COMMAND_COLONY_ID_NOT_FOUND, colonyID), true);
return 0;
}
final ICitizenData citizenData = colony.getCitizenManager().getCivilian(IntegerArgumentType.getInteger(context, CITIZENID_ARG));
if (citizenData == null) {
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_NOT_FOUND), true);
return 0;
}
final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
if (!optionalEntityCitizen.isPresent()) {
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_NOT_LOADED), true);
return 0;
}
final AbstractEntityCitizen entityCitizen = optionalEntityCitizen.get();
final ILocationArgument targetLocation = Vec3Argument.getCoordinates(context, POS_ARG);
final BlockPos targetPos = targetLocation.getBlockPos(context.getSource());
if (context.getSource().getLevel() == entityCitizen.level) {
if (entityCitizen instanceof EntityCitizen && entityCitizen.getCitizenJobHandler().getColonyJob() != null) {
final AbstractEntityAIBasic basic = ((AbstractEntityAIBasic) entityCitizen.getCitizenJobHandler().getColonyJob().getWorkerAI());
basic.setWalkTo(targetPos);
basic.registerTarget(new AIOneTimeEventTarget(AIWorkerState.WALK_TO));
} else {
entityCitizen.getNavigation().moveTo(targetPos.getX(), targetPos.getY(), targetPos.getZ(), 1f);
}
}
return 1;
}
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());
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.
the class ResearchUnlocked method test.
@Override
public boolean test(@NotNull final LootContext lootContext) {
final Entity entity = lootContext.getParamOrNull(LootParameters.KILLER_ENTITY);
if (entity instanceof AbstractEntityCitizen) {
final AbstractEntityCitizen citizen = (AbstractEntityCitizen) entity;
final IColony colony = citizen.getCitizenColonyHandler().getColony();
if (colony != null) {
return colony.getResearchManager().getResearchEffects().getEffectStrength(this.effectId) > 0;
}
}
return false;
}
Aggregations