use of com.minecolonies.api.tileentities.TileEntityGrave in project minecolonies by Minecolonies.
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 Minecolonies.
the class GraveManager method addNewGrave.
/**
* Add a grave from the Colony.
*
* @param pos position of the TileEntityGrave to add.
* @return the grave that was created and added.
*/
@Override
public boolean addNewGrave(@NotNull final BlockPos pos) {
final TileEntityGrave graveEntity = (TileEntityGrave) colony.getWorld().getBlockEntity(pos);
if (graveEntity == null) {
return false;
}
if (graves.containsKey(pos)) {
return true;
}
graves.put(pos, false);
colony.markDirty();
return true;
}
use of com.minecolonies.api.tileentities.TileEntityGrave in project minecolonies by Minecolonies.
the class GraveManager method createCitizenGrave.
/**
* Attempt to create a TileEntityGrave at @pos containing the specific @citizenData
* <p>
* On failure: drop all the citizen inventory on the ground.
*
* @param world The world.
* @param pos The position where to spawn a grave
* @param citizenData The citizenData
*/
@Override
public void createCitizenGrave(final World world, final BlockPos pos, final ICitizenData citizenData) {
final BlockState here = world.getBlockState(pos);
if (here.getBlock() == Blocks.LAVA) {
MessageUtils.format(WARNING_GRAVE_LAVA).sendTo(colony).forManagers();
return;
}
BlockPos firstValidPosition = null;
if (here.getBlock() == Blocks.WATER) {
for (int i = 1; i <= 10; i++) {
if (world.getBlockState(pos.above(i)).getBlock() instanceof AirBlock) {
firstValidPosition = searchShore(world, pos.above(i));
break;
}
}
if (firstValidPosition == null) {
MessageUtils.format(WARNING_GRAVE_WATER).sendTo(colony).forManagers();
}
} else {
firstValidPosition = BlockPosUtil.findAround(world, pos, 10, 10, (blockAccess, current) -> blockAccess.getBlockState(current).getMaterial() == Material.AIR && blockAccess.getBlockState(current.below()).getMaterial().isSolid());
}
if (firstValidPosition != null) {
world.setBlockAndUpdate(firstValidPosition, BlockMinecoloniesGrave.getPlacementState(ModBlocks.blockGrave.defaultBlockState(), new TileEntityGrave(), firstValidPosition));
final TileEntityGrave graveEntity = (TileEntityGrave) world.getBlockEntity(firstValidPosition);
if (!InventoryUtils.transferAllItemHandler(citizenData.getInventory(), graveEntity.getInventory())) {
InventoryUtils.dropItemHandler(citizenData.getInventory(), world, pos.getX(), pos.getY(), pos.getZ());
}
graveEntity.delayDecayTimer(colony.getResearchManager().getResearchEffects().getEffectStrength(GRAVE_DECAY_BONUS));
GraveData graveData = new GraveData();
graveData.setCitizenName(citizenData.getName());
if (citizenData.getJob() != null) {
final IFormattableTextComponent jobName = new TranslationTextComponent(citizenData.getJob().getJobRegistryEntry().getTranslationKey().toLowerCase());
graveData.setCitizenJobName(jobName.getString());
}
graveData.setCitizenDataNBT(citizenData.serializeNBT());
graveEntity.setGraveData(graveData);
colony.getGraveManager().addNewGrave(firstValidPosition);
MessageUtils.format(WARNING_GRAVE_SPAWNED).sendTo(colony).forManagers();
} else {
InventoryUtils.dropItemHandler(citizenData.getInventory(), world, pos.getX(), pos.getY(), pos.getZ());
}
}
use of com.minecolonies.api.tileentities.TileEntityGrave in project minecolonies by Minecolonies.
the class EntityAIWorkUndertaker method startWorking.
/**
* Prepares the undertaker for digging.
* Also requests the tools and checks if the undertaker has queued graves.
*
* @return the next IAIState
*/
@NotNull
private IAIState startWorking() {
worker.getCitizenData().setVisibleStatus(VisibleCitizenStatus.WORKING);
worker.getCitizenData().setIdleAtJob(false);
@Nullable final BlockPos currentGrave = building.getGraveToWorkOn();
if (currentGrave != null) {
if (walkToBuilding()) {
return getState();
}
final TileEntity entity = world.getBlockEntity(currentGrave);
if (entity instanceof TileEntityGrave) {
building.getFirstModuleOccurance(GraveyardManagementModule.class).setLastGraveData((GraveData) ((TileEntityGrave) entity).getGraveData());
return EMPTY_GRAVE;
}
building.ClearCurrentGrave();
}
return WANDER;
}
use of com.minecolonies.api.tileentities.TileEntityGrave in project minecolonies by Minecolonies.
the class EntityAIWorkUndertaker method emptyGrave.
/**
* The undertaker empty the inventory from a grave to the graveyard inventory
* The undertake will make multiple trip if needed
*
* @return the next IAIState
*/
private IAIState emptyGrave() {
@Nullable final BuildingGraveyard buildingGraveyard = building;
if (buildingGraveyard == null || checkForToolOrWeapon(ToolType.SHOVEL) || buildingGraveyard.getGraveToWorkOn() == null) {
return IDLE;
}
worker.getCitizenData().setVisibleStatus(EMPTYING_ICON);
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(MESSAGE_INFO_CITIZEN_STATUS_UNDERTAKER_EMPTYING));
worker.setSprinting(worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(UNDERTAKER_RUN) > 0);
unequip();
@Nullable final BlockPos gravePos = buildingGraveyard.getGraveToWorkOn();
// Still moving to the block
if (walkToBlock(gravePos, 3)) {
return getState();
}
final TileEntity entity = world.getBlockEntity(gravePos);
if (entity instanceof TileEntityGrave) {
if (((TileEntityGrave) entity).isEmpty()) {
return TRY_RESURRECT;
}
if (worker.getInventoryCitizen().isFull()) {
return INVENTORY_FULL;
}
if (effortCounter < EFFORT_EMPTY_GRAVE) {
worker.swing(Hand.MAIN_HAND);
effortCounter += getPrimarySkillLevel();
return getState();
}
effortCounter = 0;
// at position - try to take all item
if (InventoryUtils.transferAllItemHandler(((TileEntityGrave) entity).getInventory(), worker.getInventoryCitizen())) {
return TRY_RESURRECT;
}
}
return IDLE;
}
Aggregations