Search in sources :

Example 1 with TileEntityNamedGrave

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

the class BlockMinecoloniesNamedGrave 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 TileEntityNamedGrave)) {
        return super.getStateForPlacement(context);
    }
    return getPlacementState(state, entity, pos);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityNamedGrave(com.minecolonies.api.tileentities.TileEntityNamedGrave) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Nullable(javax.annotation.Nullable)

Example 2 with TileEntityNamedGrave

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

the class GraveyardManagementModule method buryCitizenHere.

/**
 * Add a citizen to the list of resting citizen in this graveyard
 */
public void buryCitizenHere(final Tuple<BlockPos, Direction> positionAndDirection) {
    if (lastGraveData != null && !restingCitizen.contains(lastGraveData.getCitizenName())) {
        final IColony colony = building.getColony();
        Direction facing = positionAndDirection.getB();
        if (facing == Direction.UP || facing == Direction.DOWN) {
            // prevent setting an invalid HorizontalDirection
            facing = Direction.NORTH;
        }
        colony.getWorld().setBlockAndUpdate(positionAndDirection.getA(), ModBlocks.blockNamedGrave.defaultBlockState().setValue(AbstractBlockMinecoloniesNamedGrave.FACING, facing));
        TileEntity tileEntity = colony.getWorld().getBlockEntity(positionAndDirection.getA());
        if (tileEntity instanceof TileEntityNamedGrave) {
            final String firstName = StringUtils.split(lastGraveData.getCitizenName())[0];
            final String lastName = lastGraveData.getCitizenName().replaceFirst(firstName, "");
            final ArrayList<String> lines = new ArrayList<>();
            lines.add(firstName);
            lines.add(lastName);
            if (lastGraveData.getCitizenJobName() != null) {
                lines.add(lastGraveData.getCitizenJobName());
            }
            ((TileEntityNamedGrave) tileEntity).setTextLines(lines);
        }
        restingCitizen.add(lastGraveData.getCitizenName());
        markDirty();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityNamedGrave(com.minecolonies.api.tileentities.TileEntityNamedGrave) IColony(com.minecolonies.api.colony.IColony) Direction(net.minecraft.util.Direction)

Example 3 with TileEntityNamedGrave

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

the class EntityAIMournCitizen method wanderAtGraveyard.

/**
 * Wander at the graveyard and visit the graves.
 * While wandering at the graveyard, the chance to stop mourning is doubled.
 * @return the next state to go to.
 */
private MourningState wanderAtGraveyard() {
    if (graveyard == null) {
        return MourningState.DECIDE;
    }
    // Double the chance to stop mourning by checking here as well.
    if (!shouldMourn()) {
        return MourningState.IDLE;
    }
    final IBuilding graveyardBuilding = citizen.getCitizenColonyHandler().getColony().getBuildingManager().getBuilding(graveyard);
    if (!(graveyardBuilding instanceof BuildingGraveyard)) {
        graveyard = null;
        return MourningState.DECIDE;
    }
    if (!citizen.getNavigation().isDone()) {
        return MourningState.WANDER_AT_GRAVEYARD;
    }
    // Wander around randomly.
    if (MathUtils.RANDOM.nextInt(100) < 90) {
        citizen.getNavigation().moveToRandomPos(10, DEFAULT_SPEED, graveyardBuilding.getCorners(), AbstractAdvancedPathNavigate.RestrictionType.XYZ);
        return MourningState.WANDER_AT_GRAVEYARD;
    }
    // Try find the grave of one of the diseased.
    final Set<Tuple<BlockPos, Direction>> gravePositions = ((BuildingGraveyard) graveyardBuilding).getGravePositions();
    for (final Tuple<BlockPos, Direction> gravePos : gravePositions) {
        if (WorldUtil.isBlockLoaded(citizen.level, gravePos.getA())) {
            final TileEntity blockEntity = citizen.level.getBlockEntity(gravePos.getA());
            if (blockEntity instanceof TileEntityNamedGrave) {
                final Iterator<String> iterator = citizen.getCitizenData().getCitizenMournHandler().getDeceasedCitizens().iterator();
                if (!iterator.hasNext()) {
                    continue;
                }
                final String deathBud = iterator.next();
                final String firstName = StringUtils.split(deathBud)[0];
                final String lastName = deathBud.replaceFirst(firstName, "");
                final List<String> graveNameList = ((TileEntityNamedGrave) blockEntity).getTextLines();
                if (!graveNameList.isEmpty() && graveNameList.contains(firstName) && graveNameList.contains(lastName)) {
                    this.gravePos = gravePos.getA();
                    return MourningState.WALK_TO_GRAVE;
                }
            }
        }
    }
    return MourningState.DECIDE;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityNamedGrave(com.minecolonies.api.tileentities.TileEntityNamedGrave) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) BuildingGraveyard(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingGraveyard) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction)

Example 4 with TileEntityNamedGrave

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

the class BlockMinecoloniesNamedGrave 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 TileEntityNamedGrave)) {
        return super.getStateForPlacement(context);
    }
    return getPlacementState(state, entity, pos);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityNamedGrave(com.minecolonies.api.tileentities.TileEntityNamedGrave) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Nullable(javax.annotation.Nullable)

Example 5 with TileEntityNamedGrave

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

the class GraveyardManagementModule method buryCitizenHere.

/**
 * Add a citizen to the list of resting citizen in this graveyard
 */
public void buryCitizenHere(final Tuple<BlockPos, Direction> positionAndDirection) {
    if (lastGraveData != null && !restingCitizen.contains(lastGraveData.getCitizenName())) {
        final IColony colony = building.getColony();
        Direction facing = positionAndDirection.getB();
        if (facing == Direction.UP || facing == Direction.DOWN) {
            // prevent setting an invalid HorizontalDirection
            facing = Direction.NORTH;
        }
        colony.getWorld().setBlockAndUpdate(positionAndDirection.getA(), ModBlocks.blockNamedGrave.defaultBlockState().setValue(AbstractBlockMinecoloniesNamedGrave.FACING, facing));
        TileEntity tileEntity = colony.getWorld().getBlockEntity(positionAndDirection.getA());
        if (tileEntity instanceof TileEntityNamedGrave) {
            final String firstName = StringUtils.split(lastGraveData.getCitizenName())[0];
            final String lastName = lastGraveData.getCitizenName().replaceFirst(firstName, "");
            final ArrayList<String> lines = new ArrayList<>();
            lines.add(firstName);
            lines.add(lastName);
            if (lastGraveData.getCitizenJobName() != null) {
                lines.add(lastGraveData.getCitizenJobName());
            }
            ((TileEntityNamedGrave) tileEntity).setTextLines(lines);
        }
        restingCitizen.add(lastGraveData.getCitizenName());
        markDirty();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityNamedGrave(com.minecolonies.api.tileentities.TileEntityNamedGrave) IColony(com.minecolonies.api.colony.IColony) Direction(net.minecraft.util.Direction)

Aggregations

TileEntityNamedGrave (com.minecolonies.api.tileentities.TileEntityNamedGrave)5 TileEntity (net.minecraft.tileentity.TileEntity)5 Direction (net.minecraft.util.Direction)3 BlockPos (net.minecraft.util.math.BlockPos)3 IColony (com.minecolonies.api.colony.IColony)2 Nullable (javax.annotation.Nullable)2 BlockState (net.minecraft.block.BlockState)2 World (net.minecraft.world.World)2 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)1 BuildingGraveyard (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingGraveyard)1