Search in sources :

Example 1 with BlockSapling

use of net.minecraft.block.BlockSapling in project Totemic by TeamTotemic.

the class CeremonyZaphkielWaltz method effect.

@Override
public void effect(World world, BlockPos pos, CeremonyEffectContext context) {
    int radius = 6;
    if (!world.isRemote && context.getTime() % 20 == 0) {
        for (EntityItem entity : EntityUtil.getEntitiesInRange(EntityItem.class, world, pos, radius, radius)) {
            EntityItem item = entity;
            if (item.getItem().getItem() == Items.EGG) {
                if (world.rand.nextInt(4) == 0) {
                    EntityChicken chicken = new EntityChicken(world);
                    chicken.setPosition(entity.posX, entity.posY, entity.posZ);
                    world.spawnEntity(chicken);
                    if (item.getItem().getCount() == 1)
                        item.setDead();
                    else {
                        ItemStack stack = item.getItem().copy();
                        stack.shrink(1);
                        item.setItem(stack);
                    }
                }
            }
        }
    }
    if (context.getTime() % 5 == 0) {
        for (int i = -radius; i <= radius; i++) for (int j = -radius; j <= radius; j++) for (int k = -radius; k <= radius; k++) {
            BlockPos p = pos.add(i, j, k);
            IBlockState state = world.getBlockState(p);
            Block block = state.getBlock();
            if (block instanceof BlockSapling && block != ModBlocks.cedar_sapling) {
                world.setBlockState(p, ModBlocks.cedar_sapling.getDefaultState(), 3);
                spawnParticles(world, p.getX() + 0.5, p.getY() + 0.5, p.getZ() + 0.5);
            } else if ((block instanceof IGrowable || block instanceof IPlantable) && block.getTickRandomly()) {
                if (world.rand.nextInt(4) < 3) {
                    if (!world.isRemote)
                        block.updateTick(world, p, state, world.rand);
                    spawnParticles(world, p.getX() + 0.5, p.getY() + 0.5, p.getZ() + 0.5);
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EntityChicken(net.minecraft.entity.passive.EntityChicken) BlockSapling(net.minecraft.block.BlockSapling) IGrowable(net.minecraft.block.IGrowable) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 2 with BlockSapling

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

the class EntityAIWorkLumberjack method plantSapling.

/**
 * Plant a sapling at said location.
 *
 * @param location the location to plant the sapling at
 * @return true if a sapling was planted
 */
private boolean plantSapling(@NotNull final BlockPos location) {
    final Block worldBlock = world.getBlockState(location).getBlock();
    if (worldBlock != Blocks.AIR && !(worldBlock instanceof BlockSapling)) {
        return false;
    }
    worker.setLatestStatus(new TextComponentTranslation("com.minecolonies.coremod.status.planting"));
    final int saplingSlot = findSaplingSlot();
    final BlockPos dirtLocation = new BlockPos(location.getX(), location.getY() - 1, location.getZ());
    final Block dirt = world.getBlockState(dirtLocation).getBlock();
    if (saplingSlot != -1 && ((job.tree.isSlimeTree() && Compatibility.isSlimeDirtOrGrass(dirt)) || (!job.tree.isSlimeTree() && !Compatibility.isSlimeDirtOrGrass(dirt)))) {
        final ItemStack stack = getInventory().getStackInSlot(saplingSlot);
        final Block block = ((ItemBlock) stack.getItem()).getBlock();
        worker.setHeldItem(saplingSlot);
        placeSaplings(saplingSlot, stack, block);
        final SoundType soundType = block.getSoundType(world.getBlockState(location), world, location, worker);
        world.playSound(null, this.worker.getPosition(), soundType.getPlaceSound(), SoundCategory.BLOCKS, soundType.getVolume(), soundType.getPitch());
        worker.swingArm(worker.getActiveHand());
        this.getOwnBuilding().getColony().getStatsManager().incrementStatistic("saplings");
    }
    if (timeWaited >= MAX_WAITING_TIME / 2 && !checkedInHut && !walkToBuilding()) {
        isInHut(new ItemStack(Blocks.SAPLING, 1, job.tree.getVariant()));
        checkedInHut = true;
    }
    if (job.tree.getStumpLocations().isEmpty() || timeWaited >= MAX_WAITING_TIME) {
        timeWaited = 0;
        incrementActionsDoneAndDecSaturation();
        setDelay(TIMEOUT_DELAY);
        return true;
    }
    timeWaited++;
    return false;
}
Also used : SoundType(net.minecraft.block.SoundType) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) BlockSapling(net.minecraft.block.BlockSapling) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock)

Example 3 with BlockSapling

use of net.minecraft.block.BlockSapling in project Cavern2 by kegare.

the class WorldGenSpruceTreePerverted method generate.

@Override
public boolean generate(World world, Random rand, BlockPos pos) {
    int treeHeight = rand.nextInt(4) + 5;
    int i = 1 + rand.nextInt(2);
    int j = treeHeight - i;
    int k = 2 + rand.nextInt(2);
    boolean flag = true;
    if (pos.getY() >= 1 && pos.getY() + treeHeight + 1 <= world.getHeight()) {
        for (int y = pos.getY(); y <= pos.getY() + 1 + treeHeight && flag; ++y) {
            int l = 1;
            if (y - pos.getY() < i) {
                l = 0;
            } else {
                l = k;
            }
            MutableBlockPos blockpos = new MutableBlockPos();
            for (int x = pos.getX() - l; x <= pos.getX() + l && flag; ++x) {
                for (int z = pos.getZ() - l; z <= pos.getZ() + l && flag; ++z) {
                    if (y >= 0 && y < world.getHeight()) {
                        IBlockState state = world.getBlockState(blockpos.setPos(x, y, z));
                        if (!state.getBlock().isAir(state, world, blockpos.setPos(x, y, z)) && !state.getBlock().isLeaves(state, world, blockpos.setPos(x, y, z))) {
                            flag = false;
                        }
                    } else {
                        flag = false;
                    }
                }
            }
        }
        if (!flag) {
            return false;
        } else {
            IBlockState wood = CaveBlocks.PERVERTED_LOG.getDefaultState().withProperty(BlockOldLog.VARIANT, BlockPlanks.EnumType.SPRUCE);
            IBlockState leaves = CaveBlocks.PERVERTED_LEAVES.getDefaultState().withProperty(BlockOldLeaf.VARIANT, BlockPlanks.EnumType.SPRUCE).withProperty(BlockLeaves.CHECK_DECAY, Boolean.valueOf(false));
            BlockPos down = pos.down();
            IBlockState state = world.getBlockState(down);
            if (state.getBlock().canSustainPlant(state, world, down, EnumFacing.UP, (BlockSapling) Blocks.SAPLING) && pos.getY() < world.getHeight() - treeHeight - 1) {
                state.getBlock().onPlantGrow(state, world, down, pos);
                int l = rand.nextInt(2);
                int m = 1;
                int n = 0;
                for (int py = 0; py <= j; ++py) {
                    int y = pos.getY() + treeHeight - py;
                    for (int x = pos.getX() - l; x <= pos.getX() + l; ++x) {
                        int px = x - pos.getX();
                        for (int z = pos.getZ() - l; z <= pos.getZ() + l; ++z) {
                            int pz = z - pos.getZ();
                            if (Math.abs(px) != l || Math.abs(pz) != l || l <= 0) {
                                BlockPos blockpos = new BlockPos(x, y, z);
                                state = world.getBlockState(blockpos);
                                if (state.getBlock().canBeReplacedByLeaves(state, world, blockpos)) {
                                    setBlockAndNotifyAdequately(world, blockpos, leaves);
                                }
                            }
                        }
                    }
                    if (l >= m) {
                        l = n;
                        n = 1;
                        ++m;
                        if (m > k) {
                            m = k;
                        }
                    } else {
                        ++l;
                    }
                }
                int py = rand.nextInt(3);
                for (int y = 0; y < treeHeight - py; ++y) {
                    BlockPos up = pos.up(y);
                    state = world.getBlockState(up);
                    if (state.getBlock().isAir(state, world, up) || state.getBlock().isLeaves(state, world, up)) {
                        setBlockAndNotifyAdequately(world, pos.up(y), wood);
                    }
                }
                return true;
            }
            return false;
        }
    }
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockSapling(net.minecraft.block.BlockSapling) BlockPos(net.minecraft.util.math.BlockPos) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos)

Example 4 with BlockSapling

use of net.minecraft.block.BlockSapling in project Galacticraft by micdoodle8.

the class TileEntityTerraformer method update.

@Override
public void update() {
    super.update();
    if (!this.worldObj.isRemote) {
        final FluidStack liquid = FluidUtil.getFluidContained(this.containingItems[0]);
        if (FluidUtil.isFluidStrict(liquid, FluidRegistry.WATER.getName())) {
            FluidUtil.loadFromContainer(waterTank, FluidRegistry.WATER, containingItems, 0, liquid.amount);
        }
        this.active = this.bubbleSize == this.MAX_SIZE && this.hasEnoughEnergyToRun && this.getFirstBonemealStack() != null && this.waterTank.getFluid() != null && this.waterTank.getFluid().amount > 0;
    }
    if (!this.worldObj.isRemote && (this.active != this.lastActive || this.ticks % 60 == 0)) {
        this.terraformableBlocksList.clear();
        this.grassBlockList.clear();
        if (this.active) {
            int bubbleSize = (int) Math.ceil(this.bubbleSize);
            double bubbleSizeSq = this.bubbleSize;
            bubbleSizeSq *= bubbleSizeSq;
            boolean doGrass = !this.grassDisabled && this.getFirstSeedStack() != null;
            boolean doTrees = !this.treesDisabled && this.getFirstSaplingStack() != null;
            for (int x = this.getPos().getX() - bubbleSize; x < this.getPos().getX() + bubbleSize; x++) {
                for (int y = this.getPos().getY() - bubbleSize; y < this.getPos().getY() + bubbleSize; y++) {
                    for (int z = this.getPos().getZ() - bubbleSize; z < this.getPos().getZ() + bubbleSize; z++) {
                        BlockPos pos = new BlockPos(x, y, z);
                        Block blockID = this.worldObj.getBlockState(pos).getBlock();
                        if (blockID == null) {
                            continue;
                        }
                        if (!(blockID.isAir(this.worldObj, pos)) && this.getDistanceFromServer(x, y, z) < bubbleSizeSq) {
                            if (doGrass && blockID instanceof ITerraformableBlock && ((ITerraformableBlock) blockID).isTerraformable(this.worldObj, pos)) {
                                this.terraformableBlocksList.add(new BlockPos(x, y, z));
                            } else if (doTrees) {
                                Block blockIDAbove = this.worldObj.getBlockState(pos.up()).getBlock();
                                if (blockID == Blocks.grass && blockIDAbove.isAir(this.worldObj, pos.up())) {
                                    this.grassBlockList.add(new BlockPos(x, y, z));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (!this.worldObj.isRemote && this.terraformableBlocksList.size() > 0 && this.ticks % 15 == 0) {
        ArrayList<BlockPos> terraformableBlocks2 = new ArrayList<BlockPos>(this.terraformableBlocksList);
        int randomIndex = this.worldObj.rand.nextInt(this.terraformableBlocksList.size());
        BlockPos vec = terraformableBlocks2.get(randomIndex);
        if (this.worldObj.getBlockState(vec).getBlock() instanceof ITerraformableBlock) {
            Block id;
            switch(this.worldObj.rand.nextInt(40)) {
                case 0:
                    if (this.worldObj.isBlockFullCube(new BlockPos(vec.getX() - 1, vec.getY(), vec.getZ())) && this.worldObj.isBlockFullCube(new BlockPos(vec.getX() + 1, vec.getY(), vec.getZ())) && this.worldObj.isBlockFullCube(new BlockPos(vec.getX(), vec.getY(), vec.getZ() - 1)) && this.worldObj.isBlockFullCube(new BlockPos(vec.getX(), vec.getY(), vec.getZ() + 1))) {
                        id = Blocks.flowing_water;
                    } else {
                        id = Blocks.grass;
                    }
                    break;
                default:
                    id = Blocks.grass;
                    break;
            }
            this.worldObj.setBlockState(vec, id.getDefaultState());
            if (id == Blocks.grass) {
                this.useCount[0]++;
                this.waterTank.drain(1, true);
                this.checkUsage(1);
            } else if (id == Blocks.flowing_water) {
                this.checkUsage(2);
            }
        }
        this.terraformableBlocksList.remove(randomIndex);
    }
    if (!this.worldObj.isRemote && !this.treesDisabled && this.grassBlockList.size() > 0 && this.ticks % 50 == 0) {
        int randomIndex = this.worldObj.rand.nextInt(this.grassBlockList.size());
        BlockPos vecGrass = grassBlockList.get(randomIndex);
        if (this.worldObj.getBlockState(vecGrass).getBlock() == Blocks.grass) {
            BlockPos vecSapling = vecGrass.add(0, 1, 0);
            ItemStack sapling = this.getFirstSaplingStack();
            boolean flag = false;
            // Attempt to prevent placement too close to other trees
            for (BlockPos testVec : this.grownTreesList) {
                if (testVec.distanceSq(vecSapling) < 9) {
                    flag = true;
                    break;
                }
            }
            if (!flag && sapling != null) {
                Block b = Block.getBlockFromItem(sapling.getItem());
                this.worldObj.setBlockState(vecSapling, b.getStateFromMeta(sapling.getItemDamage()), 3);
                if (b instanceof BlockSapling) {
                    if (this.worldObj.getLightFromNeighbors(vecSapling) >= 9) {
                        ((BlockSapling) b).grow(this.worldObj, vecSapling, this.worldObj.getBlockState(vecSapling), this.worldObj.rand);
                        this.grownTreesList.add(new BlockPos(vecSapling.getX(), vecSapling.getY(), vecSapling.getZ()));
                    }
                } else if (b instanceof BlockBush) {
                    if (this.worldObj.getLightFromNeighbors(vecSapling) >= 5) // Hammer the update tick a few times to try to get it to grow - it won't always
                    {
                        for (int j = 0; j < 12; j++) {
                            if (this.worldObj.getBlockState(vecSapling).getBlock() == b) {
                                ((BlockBush) b).updateTick(this.worldObj, vecSapling, this.worldObj.getBlockState(vecSapling), this.worldObj.rand);
                            } else {
                                this.grownTreesList.add(new BlockPos(vecSapling.getX(), vecSapling.getY(), vecSapling.getZ()));
                                break;
                            }
                        }
                    }
                }
                this.useCount[1]++;
                this.waterTank.drain(50, true);
                this.checkUsage(0);
            }
        }
        this.grassBlockList.remove(randomIndex);
    }
    if (!this.worldObj.isRemote) {
        this.terraformableBlocksListSize = this.terraformableBlocksList.size();
        this.grassBlocksListSize = this.grassBlockList.size();
    }
    if (this.hasEnoughEnergyToRun && (!this.grassDisabled || !this.treesDisabled)) {
        this.bubbleSize = (float) Math.min(Math.max(0, this.bubbleSize + 0.1F), this.MAX_SIZE);
    } else {
        this.bubbleSize = (float) Math.min(Math.max(0, this.bubbleSize - 0.1F), this.MAX_SIZE);
    }
    this.lastActive = this.active;
}
Also used : BlockSapling(net.minecraft.block.BlockSapling) ArrayList(java.util.ArrayList) Block(net.minecraft.block.Block) ITerraformableBlock(micdoodle8.mods.galacticraft.api.block.ITerraformableBlock) BlockPos(net.minecraft.util.BlockPos) ITerraformableBlock(micdoodle8.mods.galacticraft.api.block.ITerraformableBlock) ItemStack(net.minecraft.item.ItemStack) BlockBush(net.minecraft.block.BlockBush)

Example 5 with BlockSapling

use of net.minecraft.block.BlockSapling in project DynamicSurroundings by OreCruncher.

the class FootstepsRegistry method seedMap.

private void seedMap() {
    // Iterate through the blockmap looking for known pattern types.
    // Though they probably should all be registered with Forge
    // dictionary it's not a requirement.
    final Iterator<Block> itr = Block.REGISTRY.iterator();
    while (itr.hasNext()) {
        final Block block = itr.next();
        final String blockName = MCHelper.nameOf(block);
        if (block instanceof BlockCrops) {
            final BlockCrops crop = (BlockCrops) block;
            if (crop.getMaxAge() == 3) {
                registerBlocks("#beets", blockName);
            } else if (blockName.equals("minecraft:wheat")) {
                registerBlocks("#wheat", blockName);
            } else if (crop.getMaxAge() == 7) {
                registerBlocks("#crop", blockName);
            }
        } else if (block instanceof BlockSapling) {
            registerBlocks("#sapling", blockName);
        } else if (block instanceof BlockReed) {
            registerBlocks("#reed", blockName);
        } else if (block instanceof BlockFence) {
            registerBlocks("#fence", blockName);
        } else if (block instanceof BlockFlower || block instanceof BlockMushroom) {
            registerBlocks("NOT_EMITTER", blockName);
        } else if (block instanceof BlockLog || block instanceof BlockPlanks) {
            registerBlocks("wood", blockName);
        } else if (block instanceof BlockDoor) {
            registerBlocks("bluntwood", blockName);
        } else if (block instanceof BlockLeaves) {
            registerBlocks("leaves", blockName);
        } else if (block instanceof BlockOre) {
            registerBlocks("ore", blockName);
        } else if (block instanceof BlockIce) {
            registerBlocks("ice", blockName);
        }
    }
}
Also used : BlockMushroom(net.minecraft.block.BlockMushroom) BlockCrops(net.minecraft.block.BlockCrops) BlockIce(net.minecraft.block.BlockIce) BlockOre(net.minecraft.block.BlockOre) BlockLog(net.minecraft.block.BlockLog) BlockReed(net.minecraft.block.BlockReed) BlockFlower(net.minecraft.block.BlockFlower) BlockPlanks(net.minecraft.block.BlockPlanks) BlockDoor(net.minecraft.block.BlockDoor) BlockLeaves(net.minecraft.block.BlockLeaves) BlockSapling(net.minecraft.block.BlockSapling) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) BlockFence(net.minecraft.block.BlockFence)

Aggregations

BlockSapling (net.minecraft.block.BlockSapling)10 BlockPos (net.minecraft.util.math.BlockPos)7 IBlockState (net.minecraft.block.state.IBlockState)6 Block (net.minecraft.block.Block)4 ItemStack (net.minecraft.item.ItemStack)4 ItemBlock (net.minecraft.item.ItemBlock)3 ArrayList (java.util.ArrayList)2 BlockFlower (net.minecraft.block.BlockFlower)2 BlockLeaves (net.minecraft.block.BlockLeaves)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 Collection (java.util.Collection)1 List (java.util.List)1 Random (java.util.Random)1 Collectors (java.util.stream.Collectors)1 ITerraformableBlock (micdoodle8.mods.galacticraft.api.block.ITerraformableBlock)1 BlockBush (net.minecraft.block.BlockBush)1 BlockCrops (net.minecraft.block.BlockCrops)1 BlockDoor (net.minecraft.block.BlockDoor)1 BlockDoublePlant (net.minecraft.block.BlockDoublePlant)1 BlockFence (net.minecraft.block.BlockFence)1