Jump to content

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


Atijaf

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • For the HoneyBottleItem class, would I just copy/paste my Lemon Juice item into the class or would I have to make other changes? Also, for what you first said, I have copied the "getEatingSound" and the "getDrinkingSound" from the class into my ModFoods class (I could link the whole class if that would help you understand more), though nothing seems to have been done. I also do not see a way to prevent particles from appearing when the item is drank. (Could you also post some examples if possible, that would be a great help to see where I went wrong).   I am at a point where I am quite clueless as the tutorials on YouTube do not cover the area I am needing to go into. I do hope that this is not too much of a bother for you. 
    • "An unexpected problem occurred and the game crashed" "Exit code: 1" I don't know what to do. Please help
    • https://mclo.gs/iVJZfGm https://privatebin.net/?442243857e9dcaca#5MhV8JAuhNJnN587jbG2pcVQi8VnvgAVafmpAd6Gnv91
    • So im making a mod for minecraft and i want to add custom fishing rods... aka fishing rods with different bait, depending on the bait you can have a higher chance of getting other fish. I want to make basically custom fishing rods with at least one custom loot table for each (so that i can choose which fish have a higher chance of being caught in a simpler way with said loot table) Problem is i dont know even where to start with doing this, like at all. Im very beginner with modding minecraft, any help (links to any source which could help me with this is also very helpful) would be great. 1.20 forge(of course)
    • Hi, my name is Gatis. Mostly all I do is play minecraft on Hypixel server. I play Skyblock where almost every player has installed QOL mods. They are nice and work nice but recently the grind I'm on requires not wasting time on boosts and if I'm watching something I usually miss it. Let me explain better. So there is "Mining speed boost" when it's ready message appears in chat. Mod I've been using allows to copy chat message, paste it in mod and next time same message appears it flashes big notification message on screen that speed boost is ready. The thing is somehow I still miss the notification. SO, I want to create mod that can detect that message and make more noticable notification (ex. bigger) or even stop me from moving for 10 sec if I don't use it instantly. I have no knowledge about java I have prepared intellij with forge on 1.8.9 I'm just left with this:                 package com.example.examplemod;                  import net.minecraft.init.Blocks;                import net.minecraftforge.fml.common.Mod;                import net.minecraftforge.fml.common.Mod.EventHandler;                import net.minecraftforge.fml.common.event.FMLInitializationEvent;                 @Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION)               public class GatisMOD              {                           public static final String MODID = "GatisMOD"; \                           public static final String VERSION = "1.0";                            @EventHandler                          public void init(FMLInitializationEvent event)                          {                                      // some example code                                      System.out.println("DIRT BLOCK >> "+Blocks.dirt.getUnlocalizedName());                          } }     I've watched many video, mostly they show how to setup everything but how to create, prepare file and later (export I guess) export to import in mods folder to use they don't I'd appreciate any help, maybe someone would explain some things to me. In future I have plans to make other feature but I guess not for now.
  • Topics

×
×
  • Create New...

Important Information

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