Java Code Examples for net.minecraft.init.Blocks.DIRT

The following are Jave code examples for showing how to use DIRT of the net.minecraft.init.Blocks class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: customstuff4   File: DamageableShapelessOreRecipeTest.java   View Source Code Vote up 6 votes
private void doTest(boolean inOrder, boolean enoughDamage)
{
    DamageableShapelessOreRecipe recipe = new DamageableShapelessOreRecipe(new ResourceLocation("group"),
                                                                           new int[] {enoughDamage ? 5 : 5000, 0},
                                                                           new ItemStack(Blocks.DIRT), new ItemStack(Items.WOODEN_SWORD), new ItemStack(Items.APPLE));
    InventoryCrafting inv = new InventoryCrafting(new Container()
    {
        @Override
        public boolean canInteractWith(EntityPlayer playerIn)
        {
            return false;
        }
    }, 3, 3);
    inv.setInventorySlotContents(inOrder ? 3 : 4, new ItemStack(Items.WOODEN_SWORD));
    inv.setInventorySlotContents(inOrder ? 4 : 3, new ItemStack(Items.APPLE));

    assertSame(enoughDamage, recipe.matches(inv, null));

    if (enoughDamage)
    {
        NonNullList<ItemStack> remaining = recipe.getRemainingItems(inv);
        assertSame(Items.WOODEN_SWORD, remaining.get(inOrder ? 3 : 4).getItem());
        assertEquals(5, remaining.get(inOrder ? 3 : 4).getItemDamage());
    }
}
 
Example 2
Project: uniquecrops   File: UCRecipes.java   View Source Code Vote up 6 votes
private static ItemStack getDyeCraftingResult(int meta) {
	
	switch (meta) {
		default: return new ItemStack(Items.GHAST_TEAR);
		case 1: return new ItemStack(Items.FIRE_CHARGE, 8, 0);
		case 2: return new ItemStack(Items.DRAGON_BREATH);
		case 3: return new ItemStack(Items.DIAMOND);
		case 4: return new ItemStack(Items.GOLD_INGOT);
		case 5: return new ItemStack(Items.SLIME_BALL, 4, 0);
		case 6: return new ItemStack(Items.SADDLE);
		case 7: return new ItemStack(Blocks.CLAY, 8, 0);
		case 8: return new ItemStack(Items.IRON_INGOT, 2, 0);
		case 9: return new ItemStack(Blocks.STAINED_HARDENED_CLAY, 16, EnumDyeColor.CYAN.getMetadata());
		case 10: return new ItemStack(Items.CHORUS_FRUIT);
		case 11: return new ItemStack(Blocks.PRISMARINE, 8, 0);
		case 12: return new ItemStack(Blocks.DIRT, 3, 0);
		case 13: return new ItemStack(Items.EMERALD);
		case 14: return new ItemStack(Items.NETHER_WART);
		case 15: return new ItemStack(Items.SKULL, 1, 1);
	}
}
 
Example 3
Project: Backmemed   File: WorldGenMegaPineTree.java   View Source Code Vote up 6 votes
private void placePodzolAt(World worldIn, BlockPos pos)
{
    for (int i = 2; i >= -3; --i)
    {
        BlockPos blockpos = pos.up(i);
        IBlockState iblockstate = worldIn.getBlockState(blockpos);
        Block block = iblockstate.getBlock();

        if (block == Blocks.GRASS || block == Blocks.DIRT)
        {
            this.setBlockAndNotifyAdequately(worldIn, blockpos, PODZOL);
            break;
        }

        if (iblockstate.getMaterial() != Material.AIR && i < 0)
        {
            break;
        }
    }
}
 
Example 4
Project: Backmemed   File: WorldGenHugeTrees.java   View Source Code Vote up 6 votes
/**
 * returns whether or not there is dirt underneath the block where the tree will be grown.
 * It also generates dirt around the block in a 2x2 square if there is dirt underneath the blockpos.
 */
