Jump to content

(solved) Custom Bonemeal not working 1.10


hhggtg3279

Recommended Posts

for anyone stuck in the same situation heres the working code:

 

 

package top.mod.item;

 

import java.util.List;

import net.minecraft.block.Block;

import net.minecraft.block.BlockOldLog;

import net.minecraft.block.BlockPlanks;

import net.minecraft.block.IGrowable;

import net.minecraft.block.material.Material;

import net.minecraft.block.state.IBlockState;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.passive.EntitySheep;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Blocks;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.util.EnumActionResult;

import net.minecraft.util.EnumFacing;

import net.minecraft.util.EnumHand;

import net.minecraft.util.EnumParticleTypes;

import net.minecraft.util.math.BlockPos;

import net.minecraft.world.World;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

 

public class GrowthItem extends Item

{

    public static final int[] DYE_COLORS = new int[] {1973019, 11743532, 3887386, 5320730, 2437522, 8073150, 2651799, 11250603, 4408131, 14188952, 4312372, 14602026, 6719955, 12801229, 15435844, 15790320};

 

    public GrowthItem()

    {

        this.setHasSubtypes(true);

        this.setMaxDamage(0);

        this.setCreativeTab(CreativeTabs.MATERIALS);

    }

 

   

    /**

    * Called when a Block is right-clicked with this Item

    */

    public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)

    {

        if (!playerIn.canPlayerEdit(pos.offset(facing), facing, stack))

        {

            return EnumActionResult.FAIL;

        }

        else if (applyBonemeal(stack, worldIn, pos, playerIn))

                {

                    if (!worldIn.isRemote)

                    {

                        worldIn.playEvent(2005, pos, 0);

                    }

 

                    return EnumActionResult.SUCCESS;

                }

         

           

 

            return EnumActionResult.PASS;

        }

   

 

    public static boolean applyBonemeal(ItemStack stack, World worldIn, BlockPos target)

    {

        if (worldIn instanceof net.minecraft.world.WorldServer)

            return applyBonemeal(stack, worldIn, target, net.minecraftforge.common.util.FakePlayerFactory.getMinecraft((net.minecraft.world.WorldServer)worldIn));

        return false;

    }

 

    public static boolean applyBonemeal(ItemStack stack, World worldIn, BlockPos target, EntityPlayer player)

    {

        IBlockState iblockstate = worldIn.getBlockState(target);

 

        int hook = net.minecraftforge.event.ForgeEventFactory.onApplyBonemeal(player, worldIn, target, iblockstate, stack);

        if (hook != 0) return hook > 0;

 

        if (iblockstate.getBlock() instanceof IGrowable)

        {

            IGrowable igrowable = (IGrowable)iblockstate.getBlock();

 

            if (igrowable.canGrow(worldIn, target, iblockstate, worldIn.isRemote))

            {

                if (!worldIn.isRemote)

                {

                    if (igrowable.canUseBonemeal(worldIn, worldIn.rand, target, iblockstate))

                    {

                        igrowable.grow(worldIn, worldIn.rand, target, iblockstate);

                    }

 

                    --stack.stackSize;

                }

 

                return true;

            }

        }

 

        return false;

    }

 

    @SideOnly(Side.CLIENT)

    public static void spawnBonemealParticles(World worldIn, BlockPos pos, int amount)

    {

        if (amount == 0)

        {

            amount = 15;

        }

 

        IBlockState iblockstate = worldIn.getBlockState(pos);

 

        if (iblockstate.getMaterial() != Material.AIR)

        {

            for (int i = 0; i < amount; ++i)

            {

                double d0 = itemRand.nextGaussian() * 0.02D;

                double d1 = itemRand.nextGaussian() * 0.02D;

                double d2 = itemRand.nextGaussian() * 0.02D;

                worldIn.spawnParticle(EnumParticleTypes.VILLAGER_HAPPY, (double)((float)pos.getX() + itemRand.nextFloat()), (double)pos.getY() + (double)itemRand.nextFloat() * iblockstate.getBoundingBox(worldIn, pos).maxY, (double)((float)pos.getZ() + itemRand.nextFloat()), d0, d1, d2, new int[0]);

            }

        }

        else

        {

            for (int i1 = 0; i1 < amount; ++i1)

            {

                double d0 = itemRand.nextGaussian() * 0.02D;

                double d1 = itemRand.nextGaussian() * 0.02D;

                double d2 = itemRand.nextGaussian() * 0.02D;

                worldIn.spawnParticle(EnumParticleTypes.VILLAGER_HAPPY, (double)((float)pos.getX() + itemRand.nextFloat()), (double)pos.getY() + (double)itemRand.nextFloat() * 1.0f, (double)((float)pos.getZ() + itemRand.nextFloat()), d0, d1, d2, new int[0]);

            }

        }

    }

 

 

       

    }

 

 

