Jump to content

Make Sand Drop Custom Item?


GraniteDevil

Recommended Posts

I need to find a way to make an existing block (sand, in this case) drop a custom item.

 

Can this be done without editing the core class?

 

Everything I've found on this involves creating a new block (there seems to be more focus on dropping items with custom blocks and less focus on making existing blocks drop items).  Problem is, I really, really need it to be Sand.  If it can't be done, then I'll find another way to get the item in the game, it just won't be from a block drop.

Link to comment
Share on other sites

There is an much easier way what does not currupt the world and you do not need forge for it (Sorry but forge uses the slowest and hardest way)

 

You delete the class from the sand. this is the code you have to write into your files

 

i = SandBlockID (12)

 

blocksList = null;

 

now the block sand exsist but is an unfinished block than you do this;

 

blocksList[12] = (new BlockCustomSand(12, 18)).setHardness(0.5F).setStepSound(soundSandFootstep);

 

now you have the class BlockCustomSand

 

this is the sand class:

 

 

 

package net.minecraft.block;

 

import java.util.Random;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.item.EntityFallingSand;

import net.minecraft.world.World;

 

public class BlockSand extends Block

{

    /** Do blocks fall instantly to where they stop or do they fall over time */

    public static boolean fallInstantly = false;

 

    public BlockSand(int par1, int par2)

    {

        super(par1, par2, Material.sand);

        this.setCreativeTab(CreativeTabs.tabBlock);

    }

 

    public BlockSand(int par1, int par2, Material par3Material)

    {

        super(par1, par2, par3Material);

    }

 

    /**

    * Called whenever the block is added into the world. Args: world, x, y, z

    */

    public void onBlockAdded(World par1World, int par2, int par3, int par4)

    {

        par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate());

    }

 

    /**

    * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are

    * their own) Args: x, y, z, neighbor blockID

    */

    public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)

    {

        par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate());

    }

 

    /**

    * Ticks the block if it's been scheduled

    */

    public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)

    {

        if (!par1World.isRemote)

        {

            this.tryToFall(par1World, par2, par3, par4);

        }

    }

 

    /**

    * If there is space to fall below will start this block falling

    */

    private void tryToFall(World par1World, int par2, int par3, int par4)

    {

        if (canFallBelow(par1World, par2, par3 - 1, par4) && par3 >= 0)

        {

            byte var8 = 32;

 

            if (!fallInstantly && par1World.checkChunksExist(par2 - var8, par3 - var8, par4 - var8, par2 + var8, par3 + var8, par4 + var8))

            {

                if (!par1World.isRemote)

                {

                    EntityFallingSand var9 = new EntityFallingSand(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F), this.blockID, par1World.getBlockMetadata(par2, par3, par4));

                    this.onStartFalling(var9);

                    par1World.spawnEntityInWorld(var9);

                }

            }

            else

            {

                par1World.setBlockWithNotify(par2, par3, par4, 0);

 

                while (canFallBelow(par1World, par2, par3 - 1, par4) && par3 > 0)

                {

                    --par3;

                }

 

                if (par3 > 0)

                {

                    par1World.setBlockWithNotify(par2, par3, par4, this.blockID);

                }

            }

        }

    }

 

    /**

    * Called when the falling block entity for this block is created

    */

    protected void onStartFalling(EntityFallingSand par1EntityFallingSand) {}

 

    /**

    * How many world ticks before ticking

    */

    public int tickRate()

    {

        return 5;

    }

 

    /**

    * Checks to see if the sand can fall into the block below it

    */

    public static boolean canFallBelow(World par0World, int par1, int par2, int par3)

    {

        int var4 = par0World.getBlockId(par1, par2, par3);

 

        if (var4 == 0)

        {

            return true;

        }

        else if (var4 == Block.fire.blockID)

        {

            return true;

        }

        else

        {

            Material var5 = Block.blocksList[var4].blockMaterial;

            return var5 == Material.water ? true : var5 == Material.lava;

        }

    }

 

    /**

    * Called when the falling block entity for this block hits the ground and turns back into a block

    */

    public void onFinishFalling(World par1World, int par2, int par3, int par4, int par5) {}

}

 

 

 

 

you can copy the class if you want or make your own sand. but i think you want to add a specail drop like gravel?

 

than add this:

 

    public int idDropped(int par1, Random par2Random, int par3)

    {

        if (par3 > 3)

        {

            par3 = 3;

        }

 

        return par2Random.nextInt(10 - par3 * 3) == 0 ? modname.itemname/blockname.item/blockID : this.blockID;

    }

 

so now you overriden the basic sand class.

and if someone use your mod and think he do not want it anymore the world getting not currupted!

 

i hope it helps.

 

 

 

Link to comment
Share on other sites

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.