Search in sources :

Example 6 with BuildingGraveyard

use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingGraveyard in project minecolonies by Minecolonies.

the class EntityAIWorkUndertaker method tryResurrect.

/**
 * Attempt to resurrect buried citizen from its citizen data
 * Randomize to see if resurrection successful and resurrect if need be
 *
 * @return the next IAIState
 */
private IAIState tryResurrect() {
    @Nullable final BuildingGraveyard buildingGraveyard = building;
    if (checkForToolOrWeapon(ToolType.SHOVEL) || buildingGraveyard.getFirstModuleOccurance(GraveyardManagementModule.class).getLastGraveData() == null || buildingGraveyard.getGraveToWorkOn() == null) {
        return IDLE;
    }
    unequip();
    @Nullable final BlockPos gravePos = buildingGraveyard.getGraveToWorkOn();
    if (gravePos == null) {
        return IDLE;
    }
    // Still moving to the block
    if (walkToBlock(gravePos, 3)) {
        return getState();
    }
    final TileEntity entity = world.getBlockEntity(gravePos);
    if (entity instanceof TileEntityGrave) {
        if (effortCounter < EFFORT_RESURRECT) {
            worker.swing(Hand.MAIN_HAND);
            effortCounter += getSecondarySkillLevel();
            return getState();
        }
        effortCounter = 0;
        shouldDumpInventory = true;
        final double chance = getResurrectChance(buildingGraveyard);
        if (getTotemResurrectChance() > 0 && random.nextDouble() <= TOTEM_BREAK_CHANCE) {
            worker.getInventoryCitizen().extractItem(InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), Items.TOTEM_OF_UNDYING), 1, false);
            worker.playSound(SoundEvents.TOTEM_USE, 1.0f, 1.0f);
        }
        if (chance >= random.nextDouble()) {
            final ICitizenData citizenData = buildingGraveyard.getColony().getCitizenManager().resurrectCivilianData(buildingGraveyard.getFirstModuleOccurance(GraveyardManagementModule.class).getLastGraveData().getCitizenDataNBT(), true, world, gravePos);
            MessageUtils.format(MESSAGE_INFO_CITIZEN_UNDERTAKER_RESURRECTED_SUCCESS, citizenData.getName()).sendTo(buildingGraveyard.getColony()).forManagers();
            worker.getCitizenColonyHandler().getColony().getCitizenManager().updateCitizenMourn(citizenData, false);
            AdvancementUtils.TriggerAdvancementPlayersForColony(worker.getCitizenColonyHandler().getColony(), playerMP -> AdvancementTriggers.CITIZEN_RESURRECT.trigger(playerMP));
            buildingGraveyard.getFirstModuleOccurance(GraveyardManagementModule.class).setLastGraveData(null);
            world.setBlockAndUpdate(gravePos, Blocks.AIR.defaultBlockState());
            return INVENTORY_FULL;
        }
    }
    return DIG_GRAVE;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BuildingGraveyard(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingGraveyard) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave) Nullable(org.jetbrains.annotations.Nullable) GraveyardManagementModule(com.minecolonies.coremod.colony.buildings.modules.GraveyardManagementModule)

Example 7 with BuildingGraveyard

use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingGraveyard in project minecolonies by Minecolonies.

the class EntityAIMournCitizen method wanderAtGraveyard.

/**
 * Wander at the graveyard and visit the graves.
 * While wandering at the graveyard, the chance to stop mourning is doubled.
 * @return the next state to go to.
 */
private MourningState wanderAtGraveyard() {
    if (graveyard == null) {
        return MourningState.DECIDE;
    }
    // Double the chance to stop mourning by checking here as well.
    if (!shouldMourn()) {
        return MourningState.IDLE;
    }
    final IBuilding graveyardBuilding = citizen.getCitizenColonyHandler().getColony().getBuildingManager().getBuilding(graveyard);
    if (!(graveyardBuilding instanceof BuildingGraveyard)) {
        graveyard = null;
        return MourningState.DECIDE;
    }
    if (!citizen.getNavigation().isDone()) {
        return MourningState.WANDER_AT_GRAVEYARD;
    }
    // Wander around randomly.
    if (MathUtils.RANDOM.nextInt(100) < 90) {
        citizen.getNavigation().moveToRandomPos(10, DEFAULT_SPEED, graveyardBuilding.getCorners(), AbstractAdvancedPathNavigate.RestrictionType.XYZ);
        return MourningState.WANDER_AT_GRAVEYARD;
    }
    // Try find the grave of one of the diseased.
    final Set<Tuple<BlockPos, Direction>> gravePositions = ((BuildingGraveyard) graveyardBuilding).getGravePositions();
    for (final Tuple<BlockPos, Direction> gravePos : gravePositions) {
        if (WorldUtil.isBlockLoaded(citizen.level, gravePos.getA())) {
            final TileEntity blockEntity = citizen.level.getBlockEntity(gravePos.getA());
            if (blockEntity instanceof TileEntityNamedGrave) {
                final Iterator<String> iterator = citizen.getCitizenData().getCitizenMournHandler().getDeceasedCitizens().iterator();
                if (!iterator.hasNext()) {
                    continue;
                }
                final String deathBud = iterator.next();
                final String firstName = StringUtils.split(deathBud)[0];
                final String lastName = deathBud.replaceFirst(firstName, "");
                final List<String> graveNameList = ((TileEntityNamedGrave) blockEntity).getTextLines();
                if (!graveNameList.isEmpty() && graveNameList.contains(firstName) && graveNameList.contains(lastName)) {
                    this.gravePos = gravePos.getA();
                    return MourningState.WALK_TO_GRAVE;
                }
            }
        }
    }
    return MourningState.DECIDE;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityNamedGrave(com.minecolonies.api.tileentities.TileEntityNamedGrave) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) BuildingGraveyard(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingGraveyard) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction)

