Jump to content

How do I add a drop to leaves ?


Irhala

Recommended Posts

Thanks ! It's working, cuz tree leaves now :

- are Instabreakable

- don't loot sticks

- are non-transparent

 

Leaves still disappear when tree is broken, and have light opacity to 1

 

Need to fix this, and more and more thanks to you !

\o_ \o/ _o/

||    ||    ||

/ \  / \  / \

Link to comment
Share on other sites

Thanks ! It's working, cuz tree leaves now :

- are Instabreakable

- don't loot sticks

- are non-transparent

 

Leaves still disappear when tree is broken, and have light opacity to 1

 

Need to fix this, and more and more thanks to you !

\o_ \o/ _o/

||    ||    ||

/ \  / \  / \

 

i'm confused is that good or bad?

 

also... why the dancing stick men?

Link to comment
Share on other sites

It's good, because this means we (you) achieved to replace Leaves by MyLeaves (i checked, and even in the creative inventory, with the leaves ID, it's 4 non-named blocks with leaves textures)

 

I need to give MyLeaves the characteristics I want, but it may be easier from now :)

EDIT : I don't know how to do it --'

          Aren't BlockLeaves methods supposed to be usable with BlockMyLeaves ?

 

Link to comment
Share on other sites

haha, ok. Look through the wiki a bit and see what you can figure out, Try to do as much as you can without help as it's a better way of learning and you'll start to figure out how to solve these things in the future. If you get completely stuck post it or feel free DM me with the problem and i'll do my best to get back to you, and point you in the right direction. There is also quite a lot of good stuff on youtube if you do a quick search.

 

Link to comment
Share on other sites

          Aren't BlockLeaves methods supposed to be usable with BlockMyLeaves ?

 

yes. They should be if you extended it. The properties of the leaves however you will need to set using .setHardness and various other methods. Look here if you're not sure how to set the properties, it's a touch out of date, but all that's really changed is textures and you don't need to do anything about that.

Link to comment
Share on other sites

In the BlockMyLeaves class, I use the constructor

public BlockMyLeaves(int par1) {
	super(par1);
        setHardness(0.2F);
        setLightOpacity(1);
        setStepSound(soundGrassFootstep);
        setUnlocalizedName("leaves");
}

and super(...) is BlockLeaves(...) from vanilla

protected BlockLeaves(int par1)
    {
        super(par1, Material.leaves, false);
        this.setTickRandomly(true);
        this.setCreativeTab(CreativeTabs.tabDecorations);
    }

 

I don't understand why MyLeaves doesn't have the Material.leaves properties, while it is created as a block with leaves material :/

Link to comment
Share on other sites

In the BlockMyLeaves class, I use the constructor

public BlockMyLeaves(int par1) {
	super(par1);
        setHardness(0.2F);
        setLightOpacity(1);
        setStepSound(soundGrassFootstep);
        setUnlocalizedName("leaves");
}

and super(...) is BlockLeaves(...) from vanilla

protected BlockLeaves(int par1)
    {
        super(par1, Material.leaves, false);
        this.setTickRandomly(true);
        this.setCreativeTab(CreativeTabs.tabDecorations);
    }

 

I don't understand why MyLeaves doesn't have the Material.leaves properties, while it is created as a block with leaves material :/

Material.leaves is linked to a few scattered properties; the "material" thing isn't very well organized. What properties is your block missing?

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
Share on other sites

from memory I think it's these methods, Kinda set it up so my code does most of this automatically now, so i could be missing something.

@Override
public boolean renderAsNormalBlock()
{
	return false;
}

@Override
public boolean isOpaqueCube()
{
	return false;
}

 

to drop items I think something like this:

    public ArrayList<ItemStack> getBlockDropped(World world, int x, int y, int z, int metadata, int fortune)
    {
        ArrayList<ItemStack> ret = new ArrayList<ItemStack>();

        int count = quantityDropped(metadata, fortune, world.rand);
        for(int i = 0; i < count; i++)
        {
            int id = idDropped(metadata, world.rand, fortune);
            if (id > 0)
            {
                ret.add(new ItemStack(id, 1, damageDropped(metadata)));
            }
        }

        ret.add(new ItemStack(Item.stick));
        return ret;
    }

