Jump to content

Recommended Posts

Posted

Hi guys, I want to add items ingame (as drops) from a .txt file where you are able to configure the item, the enchantments for it and a custom name.

 

So far I have everything figured out, but not the custom enchantment part.

 

The .txt file looks like this

 

{item:minecraft:potato,1,0 - enchantment1:baneOfArthropods,1 - enchantment2:looting,2 - enchantment3:knockback,3 - enchantment4:featherFalling,4 - enchantment5:infinity,5 - name:Epic Potato 5}

 

Basically what I'm doing right now is, reading from 'item:' to ' - enchantment1' to get the item data and then I take that info and separate it in 3, leaving me with minecraft:potato, 1 and 0 (As item, itemQuantity, itemMeta)

 

Similar with the custom name, reading from 'name:' to the end of the line looking for that '}'

 

My problem is with the enchantments, I have already the code ready to recognize if there is only 1 enchantment, 2, 3, 4 or 5 and I get each of them again, for example

 

enchatment1: "baneOfArthropods"

enchatment1Level: 1

 

My problem is. How do I add that to the item if what I have is:

 

Item finalItem = GameData.getItemRegistry().getObject(item);
dropX = new ItemStack(finalItem);

dropX.addEnchantment(Enchantment. XXX , enchantment1Level);

 

Where I have the XXX I don't know how to "convert" enchatment1 that contains "baneOfArthropods" into something that would work there.

 

If you want to take  look at the whole code let me know.

 

Thanks a lot for any help ;)

Posted

Sorry I forgot that I'm talking about Minecraft 1.7.10

Why?

That method is 1.8 right?

Yes. You need to manually loop through all enchantments and check their "name" field (you need reflection since it's protected) in 1.7.

(Also I think for some reason, my method of getting the item wont work with non-minecraft items, right?)

It will, if you use the format "modid:item".

 

Thanks diesieben07 I will see if I understand what you mean about "reflection" and that, really not sure how that work.

 

Also, if I use modid:item wont work, what would be a better/correct way to do it? That's why I titled the post like this, I'm really lost here trying to make this from scratch, but I'm not sure I'm going the right way, or at least a way where I can finally achieve what I want.

 

Someone may suggest, hey, you can do this way easier like this or that.

 

I was thinking on having the txt file with something like:

 

dropX = new ItemStack(Items.wooden_sword,1,0);dropX.addEnchantment(Enchantment.looting, 10);dropX.setStackDisplayName("Use Less");

 

And maybe import that somehow?

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.