Jump to content

[1.8] custom crop control drops quantity <SOLVED>


perromercenary00

Recommended Posts

good nigths

 

 

i make this this custom crop "greenHerv" it only grows on flowerpots,

and  it's supose to only return one item herb when fully grow plus the pot

if not fully grow it must drops only one seed

 

 

in this video when i break the fully grow plant it returns  two seeds plus the bullet but it must return zero seeds

 

 

but not works as it's planed, on break it returns from one to three seeds plus the item herb

i alredy comment the code i think could be adding the extra seeds. but no it still returning from one to three extra seeds whith the itemherb

 

i set some system outs and clearly could see the "getSeed" been called three times   

 

console output

[19:27:13] [server thread/INFO] [sTDOUT]: [mercenarymod.blocks.plantas.hierbaVerde_blocke:quantityDropped:156]: quantityDropped
[19:27:13] [server thread/INFO] [sTDOUT]: [mercenarymod.blocks.plantas.hierbaVerde_blocke:getItemDropped:186]: getItemDropped  bala 45
[19:27:13] [server thread/INFO] [sTDOUT]: [mercenarymod.blocks.plantas.hierbaVerde_blocke:getSeed:140]: getSeed
[19:27:13] [server thread/INFO] [sTDOUT]: [mercenarymod.blocks.plantas.hierbaVerde_blocke:getSeed:140]: getSeed
[19:27:13] [server thread/INFO] [sTDOUT]: [mercenarymod.blocks.plantas.hierbaVerde_blocke:getSeed:140]: getSeed
[19:27:13] [server thread/INFO] [sTDOUT]: [mercenarymod.blocks.plantas.hierbaVerde_blocke:getDrops:271]: getDrops varios 

 



package mercenarymod.blocks.plantas;

import java.util.Random;

import mercenarymod.Mercenary;

import mercenarymod.items.MercenaryModItems;
import net.minecraft.block.Block;
import net.minecraft.block.BlockBush;
import net.minecraft.block.BlockCrops;
import net.minecraft.block.IGrowable;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class hierbaVerde_blocke extends BlockCrops  implements IGrowable
{
    //##########################################################################################################################################3
    public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 7);
    //private static final String __OBFID = "CL_00000222";

    //##########################################################################################################################################3
    public hierbaVerde_blocke()
    {
        setDefaultState(this.blockState.getBaseState().withProperty(AGE, Integer.valueOf(0)));
        setTickRandomly(true);
        float f = 0.5F;
        this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.25F, 0.5F + f);
    	
        String name = "hierbaVerde_blocke";
        setUnlocalizedName(Mercenary.MODID + "_" + name);
        GameRegistry.registerBlock(this, name);
        //setCreativeTab(Mercenary.blockes);
        
        setHardness(0.0F);
        setStepSound(soundTypeGrass);
        disableStats();
    }

    //##########################################################################################################################################3
    /**
     * is the block grass, dirt or farmland
     */
    @Override
    protected boolean canPlaceBlockOn(Block ground)
    {
        return true;//ground == Blocks.farmland;
    }

    //##########################################################################################################################################3
    @Override
    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
    {
        super.updateTick(worldIn, pos, state, rand);

        if (worldIn.getLightFromNeighbors(pos.up()) >= 2)
        {
            int i = ((Integer)state.getValue(AGE)).intValue();

            if (i < 7)
            {
                float f = getGrowthChance(this, worldIn, pos);

                if (rand.nextInt((int)(25.0F / f) + 1) == 0)
                {
                    worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(i + 1)), 2);
                }
            }
        }
    }

    //##########################################################################################################################################3
    @Override
    public void grow(World worldIn, BlockPos pos, IBlockState state)
    {
        int i = ((Integer)state.getValue(AGE)).intValue() + MathHelper.getRandomIntegerInRange(worldIn.rand, 2, 5);

        if (i > 7)
        {
            i = 7;
        }

        worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(i)), 2);
    }

    //##########################################################################################################################################3
    protected static float getGrowthChance(Block blockIn, World worldIn, BlockPos pos)
    {
        float f = 1.0F;
        BlockPos blockpos1 = pos.down();

        for (int i = -1; i <= 1; ++i)
        {
            for (int j = -1; j <= 1; ++j)
            {
                float f1 = 0.0F;
                IBlockState iblockstate = worldIn.getBlockState(blockpos1.add(i, 0, j));

                    f1 = 1.5F;


                if (i != 0 || j != 0)
                {
                    f1 /= 4.0F;
                }

                f += f1;
            }
        }

  
        return f;
    }

    //##########################################################################################################################################3
    @Override
    public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
    {
        return true;//(worldIn.getLight(pos) >= 8 || worldIn.canSeeSky(pos)) && worldIn.getBlockState(pos.down()).getBlock().canSustainPlant(worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this);
    }

    //##########################################################################################################################################3
    @Override
    protected Item getSeed()
    {
    	System.out.println("getSeed");
        return MercenaryModItems.hierbaVerdeSemilla;
    }

    //##########################################################################################################################################3
    @Override
    protected Item getCrop()
    {
    	System.out.println("getCrop");
        return MercenaryModItems.hierbaVerdePlanta;
    }
    
    //##########################################################################################################################################3
    @Override
    public int quantityDropped(Random random)
    {
    	System.out.println("quantityDropped");
    	
        return 1;
    }

    //##########################################################################################################################################3
    /**
     * Spawns this Block's drops into the World as EntityItems.
     *  
     * @param chance The chance that each Item is actually spawned (1.0 = always, 0.0 = never)
     * @param fortune The player's fortune level
     */
    @Override
    public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
    {
        super.dropBlockAsItemWithChance(worldIn, pos, state, chance, 0);
    }

    
    
    //##########################################################################################################################################3
    /**
     * Get the Item that this Block should drop when harvested.
     *  
     * @param fortune the level of the Fortune enchantment on the player's tool
     */
    @Override
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
    {
    	
    	System.out.println("getItemDropped  bala 45");
    	
        //return ( (Integer)state.getValue(AGE)).intValue() == 7 ? this.getCrop() : this.getSeed();
        
        return MercenaryModItems.bala45acp_obsidiana;  //just for testing prupourses , this is item always drop in the world
        
    }
