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    7

Luis_ST

Luis_ST    7

  • Diamond Finder
  • Luis_ST
  • Members
  • 7
  • 366 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    7696

diesieben07

diesieben07    7696

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7696
  • 56382 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    7

Luis_ST

Luis_ST    7

  • Diamond Finder
  • Luis_ST
  • Members
  • 7
  • 366 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    7696

diesieben07

diesieben07    7696

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7696
  • 56382 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    7

Luis_ST

Luis_ST    7

  • Diamond Finder
  • Luis_ST
  • Members
  • 7
  • 366 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    7696

diesieben07

diesieben07    7696

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7696
  • 56382 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    7

Luis_ST

Luis_ST    7

  • Diamond Finder
  • Luis_ST
  • Members
  • 7
  • 366 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    7696

diesieben07

diesieben07    7696

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7696
  • 56382 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    7

Luis_ST

Luis_ST    7

  • Diamond Finder
  • Luis_ST
  • Members
  • 7
  • 366 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    7696

diesieben07

diesieben07    7696

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7696
  • 56382 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    7

Luis_ST

Luis_ST    7

  • Diamond Finder
  • Luis_ST
  • Members
  • 7
  • 366 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    7696

diesieben07

diesieben07    7696

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7696
  • 56382 posts
Posted January 27

Yes

  • Thanks 1
  • Quote

Share this post


Link to post
Share on other sites

Luis_ST    7

Luis_ST

Luis_ST    7

  • Diamond Finder
  • Luis_ST
  • Members
  • 7
  • 366 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    7696

diesieben07

diesieben07    7696

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7696
  • 56382 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    7

Luis_ST

Luis_ST    7

  • Diamond Finder
  • Luis_ST
  • Members
  • 7
  • 366 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    7696

diesieben07

diesieben07    7696

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7696
  • 56382 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    7

Luis_ST

Luis_ST    7

  • Diamond Finder
  • Luis_ST
  • Members
  • 7
  • 366 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    7696

diesieben07

diesieben07    7696

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7696
  • 56382 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    7

Luis_ST

Luis_ST    7

  • Diamond Finder
  • Luis_ST
  • Members
  • 7
  • 366 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    7696

diesieben07

diesieben07    7696

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7696
  • 56382 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    7

Luis_ST

Luis_ST    7

  • Diamond Finder
  • Luis_ST
  • Members
  • 7
  • 366 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    7696

diesieben07

diesieben07    7696

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7696
  • 56382 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    7

Luis_ST

Luis_ST    7

  • Diamond Finder
  • Luis_ST
  • Members
  • 7
  • 366 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

    • Beethoven92
      1.16 Ore generation.

      By Beethoven92 · Posted 3 minutes ago

      Why using a font so big that one has to go back and forth to read a single line of text? 😪 So, once you have your ore feature registered (which, from what you said, i assume you have, correct me if i am wrong), you can add it to all biomes, or just some of them, in the BiomeLoadingEvent
    • Beethoven92
      Error at load_registries event phase

      By Beethoven92 · Posted 11 minutes ago

      Apparently here: BlockList.tutorial_slab = new SlabBlock(Block.Properties.from(BlockList.tutorial_slab)).setRegistryName(location("tutorial_slab")) your BlockList.tutorial_slab block is null when the block registration event is fired..i suggest you use deferred register to manage your registry entries
    • BeardlessBrady
      [1.16.4] Tile Registration

      By BeardlessBrady · Posted 17 minutes ago

      Ah there ya go! Thanks.
    • Beethoven92
      [1.16.4] Tile Registration

      By Beethoven92 · Posted 20 minutes ago

      public VendingTile(TileEntityType<?> tileEntityTypeIn) You don't need an argument in the constructor of your tile entity as in this case is not used since you are passing the TileEntityType to the super class: super(CommonRegistry.TILE_VENDING.get());  
    • BeardlessBrady
      [1.16.4] Tile Registration

      By BeardlessBrady · Posted 30 minutes ago

      Hello, I am having issues registering my tile entity. Here is my code as well as a link to the code in my github. The IDE is complaining that 'TileEntityType.Builder.create' has invalid arguments   // Tiles public static final DeferredRegister<TileEntityType<?>> TILE_ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, GOCurrency.MODID); public static final RegistryObject<TileEntityType<VendingTile>> TILE_VENDING = TILE_ENTITY_TYPES.register("vending_te", () -> TileEntityType.Builder.create(VendingTile::new, BLOCK_VENDING.get()).build(null));   https://github.com/Beardlessbrady/Currency-Mod/blob/95230ca4ee2d290b3e5f3ef81810a27f73137625/src/main/java/com/beardlessbrady/gocurrency/handlers/CommonRegistry.java#L42-L43
  • Topics

    • GhostGamesFSM
      1
      1.16 Ore generation.

      By GhostGamesFSM
      Started 1 hour ago

    • ThisIsNotOriginal
      1
      Error at load_registries event phase

      By ThisIsNotOriginal
      Started 1 hour ago

    • BeardlessBrady
      2
      [1.16.4] Tile Registration

      By BeardlessBrady
      Started 31 minutes ago

    • PlasmaPig13
      1
      The game crashed whilst rendering overlay Error: java.lang.NullPointerException: Rendering overlay Exit Code: -1

      By PlasmaPig13
      Started 1 hour ago

    • EnderiumSmith
      3
      The vanilla tag system isnt suitable for ore dictionary

      By EnderiumSmith
      Started 15 hours ago

  • Who's Online (See full list)

    • Beethoven92
    • ehbean
    • ThisIsNotOriginal
    • Chumbanotz
    • Microcellule
    • Milk_Shak3s
    • AstroTurffx
    • Jeldrik
    • Azurelmao
    • ichttt
    • Deadlocked47
    • BeardlessBrady
  • 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