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

The following examples show how to use net.minecraft.init.Blocks#GRASS . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
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
/**
 * 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 3
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 4
@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 5
@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 6
@Override
public ItemStack renderTabIcon(GuiWiki gui){
    return new ItemStack(Blocks.GRASS);
}
 
Example 7
Source Project: TofuCraftReload   File: MapGenTofuCaves.java    License: 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);
}
 
Example 8
Source Project: TofuCraftReload   File: BlockTofuYuba.java    License: 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 9
Source Project: TofuCraftReload   File: BlockApricotSapling.java    License: 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 10
Source Project: TofuCraftReload   File: BlockUnderVine.java    License: 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 11
Source Project: Sakura_mod   File: WorldGenMapleTreeGreen.java    License: 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 12
Source Project: Sakura_mod   File: WorldGenMapleTree.java    License: 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 13
public WorldGenSurfacePatch(IBlockState state, int size) {
	this(state, size, Blocks.DIRT, Blocks.GRASS, Blocks.STONE);
}
 
Example 14
Source Project: Sakura_mod   File: BlockMapleSaplingGreen.java    License: 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 15
Source Project: Sakura_mod   File: BlockSakuraSapling.java    License: 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 16
Source Project: Sakura_mod   File: BlockMapleSaplingYellow.java    License: 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 17
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 18
Source Project: Sakura_mod   File: BlockMapleSaplingOrange.java    License: 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 19
public WorldGenPatch(IBlockState state, int size) {
    this(state, size, Blocks.DIRT, Blocks.GRASS, Blocks.STONE);
}
 
Example 20
public WorldGenSurfacePatch(IBlockState state, int size) {
	this(state, size, Blocks.DIRT, Blocks.GRASS, Blocks.STONE);
}