Link to comment
Share on other sites

I only redefined public void dropBlockAsItemWithChance(...)

public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7)
    {
        if (!par1World.isRemote)
        {
            int j1 = 20;

            if ((par5 & 3) == 3)
            {
                j1 = 40;
            }

            if (par7 > 0)
            {
                j1 -= 2 << par7;

                if (j1 < 10)
                {
                    j1 = 10;
                }
            }

            if (par1World.rand.nextInt(j1) == 0)
            {
                int k1 = this.idDropped(par5, par1World.rand, par7);
                this.dropBlockAsItem_do(par1World, par2, par3, par4, new ItemStack(k1, 1, this.damageDropped(par5)));
            }
            
            j1 = 20;

            if ((par5 & 3) == 3)
            {
                j1 = 40;
            }

            if (par7 > 0)
            {
                j1 -= 2 << par7;

                if (j1 < 10)
                {
                    j1 = 10;
                }
            }
            
            if (par1World.rand.nextInt(j1) == 0)
            {
                int k1 = Item.stick.itemID;
                this.dropBlockAsItem_do(par1World, par2, par3, par4, new ItemStack(k1, 1, this.damageDropped(par5)));
            }

            j1 = 200;

            if (par7 > 0)
            {
                j1 -= 10 << par7;

                if (j1 < 40)
                {
                    j1 = 40;
                }
            }

            if ((par5 & 3) == 0 && par1World.rand.nextInt(j1) == 0)
            {
                this.dropBlockAsItem_do(par1World, par2, par3, par4, new ItemStack(Item.appleRed, 1, 0));
            }
        }
    }
}

 

And it works ! Sticks drop of leaves as often as saplings !

Only 2 problems left : Add recipe for spruce, birch and jungle saplings, and change transparency of leaves to make it appear correctly

EDIT : The first one was simple, i looked on sandstone recipes to know how to add :1, :2, :3 to the block ID :)

EDIT 2 : Transparency problem screenshot :

http://puu.sh/3bIOI

Link to comment
Share on other sites

BlockMyLeaves is already extending BlockLeaves, which extends BlockLeavesBase

 

I tried with renderAsNormalBlock(), isOpaqueCube(), setGraphicsLevel(), shouldSideBeRendered() and isLeaves(), and all in same time, but none of them makes it work properly. Fast graphics also render as fancy.

Link to comment
Share on other sites

It works ! I didn't tried that, i'm... kinda... ~("°A°)~

There's still 1 problem left : Fast graphics use fancy texture, and it render exactly like with fancy graphics

You'll need a graphicsLevel variable, set up as in BlockLeaves and BlockLeavesBase.

if graphicsLevel = "fancy":
    return True
else:
    return super(self, blah).shouldSideBeRendered()

You'll also want to override isOpaqueCube:

    public boolean isOpaqueCube(){
        return !this.graphicsLevel;
    }

And you'll need two sets of icons, one opaque and one transparent. Look at BlockLeaves.iconArray for how it's done.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
Share on other sites

It works ! I didn't tried that, i'm... kinda... ~("°A°)~

There's still 1 problem left : Fast graphics use fancy texture, and it render exactly like with fancy graphics

You'll need a graphicsLevel variable, set up as in BlockLeaves and BlockLeavesBase.

if graphicsLevel = "fancy":
    return True
else:
    return super(self, blah).shouldSideBeRendered()

 

Look at the BlockLeaves class, you can adapt the code where graphicsLevel is used (it's a boolean).

You don't need to declare a new variable in your block class, just use the Block.leaves.graphicsLevel reference, since the variable is public.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

It works ! I didn't tried that, i'm... kinda... ~("°A°)~

There's still 1 problem left : Fast graphics use fancy texture, and it render exactly like with fancy graphics

You'll need a graphicsLevel variable, set up as in BlockLeaves and BlockLeavesBase.

if graphicsLevel = "fancy":
    return True
else:
    return super(self, blah).shouldSideBeRendered()

 

Look at the BlockLeaves class, you can adapt the code where graphicsLevel is used (it's a boolean).

You don't need to declare a new variable in your block class, just use the Block.leaves.graphicsLevel reference, since the variable is public.

Good point. I guess I didn't want to bother doing more research than necessary :)

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

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.