Example 8 with BuildingGraveyard

use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingGraveyard in project minecolonies by ldtteam.

the class EntityAIWorkUndertaker method buryCitizen.

/**
 * The Undertaker search for an empty grave site in the graveyard and build a named graved with
 * the name of the citizen and its job as text
 *
 * @return the next IAIState
 */
private IAIState buryCitizen() {
    @Nullable final BuildingGraveyard buildingGraveyard = getOwnBuilding();
    final GraveyardManagementModule module = buildingGraveyard.getFirstModuleOccurance(GraveyardManagementModule.class);
    if (checkForToolOrWeapon(ToolType.SHOVEL) || module.getLastGraveData() == null) {
        return IDLE;
    }
    worker.getCitizenData().setVisibleStatus(BURYING_ICON);
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.burying"));
    if (burialPos == null || !world.getBlockState(burialPos.getA()).isAir()) {
        burialPos = getOwnBuilding().getRandomFreeVisualGravePos();
    }
    if (burialPos == null || burialPos.getA() == null) {
        // coudn't find a place to dig a grave
        LanguageHandler.sendPlayersMessage(buildingGraveyard.getColony().getImportantMessageEntityPlayers(), "com.minecolonies.coremod.nospaceforgrave", module.getLastGraveData().getCitizenName());
        return IDLE;
    }
    if (walkToBlock(burialPos.getA(), 3)) {
        return getState();
    }
    if (effortCounter < EFFORT_BURY) {
        equipShovel();
        worker.swing(Hand.MAIN_HAND);
        effortCounter += getPrimarySkillLevel();
        return getState();
    }
    effortCounter = 0;
    unequip();
    module.buryCitizenHere(burialPos);
    // Disabled until Mourning AI update: worker.getCitizenColonyHandler().getColony().setNeedToMourn(false, buildingGraveyard.getLastGraveData().getCitizenName());
    AdvancementUtils.TriggerAdvancementPlayersForColony(worker.getCitizenColonyHandler().getColony(), playerMP -> AdvancementTriggers.CITIZEN_BURY.trigger(playerMP));
    module.setLastGraveData(null);
    burialPos = null;
    shouldDumpInventory = true;
    return INVENTORY_FULL;
}
Also used : BuildingGraveyard(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingGraveyard) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Nullable(org.jetbrains.annotations.Nullable) GraveyardManagementModule(com.minecolonies.coremod.colony.buildings.modules.GraveyardManagementModule)

Example 9 with BuildingGraveyard

use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingGraveyard in project minecolonies by ldtteam.

the class EntityAIWorkUndertaker method digGrave.

/**
 * The undertaker dig (remove) the grave tile entity of a fallen citizen
 *
 * @return the next IAIState
 */
private IAIState digGrave() {
    @Nullable final BuildingGraveyard buildingGraveyard = getOwnBuilding();
    if (checkForToolOrWeapon(ToolType.SHOVEL) || buildingGraveyard.getGraveToWorkOn() == null) {
        return IDLE;
    }
    worker.getCitizenData().setVisibleStatus(DIGGING_ICON);
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.digging"));
    worker.setSprinting(worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(UNDERTAKER_RUN) > 0);
    @Nullable final BlockPos gravePos = buildingGraveyard.getGraveToWorkOn();
    if (gravePos == null) {
        return IDLE;
    }
    // Still moving to the block
    if (walkToBlock(gravePos, 3)) {
        return getState();
    }
    worker.setSprinting(false);
    final TileEntity entity = world.getBlockEntity(gravePos);
    if (entity instanceof TileEntityGrave) {
        // at position
        if (!digIfAble(gravePos)) {
            return getState();
        }
        worker.decreaseSaturationForAction();
        worker.getCitizenData().getCitizenSkillHandler().addXpToSkill(getModuleForJob().getPrimarySkill(), XP_PER_DIG, worker.getCitizenData());
        return BURY_CITIZEN;
    }
    return IDLE;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BuildingGraveyard(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingGraveyard) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

BuildingGraveyard (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingGraveyard)9 Nullable (org.jetbrains.annotations.Nullable)8 TileEntity (net.minecraft.tileentity.TileEntity)7 BlockPos (net.minecraft.util.math.BlockPos)7 TileEntityGrave (com.minecolonies.api.tileentities.TileEntityGrave)6 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)6 GraveyardManagementModule (com.minecolonies.coremod.colony.buildings.modules.GraveyardManagementModule)4 ICitizenData (com.minecolonies.api.colony.ICitizenData)2 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)1 TileEntityNamedGrave (com.minecolonies.api.tileentities.TileEntityNamedGrave)1 Direction (net.minecraft.util.Direction)1