Search in sources :

Example 16 with TileEntityGrave

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;
}
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 17 with TileEntityGrave

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;
}
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 18 with TileEntityGrave

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);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IColony(com.minecolonies.api.colony.IColony) BlockPos(net.minecraft.util.math.BlockPos) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with TileEntityGrave

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave)

Example 20 with TileEntityGrave

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IColony(com.minecolonies.api.colony.IColony) AbstractTileEntityGrave(com.minecolonies.api.tileentities.AbstractTileEntityGrave) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave)

Aggregations

TileEntityGrave (com.minecolonies.api.tileentities.TileEntityGrave)30 TileEntity (net.minecraft.tileentity.TileEntity)28 BlockPos (net.minecraft.util.math.BlockPos)18 Nullable (org.jetbrains.annotations.Nullable)10 AbstractTileEntityGrave (com.minecolonies.api.tileentities.AbstractTileEntityGrave)8 IColony (com.minecolonies.api.colony.IColony)6 BuildingGraveyard (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingGraveyard)6 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)6 NotNull (org.jetbrains.annotations.NotNull)6 ICitizenData (com.minecolonies.api.colony.ICitizenData)4 GraveyardManagementModule (com.minecolonies.coremod.colony.buildings.modules.GraveyardManagementModule)4 BlockState (net.minecraft.block.BlockState)4 World (net.minecraft.world.World)4 Pane (com.ldtteam.blockout.Pane)2 ScrollingList (com.ldtteam.blockout.views.ScrollingList)2 ModBlocks (com.minecolonies.api.blocks.ModBlocks)2 GraveData (com.minecolonies.api.colony.GraveData)2 IGraveManager (com.minecolonies.api.colony.managers.interfaces.IGraveManager)2 MAX_TICKRATE (com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickRateConstants.MAX_TICKRATE)2 GRAVE_DECAY_BONUS (com.minecolonies.api.research.util.ResearchConstants.GRAVE_DECAY_BONUS)2