Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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 ;)

  • Author

Sorry I forgot that I'm talking about Minecraft 1.7.10

 

That method is 1.8 right?

 

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

  • Author

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.