Java Code Examples for net.minecraft.init.Blocks#GRASS

The following examples show how to use net.minecraft.init.Blocks#GRASS . 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: CropHandler.java    From BetterChests with GNU Lesser General Public License v3.0 6 votes vote down vote up
static boolean makeFarmland(World world, BlockPos pos, IBetterChest chest, boolean simulate) {
	BlockPos below = pos.down();
	IBlockState blockBelow = world.getBlockState(below);
	boolean farmland = false;
	if (blockBelow.getBlock() == Blocks.DIRT || blockBelow.getBlock() == Blocks.GRASS) {
		int hoe = InvUtil.findInInvInternal(chest, null, test -> test.getItem() instanceof ItemHoe);
		if (hoe != -1) {
			farmland = true;
			if (!simulate) {
				ItemStack tool = chest.getStackInSlot(hoe);
				tool.attemptDamageItem(1, world.rand, null);
				if (tool.getItemDamage() > tool.getMaxDamage()) {
					tool.setItemDamage(0);
					tool.setCount(tool.getCount() - 1);
				}

				world.setBlockState(below, Blocks.FARMLAND.getDefaultState());
			}
		}
	}

	return farmland;
}
 
Example 2
Source File: EntityEnderminy.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
@Override
public boolean getCanSpawnHere() {
  boolean passedGrassCheck = true;
  if(Config.enderminySpawnOnlyOnGrass) {
    int i = MathHelper.floor(posX);
    int j = MathHelper.floor(getEntityBoundingBox().minY);
    int k = MathHelper.floor(posZ);
    passedGrassCheck = world.getBlockState(VecUtil.bpos(i, j - 1, k)).getBlock() == Blocks.GRASS;
  }
  return passedGrassCheck && posY > Config.enderminyMinSpawnY && super.getCanSpawnHere();
}
 
Example 3
Source File: HoeBehaviour.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemUse(EntityPlayer player, World world, BlockPos blockPos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = player.getHeldItem(hand);
    if (player.canPlayerEdit(blockPos, facing, stack) && !world.isAirBlock(blockPos)) {
        IBlockState blockState = world.getBlockState(blockPos);
        if (blockState.getBlock() == Blocks.GRASS || blockState.getBlock() == Blocks.DIRT) {
            if (blockState.getBlock() == Blocks.GRASS && player.isSneaking()) {
                if (GTUtility.doDamageItem(stack, this.cost, false)) {
                    if (world.rand.nextInt(3) == 0) {
                        ItemStack grassSeed = ForgeHooks.getGrassSeed(world.rand, 0);
                        Block.spawnAsEntity(world, blockPos.up(), grassSeed);
                    }
                    world.playSound(null, blockPos, SoundEvents.ITEM_HOE_TILL, SoundCategory.PLAYERS, 1.0F, 1.0F);
                    world.setBlockState(blockPos, Blocks.DIRT.getDefaultState()
                        .withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.COARSE_DIRT));
                    return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
                }
            } else if (blockState.getBlock() == Blocks.GRASS
                || blockState.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT
                || blockState.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.COARSE_DIRT) {
                if (GTUtility.doDamageItem(stack, this.cost, false)) {
                    world.playSound(null, blockPos, SoundEvents.ITEM_HOE_TILL, SoundCategory.PLAYERS, 1.0F, 1.0F);
                    world.setBlockState(blockPos, Blocks.FARMLAND.getDefaultState());
                    return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
                }
            }
        }
    }
    return ActionResult.newResult(EnumActionResult.FAIL, stack);
}
 
Example 4
Source File: TileEntityGnomeCache.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void processBlueprintLoc(BlockPosAndBlock loc, Block oldblock)
 {
 	Block normalblock = oldblock;
 	// normalize blocks
 	if (normalblock == Blocks.GRASS)
 	{
 		normalblock = Blocks.DIRT;
 	}
 	if (normalblock != loc.block)
 	{	// block mismatch
 		if (isBlockUnsafe(normalblock))
 		{	// avoid conflicts with nearby hovels by selfdestructing
 			this.selfDestruct();
 		}
 		else if (MobbableBlock.isSoftBlock(oldblock, this.world))
 		{
     		if (loc.block == Blocks.AIR) // if old block is diggable and new block is air, destroy
     		{
     			this.assignmentQueue.add(new GnomeAssignment(loc, oldblock, EnumAssignType.DESTROY));
     		}
     		else	// if old block is diggable and new block is solid, alter
     		{
 				this.assignmentQueue.add(new GnomeAssignment(loc, oldblock, EnumAssignType.ALTER));
     		}
 		}
 		else if (WorldHelper.isAirLikeBlock(this.world, loc.pos))
{	// if old block is air-like, create
	this.assignmentQueue.add(new GnomeAssignment(loc, oldblock, EnumAssignType.CREATE));
}
 	}
 	else
 	{	// no mismatch
 		this.blueprint.add(loc);
 	}
 	
 }
 
Example 5
Source File: EntityGnomeWood.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Checks if the entity's current position is a valid location to spawn this entity.
 */
public boolean getCanSpawnHere()
{
    int i = MathHelper.floor(this.posX);
    int j = MathHelper.floor(this.getEntityBoundingBox().minY);
    int k = MathHelper.floor(this.posZ);
    BlockPos blockpos = new BlockPos(i, j, k);
    return this.world.getBlockState(blockpos.down()).getBlock() == Blocks.GRASS && this.world.getLight(blockpos) > 8 && super.getCanSpawnHere();
}
 
Example 6
Source File: BlockMapleSaplingYellow.java    From Sakura_mod with MIT License 4 votes vote down vote up
@Override
protected boolean canSustainBush(IBlockState state) {

	Block block = state.getBlock();
	return block == Blocks.GRASS || block == Blocks.DIRT || block.getMaterial(state) == Material.GROUND;
}
 
Example 7
Source File: WorldGenSurfacePatch.java    From CommunityMod with GNU Lesser General Public License v2.1 4 votes vote down vote up
public WorldGenSurfacePatch(IBlockState state, int size) {
	this(state, size, Blocks.DIRT, Blocks.GRASS, Blocks.STONE);
}
 
Example 8
Source File: WorldGenPatch.java    From CommunityMod with GNU Lesser General Public License v2.1 4 votes vote down vote up
public WorldGenPatch(IBlockState state, int size) {
    this(state, size, Blocks.DIRT, Blocks.GRASS, Blocks.STONE);
}
 
Example 9
Source File: BlockMapleSaplingOrange.java    From Sakura_mod with MIT License 4 votes vote down vote up
@Override
protected boolean canSustainBush(IBlockState state) {

	Block block = state.getBlock();
	return block == Blocks.GRASS || block == Blocks.DIRT || block.getMaterial(state) == Material.GROUND;
}
 
