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 BlockMinecoloniesGrave method spawnAfterBreak.
@Override
public void spawnAfterBreak(final BlockState state, final ServerWorld worldIn, final BlockPos pos, final ItemStack stack) {
final TileEntity tileentity = worldIn.getBlockEntity(pos);
if (tileentity instanceof TileEntityGrave) {
final IItemHandler handler = ((AbstractTileEntityGrave) tileentity).getInventory();
InventoryUtils.dropItemHandler(handler, worldIn, pos.getX(), pos.getY(), pos.getZ());
}
super.spawnAfterBreak(state, worldIn, pos, stack);
}
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 BlockPos firstValidPosition = BlockPosUtil.findAround(world, pos, 15, 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);
LanguageHandler.sendPlayersMessage(colony.getImportantMessageEntityPlayers(), "com.minecolonies.coremod.gravespawned");
} 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 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 = getOwnBuilding();
if (buildingGraveyard == null || checkForToolOrWeapon(ToolType.SHOVEL) || buildingGraveyard.getGraveToWorkOn() == null) {
return IDLE;
}
worker.getCitizenData().setVisibleStatus(EMPTYING_ICON);
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.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