Search in sources :

Example 41 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by ldtteam.

the class EntityAIQuarrier method executeSpecificCompleteActions.

@Override
public void executeSpecificCompleteActions() {
    super.executeSpecificCompleteActions();
    final IBuilding quarry = job.findQuarry();
    if (quarry != null) {
        quarry.getFirstModuleOccurance(QuarryModule.class).setFinished();
    }
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) QuarryModule(com.minecolonies.coremod.colony.buildings.modules.QuarryModule)

Example 42 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by ldtteam.

the class EntityAIQuarrier method startWorkingAtOwnBuilding.

// Miner wants to work but is not at building
@NotNull
private IAIState startWorkingAtOwnBuilding() {
    worker.getCitizenData().setVisibleStatus(VisibleCitizenStatus.WORKING);
    final IBuilding quarry = job.findQuarry();
    if (quarry == null) {
        walkToBuilding();
        worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(QUARRY_MINER_NO_QUARRY), ChatPriority.BLOCKING));
        return IDLE;
    }
    if (quarry.getFirstModuleOccurance(QuarryModule.class).isFinished()) {
        walkToBuilding();
        worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(QUARRY_MINER_FINISHED_QUARRY), ChatPriority.BLOCKING));
        return IDLE;
    }
    if (walkToBlock(quarry.getPosition())) {
        return getState();
    }
    // Miner is at building
    return LOAD_STRUCTURE;
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) QuarryModule(com.minecolonies.coremod.colony.buildings.modules.QuarryModule) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) NotNull(org.jetbrains.annotations.NotNull)

Example 43 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by ldtteam.

the class EntityAISickTask method cure.

/**
 * Cure the citizen.
 */
private void cure() {
    final Disease disease = IColonyManager.getInstance().getCompatibilityManager().getDisease(citizen.getCitizenDiseaseHandler().getDisease());
    if (disease != null) {
        for (final ItemStack cure : disease.getCure()) {
            final int slot = InventoryUtils.findFirstSlotInProviderNotEmptyWith(citizen, stack -> stack.sameItem(cure));
            if (slot != -1) {
                citizenData.getInventory().extractItem(slot, 1, false);
            }
        }
    }
    if (usedBed != null) {
        final BlockPos hospitalPos = citizen.getCitizenColonyHandler().getColony().getBuildingManager().getBestBuilding(citizen, BuildingHospital.class);
        final IColony colony = citizen.getCitizenColonyHandler().getColony();
        final IBuilding hospital = colony.getBuildingManager().getBuilding(hospitalPos);
        ((BuildingHospital) hospital).registerPatient(usedBed, 0);
        usedBed = null;
        citizen.getCitizenData().setBedPos(BlockPos.ZERO);
    }
    citizen.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
    citizenData.markDirty();
    citizen.getCitizenDiseaseHandler().cure();
    citizen.setHealth(citizen.getMaxHealth());
    reset();
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) BuildingHospital(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingHospital) IColony(com.minecolonies.api.colony.IColony) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 44 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by ldtteam.

the class EntityAISickTask method waitForCure.

/**
 * Stay in bed while waiting to be cured.
 *
 * @return the next state to go to.
 */
private DiseaseState waitForCure() {
    final IColony colony = citizenData.getColony();
    placeToPath = colony.getBuildingManager().getBestBuilding(citizen, BuildingHospital.class);
    if (placeToPath == null) {
        return SEARCH_HOSPITAL;
    }
    final DiseaseState state = checkForCure();
    if (state == APPLY_CURE) {
        return APPLY_CURE;
    } else if (state == IDLE) {
        reset();
        return IDLE;
    }
    if (citizen.getRandom().nextInt(10000) < CHANCE_FOR_RANDOM_CURE) {
        cure();
        return IDLE;
    }
    if (citizen.getCitizenSleepHandler().isAsleep()) {
        final BlockPos hospital = colony.getBuildingManager().getBestBuilding(citizen, BuildingHospital.class);
        if (hospital != null) {
            final IBuilding building = colony.getBuildingManager().getBuilding(hospital);
            if (building instanceof BuildingHospital && !((BuildingHospital) building).getBedList().contains(citizen.getCitizenSleepHandler().getBedLocation())) {
                citizen.getCitizenSleepHandler().onWakeUp();
            }
        }
    }
    if (!citizen.getCitizenSleepHandler().isAsleep() && BlockPosUtil.getDistance2D(placeToPath, citizen.blockPosition()) > MINIMUM_DISTANCE_TO_HOSPITAL) {
        return GO_TO_HOSPITAL;
    }
    if (!citizen.getCitizenSleepHandler().isAsleep()) {
        return FIND_EMPTY_BED;
    }
    return WAIT_FOR_CURE;
}
Also used : BuildingHospital(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingHospital) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) IColony(com.minecolonies.api.colony.IColony) BlockPos(net.minecraft.util.math.BlockPos) DiseaseState(com.minecolonies.coremod.entity.ai.minimal.EntityAISickTask.DiseaseState)