private boolean ensureDirtsUnderneath(BlockPos pos, World worldIn)
{
    BlockPos blockpos = pos.down();
    Block block = worldIn.getBlockState(blockpos).getBlock();

    if ((block == Blocks.GRASS || block == Blocks.DIRT) && pos.getY() >= 2)
    {
        this.setDirtAt(worldIn, blockpos);
        this.setDirtAt(worldIn, blockpos.east());
        this.setDirtAt(worldIn, blockpos.south());
        this.setDirtAt(worldIn, blockpos.south().east());
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 5
Project: FoodCraft-Reloaded   File: BlockQuery.java   View Source Code Vote up 5 votes
@Override
public boolean matches(World world, BlockPos pos) {
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();

    switch (this.plantType) {
        case Desert:
            return block == Blocks.SAND || block == Blocks.HARDENED_CLAY || block == Blocks.STAINED_HARDENED_CLAY || block == Blocks.DIRT;
        case Nether:
            return block == Blocks.SOUL_SAND;
        case Crop:
            return block == Blocks.FARMLAND;
        case Cave:
            return block.isSideSolid(state, world, pos, EnumFacing.UP);
        case Plains:
            return block == Blocks.GRASS || block == Blocks.DIRT || block == Blocks.FARMLAND || block == Blocks.MYCELIUM;
        case Water:
            return state.getMaterial() == Material.WATER && state.getValue(BlockLiquid.LEVEL) == 0;
        case Beach:
            boolean isBeach = block == Blocks.GRASS || block == Blocks.DIRT || block == Blocks.SAND || block == Blocks.MYCELIUM;
            boolean hasWater = (world.getBlockState(pos.east()).getMaterial() == Material.WATER ||
                world.getBlockState(pos.west()).getMaterial() == Material.WATER ||
                world.getBlockState(pos.north()).getMaterial() == Material.WATER ||
                world.getBlockState(pos.south()).getMaterial() == Material.WATER);
            return isBeach && hasWater;
        default:
            return false;
    }
}
 
Example 6
Project: Bewitchment   File: BlockMoonbell.java   View Source Code Vote up 5 votes
private void tryAndSpawn(World w, MutableBlockPos p) {
	int oy = p.getY();
	for (int dy = -5; dy <= 5; dy++) {
		p.setY(oy + dy);
		if ((w.isAirBlock(p) || w.getBlockState(p).getBlock().isReplaceable(w, p)) && w.getBlockState(p.down()).getBlock() == Blocks.DIRT) {
			w.setBlockState(p, this.getDefaultState().withProperty(placed, false), 3);
			return;
		}
	}
}
 
Example 7
Project: CustomWorldGen   File: BlockStem.java   View Source Code Vote up 5 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    super.updateTick(worldIn, pos, state, rand);

    if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
    {
        float f = BlockCrops.getGrowthChance(this, worldIn, pos);

        if(net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, pos, state, rand.nextInt((int)(25.0F / f) + 1) == 0))
        {
            int i = ((Integer)state.getValue(AGE)).intValue();

            if (i < 7)
            {
                state = state.withProperty(AGE, Integer.valueOf(i + 1));
                worldIn.setBlockState(pos, state, 2);
            }
            else
            {
                for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
                {
                    if (worldIn.getBlockState(pos.offset(enumfacing)).getBlock() == this.crop)
                    {
                        return;
                    }
                }

                pos = pos.offset(EnumFacing.Plane.HORIZONTAL.random(rand));
                IBlockState soil = worldIn.getBlockState(pos.down());
                Block block = soil.getBlock();

                if (worldIn.isAirBlock(pos) && (block.canSustainPlant(soil, worldIn, pos.down(), EnumFacing.UP, this) || block == Blocks.DIRT || block == Blocks.GRASS))
                {
                    worldIn.setBlockState(pos, this.crop.getDefaultState());
                }
            }
            net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos));
        }
    }
}
 
Example 8
Project: Backmemed   File: BlockGrass.java   View Source Code Vote up 5 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (!worldIn.isRemote)
    {
        if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getLightOpacity() > 2)
        {
            worldIn.setBlockState(pos, Blocks.DIRT.getDefaultState());
        }
        else
        {
            if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
            {
                for (int i = 0; i < 4; ++i)
                {
                    BlockPos blockpos = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1);

                    if (blockpos.getY() >= 0 && blockpos.getY() < 256 && !worldIn.isBlockLoaded(blockpos))
                    {
                        return;
                    }

                    IBlockState iblockstate = worldIn.getBlockState(blockpos.up());
                    IBlockState iblockstate1 = worldIn.getBlockState(blockpos);

                    if (iblockstate1.getBlock() == Blocks.DIRT && iblockstate1.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && iblockstate.getLightOpacity() <= 2)
                    {
                        worldIn.setBlockState(blockpos, Blocks.GRASS.getDefaultState());
                    }
                }
            }
        }
    }
}
 
Example 9
Project: Backmemed   File: WorldGenAbstractTree.java   View Source Code Vote up 5 votes
/**
 * sets dirt at a specific location if it isn't already dirt
 */
protected void setDirtAt(World worldIn, BlockPos pos)
{
    if (worldIn.getBlockState(pos).getBlock() != Blocks.DIRT)
    {
        this.setBlockAndNotifyAdequately(worldIn, pos, Blocks.DIRT.getDefaultState());
    }
}
 