//#################################################################################################3
    @Override
    public void onBlockDestroyedByPlayer(World worldIn, BlockPos pos, IBlockState state) {

    	IBlockState materast = Blocks.flower_pot.getDefaultState();
    	
    	worldIn.setBlockState(pos, materast);
    	
    }
  //#################################################################################################3    
    /**
     * Whether this IGrowable can grow
     */
    @Override
    public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
    {
        return ((Integer)state.getValue(AGE)).intValue() < 7;
    }

    //##########################################################################################################################################3
    @Override
    public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state)
    {
        return true;
    }

    //##########################################################################################################################################3
    @Override
    @SideOnly(Side.CLIENT)
    public Item getItem(World worldIn, BlockPos pos)
    {
    	
    	System.out.println("getItem");
        return this.getSeed();
    }

    
    //##########################################################################################################################################3
    @Override
    public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)
    {
        this.grow(worldIn, pos, state);
    }

    //##########################################################################################################################################3
    /**
     * Convert the given metadata into a BlockState for this Block
     */
    @Override
    public IBlockState getStateFromMeta(int meta)
    {
        return this.getDefaultState().withProperty(AGE, Integer.valueOf(meta));
    }

    //##########################################################################################################################################3
    /**
     * Convert the BlockState into the correct metadata value
     */
    @Override
    public int getMetaFromState(IBlockState state)
    {
        return ((Integer)state.getValue(AGE)).intValue();
    }

    //##########################################################################################################################################3    
    @Override
    protected BlockState createBlockState()
    {
        return new BlockState(this, new IProperty[] {AGE});
    }

    
  //##########################################################################################################################################3
    @Override
    public java.util.List<ItemStack> getDrops(net.minecraft.world.IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
    {
        java.util.List<ItemStack> ret = super.getDrops(world, pos, state, fortune);
        
        System.out.println("getDrops varios ");
        
        
        /* part dissable
        
        int age = ((Integer)state.getValue(AGE)).intValue();
        Random rand = world instanceof World ? ((World)world).rand : new Random();

        if (age >= 7)
        {
            int k = 1 + fortune;

            for (int i = 0; i < k + fortune; ++i)
            {
                if (rand.nextInt(15) <= age)
                {
                    ret.add(new ItemStack(this.getSeed(), 1, 0));
                }
            }
        }
        */
        
        
        return ret;
    }
    
    
//##########################################################################################################################################3    
}

 

 

thanks for reading

Link to comment
Share on other sites

ñaa

 

just talking to the duck

 

// ##########################################################################################################################################3
@Override
public java.util.List<ItemStack> getDrops(net.minecraft.world.IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {

	List<ItemStack> ret = new ArrayList<ItemStack>(); //= super.getDrops(world, pos, state, fortune);

	ret.add(new ItemStack ( this.getSeed() ,1,0 ));


	int i = (((Integer) state.getValue(AGE)).intValue());

	if (i > 6)
	{
	ret.add(new ItemStack ( this.getCrop() ,1,0 ));
	}

	for (int r = 0 ; r < ret.size() ; r++)
	{
		ItemStack g = (ItemStack) ret.get(r);

		if (g != null)
		{
			System.out.println("getDrops["+r+"]="+g.getUnlocalizedName());
		}
	}

	return ret;
}

// ##########################################################################################################################################3

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.