Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.16.5] Enchantments can Apply to all Tools
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
Luis_ST

[1.16.5] Enchantments can Apply to all Tools

By Luis_ST, January 27 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Luis_ST    6

Luis_ST

Luis_ST    6

  • Diamond Finder
  • Luis_ST
  • Members
  • 6
  • 359 posts
Posted January 27 (edited)

I created some enchantments in my mod. Then I checked whether my enchantments could be traded by my custom villager (profession) and found that there were some enchantments traded with incompactable enchantments,

or several enchantments with the same level on a item. When I try to enchant the item with the enchant command, the normal vanilla error message comes up.

But if I combine enchantment in the Amposs with a item that dosent sopport the enchantment it works with all Vanilla Enchantments,

for example: i can enchant protection on a sword. Now my question is this a bug or is it because of the test version of Minecraft which use the IDE?

 

2021-01-27_08_20_01.thumb.png.5849dfc66d06d3de2064faf632360aac.png

Edited January 27 by Luis_ST
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7690

diesieben07

diesieben07    7690

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7690
  • 56283 posts
Posted January 27

Show how you are creating your enchanted book itemstacks.

  • Quote

Share this post


Link to post
Share on other sites

Luis_ST    6

Luis_ST

Luis_ST    6

  • Diamond Finder
  • Luis_ST
  • Members
  • 6
  • 359 posts
Posted January 27
1 hour ago, diesieben07 said:

Show how you are creating your enchanted book itemstacks.

first the problem with two enchantments on the same tool:

	public static BasicTrade creatTradeEmeraldForEnchantedItem(Item item, int level, boolean allowTreasure, int tradeLevel) {
		
		int count = rng.nextInt(level + level) + level;		
		ItemStack stack = new ItemStack(item);
		EnchantmentHelper.addRandomEnchantment(rng, stack, level, allowTreasure);
		return new BasicTrade(new ItemStack(Items.EMERALD, count), ItemStack.EMPTY, stack, 16, randomXp(tradeLevel), 0.2f);
		
	}

 

second why i can add the protection Enchantment to a Sword?

 

and third i can trade at the villager with the profession "enchanter" enchanted books with ench level 0

this is the way i creat books

	
// i creat a list of Trades because when i use one trade i got every time the same Enchantment (it will reset when i start minecraft again
public static List<BasicTrade> creatTradeEmeraldForEnchantedBookList(int size, int tradeLevel) {
		
		List<BasicTrade> trades = new ArrayList<>();
		for (int i = 0; i < size; i++) {
			trades.add(enchantedBook(randomXp(tradeLevel)));
		}
		
		return trades;
		
	}
                                                      
    	
private static BasicTrade enchantedBook(int xp) {
		
		ItemStack book = new ItemStack(Items.ENCHANTED_BOOK);
		List<Enchantment> enchantments = Registry.ENCHANTMENT.stream().filter((enchantment) -> {
			return !enchantment.isCurse();
		}).collect(Collectors.toList());
		Enchantment enchantment = enchantments.get(rng.nextInt(enchantments.size()));
		int enchLevel = Math.min(enchantment.getMaxLevel(), rng.nextInt(5));
		EnchantedBookItem.addEnchantment(book, new EnchantmentData(enchantment, enchLevel));
		int count = 2 + rng.nextInt(5 + enchLevel * 10) + 3 * enchLevel + 5;
		
		return new BasicTrade(new ItemStack(Items.EMERALD, count > 64 ? 64 : count), new ItemStack(Items.BOOK), book, 16, xp, 0.2f);
		
	}                                                  

 

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7690

diesieben07

diesieben07    7690

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7690
  • 56283 posts
Posted January 27
8 minutes ago, Luis_ST said:

first the problem with two enchantments on the same tool:

Look at addRandomEnchantment / buildEnchantmentList. It does not necessarily only add one enchantment.

 

8 minutes ago, Luis_ST said:

second why i can add the protection Enchantment to a Sword?

Because you are in creative mode.

 

19 minutes ago, Luis_ST said:

i can trade at the villager with the profession "enchanter" enchanted books with ench level 0