Example 10
Project: Backmemed   File: BlockMushroom.java   View Source Code Vote up 5 votes
public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
{
    if (pos.getY() >= 0 && pos.getY() < 256)
    {
        IBlockState iblockstate = worldIn.getBlockState(pos.down());
        return iblockstate.getBlock() == Blocks.MYCELIUM ? true : (iblockstate.getBlock() == Blocks.DIRT && iblockstate.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.PODZOL ? true : worldIn.getLight(pos) < 13 && this.canSustainBush(iblockstate));
    }
    else
    {
        return false;
    }
}
 
Example 11
Project: CustomWorldGen   File: WorldGenAbstractTree.java   View Source Code Vote up 5 votes
/**
 * sets dirt at a specific location if it isn't already dirt
 */
protected void setDirtAt(World worldIn, BlockPos pos)
{
    if (worldIn.getBlockState(pos).getBlock() != Blocks.DIRT)
    {
        this.setBlockAndNotifyAdequately(worldIn, pos, Blocks.DIRT.getDefaultState());
    }
}
 
Example 12
Project: uniquecrops   File: BlockOldGrass.java   View Source Code Vote up 5 votes
@Override
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (!worldIn.isRemote)
    {
        if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getLightOpacity(worldIn, pos.up()) > 2)
        {
            worldIn.setBlockState(pos, Blocks.DIRT.getDefaultState());
        }
        else
        {
            if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
            {
                for (int i = 0; i < 4; ++i)
                {
                    BlockPos blockpos = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1);

                    if (blockpos.getY() >= 0 && blockpos.getY() < 256 && !worldIn.isBlockLoaded(blockpos))
                    {
                        return;
                    }

                    IBlockState iblockstate = worldIn.getBlockState(blockpos.up());
                    IBlockState iblockstate1 = worldIn.getBlockState(blockpos);

                    if (iblockstate1.getBlock() == Blocks.DIRT && iblockstate1.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && iblockstate.getLightOpacity(worldIn, pos.up()) <= 2)
                    {
                        worldIn.setBlockState(blockpos, UCBlocks.oldGrass.getDefaultState());
                    }
                }
            }
        }
    }
}
 
