Jump to content

[1.7.10]Item entity trouble?


SureShotM

Recommended Posts

So ive created a block that on right click should drop my custom item, but when I try this it tells me that when it tries my item is an invalid item? Witch to me doesn't make any sense, either way here is the code.

 

 

 

public class CropBlock extends BlockBush implements IGrowable
{
protected int maxGrowthStage = 7;
private final ItemStack newItem;
private String target = "";
private EntityPlayer player;
@SideOnly(Side.CLIENT)
protected IIcon[] iIcon;
public CropBlock(ItemStack parItem)
{
// Basic block setup
setTickRandomly(true);
float f = 0.5F;
setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.25F, 0.5F + f);
setCreativeTab((CreativeTabs)null);
setHardness(0.0F);
setStepSound(soundTypeGrass);
disableStats();
newItem =parItem;
}
@Override
protected boolean canPlaceBlockOn(Block parBlock)
{
return parBlock == Blocks.farmland;
}
@Override
public boolean canBlockStay(World world, int parX, int parY, int parZ )
{
if (world.getBlock(parX,parY - 1, parZ) != Blocks.farmland)
{
return false;
}
return true;
}
public void incrementGrowStage(World parWorld, Random parRand, int parX, int parY, int parZ)
{
int growStage = parWorld.getBlockMetadata(parX, parY, parZ) +
MathHelper.getRandomIntegerInRange(parRand, 2, 5);
if (growStage > maxGrowthStage)
{
growStage = maxGrowthStage;
}
parWorld.setBlockMetadataWithNotify(parX, parY, parZ, growStage, 2);
}
@Override
public int getRenderType()
{
return 1; // Cross like flowers
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int parSide, int parGrowthStage)
{
return iIcon[parGrowthStage];
}
@Override
public boolean func_149851_a(World p_149851_1_, int p_149851_2_, int p_149851_3_, int p_149851_4_, boolean p_149851_5_) {
return p_149851_1_.getBlockMetadata(p_149851_2_, p_149851_3_, p_149851_4_) != 7;
}
@Override
public boolean func_149852_a(World p_149852_1_, Random p_149852_2_, int p_149852_3_, int p_149852_4_, int p_149852_5_) {
return false;
}
@Override
public void func_149853_b(World p_149853_1_, Random p_149853_2_, int p_149853_3_, int p_149853_4_, int p_149853_5_) {
incrementGrowStage(p_149853_1_, p_149853_2_, p_149853_3_, p_149853_4_, p_149853_5_);
}
@Override
public void updateTick(World parWorld, int parX, int parY, int parZ, Random parRand)
{
super.updateTick(parWorld, parX, parY, parZ, parRand);
int growStage = parWorld.getBlockMetadata(parX, parY, parZ);
if (growStage < 7)
{
float f = this.func_149864_n(parWorld, parX, parY, parZ);
if (parRand.nextInt((int)(375.0F / f) + 1) == 0)
{
++growStage;
parWorld.setBlockMetadataWithNotify(parX, parY, parZ, growStage, 2);
}
}
}
public void func_149863_m(World p_149863_1_, int p_149863_2_, int p_149863_3_, int p_149863_4_)
{
int l = p_149863_1_.getBlockMetadata(p_149863_2_, p_149863_3_, p_149863_4_) + MathHelper.getRandomIntegerInRange(p_149863_1_.rand, 2, 5);
if (l > 7)
{
l = 7;
}
if (l == 7) {
p_149863_1_.setBlockMetadataWithNotify(p_149863_2_, p_149863_3_, p_149863_4_, l, 2);
}
}
private float func_149864_n(World p_149864_1_, int p_149864_2_, int p_149864_3_, int p_149864_4_)
{
float f = 1.0F;
Block block = p_149864_1_.getBlock(p_149864_2_, p_149864_3_, p_149864_4_ - 1);
Block block1 = p_149864_1_.getBlock(p_149864_2_, p_149864_3_, p_149864_4_ + 1);
Block block2 = p_149864_1_.getBlock(p_149864_2_ - 1, p_149864_3_, p_149864_4_);
Block block3 = p_149864_1_.getBlock(p_149864_2_ + 1, p_149864_3_, p_149864_4_);
Block block4 = p_149864_1_.getBlock(p_149864_2_ - 1, p_149864_3_, p_149864_4_ - 1);
Block block5 = p_149864_1_.getBlock(p_149864_2_ + 1, p_149864_3_, p_149864_4_ - 1);
Block block6 = p_149864_1_.getBlock(p_149864_2_ + 1, p_149864_3_, p_149864_4_ + 1);
Block block7 = p_149864_1_.getBlock(p_149864_2_ - 1, p_149864_3_, p_149864_4_ + 1);
boolean flag = block2 == this || block3 == this;
boolean flag1 = block == this || block1 == this;
boolean flag2 = block4 == this || block5 == this || block6 == this || block7 == this;
for (int l = p_149864_2_ - 1; l <= p_149864_2_ + 1; ++l)
{
for (int i1 = p_149864_4_ - 1; i1 <= p_149864_4_ + 1; ++i1)
{
float f1 = 0.0F;
if (p_149864_1_.getBlock(l, p_149864_3_ - 1, i1).canSustainPlant(p_149864_1_, l, p_149864_3_ - 1, i1, ForgeDirection.UP, this))
{
f1 = 1.0F;
if (p_149864_1_.getBlock(l, p_149864_3_ - 1, i1).isFertile(p_149864_1_, l, p_149864_3_ - 1, i1))
{
f1 = 3.0F;
}
}
if (l != p_149864_2_ || i1 != p_149864_4_)
{
f1 /= 4.0F;
}
f += f1;
}
}
if (flag2 || flag && flag1)
{
f /= 2.0F;
}
return f;
}
[color=yellow][glow=red,2,300]@Override
public boolean onBlockActivated(World parWorld, int parX, int parY, int parZ, EntityPlayer par5EntityPlayer,int par6, float par7, float par8, float par9){
int growStage = parWorld.getBlockMetadata(parX, parY, parZ);
if(growStage == 7) {
if (!parWorld.isRemote) {
if (par5EntityPlayer.getHeldItem() == null) {
ItemStack myItemStack = newItem;
EntityItem myItemEntity = new EntityItem(parWorld, parX, parY, parZ, myItemStack);
parWorld.spawnEntityInWorld(myItemEntity);
parWorld.setBlockMetadataWithNotify(parX, parY, parZ, 0, 2);
return true;
}
}
}
return false;
}[/glow][/color]
@Override
public String getUnlocalizedName()
{
return String.format("tile.%s%s", Reference.MOD_ID.toLowerCase() + ":", getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister)
{
blockIcon = iconRegister.registerIcon(String.format("%s", getUnwrappedUnlocalizedName(this.getUnlocalizedName())));
}
protected String getUnwrappedUnlocalizedName(String unlocalizedName)
{
return unlocalizedName.substring(unlocalizedName.indexOf(".") + 1);
}
}

 

 

 

 

