Search in sources :

Example 1 with StreamParticleEffectMessage

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;
}
Also used : StreamParticleEffectMessage(com.minecolonies.coremod.network.messages.client.StreamParticleEffectMessage) ICitizenData(com.minecolonies.api.colony.ICitizenData) CircleParticleEffectMessage(com.minecolonies.coremod.network.messages.client.CircleParticleEffectMessage) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen)

Example 2 with StreamParticleEffectMessage

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;
}
Also used : StreamParticleEffectMessage(com.minecolonies.coremod.network.messages.client.StreamParticleEffectMessage) EnchanterStationsModule(com.minecolonies.coremod.colony.buildings.modules.EnchanterStationsModule) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) ArrayList(java.util.ArrayList) Vector3d(net.minecraft.util.math.vector.Vector3d) CircleParticleEffectMessage(com.minecolonies.coremod.network.messages.client.CircleParticleEffectMessage) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 3 with StreamParticleEffectMessage

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;
}
Also used : StreamParticleEffectMessage(com.minecolonies.coremod.network.messages.client.StreamParticleEffectMessage) EnchanterStationsModule(com.minecolonies.coremod.colony.buildings.modules.EnchanterStationsModule) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) ArrayList(java.util.ArrayList) Vector3d(net.minecraft.util.math.vector.Vector3d) CircleParticleEffectMessage(com.minecolonies.coremod.network.messages.client.CircleParticleEffectMessage) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 4 with StreamParticleEffectMessage

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;
}
Also used : StreamParticleEffectMessage(com.minecolonies.coremod.network.messages.client.StreamParticleEffectMessage) ICitizenData(com.minecolonies.api.colony.ICitizenData) CircleParticleEffectMessage(com.minecolonies.coremod.network.messages.client.CircleParticleEffectMessage) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) EntityCitizen(com.minecolonies.coremod.entity.citizen.EntityCitizen)

Aggregations

AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)4 CircleParticleEffectMessage (com.minecolonies.coremod.network.messages.client.CircleParticleEffectMessage)4 StreamParticleEffectMessage (com.minecolonies.coremod.network.messages.client.StreamParticleEffectMessage)4 ICitizenData (com.minecolonies.api.colony.ICitizenData)2 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)2 EnchanterStationsModule (com.minecolonies.coremod.colony.buildings.modules.EnchanterStationsModule)2 EntityCitizen (com.minecolonies.coremod.entity.citizen.EntityCitizen)2 ArrayList (java.util.ArrayList)2 ItemStack (net.minecraft.item.ItemStack)2 BlockPos (net.minecraft.util.math.BlockPos)2 Vector3d (net.minecraft.util.math.vector.Vector3d)2