Example 13
Project: TheOink   File: OinkBacon.java   View Source Code Vote up 5 votes
@Override
public void onLivingUpdate() {
    super.onLivingUpdate();
    //Block stuff
    List<Block> listBlocks = ImmutableList.copyOf(Block.REGISTRY);
    int blockListSize = listBlocks.size();
    int randomBlockInt = rand.nextInt(blockListSize);
    Block block = Block.getBlockById(randomBlockInt);
    Item itemBlock = Item.getItemFromBlock(block);



    if(!this.world.isRemote && timeToDiamond == 0 || timeToDiamond == -1){
        //I am creating a list of blocks I do not want the pig to drop from registy.
        List<Item> blockedItems = new ArrayList<>();
        blockedItems.add(Items.AIR);

        if(!listBlocks.isEmpty()){
            block = listBlocks.get(randomBlockInt);
        }else if(blockedItems.contains(itemBlock)){
            block = Blocks.DIRT;
        }

        this.playSound(SoundEvents.ENTITY_CHICKEN_EGG, 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
        this.dropItem(itemBlock, 1);
        this.timeToDiamond = this.rand.nextInt(6000) + 6000;
    }

    if(!world.isRemote && timeToDiamond > 0){
        timeToDiamond--;
        //System.out.println("BACON Time set to:" + timeToDiamond);
        //System.out.println(itemBlock);
    }
}
 
Example 14
Project: TheOink   File: OinkWorldGenerator.java   View Source Code Vote up 5 votes
private int getGroundFromAbove(World world, int x, int z)
{
    int y = 255;
    boolean foundGround = false;
    while(!foundGround && y-- >= 63)
    {
        Block blockAt = world.getBlockState(new BlockPos(x,y,z)).getBlock();
        foundGround = blockAt == Blocks.DIRT || blockAt == Blocks.GRASS || blockAt == Blocks.SAND || blockAt == Blocks.SNOW || blockAt == Blocks.SNOW_LAYER || blockAt == Blocks.STONE;
    }

    return y;
}
 
Example 15
Project: Backmemed   File: BlockBush.java   View Source Code Vote up 4 votes
/**
 * 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() == Blocks.FARMLAND;
}
 
Example 16
Project: Backmemed   File: BetterGrass.java   View Source Code Vote up 4 votes
private static List getFaceQuadsDirt(IBlockAccess p_getFaceQuadsDirt_0_, IBlockState p_getFaceQuadsDirt_1_, BlockPos p_getFaceQuadsDirt_2_, EnumFacing p_getFaceQuadsDirt_3_, List p_getFaceQuadsDirt_4_)
{
    Block block = getBlockAt(p_getFaceQuadsDirt_2_, EnumFacing.UP, p_getFaceQuadsDirt_0_);

    if (p_getFaceQuadsDirt_1_.getValue(BlockDirt.VARIANT) != BlockDirt.DirtType.PODZOL)
    {
        return block == Blocks.GRASS_PATH ? (betterGrassPath && getBlockAt(p_getFaceQuadsDirt_2_, p_getFaceQuadsDirt_3_, p_getFaceQuadsDirt_0_) == Blocks.GRASS_PATH ? modelCubeGrassPath.getQuads(p_getFaceQuadsDirt_1_, p_getFaceQuadsDirt_3_, 0L) : p_getFaceQuadsDirt_4_) : p_getFaceQuadsDirt_4_;
    }
    else
    {
        boolean flag = block == Blocks.SNOW || block == Blocks.SNOW_LAYER;

        if (Config.isBetterGrassFancy())
        {
            if (flag)
            {
                if (betterPodzolSnow && getBlockAt(p_getFaceQuadsDirt_2_, p_getFaceQuadsDirt_3_, p_getFaceQuadsDirt_0_) == Blocks.SNOW_LAYER)
                {
                    return modelCubeSnow.getQuads(p_getFaceQuadsDirt_1_, p_getFaceQuadsDirt_3_, 0L);
                }
            }
            else if (betterPodzol)
            {
                BlockPos blockpos = p_getFaceQuadsDirt_2_.down().offset(p_getFaceQuadsDirt_3_);
                IBlockState iblockstate = p_getFaceQuadsDirt_0_.getBlockState(blockpos);

                if (iblockstate.getBlock() == Blocks.DIRT && iblockstate.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.PODZOL)
                {
                    return modelCubePodzol.getQuads(p_getFaceQuadsDirt_1_, p_getFaceQuadsDirt_3_, 0L);
                }
            }
        }
        else if (flag)
        {
            if (betterPodzolSnow)
            {
                return modelCubeSnow.getQuads(p_getFaceQuadsDirt_1_, p_getFaceQuadsDirt_3_, 0L);
            }
        }
        else if (betterPodzol)
        {
            return modelCubePodzol.getQuads(p_getFaceQuadsDirt_1_, p_getFaceQuadsDirt_3_, 0L);
        }

        return p_getFaceQuadsDirt_4_;
    }
}
 
Example 17
Project: Bewitchment   File: BlockTorchwood.java   View Source Code Vote up 4 votes
public boolean canSustainBush(IBlockState state) {
	return state.getBlock() == Blocks.GRASS || state.getBlock() == Blocks.DIRT || state.getBlock() == Blocks.STONE || state.getBlock() == Blocks.FARMLAND || state.getBlock() == ModBlocks.coquina || state.getBlock() == Blocks.SAND || state.getBlock() == Blocks.GRAVEL || state.getBlock() == Blocks.COBBLESTONE || state.getBlock() == Blocks.NETHERRACK || state.getBlock() == Blocks.END_STONE || state.getBlock() == this;
}
 
Example 18
Project: Got-Wood   File: WorldGenBamboo.java   View Source Code Vote up 4 votes
protected boolean func_150523_a(Block block) {
	return (block.getMaterial(null) == Material.AIR) || (block.getMaterial(null) == Material.LEAVES) || (block == Blocks.GRASS) || (block == Blocks.DIRT) || (block == Blocks.LOG) || (block == Blocks.LOG2) || (block == Blocks.SAPLING) || (block == Blocks.VINE);
}
 
Example 19
Project: CustomWorldGen   File: BlockDeadBush.java   View Source Code Vote up 4 votes
/**
 * Return true if the block can sustain a Bush
 */
protected boolean canSustainBush(IBlockState state)
{
    return state.getBlock() == Blocks.SAND || state.getBlock() == Blocks.HARDENED_CLAY || state.getBlock() == Blocks.STAINED_HARDENED_CLAY || state.getBlock() == Blocks.DIRT;
}
 
Example 20
Project: Backmemed   File: WorldGenAbstractTree.java   View Source Code Vote up 4 votes
/**
 * returns whether or not a tree can grow into a block
 * For example, a tree will not grow into stone
 */
protected boolean canGrowInto(Block blockType)
{
    Material material = blockType.getDefaultState().getMaterial();
    return material == Material.AIR || material == Material.LEAVES || blockType == Blocks.GRASS || blockType == Blocks.DIRT || blockType == Blocks.LOG || blockType == Blocks.LOG2 || blockType == Blocks.SAPLING || blockType == Blocks.VINE;
}