use of com.minecolonies.coremod.entity.citizen.EntityCitizen in project minecolonies by ldtteam.
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(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();
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.coremod.entity.citizen.EntityCitizen in project minecolonies by ldtteam.
the class EntityAIWorkHealer method freeCure.
/**
* Do free cure magic.
*
* @return the next state to go to.
*/
private IAIState freeCure() {
if (currentPatient == null) {
return DECIDE;
}
final ICitizenData data = getOwnBuilding().getColony().getCitizenManager().getCivilian(currentPatient.getId());
if (data == null || !data.getEntity().isPresent() || !data.getEntity().get().getCitizenDiseaseHandler().isSick()) {
currentPatient = null;
return DECIDE;
}
final EntityCitizen citizen = (EntityCitizen) data.getEntity().get();
if (walkToBlock(citizen.blockPosition())) {
progressTicks = 0;
return FREE_CURE;
}
progressTicks++;
if (progressTicks < MAX_PROGRESS_TICKS) {
Network.getNetwork().sendToTrackingEntity(new StreamParticleEffectMessage(worker.position().add(0, 2, 0), citizen.position(), ParticleTypes.HEART, progressTicks % MAX_PROGRESS_TICKS, MAX_PROGRESS_TICKS), worker);
Network.getNetwork().sendToTrackingEntity(new CircleParticleEffectMessage(worker.position().add(0, 2, 0), ParticleTypes.HEART, progressTicks), worker);
return getState();
}
progressTicks = 0;
worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN);
citizen.getCitizenDiseaseHandler().cure();
currentPatient.setState(Patient.PatientState.TREATED);
currentPatient = null;
return DECIDE;
}
use of com.minecolonies.coremod.entity.citizen.EntityCitizen in project minecolonies by ldtteam.
the class EntityAIWorkHealer method wander.
/**
* Wander around in the colony from citizen to citizen.
*
* @return the next state to go to.
*/
private IAIState wander() {
if (remotePatient == null || !remotePatient.getEntity().isPresent()) {
return DECIDE;
}
final EntityCitizen citizen = (EntityCitizen) remotePatient.getEntity().get();
if (walkToBlock(remotePatient.getEntity().get().blockPosition())) {
return getState();
}
Network.getNetwork().sendToTrackingEntity(new CircleParticleEffectMessage(remotePatient.getEntity().get().position(), ParticleTypes.HEART, 1), worker);
citizen.heal(citizen.getMaxHealth() - citizen.getHealth() - 5 - getOwnBuilding().getBuildingLevel());
citizen.markDirty();
worker.getCitizenExperienceHandler().addExperience(1);
remotePatient = null;
return START_WORKING;
}
use of com.minecolonies.coremod.entity.citizen.EntityCitizen in project minecolonies by ldtteam.
the class EntityAIWorkHealer method requestCure.
/**
* Request the cure for a given patient.
*
* @return the next state to go to.
*/
private IAIState requestCure() {
if (currentPatient == null) {
return DECIDE;
}
final ICitizenData data = getOwnBuilding().getColony().getCitizenManager().getCivilian(currentPatient.getId());
if (data == null || !data.getEntity().isPresent() || !data.getEntity().get().getCitizenDiseaseHandler().isSick()) {
currentPatient = null;
return DECIDE;
}
final EntityCitizen citizen = (EntityCitizen) data.getEntity().get();
if (walkToBlock(citizen.blockPosition())) {
return REQUEST_CURE;
}
final String diseaseName = citizen.getCitizenDiseaseHandler().getDisease();
if (diseaseName.isEmpty()) {
currentPatient.setState(Patient.PatientState.REQUESTED);
currentPatient = null;
return DECIDE;
}
final ImmutableList<IRequest<? extends Stack>> list = getOwnBuilding().getOpenRequestsOfType(worker.getCitizenData().getId(), TypeToken.of(Stack.class));
final ImmutableList<IRequest<? extends Stack>> completed = getOwnBuilding().getCompletedRequestsOfType(worker.getCitizenData(), TypeToken.of(Stack.class));
for (final ItemStack cure : IColonyManager.getInstance().getCompatibilityManager().getDisease(diseaseName).getCure()) {
if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), cure::sameItem) && !InventoryUtils.hasItemInItemHandler(getOwnBuilding().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElseGet(null), cure::sameItem)) {
boolean hasRequest = false;
for (final IRequest<? extends Stack> request : list) {
if (request.getRequest().getStack().sameItem(cure)) {
hasRequest = true;
break;
}
}
for (final IRequest<? extends Stack> request : completed) {
if (request.getRequest().getStack().sameItem(cure)) {
hasRequest = true;
break;
}
}
if (!hasRequest) {
worker.getCitizenData().createRequestAsync(new Stack(cure, REQUEST_COUNT, 1));
}
}
}
currentPatient.setState(Patient.PatientState.REQUESTED);
currentPatient = null;
return DECIDE;
}
Aggregations