Search in sources :

Example 1 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 2 with TileEntityGrave

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

Example 3 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 4 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 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());
    }
}
Also used : 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 5 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 = 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;
}
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)27 BlockPos (net.minecraft.util.math.BlockPos)18 Nullable (org.jetbrains.annotations.Nullable)10 AbstractTileEntityGrave (com.minecolonies.api.tileentities.AbstractTileEntityGrave)8 BuildingGraveyard (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingGraveyard)6 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)6 IColony (com.minecolonies.api.colony.IColony)5 NotNull (org.jetbrains.annotations.NotNull)5 GraveyardManagementModule (com.minecolonies.coremod.colony.buildings.modules.GraveyardManagementModule)4 ICitizenData (com.minecolonies.api.colony.ICitizenData)3 BlockState (net.minecraft.block.BlockState)3 World (net.minecraft.world.World)3 Pane (com.ldtteam.blockout.Pane)2 ScrollingList (com.ldtteam.blockout.views.ScrollingList)2 GraveData (com.minecolonies.api.colony.GraveData)2 Nullable (javax.annotation.Nullable)2 IFormattableTextComponent (net.minecraft.util.text.IFormattableTextComponent)2 ServerWorld (net.minecraft.world.server.ServerWorld)2 IItemHandler (net.minecraftforge.items.IItemHandler)2