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

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

×
×
  • Create New...

Important Information

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