net.minecraftforge.common.IPlantable Java Examples

The following examples show how to use net.minecraftforge.common.IPlantable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlantItem.java    From GardenCollection with MIT License 6 votes vote down vote up
public static PlantItem getForItem (IBlockAccess blockAccess, ItemStack itemStack) {
    if (itemStack == null || itemStack.getItem() == null)
        return null;

    IPlantable plantable = PlantRegistry.getPlantable(itemStack);
    if (plantable == null)
        return getForItem(itemStack);

    Block block = plantable.getPlant(blockAccess, 0, -1, 0);
    if (block == null)
        return getForItem(itemStack);

    int meta = plantable.getPlantMetadata(blockAccess, 0, -1, 0);
    if (meta == 0)
        meta = itemStack.getItemDamage();

    return new PlantItem(itemStack, block, meta);
}
 
Example #2
Source File: BlockFarmland.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
/*******************************************************************************
 * 1. Content
 *******************************************************************************/

@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand)
{
	if(world.isRemote)
		return;

	if(!(world.getBlockState(pos.up()).getBlock() instanceof IPlantable))
	{
		if(!isFertile(world, pos) && rand.nextInt(100) == 0)
		{
			world.setBlockState(pos, TFCBlocks.Dirt.getDefaultState().withProperty(META_PROPERTY, state.getValue(META_PROPERTY)));
		}
	}
}
 
Example #3
Source File: BlockFarmland.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable)
{
	IBlockState plant = plantable.getPlant(world, pos.offset(direction));
	net.minecraftforge.common.EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));

	if(plantType == EnumPlantType.Crop)
		return true;

	if(plantType == EnumPlantType.Plains)
		return true;

	if(plantable == TFCBlocks.Sapling)
		return true;

	return false;
}
 
Example #4
Source File: BlockVegetation.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable)
{
	IBlockState plant = plantable.getPlant(world, pos.offset(direction));
	EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));

	VegType veg = (VegType)state.getValue(META_PROPERTY);
	if(plant.getBlock() == this)
	{
		if(veg == VegType.DoubleGrassBottom && plant.getValue(META_PROPERTY) == VegType.DoubleGrassTop)
			return true;
		if(veg == VegType.DoubleGrassBottomLush && plant.getValue(META_PROPERTY) == VegType.DoubleGrassTopLush)
			return true;
	}
	return false;
}
 
Example #5
Source File: BlockGrass.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable)
{
	IBlockState plant = plantable.getPlant(world, pos.offset(direction));
	net.minecraftforge.common.EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));

	if(plant.getBlock() == Blocks.SAPLING)
		return false;//This may break some cross mod compatability but for now its needed to prevent vanilla and some pam trees from generating

	if(plantType == EnumPlantType.Plains)
		return true;

	if(plant.getBlock() == TFCBlocks.VegDesert)
		return true;
	return false;
}
 
Example #6
Source File: CompostRegistry.java    From GardenCollection with MIT License 6 votes vote down vote up
private void init () {
    registerCompostMaterial(new ItemStack(Blocks.melon_block), defaultMaterial);
    registerCompostMaterial(new ItemStack(Blocks.pumpkin), defaultMaterial);
    registerCompostMaterial(new ItemStack(Blocks.hay_block), defaultMaterial);
    registerCompostMaterial(new ItemStack(Items.string), new StandardCompostMaterial(100, 0.0625f));
    registerCompostMaterial(new ItemStack(Items.wheat), new StandardCompostMaterial(100, 0.125f));
    registerCompostMaterial(new ItemStack(Items.reeds), new StandardCompostMaterial(150, 0.125f));
    registerCompostMaterial(new ItemStack(Items.feather), new StandardCompostMaterial(50, 0.0625f));
    registerCompostMaterial(new ItemStack(Items.rotten_flesh), new StandardCompostMaterial(150, 0.125f));
    registerCompostMaterial(new ItemStack(Items.leather), new StandardCompostMaterial(150, 0.125f));

    registerCompostMaterial("treeWood", new StandardCompostMaterial(300, 0.25f));
    registerCompostMaterial("logWood", new StandardCompostMaterial(300, 0.25f));
    registerCompostMaterial("treeLeaves", defaultMaterial);
    registerCompostMaterial("treeSapling", defaultMaterial);
    registerCompostMaterial("stickWood", defaultMaterial);

    registerCompostMaterial(IPlantable.class, defaultMaterial);
    registerCompostMaterial(IGrowable.class, defaultMaterial);
    registerCompostMaterial(BlockLeavesBase.class, defaultMaterial);
    registerCompostMaterial(BlockVine.class, defaultMaterial);
    registerCompostMaterial(ItemFood.class, defaultMaterial);
}
 
