Jump to content

[1.7.10] help with custom bow enchantments!


graywolf69

Recommended Posts

I made a custom bow, with its own custom arrow and arrow entity. I made an enchantment that can be put on any bow, and I know a way to make my custom arrow explode (in the custom arrow entity class). I have see in the bow class that it tests for enchantments there, and if it has an enchantment like power it will tell the EntityArrow.class to make it damage more. Is there a way I can check if it has my enchantment, and then if it does change this:

if (this.inGround)
        {
            int j = this.worldObj.getBlockMetadata(this.field_145791_d,       this.field_145792_e, this.field_145789_f);

        if (block == this.field_145790_g && j == this.inData)
        {
            ++this.ticksInGround;

            if (this.ticksInGround == 1200) //set to 1 for explosion
            {
                this.setDead();
              //this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 5.0F, true);
            }
        }
        else
        {
            this.inGround = false;
            this.motionX *= (double)(this.rand.nextFloat() * 0.2F);
            this.motionY *= (double)(this.rand.nextFloat() * 0.2F);
            this.motionZ *= (double)(this.rand.nextFloat() * 0.2F);
            this.ticksInGround = 0;
            this.ticksInAir = 0;
        }

 

to the parameters needed to make the arrow explode? Thank you for your help, I am new to modding!

 

Link to comment
Share on other sites

I don't really see your truble. If you want to make arrow have specific effect depending on what kind of bow was it shot from you can simply pass argument into arrow entity the moment you shoot it (when you spawn entity to world). What is your problem? Checking enchantment? Passing argument? Making boom? Synchronizing server with client? Maybe reading NBT from bow (your ench)?

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Nevermind, I thought about it and wrote some code that should work, but doesn't. I basically made a new boolean in my bow class called explosive and set it to false. Then I told it to check if there was my enchantment on the bow, and if so, set explosive to true. Then, in my arrow entity, I told it to check if explosive was set to true, and if so, explode when it hits the ground. If it isn't true it is supposed to act like a normal arrow. My problem is that even when the bow doesn't have my enchantment, the arrow explodes. Can anyone tell me what I am doing wrong? Here is my custom arrow: http://pastebin.com/FDLLh5GM Here is my bow class: http://pastebin.com/3AEd1wsj And here is my main registry class where I register the enchantment: http://pastebin.com/XwWLbcv4 Tell me if you need more code than this, Thank you for any help provided!

Link to comment
Share on other sites

Your problem is actually your lack of knowledge about java, cmon man - learn something, don't code blindly. :P

 

As to problem:

1. Your enchantment can't be saved in bow instance, there is only one item instance per game so making boolean inside bow class will cause it to be shared between all bows. What you need to use is NBT in ItemStack.

http://www.minecraftforge.net/wiki/Creating_NBT_for_items

 

2. When you shoot arrow you need to read enchantment value from bow's NBT and pass it into arrow entity.

Pseudocode:

ArrowEntity arrow = new arrow.... bla bla

arrow.setMyEnch(getBooleanFromMyBowsNBT) // which will set it to true/false

arrow.spawnEntityInWorld...

 

3. When you are extending some class, you don't need to copy everything what is inside, that's why there is inheritance (extends).

1.7.10 is no longer supported by forge, you are on your own.

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.