Vanilla enchantments on custom items

Started by Softi on

Topic category: Help with modding (Java Edition)

Last seen on 03:40, 24. Jul 2024
Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Vanilla enchantments on custom items

I'd lIke to add infinity to an item, meaning allowing infinity in enchant tables, and anvils. If anyone knows how i could achoeve this please reply!

Last seen on 20:37, 26. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Anvils can enchant literally…
Tue, 09/19/2023 - 22:13

Anvils can enchant literally anything, regardless of what item type it is, as long as the enchantments aren't mutually exclusive. (Like feather-falling and depth-strider). If an item is a type of tool, weapon, or ranged item, and has an enchantability level set higher than zero, it should be able to obtain vanilla enchantments from the enchanting table. (Not totally sure about ranged items though.) 

However, if you want the enchantment to actually work, you'll need to code in a behavior for it. (You should be able to give your item infinity, but it won't actually have any ammunition unless you specifically tell it to stop consuming ammunition if the item has the infinity enchantment.

Since ammunition is hard coded, I would disable the ammunition requirement for your ranged item, and instead have a specific procedure that, before firing, searches the player's inventory for ammunition, and then fires the projectile if the player either has ammunition, or the item has the infinity enchantment. (You can use an itemstack iterator to search the inventory, and a local variable to stop searching/shrinking the stack once ammunition has been consumed.)

Last seen on 03:40, 24. Jul 2024
Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I mean as in survival mode,…
Wed, 09/20/2023 - 01:29

I mean as in survival mode, allowing an enchantment do be combined with the item in the enchantment table. I know how to get the enchantment to work and have already coded its' functionality, I'm just confused on how to let survival players throw the item in the eTable and go "oh it can have infinity?"

Last seen on 20:37, 26. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
If the item is already a…
Wed, 09/20/2023 - 01:38

If the item is already a ranged item, I think it should be able to have infinity applied in the enchanting table; the available enchantments are based on the tool/item type. (Though I notice enchantability can't be set for ranged items in Mcreator's interface, you might have to lock the element and change it manually if nothing shows up.) If stuff does show up when you put it in the enchanting table, and it looks like they're what you'd expect from a bow, you should be able to get infinity. (Just keep in mind it's a rare enchantment.) 

...If this doesn't work, or if the item isn't a ranged item, you might still be able to manually make it a subclass of bow-items in the code, though I haven't been able to get this working myself. 

I've also seen a couple Mcreator plugins that add some global triggers for enchanting; might be worth looking into.

Last seen on 03:40, 24. Jul 2024
Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I'd love to know what…
Wed, 09/20/2023 - 18:28

I'd love to know what plugins you're speaking about.