Example #7
Source File: EntityVortex.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onUpdate(){
    oldMotionX = motionX;
    oldMotionY = motionY;
    oldMotionZ = motionZ;
    super.onUpdate();
    //blowOtherEntities();
    motionX *= 0.95D;// equal to the potion effect friction. 0.95F
    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);
            }
        }
    }

}
 
Example #8
Source File: ItemEnderTool.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean plantItemFromInventorySlot(World world, EntityPlayer player, EnumHand hand,
        IItemHandler inv, int slot, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
{
    boolean ret = false;
    ItemStack plantStack = inv.getStackInSlot(slot);

    if (plantStack.isEmpty() == false && plantStack.getItem() instanceof IPlantable)
    {
        plantStack = inv.extractItem(slot, 1, false);

        if (plantStack.isEmpty())
        {
            return false;
        }

        ItemStack stackHand = player.getHeldItem(hand);
        EntityUtils.setHeldItemWithoutEquipSound(player, hand, plantStack);

        if (plantStack.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ) == EnumActionResult.SUCCESS)
        {
            ret = true;
        }

        EntityUtils.setHeldItemWithoutEquipSound(player, hand, stackHand);

        if (plantStack.isEmpty() == false)
        {
            plantStack = InventoryUtils.tryInsertItemStackToInventory(inv, plantStack);

            if (plantStack.isEmpty() == false)
            {
                player.dropItem(plantStack, false, true);
            }
        }

        player.inventoryContainer.detectAndSendChanges();
    }

    return ret;
}
 
Example #9
Source File: WorldGenBigSakura.java    From Sakura_mod with MIT License 5 votes vote down vote up
/**
   * Returns a boolean indicating whether or not the current location for the tree, spanning basePos to to the height
   * limit, is valid.
   */
  private boolean validTreeLocation()
  {
      BlockPos down = this.basePos.down();
      net.minecraft.block.state.IBlockState state = this.world.getBlockState(down);
      boolean isSoil = state.getBlock().canSustainPlant(state, this.world, down, net.minecraft.util.EnumFacing.UP, ((IPlantable)BlockLoader.SAKURA_SAPLING));

      if (!isSoil)
      {
          return false;
      }
int i = this.checkBlockLine(this.basePos, this.basePos.up(this.heightLimit - 1));

if (i == -1)
{
    return true;
}
else if (i < 6)
{
    return false;
}
else
{
    this.heightLimit = i;
    return true;
}
  }
 
Example #10
Source File: CropHandler.java    From BetterChests with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ItemStack getStackToPlant(Stream<ItemStack> items, World world, BlockPos pos) {
	BlockPos posToCheck = pos.down();
	IBlockState other = world.getBlockState(posToCheck);
	return items.filter(stack -> stack.getItem() instanceof IPlantable).filter(stack -> {
		IPlantable plant = (IPlantable) stack.getItem();
		return other.getBlock().canSustainPlant(other, world, posToCheck, EnumFacing.UP, plant)
				|| Blocks.FARMLAND.canSustainPlant(Blocks.FARMLAND.getDefaultState(), world, posToCheck, EnumFacing.UP, plant);
	}).findFirst().orElse(ItemStack.EMPTY);
}
 
Example #11
Source File: BlockStone.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable)
{
	IBlockState plant = plantable.getPlant(world, pos.offset(direction));
	EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));

	if(plantable == TFCBlocks.Vegetation && (VegType)plant.getValue(BlockVegetation.META_PROPERTY) == VegType.Grass)
		return true;
	return false;
}
 
Example #12
Source File: CropHandler.java    From BetterChests with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean handlePlant(IBetterChest chest, Collection<ItemStack> items, World world, BlockPos pos) {
	ItemStack toPlant = getStackToPlant(items.stream(), world, pos);
	IPlantable plantable = (IPlantable) toPlant.getItem();
	IBlockState current = world.getBlockState(pos.down());
	if (current.getBlock().canSustainPlant(current, world, pos, EnumFacing.UP, plantable) || makeFarmland(world, pos, chest, false)) {

		world.setBlockState(pos, plantable.getPlant(world, pos));
		toPlant.setCount(toPlant.getCount() - 1);
		return true;
	}
	return false;
}
 
Example #13
Source File: BlockDirt.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
/*******************************************************************************
 * 1. Content
 *******************************************************************************/

