Skip to content

Instantly share code, notes, and snippets.

@Propucani2
Created July 17, 2014 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Propucani2/b50f339c6910b104c2e1 to your computer and use it in GitHub Desktop.
Save Propucani2/b50f339c6910b104c2e1 to your computer and use it in GitHub Desktop.
package com.itemsplusmod.plants;
import java.util.Random;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockBush;
import net.minecraft.block.IGrowable;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
public class Crops extends BlockBush implements IGrowable {
@SideOnly(Side.CLIENT)
protected IIcon[] iIcon;
public Crops() {
// Basic block setup
this.setTickRandomly(true);
float f = 0.5F;
this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.25F, 0.5F + f);
this.setCreativeTab((CreativeTabs)null);
this.setHardness(0.0F);
this.setStepSound(soundTypeGrass);
this.disableStats(); }
/**
* is the block grass, dirt or farmland
*/
@Override
protected boolean canPlaceBlockOn(Block parBlock) {
return parBlock == Blocks.farmland; }
public void incrementGrowStage(World parWorld, int parX, int parY, int parZ) {
int growStage = parWorld.getBlockMetadata(parX, parY, parZ) + MathHelper.getRandomIntegerInRange(parWorld.rand, 2, 5);
if (growStage > 7) {
growStage = 7; }
parWorld.setBlockMetadataWithNotify(parX, parY, parZ, growStage, 2); }
@Override
public Item getItemDropped (int p_149650_1_, Random parRand, int parFortune) {
return Item.getItemFromBlock(this); }
/**
* The type of render function that is called for this block
*/
@Override
public int getRenderType() {
return 1; }
/**
* Need to implement the IGrowable interface methods
*
*
* (non-Javadoc)
* @see net.minecraft.block.IGrowable#func_149851.a(net.minecraft.world.World, int, int, int, boolean)
*/
@Override
// checks if finished growing (a grow stage of 7 is final stage)
public boolean func_149851_a(World parWorld, int parX, int parY, int parZ, boolean p_149851_5_) {
return parWorld.getBlockMetadata(parX, parY, parZ) != 7; }
/*
* (non-Javadoc
* @see net.minecraft.block.IGrowable#func_149852_a(net.minecraft.world.World, java.util.Random, int, int, int)
*/
@Override
public boolean func_149852_a(World p_149852_1_, Random parRand, int p_149852_3_, int p_149852_4_, int p_149852_5_) {
return true; }
/*
* (non-Javadoc)
* @see net.minecraft.block.IGrowable#func_149853_b(net.minecraft.world.World, java.util.Random, int, int, int
*/
@Override
public void func_149853_b(World parWorld, Random parRand, int parX, int parY, int parZ) {
this.incrementGrowStage(parWorld, parX, parY, parZ); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment