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