DJ1TJOO Posted February 1, 2020 Posted February 1, 2020 (edited) How to cancel PlayerEvent.ItemCraftedEvent? Edited February 2, 2020 by DJ1TJOO Quote
Cadiboo Posted February 1, 2020 Posted February 1, 2020 You can call Event#setCancelled on cancellable events. IIRC you should not be cancelling this event though because it results in the items in the crafting matrix being consumed but the item not being given to the player. What are you trying to achieve, from an end-user’s (a player) perspective? Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
DJ1TJOO Posted February 1, 2020 Author Posted February 1, 2020 1 minute ago, Cadiboo said: You can call Event#setCancelled on cancellable events. IIRC you should not be cancelling this event though because it results in the items in the crafting matrix being consumed but the item not being given to the player. What are you trying to achieve, from an end-user’s (a player) perspective? The player has todo something first before they can craft the item. I tried making a custom condition, but I can't seem how todo that because what the docs says isn't working for me Github: https://github.com/DJ1TJOO/fantasy20/ Quote
Cadiboo Posted February 1, 2020 Posted February 1, 2020 Just now, DJ1TJOO said: I tried making a custom condition This is what you’re meant to do. What is the exact issue that you’re having? Forge provides custom conditions too so even if you’re having trouble with the docs, you can look at Forge’s code to see how it works Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
DJ1TJOO Posted February 1, 2020 Author Posted February 1, 2020 5 minutes ago, Cadiboo said: This is what you’re meant to do. What is the exact issue that you’re having? Forge provides custom conditions too so even if you’re having trouble with the docs, you can look at Forge’s code to see how it works I read the ItemExsistsCondition.class and it has a constructor with a variable and in the docs they say that the constructor must be empty so I don't understand what I need todo Quote
Cadiboo Posted February 1, 2020 Posted February 1, 2020 What is the condition that you’re trying to implement meant to do? Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
DJ1TJOO Posted February 1, 2020 Author Posted February 1, 2020 Just now, Cadiboo said: What is the condition that you’re trying to implement meant to do? I have a capability on each player with the Items they have "learned" if the item is not in the capability list then the player cannot craft it Quote
Cadiboo Posted February 1, 2020 Posted February 1, 2020 Ok so you would want a condition called something like “has_learned_item”. I’m not sure if you get a player object in the conditions, let me check Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
DJ1TJOO Posted February 1, 2020 Author Posted February 1, 2020 2 minutes ago, Cadiboo said: Ok so you would want a condition called something like “has_learned_item”. I’m not sure if you get a player object in the conditions, let me check Yes I called it researched because the way you do it is in the research table Quote
DJ1TJOO Posted February 1, 2020 Author Posted February 1, 2020 33 minutes ago, Cadiboo said: Ok so you would want a condition called something like “has_learned_item”. I’m not sure if you get a player object in the conditions, let me check Al ready have an idea? Quote
DJ1TJOO Posted February 1, 2020 Author Posted February 1, 2020 2 hours ago, diesieben07 said: You already asked about recipe conditions here: However they won't help you make player-specific conditions. For that you need a custom recipe type (check IRecipeSerializer) and then check the player inside the recipe implementation. I tried to make it but I think I need to register it somewhere. I've updated the github and the doorlock recipe has my type (for now just the copied normal shapedrecipe) as recipe. The error I'm getting when joining a world is: com.google.gson.JsonSyntaxException: Invalid or unsupported recipe type 'fantasy20:shaped_researched_recipe' Quote
Draco18s Posted February 1, 2020 Posted February 1, 2020 ...You do know that there's a game rule that already covers this, right? If you don't have the recipe in your recipe book, you can't craft it when the rule is enabled. 1 Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
DJ1TJOO Posted February 2, 2020 Author Posted February 2, 2020 9 hours ago, diesieben07 said: IRecipeSerializer is a registry entry, just like blocks or items. It works now but how would I get the player in my IRecipe because the CraftingInventory doesn't hold the owner of the inv. And its all server side so I can't use the Minecraft.getInstance() Quote
DJ1TJOO Posted February 2, 2020 Author Posted February 2, 2020 (edited) 20 minutes ago, diesieben07 said: CraftingInventory has a reference to the Container (field_70465_c, you'll need reflection). You can then look through Container#listeners which should contain the player using this inventory. @SuppressWarnings("rawtypes") Class invClass = inv.getClass(); try { Field field = invClass.getField("field_70465_c"); Container container = (Container) field.get(this); @SuppressWarnings("rawtypes") Class containerClass = container.getClass(); @SuppressWarnings("unchecked") List<IContainerListener> listeners = (List<IContainerListener>) containerClass.getField("listeners").get(this); for (IContainerListener iContainerListener : listeners) { iContainerListener. } } catch (Exception e) { e.printStackTrace(); } I have this now but I don't see how I can get the player from IContainerListener. Edit: Oh I can cast it to a serverplayer Changed this -> inv Edited February 2, 2020 by DJ1TJOO Quote
DJ1TJOO Posted February 2, 2020 Author Posted February 2, 2020 2 minutes ago, diesieben07 said: ServerPlayerEntity implements IContainerListener. You do an instanceof check. Also, why are you using raw types? How would I do it else then I've just searched reflection on the internet it's new for me Quote
DJ1TJOO Posted February 2, 2020 Author Posted February 2, 2020 (edited) 3 minutes ago, diesieben07 said: https://docs.oracle.com/javase/tutorial/java/generics/rawTypes.html what do I need todo it to avoid raw types? Edited February 2, 2020 by DJ1TJOO Quote
DJ1TJOO Posted February 2, 2020 Author Posted February 2, 2020 Just now, diesieben07 said: Please learn about Java generics. This is not a Java school. Okay Quote
DJ1TJOO Posted February 2, 2020 Author Posted February 2, 2020 22 minutes ago, diesieben07 said: Please learn about Java generics. This is not a Java school. I've this code now and I get the error that the field field_70465_c does not exist try { Class<? extends CraftingInventory> invClass = inv.getClass(); Field field = invClass.getField("field_70465_c"); Container container = (Container) field.get(inv); Class<? extends Container> containerClass = container.getClass(); Field field2 = containerClass.getField("listeners"); @SuppressWarnings("unchecked") List<IContainerListener> listeners = (List<IContainerListener>) field2.get(inv); for (IContainerListener iContainerListener : listeners) { if(iContainerListener instanceof ServerPlayerEntity) { ServerPlayerEntity p = (ServerPlayerEntity) iContainerListener; if(!p.getCapability(CapabilityResearchProvider.RESEARCH_CAPABILITY, p.getHorizontalFacing()).map(r -> { if(!r.getResearched().contains(getCraftingResult(inv).getItem())) { return false; } return true; }).orElse(Boolean.FALSE)) { return false; } } } } catch (Exception e) { e.printStackTrace(); } Quote
Cadiboo Posted February 4, 2020 Posted February 4, 2020 You can use a single line of code with ObfuscationReflectionHelper. You can also use an AT (Access Transformer) Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
Recommended Posts
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.