@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable)
{
	IBlockState plant = plantable.getPlant(world, pos.offset(direction));
	net.minecraftforge.common.EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));

	if(plantType == EnumPlantType.Plains)
		return true;
	return false;
}
 
Example #14
Source File: BlockCactus.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable)
{
	IBlockState plant = plantable.getPlant(world, pos.offset(direction));
	EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));

	DesertCactusType veg = (DesertCactusType)state.getValue(META_PROPERTY);
	if(plant.getBlock() == this)
	{

	}
	return false;
}
 
Example #15
Source File: BlockVegDesert.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable)
{
	IBlockState plant = plantable.getPlant(world, pos.offset(direction));
	EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));

	DesertVegType veg = (DesertVegType)state.getValue(META_PROPERTY);
	if(plant.getBlock() == this)
	{
		if(veg == DesertVegType.DoubleGrassBottomSparse && plant.getValue(META_PROPERTY) == DesertVegType.DoubleGrassTopSparse)
			return true;
	}
	return false;
}
 
Example #16
Source File: TileEntitySprinkler.java    From AgriCraft with MIT License 5 votes vote down vote up
/**
 * This method will search through a vertical column of positions, starting from the top. It
 * will stop searching any lower once it hits anything other than air or plants. Any plant found
 * has an independant chance for a growth tick. That percentage is controlled by
 * AgriCraftConfig. Farmland also ends the search, but it first has its moisture set to max (7)
 * if it isn't already. The lowest position is special: a plant this far away is not helped.
 * Only farmland is currently.
 */
private void irrigateColumn(final int targetX, final int targetZ, final int highestY, final int lowestY) {
    for (int targetY = highestY; targetY >= lowestY; targetY -= 1) {
        BlockPos target = new BlockPos(targetX, targetY, targetZ);
        IBlockState state = this.getWorld().getBlockState(target);
        Block block = state.getBlock();

        // Option A: Skip empty/air blocks.
        // TODO: Is there a way to use isSideSolid to ignore minor obstructions? (Farmland isn't solid.)
        if (block.isAir(state, this.getWorld(), target)) {
            continue;
        }

        // Option B: Give plants a chance to grow, and then continue onward to irrigate the farmland too.
        if ((block instanceof IPlantable || block instanceof IGrowable) && targetY != lowestY) {
            if (this.getRandom().nextInt(100) < AgriCraftConfig.sprinklerGrowthChance) {
                block.updateTick(this.getWorld(), target, state, this.getRandom());
            }
            continue;
        }

        // Option C: Dry farmland gets set as moist.
        if (block instanceof BlockFarmland) {
            if (state.getValue(BlockFarmland.MOISTURE) < 7) {
                this.getWorld().setBlockState(target, state.withProperty(BlockFarmland.MOISTURE, 7), 2);
            }
            break; // Explicitly expresses the intent to stop.
        }

        // Option D: If it's none of the above, it blocks the sprinkler's irrigation. Stop.
        break;
    }
}
 
Example #17
Source File: BlockGarden.java    From GardenCollection with MIT License 5 votes vote down vote up
public boolean canSustainPlantIndependently (IBlockAccess blockAccess, int x, int y, int z, PlantItem plant) {
    Item item = plant.getPlantSourceItem().getItem();
    if (item instanceof IPlantable)
        return canSustainPlant(blockAccess, x, y, z, ForgeDirection.UP, (IPlantable) item);

    return false;
}
 
Example #18
Source File: BlockGardenProxy.java    From GardenCollection with MIT License 5 votes vote down vote up
private Block getPlantBlock (TileEntityGarden tileEntity, Item item) {
    if (item == null)
        return null;
    if (item instanceof IPlantable)
        return ((IPlantable)item).getPlant(tileEntity.getWorldObj(), tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
    if (item instanceof ItemBlock)
        return Block.getBlockFromItem(item);

    return null;
}
 
Example #19
Source File: BlockLargePot.java    From GardenCollection with MIT License 5 votes vote down vote up
@Override
public boolean canSustainPlant (IBlockAccess world, int x, int y, int z, ForgeDirection direction, IPlantable plantable) {
    TileEntityGarden gardenTile = getTileEntity(world, x, y, z);
    EnumPlantType plantType = plantable.getPlantType(world, x, y, z);

    if (plantType == EnumPlantType.Crop)
        return substrateSupportsCrops(gardenTile.getSubstrate());

    return false;
}
 
Example #20
Source File: EntityVortex.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@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();
}
 