public class QuickSilverBush extends CropBlock
{
    public QuickSilverBush()
    {
        [color=yellow][glow=red,2,300]super(new ItemStack(ModItems.quicksilverThorn));[/glow][/color]
        // Basic block setup
        setBlockName("quicksilver_bush");
        setBlockTextureName("orestalks:"+Names.Blocks.DIAMOND + Names.BlockTextures.STAGE0);
    }

    @Override
    protected boolean canPlaceBlockOn(Block parBlock)
    {
        return parBlock == Blocks.farmland;
    }

    /**
     * Returns the quantity of items to drop on block destruction.
     */
    @Override
    public int quantityDropped(int parMetadata, int parFortune, Random parRand)
    {
        Random rand = new Random();

        int  n = rand.nextInt(50);
        if (parMetadata !=7)
        {
            return (1);
        }
        if(parMetadata == 7){
            if (n == 1)
            {
                return (2);
            }
            else {
                return (1);
            }
        }
        return (1);
    }

    @Override
    public Item getItemDropped(int parMetadata, Random parRand, int parFortune)
    {

        return (ModItems.quicksilverSeed);
    }

    @Override
    public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
    {
        ArrayList<ItemStack> ret = super.getDrops(world, x, y, z, metadata, fortune);
        if (metadata == 7) {
           [glow=red,2,300][color=yellow] ret.add(new ItemStack(ModItems.quicksilverThorn));[/color][/glow]
        }
        return ret;
    }



