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