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