Link to comment
Share on other sites

Two things, you just copied code from ItemDye for bonemeal code. Two why would

EnumDyeColor enumdyecolor = EnumDyeColor.byDyeDamage(stack.getMetadata());

                   if (enumdyecolor == EnumDyeColor.WHITE)

Ever return true if It is not A dye. Also we need the error. What is happening?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

I also tried this and it still wont do anything

 

package top.mod.item;

 

import net.minecraft.block.Block;

import net.minecraft.block.BlockOldLog;

import net.minecraft.block.BlockPlanks;

import net.minecraft.block.IGrowable;

import net.minecraft.block.state.IBlockState;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Blocks;

import net.minecraft.init.Items;

import net.minecraft.item.EnumDyeColor;

import net.minecraft.item.Item;

import net.minecraft.item.ItemDye;

import net.minecraft.item.ItemStack;

import net.minecraft.util.EnumActionResult;

import net.minecraft.util.EnumFacing;

import net.minecraft.util.EnumHand;

import net.minecraft.util.math.BlockPos;

import net.minecraft.world.World;

 

public class GrowthItem extends Item {

 

 

 

public boolean onItemUse(ItemStack stack, BlockPos player, World world, int par1, int par2, int par3, int par4, float f1, float f2, float f3) {

 

return ItemDye.applyBonemeal(stack, world, player);

}

 

public void onItemRightClick(ItemStack stack, EntityPlayer player, World world) {

 

stack.damageItem(1, player);

}

{

}

}

 

Link to comment
Share on other sites

I tried taking out the cocoa beans and it still does nothing

 

 

package top.mod.item;

 

import net.minecraft.block.Block;

import net.minecraft.block.BlockOldLog;

import net.minecraft.block.BlockPlanks;

import net.minecraft.block.IGrowable;

import net.minecraft.block.material.Material;

import net.minecraft.block.state.IBlockState;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.Entity;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Blocks;

import net.minecraft.item.EnumDyeColor;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.util.EnumActionResult;

import net.minecraft.util.EnumFacing;

import net.minecraft.util.EnumHand;

import net.minecraft.util.EnumParticleTypes;

import net.minecraft.util.math.BlockPos;

import net.minecraft.world.World;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

 

public class GrowthItem extends Item

{

    public GrowthItem()

    {

    this.setMaxDamage(0);

    }

 

 

 

/**

* Called when a Block is right-clicked with this Item

* @return

*/

public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)

{

    if (!playerIn.canPlayerEdit(pos.offset(facing), facing, stack))

    {

        return EnumActionResult.FAIL;

    }

    else

    {

        EnumDyeColor enumdyecolor = EnumDyeColor.byDyeDamage(stack.getMetadata());

 

        if (enumdyecolor == EnumDyeColor.WHITE)

        {

            if (applyBonemeal(stack, worldIn, pos, playerIn))

            {

                if (!worldIn.isRemote)

                {

                    worldIn.playEvent(2005, pos, 0);

                }

 

                return EnumActionResult.SUCCESS;

            }

        }

    }

return null;

 

        }

       

public static boolean applyBonemeal(ItemStack stack, World worldIn, BlockPos target)

{

    if (worldIn instanceof net.minecraft.world.WorldServer)

        return applyBonemeal(stack, worldIn, target, net.minecraftforge.common.util.FakePlayerFactory.getMinecraft((net.minecraft.world.WorldServer)worldIn));

    return false;

}

 

public static boolean applyBonemeal(ItemStack stack, World worldIn, BlockPos target, EntityPlayer player)