Example #21
Source File: PlantItem.java    From GardenCollection with MIT License 5 votes vote down vote up
public static PlantItem getForItem (ItemStack itemStack) {
    if (itemStack == null || itemStack.getItem() == null)
        return null;

    Block block = Block.getBlockFromItem(itemStack.getItem());
    if (block == null || !(block instanceof IPlantable))
        return null;

    return new PlantItem(itemStack, block, itemStack.getItemDamage());
}
 
Example #22
Source File: PlantUtil.java    From GardenCollection with MIT License 5 votes vote down vote up
public static Block getPlantBlock (IPlantable plant) {
    try {
        return getPlantBlock(null, 0, 0, 0, plant);
    }
    catch (Exception e) {
        return null;
    }
}
 
Example #23
Source File: PlantUtil.java    From GardenCollection with MIT License 5 votes vote down vote up
public static int getPlantMetadata (IPlantable plant) {
    try {
        return getPlantMetadata(null, 0, 0, 0, plant);
    }
    catch (Exception e) {
        return 0;
    }
}
 
Example #24
Source File: PlantUtil.java    From GardenCollection with MIT License 5 votes vote down vote up
private static int getPlantMetadata (IBlockAccess world, int x, int y, int z, IPlantable plant, int defaultMeta) {
    if (plant == null)
        return 0;

    Block itemBlock = plant.getPlant(world, x, y, z);
    int itemMeta = defaultMeta;

    if (itemBlock != null) {
        int plantMeta = plant.getPlantMetadata(world, x, y, z);
        if (plantMeta > 0)
            itemMeta = plantMeta;
    }

    return itemMeta;
}
 
Example #25
Source File: PlantRegistry.java    From GardenCollection with MIT License 5 votes vote down vote up
public boolean isValidPlantBlock (Block block) {
    if (block == null)
        return false;
    if (block instanceof IPlantable)
        return true;

    Item item = Item.getItemFromBlock(block);
    if (item instanceof IPlantable)
        return true;

    return false;
}
 
Example #26
Source File: BlockGardenFarmland.java    From GardenCollection with MIT License 5 votes vote down vote up
@Override
public boolean canSustainPlant (IBlockAccess world, int x, int y, int z, ForgeDirection direction, IPlantable plantable) {
    EnumPlantType plantType = plantable.getPlantType(world, x, y, z);
    if (plantType == EnumPlantType.Crop)
        return true;

    return false;
}
 
Example #27
Source File: BlockPlantBamboo.java    From Sakura_mod with MIT License 5 votes vote down vote up
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, net.minecraftforge.common.IPlantable plantable) {
      IBlockState plant = plantable.getPlant(world, pos.offset(direction));
      if (plant.getBlock() == BlockLoader.BAMBOO) {
          return this == BlockLoader.BAMBOO;
      }
return super.canSustainPlant(state, world, pos, direction, plantable);
  }
 
Example #28
Source File: WorldGenBigMaple.java    From Sakura_mod with MIT License 5 votes vote down vote up
/**
   * Returns a boolean indicating whether or not the current location for the tree, spanning basePos to to the height
   * limit, is valid.
   */
  private boolean validTreeLocation()
  {
      BlockPos down = this.basePos.down();
      net.minecraft.block.state.IBlockState state = this.world.getBlockState(down);
      boolean isSoil = state.getBlock().canSustainPlant(state, this.world, down, net.minecraft.util.EnumFacing.UP, ((IPlantable)metaSapling.getBlock()));

      if (!isSoil)
      {
          return false;
      }
int i = this.checkBlockLine(this.basePos, this.basePos.up(this.heightLimit - 1));

if (i == -1)
{
    return true;
}
else if (i < 6)
{
    return false;
}
else
{
    this.heightLimit = i;
    return true;
}
  }
 
Example #29
Source File: BlockPepperCrop.java    From Sakura_mod with MIT License 5 votes vote down vote up
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction,
		IPlantable plantable) {
	return state.getMaterial() == Material.GROUND || state.getMaterial() == Material.GRASS
			|| (state.getBlock() instanceof BlockPepperCrop && this.getAge(state) >= 2)
			|| (state.getBlock() instanceof BlockPepperSplint);
}
 
Example #30
Source File: BlockVanillaCrop.java    From Sakura_mod with MIT License 5 votes vote down vote up
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction,
		IPlantable plantable) {
	return state.getMaterial() == Material.GROUND || state.getMaterial() == Material.GRASS
			|| (state.getBlock() instanceof BlockVanillaCrop && this.getAge(state) >= 2)
			|| (state.getBlock() instanceof BlockVanillaSplint);
}