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

hello everyone.

i can't find a way to "stop" a player from crafting a specific item when they not shall be able to make it

 

to say it more deeply i have a boolean that normal say false but for some player it says true and i try to stop the player with the boolean = true from crafting some items

 

i already tryed ItemCraftedEvent where i cancel the event but i crash when i do that

  • Author

Currently there is no way to cancel crafting without some hacks.

ok else thanks

do you now when we might get a way?

Maybe you could take a look at the thaumcraft code?

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

  • Author

Maybe you could take a look at the thaumcraft code?

i don't think that can work with a the vanilla crafting table.

i have also try'ed to look at it but wanst able to find the code (looked in the public thaumcraft API)

That does not remove a crafting recipe.

 

With a crafting handler you could say if its the recipe close the gui and drop the items.

Removing a recipe is easy CraftingManager.getInstance().getRecipeList().removeAt();

only removing a recipe per player is hard.

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

  • Author

Removing a recipe is easy CraftingManager.getInstance().getRecipeList().removeAt();

only removing a recipe per player is hard.

yea that's why i wanna just cancel when they craft the item because the Boolean that can be true for some players can also turn false.

just so you now what i'm working on (may help)

i'm working on a new Vampire Mod and i'm currently adding a Holy Ingot that i don't wan't the vampires to craft and there is also some items that i'm thinking too add that i wan't only the vampires to be able too craft.

 

Ok guys, I'm gonna save you.

Make a new class that implements

IRecipe

. Add a private field holding another IRecipe and add a constructor that fills that field.

Then delegate all methods you need to implement from IRecipe to the wrapped IRecipe instance.

Except in the matches method you also check for your additional condition. Now, how to get the player that is crafting? Here is the tricky part:

First, get the Container from the InventoryCrafting. You can do that, by accessing the private field "eventHandler" in the InventoryCrafting class (via reflection). Now, this Container can be various types. ContainerSheep (Yes, that exists), ContainerCrafting or ContainerPlayer. Possibly even others for automated crafting of some mods. But we only care about ContainerWorkbench (=>Workbench) or ContainerPlayer (=>Crafting grid in the inventory).

Now for ContainerPlayer we need to access the protected field player, we don't even need reflection for that if we absolutely want, it would be sufficient to make a uniquely named class in the net.minecraft.inventory package.

 

For ContainerWorkbench we need even more trickery. The first Slot in a ContainerWorkbench is a SlotCrafting. We get that with the getSlot method from the container and an appropriate cast. Then in the SlotCrafting we have a private field thePlayer which we access via reflection again.

 

Voila: We successfully got the player doing the crafting. :)

 

Edit: I almost forgot. Now, in your postInit or whatever iterate through all recipes, find the one you want and replace it with your custom version, wrapping the old one.

 

love you for this post +1000

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

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.