    @Override
    @SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister parIIconRegister)
    {
        iIcon = new IIcon[maxGrowthStage+1];
        // seems that crops like to have 8 growth icons, but okay to repeat actual texture if you want

        // to make generic should loop to maxGrowthStage
        iIcon[0] = parIIconRegister.registerIcon("orestalks:"+Names.Blocks.DIAMOND + Names.BlockTextures.STAGE0);
        iIcon[1] = parIIconRegister.registerIcon("orestalks:"+Names.Blocks.DIAMOND + Names.BlockTextures.STAGE1);
        iIcon[2] = parIIconRegister.registerIcon("orestalks:"+Names.Blocks.DIAMOND + Names.BlockTextures.STAGE2);
        iIcon[3] = parIIconRegister.registerIcon("orestalks:"+Names.Blocks.DIAMOND + Names.BlockTextures.STAGE3);
        iIcon[4] = parIIconRegister.registerIcon("orestalks:"+Names.Blocks.DIAMOND + Names.BlockTextures.STAGE4);
        iIcon[5] = parIIconRegister.registerIcon("orestalks:"+Names.Blocks.DIAMOND + Names.BlockTextures.STAGE5);
        iIcon[6] = parIIconRegister.registerIcon("orestalks:"+Names.Blocks.DIAMOND + Names.BlockTextures.STAGE6);
        iIcon[7] = parIIconRegister.registerIcon("orestalks:"+Names.Blocks.DIAMOND + Names.BlockTextures.STAGE7);
    }


}

 

 

 

public class ModBlocks
{

    //plants
    public static final CropBlock DIAMONDCROP = new DiamondBush();
    public static final CropBlock COALCROP = new CoalBush();
    public static final CropBlock CHARCOALCROP = new CharcoalBush();
    public static final CropBlock EMERALDCROP = new EmeraldBush();
    public static final CropBlock GOLDCROP = new GoldBush();
    public static final CropBlock LAPISCROP = new LapisBush();
    public static final CropBlock IRONCROP = new IronBush();
    public static final CropBlock REDSTONECROP = new RedStoneBush();
    public static final CropBlock NETHERQUARTZCROP = new NetherQuartzBush();
    public static final CropBlock SHARD = new Earthshardbush();
   [color=yellow][glow=red,2,300]public static final CropBlock QUICKSILVERCROP = new QuickSilverBush();[/glow][/color]
    public static final CropBlock GLOWSTONECROP = new GlowStoneBush();

    //basic
    public static Block accelerator;

    public static void init()
    {
        //plants
        GameRegistry.registerBlock(DIAMONDCROP, Names.Blocks.DIAMOND);
        GameRegistry.registerBlock(COALCROP,Names.Blocks.COAL);
        GameRegistry.registerBlock(CHARCOALCROP,Names.Blocks.CHARCOAL);
        GameRegistry.registerBlock(EMERALDCROP,Names.Blocks.EMERALD);
        GameRegistry.registerBlock(GOLDCROP,Names.Blocks.GOLD);
        GameRegistry.registerBlock(LAPISCROP,Names.Blocks.LAPIS);
        GameRegistry.registerBlock(IRONCROP,Names.Blocks.IRON);
        GameRegistry.registerBlock(REDSTONECROP,Names.Blocks.REDSTONE);
        GameRegistry.registerBlock(NETHERQUARTZCROP,Names.Blocks.NETHERQUARTZ);
        GameRegistry.registerBlock(GLOWSTONECROP,"glow_stone_bush");


        //basic
        GameRegistry.registerBlock(accelerator = new OreStalksBlocks(Material.iron, Names.Blocks.ACCELERATOR, Names.Blocks.ACCELERATOR), Names.Blocks.ACCELERATOR);

        if (Loader.isModLoaded("Thaumcraft"))
        {
            GameRegistry.registerBlock(SHARD,"test");
            [color=yellow][glow=red,2,300]GameRegistry.registerBlock(QUICKSILVERCROP,"quicksilver_bush");[/glow][/color]
        }
    }

 

 

 

public class ModItems
{
    public static Item diamondSeed;
    public static Item coalSeed;
    public static Item charcoalSeed;
    public static Item goldSeed;
    public static Item ironSeed;
    public static Item lapisSeed;
    public static Item emeraldSeed;
    public static Item redstoneSeed;
    public static Item netherquartzSeed;
    public static Item testSeed;
    public static Item quicksilverSeed;
    public static Item glowstoneSeed;

