Jump to content

Recommended Posts

Posted (edited)

Hello, I want my block (Frozen dirt) after a while to transform into my dirt. i just didnt figure it out how to do that, here is my FrozenDirt class 

package com.studiomaker.poweredelements2.blocks;

import java.util.Random;

import com.studiomaker.poweredelements2.init.ModBlocks;
import com.studiomaker.poweredelements2.util.IHasModel;

import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.world.World;

public class FrozenDirt extends BlockBase implements IHasModel
{

	public FrozenDirt(String name, Material material) 
	{
		super(name, material);
		setSoundType(SoundType.GLASS);
		setHardness(1.0F);
		setResistance(1F);
		setTickRandomly(true);
    }
	
}

 

And here is my MarsDirt class 

package com.studiomaker.poweredelements2.blocks;

import java.util.Random;

import com.studiomaker.poweredelements2.init.ModBlocks;
import com.studiomaker.poweredelements2.init.ModItems;
import com.studiomaker.poweredelements2.util.IHasModel;

import net.minecraft.block.BlockSapling;
import net.minecraft.block.IGrowable;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class MarsDirt extends BlockBase implements IHasModel
{

	public MarsDirt(String name, Material material) 
	{
		super(name, material);
		setSoundType(SoundType.GROUND);
		setHardness(1.0F);
		setResistance(1F);
	}

	   @Override
	    public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, net.minecraftforge.common.IPlantable plantable)
	    {
	        IBlockState plant = plantable.getPlant(world, pos.offset(direction));
	        net.minecraftforge.common.EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));

	        if (plant.getBlock() instanceof BlockSapling)
	        {
	            return true;
	        }

	        return false;
	    }
	    
	    @Override
	    public void onPlantGrow(IBlockState state, World world, BlockPos pos, BlockPos source)
	    {
	    	
	    }
	    
	    
	    @Override
	    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
	    {
	       if(rand.nextInt(99)+1 <= 60)
	        {
	            IBlockState iblockstate = worldIn.getBlockState(pos.up());

	            if (iblockstate.getBlock() instanceof IGrowable && iblockstate.getBlock() != Blocks.GRASS)
	            {
	                IGrowable igrowable = (IGrowable)iblockstate.getBlock();

	                if (igrowable.canGrow(worldIn, pos.up(), iblockstate, worldIn.isRemote))
	                {
	                    if (!worldIn.isRemote)
	                    {
	                        if (igrowable.canUseBonemeal(worldIn, worldIn.rand, pos.up(), iblockstate))
	                        {
	                            igrowable.grow(worldIn, worldIn.rand, pos.up(), iblockstate);
	                            worldIn.playEvent(300, pos, 0);
	                        }

	                    }

	                }
	            }
	        }
	    }
}

 

Edited by StudioMaker
Posted (edited)

 

had same problem this should work but it updates randomly so the time can't be controlled well.

 

this will just change the block at random update

 

package com.studiomaker.poweredelements2.blocks;

import java.util.Random;

import com.studiomaker.poweredelements2.init.ModBlocks;
import com.studiomaker.poweredelements2.util.IHasModel;

import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.world.World;

public class FrozenDirt extends BlockBase implements IHasModel
{

	public FrozenDirt(String name, Material material) 
	{
		super(name, material);
		setSoundType(SoundType.GLASS);
		setHardness(1.0F);
		setResistance(1F);
		setTickRandomly(true);
    }
   
	@Override
	 public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
	    {
		
		
			
				 worldIn.setBlockState(pos, Blocks.AIR.getDefaultState());//chage this to the block you want
				 
		
		
	    }
}

 

Edited by JavaMan7

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.