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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations