Search in sources :

Example 11 with AirBlock

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

the class TileEntityCompostedDirt method updateTick.

/**
 * Update tick running on the server world.
 *
 * @param worldIn the server world.
 */
private void updateTick(@NotNull final World worldIn) {
    if (flower == null || flower.isEmpty()) {
        this.composted = false;
        return;
    }
    if (this.composted) {
        ((ServerWorld) worldIn).sendParticles(ParticleTypes.HAPPY_VILLAGER, this.getBlockPos().getX() + 0.5, this.getBlockPos().getY() + 1, this.getBlockPos().getZ() + 0.5, 1, 0.2, 0, 0.2, 0);
    }
    if (random.nextDouble() * 100 <= this.percentage) {
        final BlockPos position = worldPosition.above();
        if (worldIn.getBlockState(position).getBlock() instanceof AirBlock) {
            if (flower.getItem() instanceof BlockItem) {
                if (((BlockItem) flower.getItem()).getBlock() instanceof DoublePlantBlock) {
                    ((DoublePlantBlock) ((BlockItem) flower.getItem()).getBlock()).placeAt(worldIn, position, UPDATE_FLAG);
                } else {
                    worldIn.setBlockAndUpdate(position, ((BlockItem) flower.getItem()).getBlock().defaultBlockState());
                }
            } else {
                worldIn.setBlockAndUpdate(position, BlockUtils.getBlockStateFromStack(flower));
            }
        }
    }
    if (this.ticker >= TICKER_LIMIT * TICKS_SECOND) {
        this.ticker = 0;
        this.composted = false;
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) AirBlock(net.minecraft.block.AirBlock) BlockPos(net.minecraft.util.math.BlockPos) BlockItem(net.minecraft.item.BlockItem) DoublePlantBlock(net.minecraft.block.DoublePlantBlock)

Example 12 with AirBlock

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

the class AbstractBuilding method getTileEntity.

@Override
public AbstractTileEntityColonyBuilding getTileEntity() {
    if (tileEntity != null && tileEntity.isRemoved()) {
        tileEntity = null;
    }
    if ((tileEntity == null) && colony != null && colony.getWorld() != null && getPosition() != null && WorldUtil.isBlockLoaded(colony.getWorld(), getPosition()) && !(colony.getWorld().getBlockState(getPosition()).getBlock() instanceof AirBlock) && colony.getWorld().getBlockState(this.getPosition()).getBlock() instanceof AbstractBlockHut) {
        final TileEntity te = colony.getWorld().getBlockEntity(getPosition());
        if (te instanceof TileEntityColonyBuilding) {
            tileEntity = (TileEntityColonyBuilding) te;
            if (tileEntity.getBuilding() == null) {
                tileEntity.setColony(colony);
                tileEntity.setBuilding(this);
            }
        } else {
            Log.getLogger().error("Somehow the wrong TileEntity is at the location where the building should be!", new Exception());
            Log.getLogger().error("Trying to restore order!");
            final AbstractTileEntityColonyBuilding tileEntityColonyBuilding = new TileEntityColonyBuilding(MinecoloniesTileEntities.BUILDING);
            colony.getWorld().setBlockEntity(getPosition(), tileEntityColonyBuilding);
            this.tileEntity = tileEntityColonyBuilding;
        }
    }
    return tileEntity;
}
Also used : ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) AirBlock(net.minecraft.block.AirBlock) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) TileEntityColonyBuilding(com.minecolonies.api.tileentities.TileEntityColonyBuilding) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut)

Example 13 with AirBlock

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

the class AbstractEntityAIInteract method mineBlock.

/**
 * Will simulate mining a block with particles ItemDrop etc. Attention: Because it simulates delay, it has to be called 2 times. So make sure the code path up to this function
 * is reachable a second time. And make sure to immediately exit the update function when this returns false.
 *
 * @param blockToMine      the block that should be mined
 * @param safeStand        the block we want to stand on to do that
 * @param damageTool       boolean wether we want to damage the tool used
 * @param getDrops         boolean wether we want to get Drops
 * @param blockBreakAction Runnable that is used instead of the default block break action, can be null
 * @return true once we're done
 */
protected final boolean mineBlock(@NotNull final BlockPos blockToMine, @NotNull final BlockPos safeStand, final boolean damageTool, final boolean getDrops, final Runnable blockBreakAction) {
    final BlockState curBlockState = world.getBlockState(blockToMine);
    @Nullable final Block curBlock = curBlockState.getBlock();
    if (curBlock instanceof AirBlock || curBlock instanceof IBuilderUndestroyable || curBlock == Blocks.BEDROCK) {
        if (curBlockState.getMaterial().isLiquid()) {
            world.removeBlock(blockToMine, false);
        }
        // no need to mine block...
        return true;
    }
    if (checkMiningLocation(blockToMine, safeStand)) {
        // we have to wait for delay
        return false;
    }
    final ItemStack tool = worker.getMainHandItem();
    if (getDrops) {
        // calculate fortune enchantment
        final int fortune = ItemStackUtils.getFortuneOf(tool);
        // check if tool has Silk Touch
        final boolean silkTouch = ItemStackUtils.hasSilkTouch(tool);
        // create list for all item drops to be stored in
        List<ItemStack> localItems = new ArrayList<ItemStack>();
        // Checks to see if the equipped tool has Silk Touch AND if the blocktoMine has a viable Item SilkTouch can get.
        if (silkTouch && Item.byBlock(BlockPosUtil.getBlock(world, blockToMine)) != null) {
            // Stores Silk Touch Block in localItems
            final ItemStack silkItem = new ItemStack(Item.byBlock(BlockPosUtil.getBlock(world, blockToMine)), 1);
            localItems.add(silkItem);
        } else // If Silk Touch doesn't work, get blocks with Fortune value as normal.
        {
            localItems.addAll(BlockPosUtil.getBlockDrops(world, blockToMine, fortune, tool, worker));
        }
        localItems = increaseBlockDrops(localItems);
        // add the drops to the citizen
        for (final ItemStack item : localItems) {
            InventoryUtils.transferItemStackIntoNextBestSlotInItemHandler(item, worker.getInventoryCitizen());
        }
    }
    triggerMinedBlock(curBlockState);
    if (blockBreakAction == null) {
        // Break the block
        worker.getCitizenItemHandler().breakBlockWithToolInHand(blockToMine);
    } else {
        blockBreakAction.run();
    }
    if (tool != ItemStack.EMPTY && damageTool) {
        tool.getItem().inventoryTick(tool, world, worker, worker.getCitizenInventoryHandler().findFirstSlotInInventoryWith(tool.getItem()), true);
    }
    worker.getCitizenExperienceHandler().addExperience(XP_PER_BLOCK);
    this.incrementActionsDone();
    return true;
}
Also used : BlockState(net.minecraft.block.BlockState) AirBlock(net.minecraft.block.AirBlock) ArrayList(java.util.ArrayList) AirBlock(net.minecraft.block.AirBlock) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) Nullable(org.jetbrains.annotations.Nullable) IBuilderUndestroyable(com.minecolonies.api.entity.ai.citizen.builder.IBuilderUndestroyable)

Example 14 with AirBlock

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

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 15 with AirBlock

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

the class StructurePlacementUtils method unloadStructure.

/**
 * Unload a structure at a certain location.
 *
 * @param world    the world.
 * @param startPos      the position.
 * @param name    the name.
 * @param rotation the rotation.
 * @param mirror   the mirror.
 */
public static void unloadStructure(@NotNull final World world, @NotNull final BlockPos startPos, @NotNull final String name, final Rotation rotation, @NotNull final Mirror mirror) {
    @NotNull final IStructureHandler structure = new CreativeStructureHandler(world, startPos, name, new PlacementSettings(mirror, rotation), false);
    structure.getBluePrint().rotateWithMirror(rotation, mirror, world);
    @NotNull final StructurePlacer placer = new StructurePlacer(structure);
    placer.executeStructureStep(world, null, new BlockPos(0, 0, 0), StructurePlacer.Operation.BLOCK_REMOVAL, () -> placer.getIterator().increment((info, pos, handler) -> handler.getWorld().getBlockState(pos).getBlock() instanceof AirBlock), true);
}
Also used : TickedWorldOperation(com.ldtteam.structurize.util.TickedWorldOperation) World(net.minecraft.world.World) AirBlock(net.minecraft.block.AirBlock) BlockPos(net.minecraft.util.math.BlockPos) Mirror(net.minecraft.util.Mirror) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) Manager(com.ldtteam.structurize.management.Manager) CreativeStructureHandler(com.ldtteam.structurize.placement.structure.CreativeStructureHandler) Rotation(net.minecraft.util.Rotation) Log(com.ldtteam.structurize.api.util.Log) IStructureHandler(com.ldtteam.structurize.placement.structure.IStructureHandler) NotNull(org.jetbrains.annotations.NotNull) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) CreativeStructureHandler(com.ldtteam.structurize.placement.structure.CreativeStructureHandler) AirBlock(net.minecraft.block.AirBlock) IStructureHandler(com.ldtteam.structurize.placement.structure.IStructureHandler) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) NotNull(org.jetbrains.annotations.NotNull)

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