use of com.minecolonies.api.tileentities.TileEntityGrave 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.api.tileentities.TileEntityGrave 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;
}
use of com.minecolonies.api.tileentities.TileEntityGrave in project minecolonies by Minecolonies.
the class GraveyardManagementModule method serializeToView.
@Override
public void serializeToView(@NotNull final PacketBuffer buf) {
final IColony colony = building.getColony();
final List<BlockPos> graves = new ArrayList<>(colony.getGraveManager().getGraves().keySet());
final List<BlockPos> cleanList = new ArrayList<>();
for (@NotNull final BlockPos grave : graves) {
if (WorldUtil.isBlockLoaded(colony.getWorld(), grave)) {
final TileEntity tileEntity = colony.getWorld().getBlockEntity(grave);
if (tileEntity instanceof TileEntityGrave) {
cleanList.add(grave);
}
}
}
// grave list
buf.writeInt(cleanList.size());
for (@NotNull final BlockPos grave : cleanList) {
buf.writeBlockPos(grave);
}
// resting citizen list
buf.writeInt(restingCitizen.size());
for (@NotNull final String citizenName : restingCitizen) {
buf.writeUtf(citizenName);
}
}
use of com.minecolonies.api.tileentities.TileEntityGrave in project minecolonies by Minecolonies.
the class GravePlacementHandler method handle.
@Override
public ActionProcessingResult handle(@NotNull final World world, @NotNull final BlockPos pos, @NotNull final BlockState blockState, @Nullable final CompoundNBT tileEntityData, final boolean complete, final BlockPos centerPos, final PlacementSettings settings) {
if (world.getBlockState(pos).getBlock() == ModBlocks.blockGrave) {
return ActionProcessingResult.SUCCESS;
}
world.setBlock(pos, blockState, UPDATE_FLAG);
if (tileEntityData != null) {
handleTileEntityPlacement(tileEntityData, world, pos, settings);
}
TileEntity entity = world.getBlockEntity(pos);
if (entity instanceof TileEntityGrave) {
((TileEntityGrave) entity).updateBlockState();
}
return ActionProcessingResult.SUCCESS;
}
use of com.minecolonies.api.tileentities.TileEntityGrave in project minecolonies by Minecolonies.
the class BlockMinecoloniesGrave method use.
@Override
public ActionResultType use(final BlockState state, final World worldIn, final BlockPos pos, final PlayerEntity player, final Hand hand, final BlockRayTraceResult ray) {
final IColony colony = IColonyManager.getInstance().getColonyByPosFromWorld(worldIn, pos);
final TileEntity tileEntity = worldIn.getBlockEntity(pos);
if ((colony == null || colony.getPermissions().hasPermission(player, Action.ACCESS_HUTS)) && tileEntity instanceof TileEntityGrave) {
final TileEntityGrave grave = (TileEntityGrave) tileEntity;
if (!worldIn.isClientSide) {
NetworkHooks.openGui((ServerPlayerEntity) player, grave, buf -> buf.writeBlockPos(grave.getBlockPos()));
}
return ActionResultType.SUCCESS;
}
return ActionResultType.FAIL;
}
Aggregations