Example 10
Source File: ItemEnderTool.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
public boolean useHoe(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side)
{
    if (player.canPlayerEdit(pos, side, stack) == false)
    {
        return false;
    }

    int hook = net.minecraftforge.event.ForgeEventFactory.onHoeUse(stack, player, world, pos);
    if (hook != 0)
    {
        return hook > 0;
    }

    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();

    if (side != EnumFacing.DOWN && world.isAirBlock(pos.up()))
    {
        IBlockState newBlockState = null;

        if (block == Blocks.GRASS)
        {
            newBlockState = Blocks.FARMLAND.getDefaultState();
        }
        else if (block == Blocks.DIRT)
        {
            if (state.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT ||
                state.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.COARSE_DIRT)
            {
                newBlockState = Blocks.FARMLAND.getDefaultState();
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }

        if (newBlockState != null)
        {
            world.setBlockState(pos, newBlockState, 3);
            this.addToolDamage(stack, 1, player, player);

            world.playSound(null, pos.getX() + 0.5d, pos.getY() + 0.5d, pos.getZ() + 0.5d,
                    SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0f, 1.0f);

            return true;
        }
    }

    return false;
}
 
Example 11
Source File: BlockAndItemWikiTab.java    From IGW-mod with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ItemStack renderTabIcon(GuiWiki gui){
    return new ItemStack(Blocks.GRASS);
}
 
Example 12
Source File: BlockSakuraSapling.java    From Sakura_mod with MIT License 4 votes vote down vote up
@Override
protected boolean canSustainBush(IBlockState state) {

	Block block = state.getBlock();
	return block == Blocks.GRASS || block == Blocks.DIRT || block.getMaterial(state) == Material.GROUND;
}
 
Example 13
Source File: BlockMapleSaplingGreen.java    From Sakura_mod with MIT License 4 votes vote down vote up
@Override
protected boolean canSustainBush(IBlockState state) {

	Block block = state.getBlock();
	return block == Blocks.GRASS || block == Blocks.DIRT || block.getMaterial(state) == Material.GROUND;
}
 
Example 14
Source File: WorldGenSurfacePatch.java    From Traverse-Legacy-1-12-2 with MIT License 4 votes vote down vote up
public WorldGenSurfacePatch(IBlockState state, int size) {
	this(state, size, Blocks.DIRT, Blocks.GRASS, Blocks.STONE);
}
 
Example 15
Source File: WorldGenMapleTree.java    From Sakura_mod with MIT License 4 votes vote down vote up
/**
 * Fill the given area with the selected blocks
 */
private void fallenLeaves(World worldIn,BlockPos pos, int xADD, int yADD, int zADD, IBlockState insideBlockState){
	int xx = pos.getX();
    int yy = pos.getY();
    int zz = pos.getZ();
    
    boolean setFlg = false;
    int YEND = 4;
    for (int xx1 = xx - xADD; xx1 <= xx + xADD; xx1++) {
      for (int zz1 = zz - zADD; zz1 <= zz + zADD; zz1++) {
        if (((xx1 != xx - xADD) || (zz1 != zz - zADD)) && ((xx1 != xx + xADD) || (zz1 != zz - zADD)) && ((xx1 != xx - xADD) || (zz1 != zz + zADD)) && ((xx1 != xx + xADD) || (zz1 != zz + zADD)) && (((xx1 >= xx - xADD + 1) && (xx1 <= xx + xADD - 1) && (zz1 >= zz - zADD + 1) && (zz1 <= zz + zADD - 1)) || (worldIn.rand.nextInt(2) != 0)))
        {
          setFlg = false;
          int yy1 = yy + yADD;
          Block cBl = worldIn.getBlockState(new BlockPos(xx1, yy + yADD, zz1)).getBlock();
          
          if ((cBl == Blocks.AIR) || (cBl instanceof BlockLeaves) || (cBl == BlockLoader.CHESTNUTBURR)) {
            for (yy1 = yy + yADD; yy1 >= yy - YEND; yy1--)
            {
              boolean cAir = worldIn.isAirBlock(new BlockPos(xx1, yy1, zz1));
              cBl = worldIn.getBlockState(new BlockPos(xx1, yy1 - 1, zz1)).getBlock();
              if ((cBl == Blocks.AIR) || ((cBl != Blocks.GRASS) && !(cBl instanceof BlockLeaves) && (!worldIn.getBlockState(new BlockPos(xx1, yy1 - 1, zz1)).isOpaqueCube())))
              {
                if (cBl != Blocks.AIR) {
                  break;
                }
              }
              else if (cAir)
              {
                setFlg = true;
                break;
              }
            }
          }
          if (setFlg) {
            setBlockAndNotifyAdequately(worldIn, new BlockPos(xx1, yy1, zz1), insideBlockState);
          }
        }
      }
    }
}
 
Example 16
Source File: WorldGenMapleTreeGreen.java    From Sakura_mod with MIT License 4 votes vote down vote up
/**
 * Fill the given area with the selected blocks
 */
private void fallenLeaves(World worldIn,BlockPos pos, int xADD, int yADD, int zADD, IBlockState insideBlockState){
	int xx = pos.getX();
    int yy = pos.getY();
    int zz = pos.getZ();
    
    boolean setFlg = false;
    int YEND = 4;
    for (int xx1 = xx - xADD; xx1 <= xx + xADD; xx1++) {
      for (int zz1 = zz - zADD; zz1 <= zz + zADD; zz1++) {
        if (((xx1 != xx - xADD) || (zz1 != zz - zADD)) && ((xx1 != xx + xADD) || (zz1 != zz - zADD)) && ((xx1 != xx - xADD) || (zz1 != zz + zADD)) && ((xx1 != xx + xADD) || (zz1 != zz + zADD)) && (((xx1 >= xx - xADD + 1) && (xx1 <= xx + xADD - 1) && (zz1 >= zz - zADD + 1) && (zz1 <= zz + zADD - 1)) || (worldIn.rand.nextInt(2) != 0)))
        {
          setFlg = false;
          int yy1 = yy + yADD;
          Block cBl = worldIn.getBlockState(new BlockPos(xx1, yy + yADD, zz1)).getBlock();
          
          if ((cBl == Blocks.AIR) || (cBl instanceof BlockLeaves) || (cBl == BlockLoader.CHESTNUTBURR)) {
            for (yy1 = yy + yADD; yy1 >= yy - YEND; yy1--)
            {
              boolean cAir = worldIn.isAirBlock(new BlockPos(xx1, yy1, zz1));
              cBl = worldIn.getBlockState(new BlockPos(xx1, yy1 - 1, zz1)).getBlock();
              if ((cBl == Blocks.AIR) || ((cBl != Blocks.GRASS) && !(cBl instanceof BlockLeaves) && (!worldIn.getBlockState(new BlockPos(xx1, yy1 - 1, zz1)).isOpaqueCube())))
              {
                if (cBl != Blocks.AIR) {
                  break;
                }
              }
              else if (cAir)
              {
                setFlg = true;
                break;
              }
            }
          }
          if (setFlg) {
            setBlockAndNotifyAdequately(worldIn, new BlockPos(xx1, yy1, zz1), insideBlockState);
          }
        }
      }
    }
}
 
Example 17
Source File: BlockUnderVine.java    From TofuCraftReload with MIT License 4 votes vote down vote up
/**
 * Return true if the block can sustain a Bush
 */
protected boolean canSustainBush(IBlockState state) {
    return state.getBlock() == Blocks.GRASS || state.getBlock() == Blocks.DIRT || state.getBlock() == BlockLoader.tofuTerrain || state.getBlock() == this;
}
 
Example 18
Source File: BlockApricotSapling.java    From TofuCraftReload with MIT License 4 votes vote down vote up
@Override
protected boolean canSustainBush(IBlockState state) {

    Block block = state.getBlock();
    return block == Blocks.GRASS || block == Blocks.DIRT;
}
 
Example 19
Source File: BlockTofuYuba.java    From TofuCraftReload with MIT License 4 votes vote down vote up
/**
 * Return true if the block can sustain a Bush
 */
protected boolean canSustainBush(IBlockState state) {
    return state.getBlock() == Blocks.GRASS || state.getBlock() == Blocks.DIRT || state.getBlock() == BlockLoader.tofuTerrain|| state.getBlock() == BlockLoader.yubaGrass;
}
 
Example 20
Source File: MapGenTofuCaves.java    From TofuCraftReload with MIT License 4 votes vote down vote up
private boolean isTopBlock(ChunkPrimer data, int x, int y, int z, int chunkX, int chunkZ) {
    net.minecraft.world.biome.Biome biome = world.getBiome(new BlockPos(x + chunkX * 16, 0, z + chunkZ * 16));
    IBlockState state = data.getBlockState(x, y, z);
    return (isExceptionBiome(biome) ? state.getBlock() == Blocks.GRASS : state.getBlock() == biome.topBlock);
}