This can produce 0:

19 minutes ago, Luis_ST said:

int enchLevel = Math.min(enchantment.getMaxLevel(), rng.nextInt(5));

 

  • Quote

Share this post


Link to post
Share on other sites

Luis_ST    6

Luis_ST

Luis_ST    6

  • Diamond Finder
  • Luis_ST
  • Members
  • 6
  • 359 posts
Posted January 27
9 minutes ago, diesieben07 said:

Look at addRandomEnchantment / buildEnchantmentList. It does not necessarily only add one enchantment.

i know i just look at this methods but why i can get the an enchantment twice with the same level?

and how do I prevent that?

 

12 minutes ago, diesieben07 said:

Because you are in creative mode.

okay thats clear

 

12 minutes ago, diesieben07 said:

int enchLevel = Math.min(enchantment.getMaxLevel(), rng.nextInt(5));

okay that's a mistake on my part -> int enchLevel = Math.min(enchantment.getMaxLevel(), rng.nextInt(5) + 1); will fix that

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7690

diesieben07

diesieben07    7690

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7690
  • 56283 posts
Posted January 27
4 minutes ago, Luis_ST said:

why i can get the an enchantment twice with the same level?

and how do I prevent that?

Not sure, that should not be happening. From the code you posted I can't tell.

  • Quote

Share this post


Link to post
Share on other sites

Luis_ST    6

Luis_ST

Luis_ST    6

  • Diamond Finder
  • Luis_ST
  • Members
  • 6
  • 359 posts
Posted January 27
7 minutes ago, diesieben07 said:

Not sure, that should not be happening. From the code you posted I can't tell.

if there is no way to prevent it then i try to create my own method that enchants the item

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7690

diesieben07

diesieben07    7690

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7690
  • 56283 posts
Posted January 27

There probably is something wrong - please post a Git repo so I can use the debugger.

  • Quote

Share this post


Link to post
Share on other sites

Luis_ST    6

Luis_ST

Luis_ST    6

  • Diamond Finder
  • Luis_ST
  • Members
  • 6
  • 359 posts
Posted January 27 (edited)
3 hours ago, diesieben07 said:

There probably is something wrong - please post a Git repo so I can use the debugger.

https://github.com/Luis-st/Forge-1.16.5-36.0.1-mdk

Edited January 27 by Luis_ST
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7690

diesieben07

diesieben07    7690

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7690
  • 56283 posts
Posted January 27

Yeah, looking at this, this is normal behavior. Even vanilla villagers should have the same effect, they use the same code.

  • Quote

Share this post


Link to post
Share on other sites

Luis_ST    6

Luis_ST

Luis_ST    6

  • Diamond Finder
  • Luis_ST
  • Members
  • 6
  • 359 posts
Posted January 27
16 minutes ago, diesieben07 said:

Yeah, looking at this, this is normal behavior. Even vanilla villagers should have the same effect, they use the same code.

so there is no error

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7690

diesieben07

diesieben07    7690

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7690
  • 56283 posts
Posted January 27

Yes

  • Thanks 1
  • Quote

Share this post


Link to post
Share on other sites

Luis_ST    6

Luis_ST

Luis_ST    6

  • Diamond Finder
  • Luis_ST
  • Members
  • 6
  • 359 posts
Posted January 28

i tested the minecraft code a bit and vanilla trades work fine. there are no enchantment twice?

so i creat my custom addRandomEnchantment and it works fine but: when i remove incompatible enchantments i got an error:

	private static Map<Enchantment, Integer> removeIncompatible(Map<Enchantment, Integer> enchantments) {
		
		Map<Enchantment, Integer> returnMap = new HashMap<Enchantment, Integer>();
		List<Enchantment> enchantmentList = enchantments.keySet().stream().collect(Collectors.toList());
		List<Integer> levelList = enchantments.values().stream().collect(Collectors.toList());
		
		for (int i = 0; i < enchantmentList.size(); i++) {
			
			for (Enchantment enchantment : enchantmentList) {
				
				if (!enchantment.isCompatibleWith(enchantmentList.get(i))) {
					
					enchantmentList.remove(i);
					levelList.remove(i);
					
				}
				
			}
			
		}
		
		for (int i = 0; i < enchantmentList.size(); i++) {
			
			returnMap.put(enchantmentList.get(i), levelList.get(i));
			
		}
		
		return returnMap;
		
	}

 

and the error:

java.util.ConcurrentModificationException: null
	at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1013) ~[?:?] {}
	at java.util.ArrayList$Itr.next(ArrayList.java:967) ~[?:?] {}
	at net.luis.cave.lib.EnchantmentManager.removeIncompatible(EnchantmentManager.java:144) ~[main/:?] {re:classloading}
	at net.luis.cave.lib.EnchantmentManager.addRandomEnchantment(EnchantmentManager.java:116) ~[main/:?] {re:classloading}
	at net.luis.cave.events.entity.player.interact.OnRightClickBlockEvent.PlayerInteract(OnRightClickBlockEvent.java:34) ~[main/:?] {re:classloading}
	at net.minecraftforge.eventbus.ASMEventHandler_24_OnRightClickBlockEvent_PlayerInteract_RightClickBlock.invoke(.dynamic) ~[?:?] {}
	at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) ~[eventbus-4.0.0.jar:?] {}
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302) ~[eventbus-4.0.0.jar:?] {}
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) ~[eventbus-4.0.0.jar:?] {}
	at net.minecraftforge.common.ForgeHooks.onRightClickBlock(ForgeHooks.java:803) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading}
	at net.minecraft.client.multiplayer.PlayerController.func_217292_a(PlayerController.java:286) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1407) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:1692) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.runTick(Minecraft.java:1507) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:979) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:612) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:184) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[?:?] {}
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}
	at java.lang.reflect.Method.invoke(Method.java:564) ~[?:?] {}
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52) ~[forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.0.9.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.0.9.jar:?] {}
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:105) [forge-1.16.5-36.0.1_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {}

 

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7690

diesieben07

diesieben07    7690

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7690
  • 56283 posts
Posted January 28

You can't remove from a list while you are iterating over it. If you want to do that, you need to remove using the Iterator#remove method.

  • Quote

Share this post


Link to post
Share on other sites

Luis_ST    6

Luis_ST

Luis_ST    6

  • Diamond Finder
  • Luis_ST
  • Members
  • 6
  • 359 posts
Posted January 28
20 minutes ago, diesieben07 said:

You can't remove from a list while you are iterating over it. If you want to do that, you need to remove using the Iterator#remove method.

so i have to convert the list to an iterator?

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7690

diesieben07

diesieben07    7690

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7690
  • 56283 posts
Posted January 28

You have to do manual iteration instead of just an enhanced for loop, yes.

  • Quote

Share this post


Link to post
Share on other sites

Luis_ST    6

Luis_ST

Luis_ST    6

  • Diamond Finder
  • Luis_ST
  • Members
  • 6
  • 359 posts
Posted January 28
15 minutes ago, diesieben07 said:

You have to do manual iteration instead of just an enhanced for loop, yes.

but how to do that

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7690

diesieben07

diesieben07    7690

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7690
  • 56283 posts
Posted January 28

https://www.geeksforgeeks.org/how-to-use-iterator-in-java/

  • Quote

Share this post


Link to post
Share on other sites

Luis_ST    6

Luis_ST

Luis_ST    6

  • Diamond Finder
  • Luis_ST
  • Members
  • 6
  • 359 posts
Posted January 28
18 minutes ago, diesieben07 said:

https://www.geeksforgeeks.org/how-to-use-iterator-in-java/

		while (enchantmentIterator.hasNext()) {
			
			Enchantment enchantment = (Enchantment) enchantmentIterator.next();
			
			if (!enchantment.isCompatibleWith((Enchantment) enchantmentIterator)) {
				
				enchantmentIterator.remove();
				
			}
			
		}

so is this correct?

and how to remove now the level of the enchantment?

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7690

diesieben07

diesieben07    7690

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7690
  • 56283 posts
Posted January 28

By calling remove on the iterator you remove the current element from the collection you are iterating.

  • Quote

Share this post


Link to post
Share on other sites

Luis_ST    6

Luis_ST

Luis_ST    6

  • Diamond Finder
  • Luis_ST
  • Members
  • 6
  • 359 posts
Posted January 28
2 minutes ago, diesieben07 said:

By calling remove on the iterator you remove the current element from the collection you are iterating.

than this

		while (enchantmentIterator.hasNext()) {
			
			Enchantment enchantment = (Enchantment) enchantmentIterator;
			
			if (!enchantment.isCompatibleWith(enchantmentIterator.next())) {
				
				enchantmentIterator.remove();
				
			}
			
		}

 

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7690

diesieben07

diesieben07    7690

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7690
  • 56283 posts
Posted January 28

Sure. Although you should not need that cast.

 

Actually. I looked again. No, that does not make sense.

Why are you trying to cast the iterator.

  • Thanks 1
  • Quote

Share this post


Link to post
Share on other sites

Luis_ST    6

Luis_ST

Luis_ST    6

  • Diamond Finder
  • Luis_ST
  • Members
  • 6
  • 359 posts
Posted January 28 (edited)

i currently fixed the error so it works thanks

 

Edited January 28 by Luis_ST
  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • JayNeedsHelp
      How can I fix this encoding issue?

      By JayNeedsHelp · Posted 25 minutes ago

      Hey so I'm creating a forge mod and I'm trying to use the "§" character but I'm getting an illegal character error in the compiler. I've tried using the -encoding option in the compiler, I've also tried converting the file to UTF-8 without BOM, but it wasn't UTF-8 BOM in the first place. I was making a jar mod with mcp in eclipse and everything was working just fine with these characters, which I'm now moving to a forge mod. I'm using IntelliJ Community IDEA currently.   Here's a link to part of the error list: https://jay-hosts-a.dark-web.store/6AXsbJqG. Obviously the other errors were due to the illegal character error but I thought I might as well show it. I'm making a forge mod for 1.12.2, forgegradle is version 2.3-SNAPSHOT and I'm using mixingradle-0.6-SNAPSHOT.   I'm not sure how to fix this and any help would be greatly appreciated.
    • mchase
      Forge crashing

      By mchase · Posted 34 minutes ago

      I downloaded and installed forge for 1.16.4 and it shows up in my installations and will start to open but then crashes and gives me "exit code 255". I am on MacOS if that makes a difference. it says The game crashed whilst initializing game Error: java.lang.IllegalStateException: GLFW error before init: [0x10008]Cocoa: Failed to find service port for display Exit Code: 255 does forge just not work on Mac? am I missing something? please help
    • MiToKonndria
      cant download pixelmon

      By MiToKonndria · Posted 1 hour ago

      when i click install on the Pixelmon modpack it gets to 42% and mod 3 out of 7 and then gives me the error message: Timeout attempting to download: "https://edge.forgecdn.net/files/3072/298/pixelmon-1.12.2-8.1.2-universal.jar"
    • lupicus
      can someone help with server crashing

      By lupicus · Posted 1 hour ago

      Looks like Wonderful Enchantments has problems, try and remove it.
    • Draco18s
      can someone help with server crashing

      By Draco18s · Posted 1 hour ago

      Surprise, accessing the client thread from the server thread isn't possible. Bitch at the author of wonderfulenchantments.
  • Topics

    • JayNeedsHelp
      0
      How can I fix this encoding issue?

      By JayNeedsHelp
      Started 25 minutes ago

    • mchase
      0
      Forge crashing

      By mchase
      Started 35 minutes ago

    • MiToKonndria
      0
      cant download pixelmon

      By MiToKonndria
      Started 1 hour ago

    • IRONDALEK
      3
      can someone help with server crashing

      By IRONDALEK
      Started 5 hours ago

    • Twu
      0
      Need help with Potion Brewing recipes

      By Twu
      Started 1 hour ago

  • Who's Online (See full list)

    • Uncreative
    • mchase
    • NotAPotato
    • Daeruin
    • ehbean
    • LK1905
    • Befell
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.16.5] Enchantments can Apply to all Tools
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community