Search in sources :

Example 6 with IPlantable

use of net.minecraftforge.common.IPlantable in project AgriCraft by AgriCraft.

the class TileEntitySprinkler method irrigate.

/**
     * Depending on the block type either irrigates farmland or forces plant
     * GROWTH (based on chance)
     */
private void irrigate(BlockPos pos, boolean farmlandOnly) {
    IBlockState state = this.getWorld().getBlockState(pos);
    Block block = state.getBlock();
    if (block instanceof BlockFarmland && block.getMetaFromState(state) < 7) {
        // irrigate farmland
        int flag = counter == 0 ? 2 : 6;
        worldObj.setBlockState(pos, block.getStateFromMeta(7), flag);
    } else if (!farmlandOnly && ((block instanceof IPlantable) || (block instanceof IGrowable))) {
        // X1 chance to force GROWTH tick on plant every Y1 ticks
        if (counter == 0 && worldObj.rand.nextDouble() <= AgriCraftConfig.sprinklerGrowthChancePercent) {
            block.updateTick(this.getWorld(), pos, state, worldObj.rand);
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockFarmland(net.minecraft.block.BlockFarmland) IGrowable(net.minecraft.block.IGrowable) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block)

Example 7 with IPlantable

use of net.minecraftforge.common.IPlantable in project BluePower by Qmunity.

the class ItemSeedBag method onItemUse.

@Override
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int posX, int posY, int posZ, int par7, float par8, float par9, float par10) {
    if (par2EntityPlayer.isSneaking()) {
        return false;
    }
    IInventory seedBagInventory = InventoryItem.getItemInventory(par2EntityPlayer, par2EntityPlayer.getCurrentEquippedItem(), "Seed Bag", 9);
    seedBagInventory.openInventory();
    ItemStack seed = getSeedType(par1ItemStack);
    if (seed != null && seed.getItem() instanceof IPlantable) {
        IPlantable plant = (IPlantable) seed.getItem();
        for (int modX = -2; modX < 3; modX++) {
            for (int modZ = -2; modZ < 3; modZ++) {
                Block b = par3World.getBlock(posX + modX, posY, posZ + modZ);
                if (b.canSustainPlant(par3World, posX, posY, posZ, ForgeDirection.UP, plant) && par3World.isAirBlock(posX + modX, posY + 1, posZ + modZ)) {
                    for (int i = 0; i < seedBagInventory.getSizeInventory(); i++) {
                        ItemStack is = seedBagInventory.getStackInSlot(i);
                        if (is != null) {
                            Item item = is.getItem();
                            item.onItemUse(is, par2EntityPlayer, par3World, posX + modX, posY, posZ + modZ, par7, par8 + modX, par9, par10 + modZ);
                            seedBagInventory.decrStackSize(i, 0);
                            break;
                        }
                    }
                }
            }
        }
        return true;
    }
    seedBagInventory.closeInventory();
    return false;
}
Also used : IInventory(net.minecraft.inventory.IInventory) Item(net.minecraft.item.Item) InventoryItem(com.bluepowermod.container.inventory.InventoryItem) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Example 8 with IPlantable

use of net.minecraftforge.common.IPlantable in project PneumaticCraft by MineMaarten.

the class EntityVortex method onUpdate.

@Override
public void onUpdate() {
    oldMotionX = motionX;
    oldMotionY = motionY;
    oldMotionZ = motionZ;
    super.onUpdate();
    //blowOtherEntities();
    // equal to the potion effect friction. 0.95F
    motionX *= 0.95D;
    motionY *= 0.95D;
    motionZ *= 0.95D;
    if (motionX * motionX + motionY * motionY + motionZ * motionZ < 0.1D) {
        setDead();
    }
    if (!worldObj.isRemote) {
        int blockX = (int) Math.floor(posX);
        int blockY = (int) Math.floor(posY);
        int blockZ = (int) Math.floor(posZ);
        for (int i = 0; i < 7; i++) {
            // to 7 so the middle block will also trigger (with UNKNOWN direction)
            Block block = worldObj.getBlock(blockX + ForgeDirection.getOrientation(i).offsetX, blockY + ForgeDirection.getOrientation(i).offsetY, blockZ + ForgeDirection.getOrientation(i).offsetZ);
            if (block instanceof IPlantable || block instanceof BlockLeaves) {
                worldObj.func_147480_a(blockX + ForgeDirection.getOrientation(i).offsetX, blockY + ForgeDirection.getOrientation(i).offsetY, blockZ + ForgeDirection.getOrientation(i).offsetZ, true);
            }
        }
    }
}
Also used : BlockLeaves(net.minecraft.block.BlockLeaves) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block)

