use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.
the class CommandCitizenTeleport 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) {
entityCitizen.moveTo(targetPos.getX(), targetPos.getY(), targetPos.getZ(), entityCitizen.getViewYRot(1F), entityCitizen.getViewXRot(1F));
entityCitizen.getNavigation().stop();
}
return 1;
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.
the class RecallCitizenHutMessage method onExecute.
@Override
protected void onExecute(@NotNull final NetworkEvent.Context ctxIn, final boolean isLogicalServer, @NotNull final IColony colony, @NotNull final IBuilding building) {
final BlockPos location = building.getPosition();
final World world = colony.getWorld();
for (final ICitizenData citizenData : building.getAllAssignedCitizen()) {
Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
if (!optionalEntityCitizen.isPresent()) {
Log.getLogger().warn(String.format("Citizen #%d:%d has gone AWOL, respawning them!", colony.getID(), citizenData.getId()));
citizenData.setNextRespawnPosition(EntityUtils.getSpawnPoint(world, location));
citizenData.updateEntityIfNecessary();
optionalEntityCitizen = citizenData.getEntity();
}
if (optionalEntityCitizen.isPresent() && !TeleportHelper.teleportCitizen(optionalEntityCitizen.get(), world, location)) {
final PlayerEntity player = ctxIn.getSender();
if (player == null) {
return;
}
MessageUtils.format(WARNING_CITIZEN_RECALL_FAILED).sendTo(player);
}
}
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by ldtteam.
the class JobKnight method onLevelUp.
@Override
public void onLevelUp() {
// Bonus Health for knights(gets reset upon Firing)
if (getCitizen().getEntity().isPresent()) {
final AbstractEntityCitizen citizen = getCitizen().getEntity().get();
// +1 Heart every 2 level
final AttributeModifier healthModLevel = new AttributeModifier(GUARD_HEALTH_MOD_LEVEL_NAME, getCitizen().getCitizenSkillHandler().getLevel(Skill.Stamina) + KNIGHT_HP_BONUS, AttributeModifier.Operation.ADDITION);
AttributeModifierUtils.addHealthModifier(citizen, healthModLevel);
}
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by ldtteam.
the class JobKnight method ignoresDamage.
@Override
public boolean ignoresDamage(@NotNull final DamageSource damageSource) {
if (damageSource.isExplosion() && this.getColony().getResearchManager().getResearchEffects().getEffectStrength(SHIELD_USAGE) > 0 && InventoryUtils.findFirstSlotInItemHandlerWith(this.getCitizen().getInventory(), Items.SHIELD) != -1) {
if (!this.getCitizen().getEntity().isPresent()) {
return true;
}
final AbstractEntityCitizen worker = this.getCitizen().getEntity().get();
worker.getCitizenItemHandler().setHeldItem(Hand.OFF_HAND, InventoryUtils.findFirstSlotInItemHandlerWith(this.getCitizen().getInventory(), Items.SHIELD));
worker.startUsingItem(Hand.OFF_HAND);
// Apply the colony Flag to the shield
ItemStack shieldStack = worker.getInventoryCitizen().getHeldItem(Hand.OFF_HAND);
CompoundNBT nbt = shieldStack.getOrCreateTagElement("BlockEntityTag");
nbt.put(TAG_BANNER_PATTERNS, worker.getCitizenColonyHandler().getColony().getColonyFlag());
worker.decreaseSaturationForContinuousAction();
return true;
}
return super.ignoresDamage(damageSource);
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by ldtteam.
the class JobLumberjack method onLevelUp.
@Override
public void onLevelUp() {
if (getCitizen().getEntity().isPresent()) {
final AbstractEntityCitizen worker = getCitizen().getEntity().get();
final AttributeModifier speedModifier = new AttributeModifier(SKILL_BONUS_ADD, (getCitizen().getCitizenSkillHandler().getLevel(getCitizen().getWorkBuilding().getModuleMatching(WorkerBuildingModule.class, m -> m.getJobEntry() == this.getJobRegistryEntry()).getSecondarySkill()) / 2.0) * BONUS_SPEED_PER_LEVEL, AttributeModifier.Operation.ADDITION);
AttributeModifierUtils.addModifier(worker, speedModifier, Attributes.MOVEMENT_SPEED);
}
}
Aggregations