Search in sources :

Example 21 with TileEntityGrave

use of com.minecolonies.api.tileentities.TileEntityGrave in project minecolonies by Minecolonies.

the class BlockMinecoloniesGrave method getStateForPlacement.

@Nullable
@Override
public BlockState getStateForPlacement(final BlockItemUseContext context) {
    final World worldIn = context.getLevel();
    final BlockPos pos = context.getClickedPos();
    final BlockState state = defaultBlockState();
    final TileEntity entity = worldIn.getBlockEntity(pos);
    if (!(entity instanceof TileEntityGrave)) {
        return super.getStateForPlacement(context);
    }
    return getPlacementState(state, entity, pos);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) AbstractTileEntityGrave(com.minecolonies.api.tileentities.AbstractTileEntityGrave) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave) ServerWorld(net.minecraft.world.server.ServerWorld) World(net.minecraft.world.World) Nullable(javax.annotation.Nullable)

Example 22 with TileEntityGrave

use of com.minecolonies.api.tileentities.TileEntityGrave in project minecolonies by Minecolonies.

the class GraveManager method onColonyTick.

/**
 * Ticks all grave when this building manager receives a tick.
 *
 * @param colony the colony which is being ticked.
 */
@Override
public void onColonyTick(final IColony colony) {
    for (final Iterator<BlockPos> iterator = graves.keySet().iterator(); iterator.hasNext(); ) {
        final BlockPos pos = iterator.next();
        if (!WorldUtil.isBlockLoaded(colony.getWorld(), pos)) {
            continue;
        }
        final TileEntity graveEntity = colony.getWorld().getBlockEntity(pos);
        if (!(graveEntity instanceof TileEntityGrave)) {
            iterator.remove();
            colony.markDirty();
            continue;
        }
        if (!((TileEntityGrave) graveEntity).onColonyTick(MAX_TICKRATE)) {
            iterator.remove();
            colony.markDirty();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave)

Example 23 with TileEntityGrave

use of com.minecolonies.api.tileentities.TileEntityGrave in project minecolonies by Minecolonies.

the class BuildingGraveyard method getGraveToWorkOn.

/**
 * Retrieves a random grave to work on for the undertaker.
 *
 * @return a field to work on.
 */
@Nullable
public BlockPos getGraveToWorkOn() {
    if (currentGrave != null) {
        if (WorldUtil.isBlockLoaded(colony.getWorld(), currentGrave)) {
            final TileEntity tileEntity = getColony().getWorld().getBlockEntity(currentGrave);
            if (tileEntity instanceof TileEntityGrave) {
                return currentGrave;
            }
        }
        colony.getGraveManager().unReserveGrave(currentGrave);
        currentGrave = null;
    }
    currentGrave = colony.getGraveManager().reserveNextFreeGrave();
    return currentGrave;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave) Nullable(org.jetbrains.annotations.Nullable)

Example 24 with TileEntityGrave

use of com.minecolonies.api.tileentities.TileEntityGrave 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)

Example 25 with TileEntityGrave

use of com.minecolonies.api.tileentities.TileEntityGrave in project minecolonies by ldtteam.

the class GraveManager method onColonyTick.

/**
 * Ticks all grave when this building manager receives a tick.
 *
 * @param colony the colony which is being ticked.
 */
@Override
public void onColonyTick(final IColony colony) {
    for (final Iterator<BlockPos> iterator = graves.keySet().iterator(); iterator.hasNext(); ) {
        final BlockPos pos = iterator.next();
        if (!WorldUtil.isBlockLoaded(colony.getWorld(), pos)) {
            continue;
        }
        final TileEntity graveEntity = colony.getWorld().getBlockEntity(pos);
        if (!(graveEntity instanceof TileEntityGrave)) {
            iterator.remove();
            colony.markDirty();
            continue;
        }
        if (!((TileEntityGrave) graveEntity).onColonyTick(MAX_TICKRATE)) {
            iterator.remove();
            colony.markDirty();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) 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