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

The following examples show how to use net.minecraft.init.Blocks#DIRT . 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
Source Project: TofuCraftReload   File: MapGenTofuCaves.java    License: MIT License 6 votes vote down vote up
protected boolean canReplaceBlock(IBlockState p_175793_1_, IBlockState p_175793_2_) {
    if (p_175793_1_.getBlock() == Blocks.STONE) {
        return true;
    } else if (p_175793_1_.getBlock() == Blocks.DIRT) {
        return true;
    } else if (p_175793_1_.getBlock() == Blocks.GRASS) {
        return true;
    } else if (p_175793_1_.getBlock() == Blocks.HARDENED_CLAY) {
        return true;
    } else if (p_175793_1_.getBlock() == Blocks.STAINED_HARDENED_CLAY) {
        return true;
    } else if (p_175793_1_.getBlock() == Blocks.SANDSTONE) {
        return true;
    } else if (p_175793_1_.getBlock() == Blocks.RED_SANDSTONE) {
        return true;
    } else if (p_175793_1_.getBlock() == Blocks.MYCELIUM) {
        return true;
    } else if (p_175793_1_.getBlock() == Blocks.SNOW_LAYER) {
        return true;
    } else {
        return (/*p_175793_1_.getBlock() == TcBlocks.tofuMinced || */p_175793_1_.getBlock() == Blocks.GRAVEL)
                && p_175793_2_.getMaterial() != Material.WATER;

    }
}
 
Example 2
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 3
@Test
public void test_useUpItem()
{
    ShapedOreRecipe recipe = new DamageableShapedOreRecipe(new ResourceLocation("group"),
                                                           new int[] {60}, new ItemStack(Blocks.DIRT),
                                                           "A",
                                                           'A', new ItemStack(Items.WOODEN_SWORD));

    InventoryCrafting inv = new InventoryCrafting(new Container()
    {
        @Override
        public boolean canInteractWith(EntityPlayer playerIn)
        {
            return false;
        }
    }, 3, 3);

    inv.setInventorySlotContents(0, new ItemStack(Items.WOODEN_SWORD));
    assertTrue(recipe.matches(inv, null));

    NonNullList<ItemStack> remaining = recipe.getRemainingItems(inv);
    assertTrue(remaining.get(0).isEmpty());
}
 
Example 4
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 5
@Override
  public void onLivingUpdate()
  {
if (this.world.getBlockState(new BlockPos((int)this.posX, (int)this.posY, (int)this.posZ)).getBlock() == Blocks.DIRT)
      {
      	this.heal(0.1F);
      }

      super.onLivingUpdate();
  }
 
Example 6
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 7
Source Project: GokiStats   File: StatTreasureFinder.java    License: MIT License 5 votes vote down vote up
public List<ItemStack> getApplicableItemStackList(Block block, int blockMD, int level) {
    List<ItemStack> items = new ArrayList<>();
    for (TreasureFinderEntry tfe : entries) {
        if (tfe.minimumLevel <= level) {
            if (((tfe.getBlock() == null) && ((block == Blocks.DIRT) || (block == Blocks.GRASS))) || ((tfe.getBlock() == block) && (tfe.blockMetadata == blockMD))) {
                items.add(new ItemStack(tfe.getItem(), 1, tfe.itemMetadata));
            }
        }
    }
    return items;
}
 
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
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 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 12
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 13
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 14
Source Project: Sakura_mod   File: BlockMapleSaplingRed.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: 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 16
public WorldGenPatch(IBlockState state, int size) {
    this(state, size, Blocks.DIRT, Blocks.GRASS, Blocks.STONE);
}
 
Example 17
public WorldGenSurfacePatch(IBlockState state, int size) {
	this(state, size, Blocks.DIRT, Blocks.GRASS, Blocks.STONE);
}
 
Example 18
@Nullable
protected ItemStack getStateToItemOverride(IBlockState state)
{
    Block block = state.getBlock();

    if (block == Blocks.PISTON_HEAD ||
        block == Blocks.PISTON_EXTENSION ||
        block == Blocks.PORTAL ||
        block == Blocks.END_PORTAL ||
        block == Blocks.END_GATEWAY)
    {
        return ItemStack.EMPTY;
    }
    else if (block == Blocks.FARMLAND)
    {
        return new ItemStack(Blocks.DIRT);
    }
    else if (block == Blocks.GRASS_PATH)
    {
        return new ItemStack(Blocks.GRASS);
    }
    else if (block == Blocks.BROWN_MUSHROOM_BLOCK)
    {
        return new ItemStack(Blocks.BROWN_MUSHROOM_BLOCK);
    }
    else if (block == Blocks.RED_MUSHROOM_BLOCK)
    {
        return new ItemStack(Blocks.RED_MUSHROOM_BLOCK);
    }
    else if (block == Blocks.LAVA)
    {
        if (state.getValue(BlockLiquid.LEVEL) == 0)
        {
            return new ItemStack(Items.LAVA_BUCKET);
        }
        else
        {
            return ItemStack.EMPTY;
        }
    }
    else if (block == Blocks.WATER)
    {
        if (state.getValue(BlockLiquid.LEVEL) == 0)
        {
            return new ItemStack(Items.WATER_BUCKET);
        }
        else
        {
            return ItemStack.EMPTY;
        }
    }
    else if (block instanceof BlockDoor && state.getValue(BlockDoor.HALF) == BlockDoor.EnumDoorHalf.UPPER)
    {
        return ItemStack.EMPTY;
    }
    else if (block instanceof BlockBed && state.getValue(BlockBed.PART) == BlockBed.EnumPartType.HEAD)
    {
        return ItemStack.EMPTY;
    }
    else if (block instanceof BlockDoublePlant && state.getValue(BlockDoublePlant.HALF) == BlockDoublePlant.EnumBlockHalf.UPPER)
    {
        return ItemStack.EMPTY;
    }

    return null;
}
 
Example 19
@Test
public void testEquals(){
	MetaBlock dirt = new MetaBlock(Blocks.DIRT);
	MetaBlock dirt2 = new MetaBlock(Blocks.DIRT);
	assert(dirt.equals(dirt2));
}
 
Example 20
public WorldGenSurfacePatch(IBlockState state, int size) {
	this(state, size, Blocks.DIRT, Blocks.GRASS, Blocks.STONE);
}