use of com.minecolonies.coremod.network.messages.client.StreamParticleEffectMessage in project minecolonies by Minecolonies.
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.network.messages.client.StreamParticleEffectMessage in project minecolonies by Minecolonies.
the class EntityAIWorkEnchanter method gatherAndDrain.
/**
* Gather experience from a worker. Go to the hut of the worker. Wait for the worker. Drain, and then return to work building.
*
* @return next state to go to.
*/
private IAIState gatherAndDrain() {
if (job.getPosToDrainFrom() == null) {
return IDLE;
}
if (walkToBlock(job.getPosToDrainFrom())) {
return getState();
}
final AbstractBuilding buildingWorker = getOwnBuilding().getColony().getBuildingManager().getBuilding(job.getPosToDrainFrom(), AbstractBuilding.class);
if (buildingWorker == null) {
resetDraining();
getOwnBuilding().getFirstModuleOccurance(EnchanterStationsModule.class).removeWorker(job.getPosToDrainFrom());
return IDLE;
}
if (citizenToGatherFrom == null) {
final List<AbstractEntityCitizen> workers = new ArrayList<>();
for (final Optional<AbstractEntityCitizen> citizen : getModuleForJob().getAssignedEntities()) {
citizen.ifPresent(workers::add);
}
final AbstractEntityCitizen citizen;
if (workers.size() > 1) {
citizen = workers.get(worker.getRandom().nextInt(workers.size()));
} else {
if (workers.isEmpty()) {
resetDraining();
return DECIDE;
}
citizen = workers.get(0);
}
citizenToGatherFrom = citizen.getCitizenData();
progressTicks = 0;
return getState();
}
if (!citizenToGatherFrom.getEntity().isPresent()) {
citizenToGatherFrom = null;
return getState();
}
if (progressTicks == 0) {
// If worker is too far away wait.
if (BlockPosUtil.getDistance2D(citizenToGatherFrom.getEntity().get().blockPosition(), worker.blockPosition()) > MIN_DISTANCE_TO_DRAIN) {
if (!job.incrementWaitingTicks()) {
resetDraining();
return DECIDE;
}
return getState();
}
}
progressTicks++;
if (progressTicks < MAX_PROGRESS_TICKS) {
final Vector3d start = worker.position().add(0, 2, 0);
final Vector3d goal = citizenToGatherFrom.getEntity().get().position().add(0, 2, 0);
Network.getNetwork().sendToTrackingEntity(new StreamParticleEffectMessage(start, goal, ParticleTypes.ENCHANT, progressTicks % MAX_PROGRESS_TICKS, MAX_PROGRESS_TICKS), worker);
Network.getNetwork().sendToTrackingEntity(new CircleParticleEffectMessage(start, ParticleTypes.HAPPY_VILLAGER, progressTicks), worker);
WorkerUtil.faceBlock(new BlockPos(goal), worker);
if (worker.getRandom().nextBoolean()) {
worker.swing(Hand.MAIN_HAND);
} else {
worker.swing(Hand.OFF_HAND);
}
return getState();
}
final int bookSlot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), Items.BOOK);
if (bookSlot != -1) {
final int size = citizenToGatherFrom.getInventory().getSlots();
final int attempts = (int) (getSecondarySkillLevel() / 5.0);
for (int i = 0; i < attempts; i++) {
int randomSlot = worker.getRandom().nextInt(size);
final ItemStack stack = citizenToGatherFrom.getInventory().getStackInSlot(randomSlot);
if (!stack.isEmpty() && stack.isEnchantable()) {
EnchantmentHelper.enchantItem(worker.getRandom(), stack, getSecondarySkillLevel() > 50 ? 2 : 1, false);
break;
}
}
worker.getInventoryCitizen().extractItem(bookSlot, 1, false);
worker.getCitizenData().getCitizenSkillHandler().incrementLevel(Skill.Mana, 1);
worker.getCitizenExperienceHandler().addExperience(XP_PER_DRAIN);
worker.getCitizenData().markDirty();
}
resetDraining();
return IDLE;
}
use of com.minecolonies.coremod.network.messages.client.StreamParticleEffectMessage in project minecolonies by ldtteam.
the class EntityAIWorkEnchanter method gatherAndDrain.
/**
* Gather experience from a worker. Go to the hut of the worker. Wait for the worker. Drain, and then return to work building.
*
* @return next state to go to.
*/
private IAIState gatherAndDrain() {
if (job.getPosToDrainFrom() == null) {
return IDLE;
}
if (walkToBlock(job.getPosToDrainFrom())) {
return getState();
}
final AbstractBuilding buildingWorker = getOwnBuilding().getColony().getBuildingManager().getBuilding(job.getPosToDrainFrom(), AbstractBuilding.class);
if (buildingWorker == null) {
resetDraining();
getOwnBuilding().getFirstModuleOccurance(EnchanterStationsModule.class).removeWorker(job.getPosToDrainFrom());
return IDLE;
}
if (citizenToGatherFrom == null) {
final List<AbstractEntityCitizen> workers = new ArrayList<>();
for (final Optional<AbstractEntityCitizen> citizen : getModuleForJob().getAssignedEntities()) {
citizen.ifPresent(workers::add);
}
final AbstractEntityCitizen citizen;
if (workers.size() > 1) {
citizen = workers.get(worker.getRandom().nextInt(workers.size()));
} else {
if (workers.isEmpty()) {
resetDraining();
return DECIDE;
}
citizen = workers.get(0);
}
citizenToGatherFrom = citizen.getCitizenData();
progressTicks = 0;
return getState();
}
if (!citizenToGatherFrom.getEntity().isPresent()) {
citizenToGatherFrom = null;
return getState();
}
if (progressTicks == 0) {
// If worker is too far away wait.
if (BlockPosUtil.getDistance2D(citizenToGatherFrom.getEntity().get().blockPosition(), worker.blockPosition()) > MIN_DISTANCE_TO_DRAIN) {
if (!job.incrementWaitingTicks()) {
resetDraining();
return DECIDE;
}
return getState();
}
}
progressTicks++;
if (progressTicks < MAX_PROGRESS_TICKS) {
final Vector3d start = worker.position().add(0, 2, 0);
final Vector3d goal = citizenToGatherFrom.getEntity().get().position().add(0, 2, 0);
Network.getNetwork().sendToTrackingEntity(new StreamParticleEffectMessage(start, goal, ParticleTypes.ENCHANT, progressTicks % MAX_PROGRESS_TICKS, MAX_PROGRESS_TICKS), worker);
Network.getNetwork().sendToTrackingEntity(new CircleParticleEffectMessage(start, ParticleTypes.HAPPY_VILLAGER, progressTicks), worker);
WorkerUtil.faceBlock(new BlockPos(goal), worker);
if (worker.getRandom().nextBoolean()) {
worker.swing(Hand.MAIN_HAND);
} else {
worker.swing(Hand.OFF_HAND);
}
return getState();
}
final int bookSlot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), Items.BOOK);
if (bookSlot != -1) {
final int size = citizenToGatherFrom.getInventory().getSlots();
final int attempts = (int) (getSecondarySkillLevel() / 5.0);
for (int i = 0; i < attempts; i++) {
int randomSlot = worker.getRandom().nextInt(size);
final ItemStack stack = citizenToGatherFrom.getInventory().getStackInSlot(randomSlot);
if (!stack.isEmpty() && stack.isEnchantable()) {
EnchantmentHelper.enchantItem(worker.getRandom(), stack, getSecondarySkillLevel() > 50 ? 2 : 1, false);
break;
}
}
worker.getInventoryCitizen().extractItem(bookSlot, 1, false);
worker.getCitizenData().getCitizenSkillHandler().incrementLevel(Skill.Mana, 1);
worker.getCitizenExperienceHandler().addExperience(XP_PER_DRAIN);
worker.getCitizenData().markDirty();
}
resetDraining();
return IDLE;
}
use of com.minecolonies.coremod.network.messages.client.StreamParticleEffectMessage 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;
}
Aggregations