Search in sources :

Example 16 with AirBlock

use of net.minecraft.block.AirBlock in project Structurize by ldtteam.

the class Blueprint method getItem.

/**
 * Calculate the item needed to place the current block in the structure.
 *
 * @param pos the pos its at.
 * @return an item or null if not initialized.
 */
@Nullable
public Item getItem(final BlockPos pos) {
    @Nullable final BlockInfo info = this.getBlockInfoAsMap().getOrDefault(pos, null);
    if (info == null || info.getState() == null || info.getState().getBlock() instanceof AirBlock || info.getState().getMaterial().isLiquid()) {
        return null;
    }
    final ItemStack stack = BlockUtils.getItemStackFromBlockState(info.getState());
    if (!ItemStackUtils.isEmpty(stack)) {
        return stack.getItem();
    }
    return null;
}
Also used : AirBlock(net.minecraft.block.AirBlock) BlockInfo(com.ldtteam.structurize.util.BlockInfo) ItemStack(net.minecraft.item.ItemStack) Nullable(org.jetbrains.annotations.Nullable) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with AirBlock

use of net.minecraft.block.AirBlock in project minecolonies by ldtteam.

the class EntityAIWorkPlanter method decide.

@Override
protected IAIState decide() {
    final IAIState nextState = super.decide();
    if (nextState != START_WORKING && nextState != IDLE) {
        return nextState;
    }
    final BuildingPlantation plantation = getOwnBuilding();
    final List<BlockPos> list = plantation.getPosForPhase();
    for (final BlockPos pos : list) {
        if (isAtLeastThreeHigh(pos)) {
            this.workPos = pos;
            return PLANTATION_FARM;
        }
    }
    final Item current = plantation.nextPlantPhase();
    final int plantInBuilding = InventoryUtils.getCountFromBuilding(getOwnBuilding(), itemStack -> itemStack.sameItem(new ItemStack(current)));
    final int plantInInv = InventoryUtils.getItemCountInItemHandler((worker.getInventoryCitizen()), itemStack -> itemStack.sameItem(new ItemStack(current)));
    if (plantInBuilding + plantInInv <= 0) {
        requestPlantable(current);
        return START_WORKING;
    }
    if (plantInInv == 0 && plantInBuilding > 0) {
        needsCurrently = new Tuple<>(itemStack -> itemStack.sameItem(new ItemStack(current)), Math.min(plantInBuilding, PLANT_TO_REQUEST));
        return GATHERING_REQUIRED_MATERIALS;
    }
    for (final BlockPos pos : list) {
        if (world.getBlockState(pos.above()).getBlock() instanceof AirBlock) {
            this.workPos = pos;
            return PLANTATION_PLANT;
        }
    }
    return START_WORKING;
}
Also used : BuildingPlantation(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingPlantation) JobPlanter(com.minecolonies.coremod.colony.jobs.JobPlanter) TICKS_20(com.minecolonies.api.util.constant.CitizenConstants.TICKS_20) BuildingPlantation(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingPlantation) Item(net.minecraft.item.Item) AirBlock(net.minecraft.block.AirBlock) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) BlockPos(net.minecraft.util.math.BlockPos) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) Tuple(com.minecolonies.api.util.Tuple) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) BlockUtils(com.ldtteam.structurize.util.BlockUtils) InventoryUtils(com.minecolonies.api.util.InventoryUtils) AbstractEntityAICrafting(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAICrafting) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) ItemEntity(net.minecraft.entity.item.ItemEntity) NotNull(org.jetbrains.annotations.NotNull) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack) Item(net.minecraft.item.Item) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) AirBlock(net.minecraft.block.AirBlock) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 18 with AirBlock

use of net.minecraft.block.AirBlock in project minecolonies by ldtteam.

the class ColonyPermissionEventHandler method on.

/**
 * PlayerInteractEvent handler.
 * <p>
 * Check, if a player right clicked a block. Deny if: - If the block is in colony - block is AbstractBlockHut - player has not permission
 *
 * @param event PlayerInteractEvent
 */
@SubscribeEvent
public void on(final PlayerInteractEvent event) {
    if (colony.isCoordInColony(event.getWorld(), event.getPos()) && !(event instanceof PlayerInteractEvent.EntityInteract || event instanceof PlayerInteractEvent.EntityInteractSpecific)) {
        final Block block = event.getWorld().getBlockState(event.getPos()).getBlock();
        // Huts
        if (event instanceof PlayerInteractEvent.RightClickBlock && block instanceof AbstractBlockHut && !colony.getPermissions().hasPermission(event.getPlayer(), Action.ACCESS_HUTS)) {
            cancelEvent(event, event.getPlayer(), colony, Action.ACCESS_HUTS, event.getPos());
            return;
        }
        final Permissions perms = colony.getPermissions();
        if (isFreeToInteractWith(block, event.getPos()) && perms.hasPermission(event.getPlayer(), Action.ACCESS_FREE_BLOCKS)) {
            return;
        }
        if (MineColonies.getConfig().getServer().enableColonyProtection.get()) {
            if (!perms.hasPermission(event.getPlayer(), Action.RIGHTCLICK_BLOCK) && !(block instanceof AirBlock)) {
                checkEventCancelation(Action.RIGHTCLICK_BLOCK, event.getPlayer(), event.getWorld(), event, event.getPos());
                return;
            }
            if (block instanceof ContainerBlock && !perms.hasPermission(event.getPlayer(), Action.OPEN_CONTAINER)) {
                cancelEvent(event, event.getPlayer(), colony, Action.OPEN_CONTAINER, event.getPos());
                return;
            }
            if (event.getWorld().getBlockEntity(event.getPos()) != null && !perms.hasPermission(event.getPlayer(), Action.RIGHTCLICK_ENTITY)) {
                checkEventCancelation(Action.RIGHTCLICK_ENTITY, event.getPlayer(), event.getWorld(), event, event.getPos());
                return;
            }
            final ItemStack stack = event.getItemStack();
            if (ItemStackUtils.isEmpty(stack) || stack.getItem().isEdible()) {
                return;
            }
            if (stack.getItem() instanceof PotionItem) {
                checkEventCancelation(Action.THROW_POTION, event.getPlayer(), event.getWorld(), event, event.getPos());
                return;
            }
            if (stack.getItem() instanceof ItemScanTool && !perms.hasPermission(event.getPlayer(), Action.USE_SCAN_TOOL)) {
                cancelEvent(event, event.getPlayer(), colony, Action.USE_SCAN_TOOL, event.getPos());
            }
        }
    }
}
Also used : AirBlock(net.minecraft.block.AirBlock) ItemScanTool(com.ldtteam.structurize.items.ItemScanTool) ContainerBlock(net.minecraft.block.ContainerBlock) PotionItem(net.minecraft.item.PotionItem) Permissions(com.minecolonies.coremod.colony.permissions.Permissions) AirBlock(net.minecraft.block.AirBlock) Block(net.minecraft.block.Block) ContainerBlock(net.minecraft.block.ContainerBlock) ItemStack(net.minecraft.item.ItemStack) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 19 with AirBlock

use of net.minecraft.block.AirBlock in project minecolonies by ldtteam.

the class BlockPosUtil method findLand.

/**
 * this checks that you are not in the air or underground. If so it will look up and down for a good landing spot before TP.
 *
 * @param blockPos for the current block LOC.
 * @param world    the world to search in.
 * @return blockPos to be used for the TP.
 */
public static BlockPos findLand(final BlockPos blockPos, final World world) {
    int top = blockPos.getY();
    int bot = 0;
    int mid = blockPos.getY();
    BlockPos foundland = null;
    BlockPos tempPos = blockPos;
    // We are doing a binary search to limit the amount of checks (usually at most 9 this way)
    while (top >= bot) {
        tempPos = new BlockPos(tempPos.getX(), mid, tempPos.getZ());
        final Block block = world.getBlockState(tempPos).getBlock();
        if (block instanceof AirBlock && world.canSeeSkyFromBelowWater(tempPos)) {
            top = mid - 1;
            foundland = tempPos;
        } else {
            bot = mid + 1;
            foundland = tempPos;
        }
        mid = (bot + top) / 2;
    }
    if (world.getBlockState(tempPos).getMaterial().isSolid()) {
        return foundland.above();
    }
    return foundland;
}
Also used : AirBlock(net.minecraft.block.AirBlock) AirBlock(net.minecraft.block.AirBlock) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Example 20 with AirBlock

use of net.minecraft.block.AirBlock in project minecolonies by ldtteam.

the class AbstractEntityAIStructure method structureStep.

/**
 * The Structure step to execute the actual placement actions etc.
 *
 * @return the next step to go to.
 */
