use of com.minecolonies.coremod.network.messages.client.CircleParticleEffectMessage in project minecolonies by Minecolonies.
the class EntityAIWorkEnchanter method enchant.
/**
* Actually do the enchanting. Making some great effects for some time and then apply a random enchantment. Reduce own levels depending on the found enchantment.
*
* @return the next state to go to.
*/
private IAIState enchant() {
// this assumes that the only empty-output (pure loot table) recipes are for ancient tome -> enchanted book
currentRecipeStorage = building.getFirstModuleOccurance(BuildingEnchanter.CraftingModule.class).getFirstFulfillableRecipe(ItemStackUtils::isEmpty, 1, false);
if (currentRecipeStorage == null) {
progressTicks = 0;
return DECIDE;
}
if (progressTicks++ < MAX_ENCHANTMENT_TICKS / building.getBuildingLevel()) {
Network.getNetwork().sendToTrackingEntity(new CircleParticleEffectMessage(worker.position().add(0, 2, 0), ParticleTypes.ENCHANT, progressTicks), worker);
Network.getNetwork().sendToTrackingEntity(new CircleParticleEffectMessage(worker.position().add(0, 1.5, 0), ParticleTypes.ENCHANT, progressTicks), worker);
Network.getNetwork().sendToTrackingEntity(new CircleParticleEffectMessage(worker.position().add(0, 1, 0), ParticleTypes.ENCHANT, progressTicks), worker);
if (worker.getRandom().nextBoolean()) {
worker.swing(Hand.MAIN_HAND);
} else {
worker.swing(Hand.OFF_HAND);
}
return getState();
}
final ICitizenData data = worker.getCitizenData();
if (data != null) {
final List<ItemStack> loot = currentRecipeStorage.fullfillRecipeAndCopy(getLootContext(), building.getHandlers(), true);
if (loot != null) {
final int enchantmentLevel = loot.stream().mapToInt(EntityAIWorkEnchanter::getEnchantedBookLevel).max().orElse(0);
// Decrement mana.
data.getCitizenSkillHandler().incrementLevel(Skill.Mana, -enchantmentLevel);
incrementActionsDoneAndDecSaturation();
}
}
currentRecipeStorage = null;
progressTicks = 0;
return IDLE;
}
use of com.minecolonies.coremod.network.messages.client.CircleParticleEffectMessage in project minecolonies by ldtteam.
the class EntityAISickTask method applyCure.
/**
* Actual action of eating.
*
* @return the next state to go to, if successful idle.
*/
private DiseaseState applyCure() {
if (checkForCure() != APPLY_CURE) {
return CHECK_FOR_CURE;
}
final List<ItemStack> list = IColonyManager.getInstance().getCompatibilityManager().getDisease(citizen.getCitizenDiseaseHandler().getDisease()).getCure();
citizen.setItemInHand(Hand.MAIN_HAND, list.get(citizen.getRandom().nextInt(list.size())));
citizen.swing(Hand.MAIN_HAND);
citizen.playSound(SoundEvents.NOTE_BLOCK_HARP, (float) BASIC_VOLUME, (float) SoundUtils.getRandomPentatonic(citizen.getRandom()));
Network.getNetwork().sendToTrackingEntity(new CircleParticleEffectMessage(citizen.position().add(0, 2, 0), ParticleTypes.HAPPY_VILLAGER, waitingTicks), citizen);
waitingTicks++;
if (waitingTicks < REQUIRED_TIME_TO_CURE) {
return APPLY_CURE;
}
cure();
return IDLE;
}
use of com.minecolonies.coremod.network.messages.client.CircleParticleEffectMessage in project minecolonies by ldtteam.
the class EntityAIWorkPupil method study.
/**
* Sit down a bit and study. If has paper consume it.
*
* @return next state to go to.
*/
private IAIState study() {
if (studyPos == null) {
return DECIDE;
}
if (walkToBlock(studyPos)) {
return getState();
}
if (!world.getLoadedEntitiesOfClass(EntityCitizen.class, new AxisAlignedBB(studyPos.getX(), studyPos.getY(), studyPos.getZ(), studyPos.getX(), studyPos.getY(), studyPos.getZ())).isEmpty()) {
studyPos = null;
return DECIDE;
}
if (sittingTicks == 0 || worker.vehicle == null) {
// Sit for 60-120 seconds.
maxSittingTicks = worker.getRandom().nextInt(120 / 2) + 60;
SittingEntity.sitDown(studyPos, worker, maxSittingTicks * 20);
}
final int slot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), PAPER);
if (slot != -1) {
worker.setItemSlot(EquipmentSlotType.MAINHAND, worker.getInventoryCitizen().getStackInSlot(slot));
Network.getNetwork().sendToTrackingEntity(new CircleParticleEffectMessage(worker.position().add(0, 1, 0), ParticleTypes.ENCHANT, sittingTicks), worker);
} else {
worker.setItemSlot(EquipmentSlotType.MAINHAND, ItemStack.EMPTY);
Network.getNetwork().sendToTrackingEntity(new CircleParticleEffectMessage(worker.position().add(0, 1, 0), ParticleTypes.HAPPY_VILLAGER, sittingTicks), worker);
}
sittingTicks++;
if (sittingTicks < maxSittingTicks) {
return getState();
}
worker.setItemSlot(EquipmentSlotType.MAINHAND, ItemStack.EMPTY);
if (worker.vehicle != null) {
worker.stopRiding();
worker.setPos(worker.getX(), worker.getY() + 1, worker.getZ());
}
if (slot != -1) {
InventoryUtils.reduceStackInItemHandler(worker.getInventoryCitizen(), new ItemStack(Items.PAPER), 1);
final double bonus = 50.0 * (1 + worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(TEACHING));
worker.getCitizenData().getCitizenSkillHandler().addXpToSkill(Skill.Intelligence, bonus, worker.getCitizenData());
}
worker.decreaseSaturationForContinuousAction();
maxSittingTicks = 0;
sittingTicks = 0;
return null;
}
use of com.minecolonies.coremod.network.messages.client.CircleParticleEffectMessage in project minecolonies by ldtteam.
the class EntityAIWorkEnchanter method enchant.
/**
* Actually do the enchanting. Making some great effects for some time and then apply a random enchantment. Reduce own levels depending on the found enchantment.
*
* @return the next state to go to.
*/
private IAIState enchant() {
// this assumes that the only empty-output (pure loot table) recipes are for ancient tome -> enchanted book
currentRecipeStorage = getOwnBuilding().getFirstModuleOccurance(BuildingEnchanter.CraftingModule.class).getFirstFulfillableRecipe(ItemStackUtils::isEmpty, 1, false);
if (currentRecipeStorage == null) {
progressTicks = 0;
return DECIDE;
}
if (progressTicks++ < MAX_ENCHANTMENT_TICKS / getOwnBuilding().getBuildingLevel()) {
Network.getNetwork().sendToTrackingEntity(new CircleParticleEffectMessage(worker.position().add(0, 2, 0), ParticleTypes.ENCHANT, progressTicks), worker);
Network.getNetwork().sendToTrackingEntity(new CircleParticleEffectMessage(worker.position().add(0, 1.5, 0), ParticleTypes.ENCHANT, progressTicks), worker);
Network.getNetwork().sendToTrackingEntity(new CircleParticleEffectMessage(worker.position().add(0, 1, 0), ParticleTypes.ENCHANT, progressTicks), worker);
if (worker.getRandom().nextBoolean()) {
worker.swing(Hand.MAIN_HAND);
} else {
worker.swing(Hand.OFF_HAND);
}
return getState();
}
final ICitizenData data = worker.getCitizenData();
if (data != null) {
final List<ItemStack> loot = currentRecipeStorage.fullfillRecipeAndCopy(getLootContext(), getOwnBuilding().getHandlers(), true);
if (loot != null) {
final int enchantmentLevel = loot.stream().mapToInt(EntityAIWorkEnchanter::getEnchantedBookLevel).max().orElse(0);
// Decrement mana.
data.getCitizenSkillHandler().incrementLevel(Skill.Mana, -enchantmentLevel);
incrementActionsDoneAndDecSaturation();
}
}
currentRecipeStorage = null;
progressTicks = 0;
return IDLE;
}
use of com.minecolonies.coremod.network.messages.client.CircleParticleEffectMessage 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;
}
Aggregations