{

    IBlockState iblockstate = worldIn.getBlockState(target);

 

    int hook = net.minecraftforge.event.ForgeEventFactory.onApplyBonemeal(player, worldIn, target, iblockstate, stack);

    if (hook != 0) return hook > 0;

 

    if (iblockstate.getBlock() instanceof IGrowable)

    {

        IGrowable igrowable = (IGrowable)iblockstate.getBlock();

 

        if (igrowable.canGrow(worldIn, target, iblockstate, worldIn.isRemote))

        {

            if (!worldIn.isRemote)

            {

                if (igrowable.canUseBonemeal(worldIn, worldIn.rand, target, iblockstate))

                {

                    igrowable.grow(worldIn, worldIn.rand, target, iblockstate);

                }

 

                --stack.stackSize;

            }

 

            return true;

        }

    }

 

    return false;

}

 

@SideOnly(Side.CLIENT)

public static void spawnBonemealParticles(World worldIn, BlockPos pos, int amount)

{

    if (amount == 0)

    {

        amount = 15;

    }

 

    IBlockState iblockstate = worldIn.getBlockState(pos);

 

    if (iblockstate.getMaterial() != Material.AIR)

    {

        for (int i = 0; i < amount; ++i)

        {

            double d0 = itemRand.nextGaussian() * 0.02D;

            double d1 = itemRand.nextGaussian() * 0.02D;

            double d2 = itemRand.nextGaussian() * 0.02D;

            worldIn.spawnParticle(EnumParticleTypes.VILLAGER_HAPPY, (double)((float)pos.getX() + itemRand.nextFloat()), (double)pos.getY() + (double)itemRand.nextFloat() * iblockstate.getBoundingBox(worldIn, pos).maxY, (double)((float)pos.getZ() + itemRand.nextFloat()), d0, d1, d2, new int[0]);

        }

    }

    else

    {

        for (int i1 = 0; i1 < amount; ++i1)

        {

            double d0 = itemRand.nextGaussian() * 0.02D;

            double d1 = itemRand.nextGaussian() * 0.02D;

            double d2 = itemRand.nextGaussian() * 0.02D;

            worldIn.spawnParticle(EnumParticleTypes.VILLAGER_HAPPY, (double)((float)pos.getX() + itemRand.nextFloat()), (double)pos.getY() + (double)itemRand.nextFloat() * 1.0f, (double)((float)pos.getZ() + itemRand.nextFloat()), d0, d1, d2, new int[0]);

        }

    }

}

}

 

 

Link to comment
Share on other sites

Two things, you just copied code from ItemDye for bonemeal code. Two why would

EnumDyeColor enumdyecolor = EnumDyeColor.byDyeDamage(stack.getMetadata());

                   if (enumdyecolor == EnumDyeColor.WHITE)

Ever return true if It is not A dye.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

tried this code

 

 

package top.mod.item;

 

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemDye;

import net.minecraft.item.ItemStack;

import net.minecraft.world.World;

 

 

public class GrowthItem extends Item {

 

public GrowthItem(String unlocalizedName) {

 

super();

this.setMaxStackSize(1);

this.setMaxDamage(132);

}

 

public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int par1, int par2, int par3, int par4, float f1, float f2, float f3) {

 

return ItemDye.applyBonemeal(stack, world, par1, par2, par3, player);

}

 

public void onItemRightClick(ItemStack stack, EntityPlayer player, World world) {

 

stack.damageItem(1, player);

}

}

 

 

 

 

but on ItemDye.applyBonemeal I get the error,

 

The method applyBonemeal(ItemStack, World, BlockPos, EntityPlayer) in the type ItemDye is not

applicable for the arguments (ItemStack, World, int, int, int, EntityPlayer)

Link to comment
Share on other sites

stop being sarcastic and please help, its the only thing stumping me and just help

The thing was I wasn't being sarcastic...That error literally tells you what is wrong.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

First time modding or first time using java. Why don't you look at the method applyBonemeal and see what the difference is between what you call, and what it is.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

First time using java, I have kinda been going off making the mod off tuts and generally searching the forums, I have spent over 2 hours looking for fool proof code that works. My knowledge is very limited and I just need this one thing solving, so can you show me what it should look like?

Link to comment
Share on other sites

Nobody's going to just give you the code, that's not how this forum works.

 

You need to spend the time to learn Java properly and then fix the code yourself.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Good job learning nothing. :)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.



×
×
  • Create New...

Important Information

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