protected IAIState structureStep() {
    if (structurePlacer.getB().getStage() == null) {
        return PICK_UP_RESIDUALS;
    }
    if (InventoryUtils.isItemHandlerFull(worker.getInventoryCitizen())) {
        return INVENTORY_FULL;
    }
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.building"));
    checkForExtraBuildingActions();
    // some things to do first! then we go to the actual phase!
    // Fill workFrom with the position from where the builder should build.
    // also ensure we are at that position.
    final BlockPos progress = getProgressPos() == null ? NULL_POS : getProgressPos().getA();
    final BlockPos worldPos = structurePlacer.getB().getProgressPosInWorld(progress);
    if (getProgressPos() != null) {
        structurePlacer.getB().setStage(getProgressPos().getB());
    }
    if (!progress.equals(NULL_POS) && !limitReached && (blockToMine == null ? !walkToConstructionSite(worldPos) : !walkToConstructionSite(blockToMine))) {
        return getState();
    }
    limitReached = false;
    final StructurePhasePlacementResult result;
    final StructurePlacer placer = structurePlacer.getA();
    switch(structurePlacer.getB().getStage()) {
        case BUILD_SOLID:
            // structure
            result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.BLOCK_PLACEMENT, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> !info.getBlockInfo().getState().getMaterial().isSolid() || isDecoItem(info.getBlockInfo().getState().getBlock()))), false);
            break;
        case CLEAR_WATER:
            // water
            result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.WATER_REMOVAL, () -> placer.getIterator().decrement((info, pos, handler) -> handler.getWorld().getBlockState(pos).getFluidState().isEmpty()), false);
            break;
        case CLEAR_NON_SOLIDS:
            // clear air
            result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.BLOCK_PLACEMENT, () -> placer.getIterator().decrement(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> !(info.getBlockInfo().getState().getBlock() instanceof AirBlock) || (handler.getWorld().isEmptyBlock(pos)))), false);
            break;
        case DECORATE:
            // not solid
            result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.BLOCK_PLACEMENT, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getBlockInfo().getState().getMaterial().isSolid() && !isDecoItem(info.getBlockInfo().getState().getBlock()))), false);
            break;
        case SPAWN:
            // entities
            result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.BLOCK_PLACEMENT, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getEntities().length == 0)), true);
            break;
        case REMOVE_WATER:
            // water
            placer.getIterator().setRemoving();
            result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.WATER_REMOVAL, () -> placer.getIterator().decrement((info, pos, handler) -> info.getBlockInfo().getState().getFluidState().isEmpty()), false);
            break;
        case REMOVE:
            placer.getIterator().setRemoving();
            result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.BLOCK_REMOVAL, () -> placer.getIterator().decrement((info, pos, handler) -> handler.getWorld().getBlockState(pos).getBlock() instanceof AirBlock || info.getBlockInfo().getState().getBlock() instanceof AirBlock || !handler.getWorld().getBlockState(pos).getFluidState().isEmpty() || info.getBlockInfo().getState().getBlock() == com.ldtteam.structurize.blocks.ModBlocks.blockSolidSubstitution.get() || info.getBlockInfo().getState().getBlock() == com.ldtteam.structurize.blocks.ModBlocks.blockSubstitution.get() || info.getBlockInfo().getState().getBlock() == com.ldtteam.structurize.blocks.ModBlocks.blockSubstitution.get() || handler.getWorld().getBlockState(pos).getBlock() instanceof IBuilderUndestroyable), true);
            break;
        case CLEAR:
        default:
            result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.BLOCK_REMOVAL, () -> placer.getIterator().decrement((info, pos, handler) -> handler.getWorld().getBlockState(pos).getBlock() instanceof IBuilderUndestroyable || handler.getWorld().getBlockState(pos).getBlock() == Blocks.BEDROCK || handler.getWorld().getBlockState(pos).getBlock() instanceof AirBlock || info.getBlockInfo().getState().getBlock() == com.ldtteam.structurize.blocks.ModBlocks.blockFluidSubstitution.get() || !handler.getWorld().getBlockState(pos).getFluidState().isEmpty()), false);
            if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
                getOwnBuilding().checkOrRequestBucket(getOwnBuilding().getRequiredResources(), worker.getCitizenData(), true);
            }
            break;
    }
    if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FAIL) {
        Log.getLogger().error("Failed placement at: " + result.getBlockResult().getWorldPos().toShortString());
    }
    if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
        getOwnBuilding().nextStage();
        if (!structurePlacer.getB().nextStage()) {
            getOwnBuilding().setProgressPos(null, null);
            return COMPLETE_BUILD;
        }
    } else if (result.getBlockResult().getResult() == BlockPlacementResult.Result.LIMIT_REACHED) {
        this.limitReached = true;
    }
    this.storeProgressPos(result.getIteratorPos(), structurePlacer.getB().getStage());
    if (result.getBlockResult().getResult() == BlockPlacementResult.Result.MISSING_ITEMS) {
        if (hasListOfResInInvOrRequest(this, result.getBlockResult().getRequiredItems(), result.getBlockResult().getRequiredItems().size() > 1) == RECALC) {
            job.getWorkOrder().setRequested(false);
            return LOAD_STRUCTURE;
        }
        return NEEDS_ITEM;
    }
    if (result.getBlockResult().getResult() == BlockPlacementResult.Result.BREAK_BLOCK) {
        blockToMine = result.getBlockResult().getWorldPos();
        return MINE_BLOCK;
    } else {
        blockToMine = null;
    }
    if (MineColonies.getConfig().getServer().builderBuildBlockDelay.get() > 0) {
        final double decrease = 1 - worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(BLOCK_PLACE_SPEED);
        setDelay((int) ((MineColonies.getConfig().getServer().builderBuildBlockDelay.get() * PROGRESS_MULTIPLIER / (getPlaceSpeedLevel() / 2 + PROGRESS_MULTIPLIER)) * decrease));
    }
    return getState();
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) BLOCK_PLACE_SPEED(com.minecolonies.api.research.util.ResearchConstants.BLOCK_PLACE_SPEED) AirBlock(net.minecraft.block.AirBlock) IBuilderUndestroyable(com.minecolonies.api.entity.ai.citizen.builder.IBuilderUndestroyable) TileEntityDecorationController(com.minecolonies.coremod.tileentities.TileEntityDecorationController) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) TriPredicate(net.minecraftforge.common.util.TriPredicate) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) Block(net.minecraft.block.Block) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) BlockTags(net.minecraft.tags.BlockTags) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) BlockState(net.minecraft.block.BlockState) CitizenConstants(com.minecolonies.api.util.constant.CitizenConstants) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) AIEventTarget(com.minecolonies.api.entity.ai.statemachine.AIEventTarget) Predicate(java.util.function.Predicate) BlueprintPositionInfo(com.ldtteam.structurize.util.BlueprintPositionInfo) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Nullable(org.jetbrains.annotations.Nullable) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) BlockItem(net.minecraft.item.BlockItem) MineColonies(com.minecolonies.coremod.MineColonies) AbstractJobStructure(com.minecolonies.coremod.colony.jobs.AbstractJobStructure) IStructureHandler(com.ldtteam.structurize.placement.structure.IStructureHandler) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) BuilderBucket(com.minecolonies.coremod.colony.buildings.utils.BuilderBucket) java.util(java.util) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ModBlocks(com.minecolonies.api.blocks.ModBlocks) Mirror(net.minecraft.util.Mirror) ItemStack(net.minecraft.item.ItemStack) BuildingResourcesModule(com.minecolonies.coremod.colony.buildings.modules.BuildingResourcesModule) ImmutableList(com.google.common.collect.ImmutableList) AbstractBuildingStructureBuilder(com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder) Hand(net.minecraft.util.Hand) com.minecolonies.api.util(com.minecolonies.api.util) StructurePhasePlacementResult(com.ldtteam.structurize.placement.StructurePhasePlacementResult) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) BuildingStructureHandler(com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler) ModTags(com.minecolonies.api.items.ModTags) AIBlockingEventType(com.minecolonies.api.entity.ai.statemachine.states.AIBlockingEventType) BlockPos(net.minecraft.util.math.BlockPos) NULL_POS(com.ldtteam.structurize.placement.AbstractBlueprintIterator.NULL_POS) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut) Blocks(net.minecraft.block.Blocks) Stage(com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler.Stage) TypeConstants(com.minecolonies.api.util.constant.TypeConstants) BlockPlacementResult(com.ldtteam.structurize.placement.BlockPlacementResult) BlockUtils(com.ldtteam.structurize.util.BlockUtils) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) BlockFluidSubstitution(com.ldtteam.structurize.blocks.schematic.BlockFluidSubstitution) TileEntity(net.minecraft.tileentity.TileEntity) ItemCheckResult(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIStructure.ItemCheckResult) AirBlock(net.minecraft.block.AirBlock) StructurePhasePlacementResult(com.ldtteam.structurize.placement.StructurePhasePlacementResult) StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) IBuilderUndestroyable(com.minecolonies.api.entity.ai.citizen.builder.IBuilderUndestroyable)

Aggregations

AirBlock (net.minecraft.block.AirBlock)21 BlockPos (net.minecraft.util.math.BlockPos)13 ItemStack (net.minecraft.item.ItemStack)9 Block (net.minecraft.block.Block)8 BlockState (net.minecraft.block.BlockState)8 AbstractBlockHut (com.minecolonies.api.blocks.AbstractBlockHut)6 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)6 NotNull (org.jetbrains.annotations.NotNull)6 TileEntity (net.minecraft.tileentity.TileEntity)5 Nullable (org.jetbrains.annotations.Nullable)5 BlockUtils (com.ldtteam.structurize.util.BlockUtils)4 Stack (com.minecolonies.api.colony.requestsystem.requestable.Stack)4 IBuilderUndestroyable (com.minecolonies.api.entity.ai.citizen.builder.IBuilderUndestroyable)4 AITarget (com.minecolonies.api.entity.ai.statemachine.AITarget)4 AIWorkerState (com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState)4 IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)4 Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)3 IStructureHandler (com.ldtteam.structurize.placement.structure.IStructureHandler)3 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)3 ModBlocks (com.minecolonies.api.blocks.ModBlocks)3