Search in sources :

Example 26 with TileEntityGrave

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

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 27 with TileEntityGrave

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

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)

Example 28 with TileEntityGrave

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

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 29 with TileEntityGrave

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

the class BlockMinecoloniesGrave method onRemove.

@Override
public void onRemove(BlockState state, @NotNull World worldIn, @NotNull BlockPos pos, BlockState newState, boolean isMoving) {
    if (state.getBlock() != newState.getBlock()) {
        TileEntity tileEntity = worldIn.getBlockEntity(pos);
        if (tileEntity instanceof TileEntityGrave) {
            TileEntityGrave tileEntityGrave = (TileEntityGrave) tileEntity;
            InventoryUtils.dropItemHandler(tileEntityGrave.getInventory(), worldIn, tileEntityGrave.getBlockPos().getX(), tileEntityGrave.getBlockPos().getY(), tileEntityGrave.getBlockPos().getZ());
            worldIn.updateNeighbourForOutputSignal(pos, this);
        }
        super.onRemove(state, worldIn, pos, newState, isMoving);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AbstractTileEntityGrave(com.minecolonies.api.tileentities.AbstractTileEntityGrave) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave)

Example 30 with TileEntityGrave

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

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)

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