    //materials
    [color=yellow][glow=red,2,300]public static Item quicksilverThorn;[/glow][/color]
    public static ItemStack moretest;


    public static void init() {
        GameRegistry.registerItem(diamondSeed = new OreSeeds(Names.Items.DIAMONDSEED,Names.Items.DIAMONDSEED,ModBlocks.DIAMONDCROP, Blocks.farmland),Names.Items.DIAMONDSEED);
        GameRegistry.registerItem(ironSeed = new OreSeeds(Names.Items.IRONSEED,Names.Items.IRONSEED,ModBlocks.IRONCROP, Blocks.farmland),Names.Items.IRONSEED);
        GameRegistry.registerItem(redstoneSeed = new OreSeeds(Names.Items.REDSTONESEED,Names.Items.REDSTONESEED,ModBlocks.REDSTONECROP, Blocks.farmland),Names.Items.REDSTONESEED);
        GameRegistry.registerItem(lapisSeed = new OreSeeds(Names.Items.LAPISSEED,Names.Items.LAPISSEED,ModBlocks.LAPISCROP, Blocks.farmland),Names.Items.LAPISSEED);
        GameRegistry.registerItem(emeraldSeed = new OreSeeds(Names.Items.EMERALDSEED,Names.Items.EMERALDSEED,ModBlocks.EMERALDCROP, Blocks.farmland),Names.Items.EMERALDSEED);
        GameRegistry.registerItem(goldSeed = new OreSeeds(Names.Items.GOLDSEED,Names.Items.GOLDSEED,ModBlocks.GOLDCROP, Blocks.farmland),Names.Items.GOLDSEED);
        GameRegistry.registerItem(coalSeed = new OreSeeds(Names.Items.COALSEED,Names.Items.COALSEED,ModBlocks.COALCROP, Blocks.farmland),Names.Items.COALSEED);
        GameRegistry.registerItem(charcoalSeed = new OreSeeds(Names.Items.CHARCOALSEED,Names.Items.CHARCOALSEED,ModBlocks.CHARCOALCROP, Blocks.farmland),Names.Items.CHARCOALSEED);
        GameRegistry.registerItem(netherquartzSeed = new OreSeeds(Names.Items.NETHERQUARTZSEED,Names.Items.NETHERQUARTZSEED,ModBlocks.NETHERQUARTZCROP, Blocks.farmland),Names.Items.NETHERQUARTZSEED);
        GameRegistry.registerItem(glowstoneSeed = new OreSeeds("glow_stone_seeds","glow_stone_seeds",ModBlocks.GLOWSTONECROP, Blocks.farmland),"glow_stone_seeds");

        if (Loader.isModLoaded("Thaumcraft"))
        {
            GameRegistry.registerItem(testSeed = new OreSeeds("test_seed","test_seed",ModBlocks.SHARD,Blocks.farmland),"test_seed");
            GameRegistry.registerItem(quicksilverSeed = new OreSeeds("quicksilver_seed","quicksilver_seed",ModBlocks.QUICKSILVERCROP,Blocks.farmland),"quicksilver_seed");
            [color=yellow][glow=red,2,300]GameRegistry.registerItem(quicksilverThorn = new OreStalksMatierials("quicksilver_thorn","quicksilver_thorn"),"quicksilver_thorn");[/glow][/color]
        }
    }

}

 

~SureShotM/Leo~ gaming coding all around fun!

Link to comment
Share on other sites

I tried to have the right bits of code Highlighted but that didn't work,

 

the first code is the General block

the second code is the block with the specific item I'm trying to drop to player

the last 2 codes are the initializes.

 

note I have tried to use if(world.isRemote) instead of if(!world.isRemote)

it still gave same error.

~SureShotM/Leo~ gaming coding all around fun!

Link to comment
Share on other sites

Do you mean in here, and in that case are you suggesting that I put this code in the individual bush blocks. 

 

@Override

public boolean onBlockActivated(World parWorld, int parX, int parY, int parZ, EntityPlayer par5EntityPlayer,int par6, float par7, float par8, float par9){

int growStage = parWorld.getBlockMetadata(parX, parY, parZ);

if(growStage == 7) {

if (!parWorld.isRemote) {

if (par5EntityPlayer.getHeldItem() == null) {

ItemStack myItemStack = newItem;

EntityItem myItemEntity = new EntityItem(parWorld, parX, parY, parZ, myItemStack);

parWorld.spawnEntityInWorld(myItemEntity);

parWorld.setBlockMetadataWithNotify(parX, parY, parZ, 0, 2);

return true;

}

}

}

return false;

}

 

~SureShotM/Leo~ gaming coding all around fun!

Link to comment
Share on other sites

okay so you are talking about this private final ItemStack newItem;, correct or since you mentioned item class are you talking about the ModItems class? sorry I guess I'm confused on witch exact part of the code you are talking about, O wait i think I know what your talking about,  super(new ItemStack(ModItems.quicksilverThorn)); this is what is being reused right. 

~SureShotM/Leo~ gaming coding all around fun!

Link to comment
Share on other sites

Ok thats the thing though that I guess I'm getting confused, all my individual bushes are referencing to "cropBlock", and "newItem" gets passed through the bush constructor in super(new ItemStack(...));, I decided to do it that way cause I didn't want to have to put  this in every bush code.

 

@Override

public boolean onBlockActivated(World parWorld, int parX, int parY, int parZ, EntityPlayer par5EntityPlayer,int par6, float par7, float par8, float par9){

int growStage = parWorld.getBlockMetadata(parX, parY, parZ);

if(growStage == 7) {

if (!parWorld.isRemote) {

if (par5EntityPlayer.getHeldItem() == null) {

ItemStack myItemStack = newItem;

EntityItem myItemEntity = new EntityItem(parWorld, parX, parY, parZ, myItemStack);

parWorld.spawnEntityInWorld(myItemEntity);

parWorld.setBlockMetadataWithNotify(parX, parY, parZ, 0, 2);

return true;

}

}

}

return false;

}

~SureShotM/Leo~ gaming coding all around fun!

Link to comment
Share on other sites

If you're looking to get an item from right-clicking on bushes, check the code for Tinkers' Construct:

https://github.com/SlimeKnights/TinkersConstruct/blob/master/src/main/java/tconstruct/world/blocks/OreberryBush.java <-- is a bush similar to yours from the sounds of it

https://github.com/SlimeKnights/TinkersConstruct/tree/master/src/main/java/tconstruct <-- the link to all the code

Link to comment
Share on other sites

So I got it sorta solved I pretty much said forget doing it the fancy way and just put the onblockactivate method into the individual bushes(not going to be bushes for much longer it was the only thing I could think of at the moment of first creation). I did think of a way I could make the new itemstack and reference it like I already am but even then it didn't work so I kinda gave up, I might try again but I want to get further into the mod before I do or ill get stuck on this forever. so I guess at this point I'm going to ask if it is okay if we keep this open so I can come back to it as needed.

~SureShotM/Leo~ gaming coding all around fun!

Link to comment
Share on other sites

ItemStack myItemStack = newItem.copy();

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

ok that didn't work, and I even tried to make my own method for it and it still didn't work so screw it ill just keep with the plant itself having the right click method. thanks for the help though even though it never got me anywhere.

~SureShotM/Leo~ gaming coding all around fun!

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.