use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.
the class AdjustSkillCitizenMessage method onExecute.
@Override
protected void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony) {
final ICitizenData citizenData = colony.getCitizenManager().getCivilian(citizenId);
if (citizenData == null) {
Log.getLogger().warn("AdjustSkillCitizenMessage citizenData is null");
return;
}
final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
if (!optionalEntityCitizen.isPresent()) {
Log.getLogger().warn("AdjustSkillCitizenMessage entity citizen is null");
return;
}
final PlayerEntity player = ctxIn.getSender();
if (player == null) {
return;
}
final boolean isCreative = player.isCreative();
if (!isCreative) {
Log.getLogger().warn("AdjustSkillCitizenMessage player must be creative.");
return;
}
citizenData.getCitizenSkillHandler().incrementLevel(skill, quantity);
citizenData.markDirty();
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.
the class RecallSingleCitizenMessage method onExecute.
@Override
protected void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony, final IBuilding building) {
final ICitizenData citizenData = colony.getCitizenManager().getCivilian(citizenId);
citizenData.setLastPosition(building.getPosition());
Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
if (!optionalEntityCitizen.isPresent()) {
citizenData.updateEntityIfNecessary();
optionalEntityCitizen = citizenData.getEntity();
}
if (optionalEntityCitizen.isPresent() && optionalEntityCitizen.get().getTicksExisted() == 0) {
citizenData.updateEntityIfNecessary();
}
final BlockPos loc = building.getID();
if (optionalEntityCitizen.isPresent() && !TeleportHelper.teleportCitizen(optionalEntityCitizen.get(), colony.getWorld(), loc)) {
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 Minecolonies.
the class CitizenManager method registerCivilian.
@Override
public void registerCivilian(final AbstractCivilianEntity entity) {
if (entity.getCivilianID() == 0 || citizens.get(entity.getCivilianID()) == null) {
entity.remove();
return;
}
final ICitizenData data = citizens.get(entity.getCivilianID());
final Optional<AbstractEntityCitizen> existingCitizen = data.getEntity();
if (!existingCitizen.isPresent()) {
data.setEntity(entity);
entity.level.getScoreboard().addPlayerToTeam(entity.getScoreboardName(), colony.getTeam());
return;
}
if (existingCitizen.get() == entity) {
entity.level.getScoreboard().addPlayerToTeam(entity.getScoreboardName(), colony.getTeam());
return;
}
if (entity.isAlive()) {
existingCitizen.get().remove();
data.setEntity(entity);
entity.setCivilianData(data);
entity.level.getScoreboard().addPlayerToTeam(entity.getScoreboardName(), colony.getTeam());
return;
}
entity.remove();
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.
the class JobDruid method onLevelUp.
@Override
public void onLevelUp() {
// Bonus Health for druids(gets reset upon Firing)
if (getCitizen().getEntity().isPresent()) {
final AbstractEntityCitizen citizen = getCitizen().getEntity().get();
// +1 Heart every 4 level
final AttributeModifier healthModLevel = new AttributeModifier(GUARD_HEALTH_MOD_LEVEL_NAME, getCitizen().getCitizenSkillHandler().getLevel(Skill.Mana) / 2.0 + DRUID_HP_BONUS, AttributeModifier.Operation.ADDITION);
AttributeModifierUtils.addHealthModifier(citizen, healthModLevel);
}
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by Minecolonies.
the class CommandCitizenInfo 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;
}
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_INFO, citizenData.getId(), citizenData.getName()), true);
final AbstractEntityCitizen entityCitizen = optionalEntityCitizen.get();
final BlockPos citizenPosition = entityCitizen.blockPosition();
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_INFO_POSITION, citizenPosition.getX(), citizenPosition.getY(), citizenPosition.getZ()), true);
final BlockPos homePosition = entityCitizen.getRestrictCenter();
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_INFO_HOME_POSITION, homePosition.getX(), homePosition.getY(), homePosition.getZ()), true);
if (entityCitizen.getCitizenColonyHandler().getWorkBuilding() == null) {
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_INFO_NO_WORKING_POSITION), true);
} else {
final BlockPos workingPosition = entityCitizen.getCitizenColonyHandler().getWorkBuilding().getPosition();
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_INFO_WORKING_POSITION, workingPosition.getX(), workingPosition.getY(), workingPosition.getZ()), true);
}
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_INFO_HEALTH, entityCitizen.getHealth(), entityCitizen.getMaxHealth()), true);
Object[] skills = new Object[] { citizenData.getCitizenSkillHandler().getSkills().get(Skill.Athletics).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Dexterity).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Strength).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Agility).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Stamina).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Mana).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Adaptability).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Focus).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Creativity).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Knowledge).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Intelligence).getA() };
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_INFO_SKILLS, skills), true);
if (entityCitizen.getCitizenJobHandler().getColonyJob() == null) {
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_INFO_NO_JOB), true);
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_INFO_NO_ACTIVITY), true);
} else if (entityCitizen.getCitizenColonyHandler().getWorkBuilding() != null && entityCitizen.getCitizenColonyHandler().getWorkBuilding().hasModule(WorkerBuildingModule.class)) {
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_INFO_JOB, entityCitizen.getCitizenColonyHandler().getWorkBuilding().getFirstModuleOccurance(WorkerBuildingModule.class).getJobEntry().getTranslationKey()), true);
context.getSource().sendSuccess(new TranslationTextComponent(CommandTranslationConstants.COMMAND_CITIZEN_INFO_ACTIVITY, entityCitizen.getDesiredActivity(), entityCitizen.getCitizenJobHandler().getColonyJob().getNameTagDescription(), entityCitizen.goalSelector.getRunningGoals().findFirst().get().getGoal().toString()), true);
}
return 1;
}
Aggregations