Jump to content

Recommended Posts

Posted

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;
}
}

  • 4 months later...
Posted

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

Posted

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.

Posted
i wrote it as an example
You haven't said it was example, you wrote that and said "use it"...

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

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello! I have been having a problem with Forgematica, Embeddium, Oculus, and create. I wanted to download litematica so I could see which blocks are in my creative mode build, so that I could collect them all in survival. However, litematica is a fabric mod. I found a port called forgematica, which I added (along with it's dependency) to my mods folder. I loaded into a new world, and built a structure. Then, I added a part from the create mod, and the game crashed instantly, with exit code -1. Thanks for any help! Crash Report and mods list: ---- Minecraft Crash Report ----// Embeddium instance tainted by mods: [entity - Pastebin.com
    • To say that losing 40,000 BTC was a devastating blow would be an understatement. It was an emotional and financial crisis that left me feeling hopeless and utterly lost. For weeks, I was trapped in a whirlwind of regret, second-guessing every decision that led me to that point. The fear that I would never be able to recover such a significant sum of cryptocurrency consumed me, and with each passing day, my despair deepened. I had all but given up on ever regaining my wealth. Then I happened to stumble onto Tech Cyber Force Recovery. In the beginning, I was hesitant. It looked too good to be true: could someone get back so much of their lost Bitcoin? After trying several different approaches and programs without success, I was hesitant to put my trust in another recovery agency. However, I changed my mind after reading Tech Cyber Force Recovery's stellar reviews and reputation. Reaching out to their team was a risk I made. They were courteous and professional from the first time I got in touch with them. I felt like I wasn't just another case to be solved by the staff at Tech Cyber Force Recovery; they truly cared about getting me my lost Bitcoin back. They listened carefully to my circumstances and guided me through each stage, giving me succinct and understandable explanations as I went. Their passion gave me new hope, and their openness instantly made me feel better. As the recovery process began, I still had my doubts, but I knew I had placed my trust in the right hands. The Tech Cyber Force Recovery team kept me informed and updated on their progress, ensuring I never felt in the dark. Despite the complexity of my case, they worked tirelessly, and their expertise became evident at every turn. The level of professionalism and attention to detail they demonstrated throughout the process was beyond impressive. And then, after what felt like an eternity of anticipation, the moment I had been waiting for arrived. I received the news that my 40,000 BTC had been successfully recovered. It was hard to believe at first—it felt like a dream. The weight that had been dragging me down for so long was suddenly lifted, and I could breathe again. The financial loss I had feared would define my future was no longer a reality. I can’t fully express the emotions I felt during that moment. It was a mix of relief, joy, and an overwhelming sense of gratitude. I had gone from a place of utter despair to a complete resurgence of wealth, both emotionally and financially. The Tech Cyber Force Recovery team didn’t just restore my Bitcoin—they restored my faith in the possibility of recovery and gave me back something far more valuable: peace of mind. I will urge anyone in this same predicament to.  
    • Have you found a modder for this vehicle project? Because it will be really hard and I want to know that hero who can create all this
    • and what?????????
  • Topics

×
×
  • Create New...

Important Information

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