Search in sources :

Example 1 with BuildingGraveyard

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

the class EntityAIWorkUndertaker method emptyGrave.

/**
 * The undertaker empty the inventory from a grave to the graveyard inventory
 * The undertake will make multiple trip if needed
 *
 * @return the next IAIState
 */
private IAIState emptyGrave() {
    @Nullable final BuildingGraveyard buildingGraveyard = getOwnBuilding();
    if (buildingGraveyard == null || checkForToolOrWeapon(ToolType.SHOVEL) || buildingGraveyard.getGraveToWorkOn() == null) {
        return IDLE;
    }
    worker.getCitizenData().setVisibleStatus(EMPTYING_ICON);
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.emptying"));
    worker.setSprinting(worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(UNDERTAKER_RUN) > 0);
    unequip();
    @Nullable final BlockPos gravePos = buildingGraveyard.getGraveToWorkOn();
    // Still moving to the block
    if (walkToBlock(gravePos, 3)) {
        return getState();
    }
    final TileEntity entity = world.getBlockEntity(gravePos);
    if (entity instanceof TileEntityGrave) {
        if (((TileEntityGrave) entity).isEmpty()) {
            return TRY_RESURRECT;
        }
        if (worker.getInventoryCitizen().isFull()) {
            return INVENTORY_FULL;
        }
        if (effortCounter < EFFORT_EMPTY_GRAVE) {
            worker.swing(Hand.MAIN_HAND);
            effortCounter += getPrimarySkillLevel();
            return getState();
        }
        effortCounter = 0;
        // at position - try to take all item
        if (InventoryUtils.transferAllItemHandler(((TileEntityGrave) entity).getInventory(), worker.getInventoryCitizen())) {
            return TRY_RESURRECT;
        }
    }
    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)

Example 2 with BuildingGraveyard

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

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 = getOwnBuilding();
    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);
            LanguageHandler.sendPlayersMessage(buildingGraveyard.getColony().getImportantMessageEntityPlayers(), "com.minecolonies.coremod.resurrect", citizenData.getName());
            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 3 with BuildingGraveyard

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

the class EntityAIWorkUndertaker method emptyGrave.

/**
 * The undertaker empty the inventory from a grave to the graveyard inventory
 * The undertake will make multiple trip if needed
 *
 * @return the next IAIState
 */
private IAIState emptyGrave() {
    @Nullable final BuildingGraveyard buildingGraveyard = building;
    if (buildingGraveyard == null || checkForToolOrWeapon(ToolType.SHOVEL) || buildingGraveyard.getGraveToWorkOn() == null) {
        return IDLE;
    }
    worker.getCitizenData().setVisibleStatus(EMPTYING_ICON);
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(MESSAGE_INFO_CITIZEN_STATUS_UNDERTAKER_EMPTYING));
    worker.setSprinting(worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(UNDERTAKER_RUN) > 0);
    unequip();
    @Nullable final BlockPos gravePos = buildingGraveyard.getGraveToWorkOn();
    // Still moving to the block
    if (walkToBlock(gravePos, 3)) {
        return getState();
    }
    final TileEntity entity = world.getBlockEntity(gravePos);
    if (entity instanceof TileEntityGrave) {
        if (((TileEntityGrave) entity).isEmpty()) {
            return TRY_RESURRECT;
        }
        if (worker.getInventoryCitizen().isFull()) {
            return INVENTORY_FULL;
        }
        if (effortCounter < EFFORT_EMPTY_GRAVE) {
            worker.swing(Hand.MAIN_HAND);
            effortCounter += getPrimarySkillLevel();
            return getState();
        }
        effortCounter = 0;
        // at position - try to take all item
        if (InventoryUtils.transferAllItemHandler(((TileEntityGrave) entity).getInventory(), worker.getInventoryCitizen())) {
            return TRY_RESURRECT;
        }
    }
    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)

Example 4 with BuildingGraveyard

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

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 = building;
    if (checkForToolOrWeapon(ToolType.SHOVEL) || buildingGraveyard.getGraveToWorkOn() == null) {
        return IDLE;
    }
    worker.getCitizenData().setVisibleStatus(DIGGING_ICON);
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(MESSAGE_INFO_CITIZEN_STATUS_UNDERTAKER_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)

Example 5 with BuildingGraveyard

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

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 = building;
    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(MESSAGE_INFO_CITIZEN_UNDERTAKER_BURYING));
    if (burialPos == null || !world.getBlockState(burialPos.getA()).isAir()) {
        burialPos = building.getRandomFreeVisualGravePos();
    }
    if (burialPos == null || burialPos.getA() == null) {
        // couldn't find a place to dig a grave
        worker.getCitizenChatHandler().sendLocalizedChat(new TranslationTextComponent(MESSAGE_INFO_CITIZEN_UNDERTAKER_GRAVEYARD_NO_SPACE, 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)

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