Search in sources :

Example 6 with TileEntityGrave

use of com.minecolonies.api.tileentities.TileEntityGrave in project minecolonies by ldtteam.

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)

Example 7 with TileEntityGrave

use of com.minecolonies.api.tileentities.TileEntityGrave in project minecolonies by ldtteam.

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 = getOwnBuilding().getGraveToWorkOn();
    if (currentGrave != null) {
        if (walkToBuilding()) {
            return getState();
        }
        final TileEntity entity = world.getBlockEntity(currentGrave);
        if (entity instanceof TileEntityGrave) {
            getOwnBuilding().getFirstModuleOccurance(GraveyardManagementModule.class).setLastGraveData((GraveData) ((TileEntityGrave) entity).getGraveData());
            return EMPTY_GRAVE;
        }
        getOwnBuilding().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 8 with TileEntityGrave

use of com.minecolonies.api.tileentities.TileEntityGrave in project minecolonies by ldtteam.

the class EntityAIWorkUndertaker method tryResurrect.

/**
 * Attempt to resurrect buried citizen from its citizen data
 * Randomize to see if resurrection successful and resurrect if need be
 *
 * @return the next IAIState
 */
private IAIState tryResurrect() {
    @Nullable final BuildingGraveyard buildingGraveyard = getOwnBuilding();
    if (checkForToolOrWeapon(ToolType.SHOVEL) || buildingGraveyard.getFirstModuleOccurance(GraveyardManagementModule.class).getLastGraveData() == null || buildingGraveyard.getGraveToWorkOn() == null) {
        return IDLE;
    }
    unequip();
    @Nullable final BlockPos gravePos = buildingGraveyard.getGraveToWorkOn();
    if (gravePos == null) {
        return IDLE;
    }
    // Still moving to the block
    if (walkToBlock(gravePos, 3)) {
        return getState();
    }
    final TileEntity entity = world.getBlockEntity(gravePos);
    if (entity instanceof TileEntityGrave) {
        if (effortCounter < EFFORT_RESURRECT) {
            worker.swing(Hand.MAIN_HAND);
            effortCounter += getSecondarySkillLevel();
            return getState();
        }
        effortCounter = 0;
        shouldDumpInventory = true;
        final double chance = getResurrectChance(buildingGraveyard);
        if (getTotemResurrectChance() > 0 && random.nextDouble() <= TOTEM_BREAK_CHANCE) {
            worker.getInventoryCitizen().extractItem(InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), Items.TOTEM_OF_UNDYING), 1, false);
            worker.playSound(SoundEvents.TOTEM_USE, 1.0f, 1.0f);
        }
        if (chance >= random.nextDouble()) {
            final ICitizenData citizenData = buildingGraveyard.getColony().getCitizenManager().resurrectCivilianData(buildingGraveyard.getFirstModuleOccurance(GraveyardManagementModule.class).getLastGraveData().getCitizenDataNBT(), true, world, gravePos);
            LanguageHandler.sendPlayersMessage(buildingGraveyard.getColony().getImportantMessageEntityPlayers(), "com.minecolonies.coremod.resurrect", citizenData.getName());
            worker.getCitizenColonyHandler().getColony().getCitizenManager().updateCitizenMourn(citizenData, false);
            AdvancementUtils.TriggerAdvancementPlayersForColony(worker.getCitizenColonyHandler().getColony(), playerMP -> AdvancementTriggers.CITIZEN_RESURRECT.trigger(playerMP));
            buildingGraveyard.getFirstModuleOccurance(GraveyardManagementModule.class).setLastGraveData(null);
            world.setBlockAndUpdate(gravePos, Blocks.AIR.defaultBlockState());
            return INVENTORY_FULL;
        }
    }
    return DIG_GRAVE;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BuildingGraveyard(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingGraveyard) ICitizenData(com.minecolonies.api.colony.ICitizenData) 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)

Example 9 with TileEntityGrave

use of com.minecolonies.api.tileentities.TileEntityGrave in project minecolonies by Minecolonies.

the class GraveyardManagementWindow method onOpened.

@Override
public void onOpened() {
    super.onOpened();
    /*
         * ScrollList with the graves.
         */
    final ScrollingList graveList = findPaneOfTypeByID(LIST_GRAVES, ScrollingList.class);
    graveList.setDataProvider(new ScrollingList.DataProvider() {

        @Override
        public int getElementCount() {
            return moduleView.getGraves().size();
        }

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final BlockPos grave = moduleView.getGraves().get(index);
            @NotNull final String distance = Integer.toString((int) Math.sqrt(BlockPosUtil.getDistanceSquared(grave, buildingView.getPosition())));
            final ITextComponent direction = BlockPosUtil.calcDirection(buildingView.getPosition(), grave);
            final TileEntity entity = world.getBlockEntity(grave);
            if (entity instanceof TileEntityGrave) {
                rowPane.findPaneOfTypeByID(TAG_NAME, Text.class).setText("Grave of " + ((((TileEntityGrave) entity).getGraveData() != null) ? ((TileEntityGrave) entity).getGraveData().getCitizenName() : "Unknown Citizen"));
                rowPane.findPaneOfTypeByID(TAG_DISTANCE, Text.class).setText(distance + "m");
                rowPane.findPaneOfTypeByID(TAG_DIRECTION, Text.class).setText(direction);
            }
        }
    });
    /*
         * ScrollList with the resting citizen.
         */
    final ScrollingList ripList = findPaneOfTypeByID(LIST_CITIZEN, ScrollingList.class);
    ripList.setDataProvider(new ScrollingList.DataProvider() {

        @Override
        public int getElementCount() {
            return moduleView.getRestingCitizen().size();
        }

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final String citizenName = moduleView.getRestingCitizen().get(index);
            rowPane.findPaneOfTypeByID(TAG_CITIZEN_NAME, Text.class).setText(citizenName);
        }
    });
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITextComponent(net.minecraft.util.text.ITextComponent) BlockPos(net.minecraft.util.math.BlockPos) TileEntityGrave(com.minecolonies.api.tileentities.TileEntityGrave) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane)

Example 10 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)

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