Jump to content

[1.8] Stopping the player from receiving item after crafting [SOLVED]


Recommended Posts

Posted

Is there some way to stop the player from obtaining the item crafted?

 

I have used this

@SubscribeEvent
public void onItemCrafted(ItemCraftedEvent event){
        event.player.inventory.setItemStack(null)
}

which deletes what the player is holding with the mouse.

However, if the player shift clicks the item, he still gets it.

 

I would prefer to leave the shift clicking ability in there.

Posted

I may be wrong, but I don't think there is any easy Forge hook that lets you change that.

 

The only way to restrict it for certain players that I have ever seen is to substitute in your own crafting matrix for the vanilla one, so that you can inject your own logic. Not very inter-mod compatible, but it gets the job done.

 

That assumes you already have a way to know which recipes are restricted for which players, such as storing their 'learned recipes' in IExtendedEntityProperties or whatever it is you are doing.

Posted

Do you want the item to not even appear in the output, or you want it to be there but not able to pick up, or you want it to disappear when the certain player tries to pick it up?

 

Not appearing in the output would be neat, but not required.  Honestly, any of those will work.  Whichever is easier I suppose.

 

I may be wrong, but I don't think there is any easy Forge hook that lets you change that.

 

I believe you when you say it's not easy.  I've looked around a little bit and haven't found too much.

 

The only way to restrict it for certain players that I have ever seen is to substitute in your own crafting matrix for the vanilla one, so that you can inject your own logic. Not very inter-mod compatible, but it gets the job done.

This is similar to what I found, but was confused and was hoping to find an alternative.

Also, incompatibility is just fine.  It's the only mod my friends and I will be using.

 

That assumes you already have a way to know which recipes are restricted for which players, such as storing their 'learned recipes' in IExtendedEntityProperties or whatever it is you are doing.

Yes.

 

Posted

There is a way to restrict recipes for certain player. diesieben07 has a tutorial on how to do that, I already used it once and it worked like a charm. gimme a second to find it..

Posted

http://www.minecraftforge.net/forum/index.php/topic,23133.0.html

 

There you go! Using this technique u can make recipes that can only be crafted under specific circumstances! Should be exactly what u want! Go and bumb diesieben's karma up, he did a great job there ;)

That only works for new recipes, though. The OP seems to be looking for a way to restrict vanilla recipes. I guess you could remove all of the recipes and replace them with custom IRecipes... seems like a lot of work :P

Posted

Well, the OP has to clarify, but it sounds like maybe he only wants to do it for a couple recipes, so just replacing those using diesieben07'2 method might be pretty easy.

 

Since he said that it is okay for the player to be able to pick up the item but then it disappears, that means you can do one other approach. You could use the ItemCraftedEvent to set a boolean in an extended property for the player (that represents that the player picked up a restricted item), and then in the PlayerTickEvent check for that boolean and delete the itemstack that is being held. Since it would happen one tick later, I think it is safe to assume that the item in the hand is the one taken from the crafting, but to be really sure you could also have an extended property to indicate the itemstack.

 

Yet another possible approach is to use a player tick handler and check if the crafting gui is open. If it is, I think you could monitor for something in the output slot and delete it. Of course the crafting matrix would continuously replenish it, but depending on the order of the tick events (probably need to play around with Post and Pre tick events to see which works better), it might work.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

I think it is safe to assume that the item in the hand is the one taken from the crafting

Really? You never click an item and put it in any of the other 30 some slots in your inventory? You always place it in your current slot? I don't think I ever put it in my current slot, as I'm usually already carrying something.

 

Sorry, but I don't think using any kind of ticking event is the answer to this question.

Posted

I think it is safe to assume that the item in the hand is the one taken from the crafting

Really? You never click an item and put it in any of the other 30 some slots in your inventory? You always place it in your current slot? I don't think I ever put it in my current slot, as I'm usually already carrying something.

 

Sorry, but I don't think using any kind of ticking event is the answer to this question.

 

agreed. I still cheer for readding the recipes if its only a couple

Posted

I think it is safe to assume that the item in the hand is the one taken from the crafting

Really? You never click an item and put it in any of the other 30 some slots in your inventory? You always place it in your current slot? I don't think I ever put it in my current slot, as I'm usually already carrying something.

 

Yeah, I guess I didn't mean held item, I meant what your mouse was moving (i.e. once you pick it up) but that isn't really in your inventory slot at that point so I guess you can't hook into that.

 

I think ultimately it depends on how many recipes he wants to affect. Replacing them all might be a bit of work and may create some inter-mod compatibility issues. But it would be really easy if he just wants to do a couple.

 

One other approach might be to intercept the interact event with the crafting table and bring up a custom gui associated with a custom container that gives the control you want.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Thank you all for the amount of replies and discussions.  I have been away from home and am delighted to see all these answers to my question.  I will probably be using diesieben07's tutorial, even though I will be replacing many crafting recipes, if not all.  I would like complete control and customizable crafting recipes as well as requirements to craft them, so with diesieben07's tutorial, it looks like I can have that.

 

Again, thanks for all the input.  It helped me immensely!

 

Edit:

With a few tweaks here and there, I was able to recreate my own way of adding recipes (i.e. extending shapedOreRecipes)

This way, I can now use my new class, which is pretty much a copy of shapedOreRecipes, except I added a few variables such as required level and skill name.

 

No need to create a new class for each recipe.

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...

×   Pasted as rich text.   Restore formatting

  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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.