Example 45 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by ldtteam.

the class CitizenExperienceHandler method addExperience.

@Override
public void addExperience(final double xp) {
    final IBuilding home = citizen.getCitizenColonyHandler().getHomeBuilding();
    final double citizenHutLevel = home == null ? 0 : home.getBuildingLevel();
    final ICitizenData data = citizen.getCitizenData();
    final IBuilding workBuilding = data.getWorkBuilding();
    if (workBuilding == null || !workBuilding.hasModule(WorkerBuildingModule.class)) {
        return;
    }
    final double workBuildingLevel = workBuilding.getBuildingLevel();
    final double buildingXPModifier = 1 + (workBuildingLevel + citizenHutLevel) / 10;
    double localXp = xp * buildingXPModifier;
    final double saturation = citizen.getCitizenData().getSaturation();
    final int intelligenceLevel = data.getCitizenSkillHandler().getLevel(Skill.Intelligence);
    localXp += localXp * (intelligenceLevel / 100.0);
    if (saturation <= 0) {
        return;
    }
    localXp *= (1 + citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(LEVELING));
    localXp = citizen.getCitizenItemHandler().applyMending(localXp);
    final WorkerBuildingModule module = workBuilding.getModuleMatching(WorkerBuildingModule.class, m -> m.getAssignedCitizen().contains(data));
    final Skill primary = module.getPrimarySkill();
    final Skill secondary = module.getSecondarySkill();
    data.getCitizenSkillHandler().addXpToSkill(primary, localXp, data);
    data.getCitizenSkillHandler().addXpToSkill(primary.getComplimentary(), localXp / (100.0 / PRIMARY_DEPENDENCY_SHARE), data);
    data.getCitizenSkillHandler().removeXpFromSkill(primary.getAdverse(), localXp / (100.0 / PRIMARY_DEPENDENCY_SHARE), data);
    data.getCitizenSkillHandler().addXpToSkill(secondary, localXp / 2.0, data);
    data.getCitizenSkillHandler().addXpToSkill(secondary.getComplimentary(), localXp / (100.0 / SECONDARY_DEPENDENCY_SHARE), data);
    data.getCitizenSkillHandler().removeXpFromSkill(secondary.getAdverse(), localXp / (100.0 / SECONDARY_DEPENDENCY_SHARE), data);
}
Also used : Skill(com.minecolonies.api.entity.citizen.Skill) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Aggregations

IBuilding (com.minecolonies.api.colony.buildings.IBuilding)187 BlockPos (net.minecraft.util.math.BlockPos)71 NotNull (org.jetbrains.annotations.NotNull)45 IColony (com.minecolonies.api.colony.IColony)37 Nullable (org.jetbrains.annotations.Nullable)26 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)24 ICitizenData (com.minecolonies.api.colony.ICitizenData)22 World (net.minecraft.world.World)20 ItemStack (net.minecraft.item.ItemStack)19 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)19 TileEntity (net.minecraft.tileentity.TileEntity)17 CompoundNBT (net.minecraft.nbt.CompoundNBT)15 ArrayList (java.util.ArrayList)14 AbstractBuildingGuards (com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards)10 ItemStorage (com.minecolonies.api.crafting.ItemStorage)9 ResourceLocation (net.minecraft.util.ResourceLocation)9 IItemHandler (net.minecraftforge.items.IItemHandler)9 InventoryUtils (com.minecolonies.api.util.InventoryUtils)8 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)8 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)8