Example 9 with IPlantable

use of net.minecraftforge.common.IPlantable in project PneumaticCraft by MineMaarten.

the class EntityVortex method onImpact.

@Override
protected void onImpact(MovingObjectPosition objectPosition) {
    if (objectPosition.entityHit != null) {
        Entity entity = objectPosition.entityHit;
        entity.motionX += motionX;
        entity.motionY += motionY;
        entity.motionZ += motionZ;
        if (!entity.worldObj.isRemote && entity instanceof IShearable) {
            IShearable shearable = (IShearable) entity;
            int x = (int) Math.floor(posX);
            int y = (int) Math.floor(posY);
            int z = (int) Math.floor(posZ);
            if (shearable.isShearable(null, worldObj, x, y, z)) {
                List<ItemStack> drops = shearable.onSheared(null, worldObj, x, y, z, 0);
                for (ItemStack stack : drops) {
                    PneumaticCraftUtils.dropItemOnGround(stack, worldObj, entity.posX, entity.posY, entity.posZ);
                }
            }
        }
    } else {
        Block block = worldObj.getBlock(objectPosition.blockX, objectPosition.blockY, objectPosition.blockZ);
        if (block instanceof IPlantable || block instanceof BlockLeaves) {
            motionX = oldMotionX;
            motionY = oldMotionY;
            motionZ = oldMotionZ;
        } else {
            setDead();
        }
    }
    hitCounter++;
    if (hitCounter > 20)
        setDead();
}
Also used : Entity(net.minecraft.entity.Entity) BlockLeaves(net.minecraft.block.BlockLeaves) IShearable(net.minecraftforge.common.IShearable) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Example 10 with IPlantable

use of net.minecraftforge.common.IPlantable in project ArsMagica2 by Mithion.

the class Plant method applyEffectBlock.

@Override
public boolean applyEffectBlock(ItemStack stack, World world, int blockx, int blocky, int blockz, int blockFace, double impactX, double impactY, double impactZ, EntityLivingBase caster) {
    Block soil = world.getBlock(blockx, blocky, blockz);
    IInventory inventory = DummyEntityPlayer.fromEntityLiving(caster).inventory;
    HashMap<Integer, ItemStack> seeds = GetAllSeedsInInventory(inventory);
    int currentSlot = 0;
    if (soil != Blocks.air && seeds.size() > 0) {
        currentSlot = seeds.keySet().iterator().next();
        ItemStack seedStack = seeds.get(currentSlot);
        IPlantable seed = (IPlantable) seedStack.getItem();
        if (soil != null && soil.canSustainPlant(world, blockx, blocky, blockz, ForgeDirection.UP, seed) && world.isAirBlock(blockx, blocky + 1, blockz)) {
            world.setBlock(blockx, blocky + 1, blockz, seed.getPlant(world, blockx, blocky, blockz));
            seedStack.stackSize--;
            if (seedStack.stackSize <= 0) {
                inventory.setInventorySlotContents(currentSlot, null);
                seeds.remove(currentSlot);
                if (seeds.size() == 0)
                    return true;
            }
        }
        return true;
    }
    return false;
}
Also used : IInventory(net.minecraft.inventory.IInventory) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IPlantable (net.minecraftforge.common.IPlantable)15 Block (net.minecraft.block.Block)11 IBlockState (net.minecraft.block.state.IBlockState)7 ItemStack (net.minecraft.item.ItemStack)6 BlockPos (net.minecraft.util.math.BlockPos)4 IGrowable (net.minecraft.block.IGrowable)3 Item (net.minecraft.item.Item)3 CABlock (convenientadditions.base.block.CABlock)2 BlockLeaves (net.minecraft.block.BlockLeaves)2 IInventory (net.minecraft.inventory.IInventory)2 ItemBlock (net.minecraft.item.ItemBlock)2 World (net.minecraft.world.World)2 IShearable (net.minecraftforge.common.IShearable)2 Affinity (am2.api.spell.enums.Affinity)1 AMParticle (am2.particles.AMParticle)1 ParticleFloatUpward (am2.particles.ParticleFloatUpward)1 InventoryItem (com.bluepowermod.container.inventory.InventoryItem)1 IAgriCrop (com.infinityraider.agricraft.api.v1.crop.IAgriCrop)1 HashMap (java.util.HashMap)1 Filter (mcjty.rftoolsdim.config.Filter)1