Search in sources :

Example 11 with TileEntityGrave

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);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AbstractTileEntityGrave(com.minecolonies.api.tileentities.AbstractTileEntityGrave) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave)

Example 12 with TileEntityGrave

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;
}
Also used : TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave)

Example 13 with TileEntityGrave

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());
    }
}
Also used : AirBlock(net.minecraft.block.AirBlock) Constants(net.minecraftforge.common.util.Constants) CompoundNBT(net.minecraft.nbt.CompoundNBT) ICitizenData(com.minecolonies.api.colony.ICitizenData) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent) HashMap(java.util.HashMap) Direction(net.minecraft.util.Direction) ModBlocks(com.minecolonies.api.blocks.ModBlocks) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockMinecoloniesGrave(com.minecolonies.coremod.blocks.BlockMinecoloniesGrave) Map(java.util.Map) BlockState(net.minecraft.block.BlockState) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave) ListNBT(net.minecraft.nbt.ListNBT) MAX_TICKRATE(com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickRateConstants.MAX_TICKRATE) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) MessageUtils(com.minecolonies.api.util.MessageUtils) Iterator(java.util.Iterator) Colony(com.minecolonies.coremod.colony.Colony) World(net.minecraft.world.World) GraveData(com.minecolonies.api.colony.GraveData) BlockPos(net.minecraft.util.math.BlockPos) BlockPosUtil(com.minecolonies.api.util.BlockPosUtil) Blocks(net.minecraft.block.Blocks) IGraveManager(com.minecolonies.api.colony.managers.interfaces.IGraveManager) Material(net.minecraft.block.material.Material) InventoryUtils(com.minecolonies.api.util.InventoryUtils) NbtTagConstants(com.minecolonies.api.util.constant.NbtTagConstants) IColony(com.minecolonies.api.colony.IColony) TileEntity(net.minecraft.tileentity.TileEntity) WorldUtil(com.minecolonies.api.util.WorldUtil) NotNull(org.jetbrains.annotations.NotNull) GRAVE_DECAY_BONUS(com.minecolonies.api.research.util.ResearchConstants.GRAVE_DECAY_BONUS) BlockState(net.minecraft.block.BlockState) AirBlock(net.minecraft.block.AirBlock) GraveData(com.minecolonies.api.colony.GraveData) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent)

Example 14 with TileEntityGrave

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave) Nullable(org.jetbrains.annotations.Nullable) GraveyardManagementModule(com.minecolonies.coremod.colony.buildings.modules.GraveyardManagementModule) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with TileEntityGrave

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BuildingGraveyard(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingGraveyard) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

TileEntityGrave (com.minecolonies.api.tileentities.TileEntityGrave)30 TileEntity (net.minecraft.tileentity.TileEntity)28 BlockPos (net.minecraft.util.math.BlockPos)18 Nullable (org.jetbrains.annotations.Nullable)10 AbstractTileEntityGrave (com.minecolonies.api.tileentities.AbstractTileEntityGrave)8 IColony (com.minecolonies.api.colony.IColony)6 BuildingGraveyard (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingGraveyard)6 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)6 NotNull (org.jetbrains.annotations.NotNull)6 ICitizenData (com.minecolonies.api.colony.ICitizenData)4 GraveyardManagementModule (com.minecolonies.coremod.colony.buildings.modules.GraveyardManagementModule)4 BlockState (net.minecraft.block.BlockState)4 World (net.minecraft.world.World)4 Pane (com.ldtteam.blockout.Pane)2 ScrollingList (com.ldtteam.blockout.views.ScrollingList)2 ModBlocks (com.minecolonies.api.blocks.ModBlocks)2 GraveData (com.minecolonies.api.colony.GraveData)2 IGraveManager (com.minecolonies.api.colony.managers.interfaces.IGraveManager)2 MAX_TICKRATE (com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickRateConstants.MAX_TICKRATE)2 GRAVE_DECAY_BONUS (com.minecolonies.api.research.util.ResearchConstants.GRAVE_DECAY_BONUS)2