Jump to content

Hoe, till more then just 1 block?


Mark719

Recommended Posts

Just wondering how you make a tools, in my case a hoe do more then just the 1 block it would normally do, e.g I want my hoe to farm a 3x3 area just on 1 click. hope someone can help.

 

My hoe code:

package magicCrop;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class MagicHoe extends ItemHoe {
public MagicHoe(int ItemID, EnumToolMaterial material){
	super(ItemID, material);
	this.maxStackSize = 1;
	this.setCreativeTab(CreativeTabs.tabTools);
}

public String getTextureFile(){
	return "/magiccrops/crops.png";
}

@SideOnly(Side.CLIENT)
public EnumRarity getRarity(ItemStack par2){
	return EnumRarity.epic;
}
}

Link to comment
Share on other sites

  • 4 months later...

I think this should work:

 

package kaiKaii99Items;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.Event.Result;
import net.minecraftforge.event.entity.player.UseHoeEvent;

public class SpecialItemHoe extends Item
{
    protected EnumToolMaterial theToolMaterial;

    public SpecialItemHoe(int par1, EnumToolMaterial par2EnumToolMaterial)
    {
        super(par1);
        this.theToolMaterial = par2EnumToolMaterial;
        this.maxStackSize = 1;
        this.setMaxDamage(par2EnumToolMaterial.getMaxUses());
        this.setCreativeTab(CreativeTabs.tabTools);
    }


    /**
     * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
     * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
     */
    public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
    {
        if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack))
        {
            return false;
        }
        else
        {
            UseHoeEvent event = new UseHoeEvent(par2EntityPlayer, par1ItemStack, par3World, par4, par5, par6);
            if (MinecraftForge.EVENT_BUS.post(event))
            {
                return false;
            }

            if (event.getResult() == Result.ALLOW)
            {
                par1ItemStack.damageItem(1, par2EntityPlayer);
                return true;
            }

            int i1 = par3World.getBlockId(par4, par5, par6);
            int i2 = par3World.getBlockId(par4+1, par5, par6);
            int i3 = par3World.getBlockId(par4, par5, par6+1);
            int i4 = par3World.getBlockId(par4+1, par5, par6+1);
            int i5 = par3World.getBlockId(par4-1, par5, par6);
            int i6 = par3World.getBlockId(par4, par5, par6-1);
            int i7 = par3World.getBlockId(par4-1, par5, par6-1);
            int i8 = par3World.getBlockId(par4-1, par5, par6+1);
            int i9 = par3World.getBlockId(par4+1, par5, par6-1);
            int j1 = par3World.getBlockId(par4, par5 + 1, par6);

            if ((par7 == 0 || j1 != 0 || i1 != Block.grass.blockID) && i1 != Block.dirt.blockID && i2 != Block.dirt.blockID && i3 != Block.dirt.blockID && i4 != Block.dirt.blockID && i5 != Block.dirt.blockID && i6 != Block.dirt.blockID && i7 != Block.dirt.blockID && i8 != Block.dirt.blockID && i9 != Block.dirt.blockID)
            {
                return false;
            }
            else
            {
                Block block = Block.tilledField;
                par3World.playSoundEffect((double)((float)par4 + 0.5F), (double)((float)par5 + 0.5F), (double)((float)par6 + 0.5F), block.stepSound.getStepSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);

                if (par3World.isRemote)
                {
                    return true;
                }
                else
                {
                    par3World.setBlock(par4+1, par5, par6, block.blockID);
                    par3World.setBlock(par4, par5, par6+1, block.blockID);
                    par3World.setBlock(par4+1, par5, par6+1, block.blockID);
                  	par3World.setBlock(par4-1, par5, par6, block.blockID);
                    par3World.setBlock(par4, par5, par6-1, block.blockID);
                    par3World.setBlock(par4-1, par5, par6-1, block.blockID);
                    par3World.setBlock(par4-1, par5, par6+1, block.blockID);
                    par3World.setBlock(par4+1, par5, par6-1, block.blockID);
                	par3World.setBlock(par4, par5, par6, block.blockID);
                    par1ItemStack.damageItem(1, par2EntityPlayer);
                    return true;
                }
            }
        }
    }

    @SideOnly(Side.CLIENT)

    /**
     * Returns True is the item is renderer in full 3D when hold.
     */
    public boolean isFull3D()
    {
        return true;
    }

    /**
     * Returns the name of the material this tool is made from as it is declared in EnumToolMaterial (meaning diamond
     * would return "EMERALD")
     */
    public String getMaterialName()
    {
        return this.theToolMaterial.toString();
    }
}

just make an item that extens SpecialItemHoe and done

Link to comment
Share on other sites

I think, what you gonna do is override onItemUse in your MagicHoe class:

@Override
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10){
        if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack)){
            return false;
        }else{
            UseHoeEvent event = new UseHoeEvent(par2EntityPlayer, par1ItemStack, par3World, par4, par5, par6);
            if (MinecraftForge.EVENT_BUS.post(event)){
                return false;
            }

            if (event.getResult() == Result.ALLOW){
                par1ItemStack.damageItem(1, par2EntityPlayer);
                return true;
            }
            for(int i = -1; i < 2; i++){
            	for(int j = -1; j < 2; j++){
            		int i1 = par3World.getBlockId(par4+j, par5, par6+i);
            		int j1 = par3World.getBlockId(par4+j, par5 + 1, par6+i);

            		if (!((par7 == 0 || j1 != 0 || i1 != Block.grass.blockID) && i1 != Block.dirt.blockID)){
            			Block block = Block.tilledField;
            			par3World.playSoundEffect((double)((float)par4 + j + 0.5F), 
                                             (double)((float)par5 + 0.5F), (double)((float)par6 + j + 0.5F), block.stepSound.getStepSound(), 
                                             block.stepSound.getVolume() + 1.0F) /2.0F, block.stepSound.getPitch() * 0.8F);
            			if (!par3World.isRemote){
            				par3World.setBlock(par4 + j, par5, par6 + i, Block.tilledField.blockID);
            			}
            		}
            	}
            }
            par1ItemStack.damageItem(1, par2EntityPlayer);
            return true;
        }
    }

kaikaii99, your code is extremely bulky and unoptimized...

And why should he create a new class and extend his MagicHoe with it, when he can just add that one method (sic!) that does the work, to his own class?

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

Link to comment
Share on other sites

1st, it's bulky because i didn't write the most of it, i just edited the itemhoe class, which its obvious. 2nd, Of course its unoptimized, i wrote it as an example, you can just write 1 simple for loop and its done, 3rd maybe he wants to make more 'magic' hoes, its easier if you just extend your class to the MagicHoe class

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.