Jump to content
  • Home
  • Files
  • Docs
  • Merch
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
  • [Almost Solved][1.8] Detect Player Using Furnace or Craft's an item
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 0
PlayPrey

[Almost Solved][1.8] Detect Player Using Furnace or Craft's an item

By PlayPrey, June 28, 2015 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

PlayPrey    0

PlayPrey

PlayPrey    0

  • Tree Puncher
  • PlayPrey
  • Members
  • 0
  • 26 posts
Posted June 28, 2015

Hello, this is something I could do fine (3 years ago)... Now I returned and see that this is completely diffrent.

How do I check if the player has smelted or crafted an item?

 

I tried:

 

public class CraftingHandler (Usually I could implement CraftingHandler, however its now gone??? )

{

@SubscribeEvent

public void onSmelt(EntityPlayer player, ItemStack item)

{

if (item == new ItemStack(Items.baked_potato))

        {

                player.addStat(AE.bakePotato, 1);

        }

}

}

 

I am sorry for all the stupid questions, but it has been a long time since I modded Minecraft, I lost almost all the knowledge I had :P

 

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2096

Draco18s

Draco18s    2096

  • Reality Controller
  • Draco18s
  • Members
  • 2096
  • 14031 posts
Posted June 28, 2015

Creating is an event now.

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6689

diesieben07

diesieben07    6689

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6689
  • 45730 posts
Posted June 28, 2015

PlayerEvent.ItemSmeltedEvent is the event. Also you cannot compare ItemStacks that way. Please learn what == does in Java.

  • Quote

Share this post


Link to post
Share on other sites

iame6162013    0

iame6162013

iame6162013    0

  • Tree Puncher
  • iame6162013
  • Forge Modder
  • 0
  • 43 posts
Posted June 28, 2015

"item == new ItemStack(Items.baked_potato)" I think this is wrong... (because nothing will ever be == to it.)

  • Quote

Share this post


Link to post
Share on other sites

PlayPrey    0

PlayPrey

PlayPrey    0

  • Tree Puncher
  • PlayPrey
  • Members
  • 0
  • 26 posts
Posted June 28, 2015

Hmm, just noticed that some code didnt get pasted.

 

So I got;

 

@SubscribeEvent

public void onSmelt(PlayerEvent.ItemSmeltedEvent e)

{

EntityPlayer player = (EntityPlayer) e.player;

player.addChatMessage(new ChatComponentText("TYETJOASD"));

if (e.smelting.equals(Items.baked_potato))

        {

                player.addStat(AE.bakePotato 1);

        }

}

 

But the achievement is still not unlocking, neither am I getting the chat message.

 

What am I missing here?

 

(Also; I do know basic Java, but it has been 3 years since I programmed with Java, so things go about slowly. Also; Forge was diffrent back then.. Very diffrent :P , Nothing of my old code was usable.. :P )

 

So I am sorry for the stupid questions; I really am. But how do I compare with the event, and an Item?

 

(Also x2: I know what == does, it compares 2 values to see if theyre the same... right? :) )

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6689

diesieben07

diesieben07    6689

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6689
  • 45730 posts
Posted June 28, 2015

Ok, now you are comparing ItemStack with Item using equals. Do not tell me you know Java if you code that.

ItemStack has getItem method.

 

Did you register your event handler? If not: there is your problem. If yes: show the code.

  • Quote

Share this post


Link to post
Share on other sites

PlayPrey    0

PlayPrey

PlayPrey    0

  • Tree Puncher
  • PlayPrey
  • Members
  • 0
  • 26 posts
Posted June 28, 2015

Hehe sorry; Dont know why I tried equals.

 

Here's the up to date code: (Not including the proxy classes)

 

Main.java

http://pastebin.com/9PCZ05hS

 

CraftingHandler.java

http://pastebin.com/qz4RKLx7

 

Additional notes;

-Yes the achievement is being registered.

-The other handler's (found in main.java) work fine for what I use them for.

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6689

diesieben07

diesieben07    6689

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6689
  • 45730 posts
Posted June 28, 2015

ItemCraftedEvent is an FML event, you have to use the FML EventBus (FMLCommonHandler.instance().bus()).

  • Quote

Share this post


Link to post
Share on other sites

PlayPrey    0

PlayPrey

PlayPrey    0

  • Tree Puncher
  • PlayPrey
  • Members
  • 0
  • 26 posts
Posted June 28, 2015

Thank you! :) The game now gives the achievement and outputs the text!

 

Just wondering though, why does the message appear at a random amount? Sometimes I get the message 4 times, sometimes 2, others 5 and so on...

If I were to try and count the amount of times something has been smelted, I would get a completely wrong resoult.

 

(int bakedPotatos;

(inside method)

 

bakedPotatos += 1;  )

 

If I did that It would get more than just one.

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6689

diesieben07

diesieben07    6689

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6689
  • 45730 posts
Posted June 29, 2015

That's not what the event is for, the event is pretty much just for achievements. The vanilla code for this is messy. The event fires in the same location that vanilla checks for achievements.

  • 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

    • AdieCraft
      Japanese Style Temple Base

      By AdieCraft · Posted 14 minutes ago

      Hello there!   Check out my latest tutorial in my Japanese Builds series, building a Japanese Temple base.   Make sure to Subscribe, so you don't miss any future videos.   Thanks   Adie   Japanese Style Temple Base    
    • DaemonUmbra
      Forge crashes on start

      By DaemonUmbra · Posted 54 minutes ago

      Forge for 1.13+ requires Java 8-10 Forge for 1.12.2- requires Java 8
    • GttiqwT
      [1.12.2] Multiple Structure Generation

      By GttiqwT · Posted 1 hour ago

      Yeah I get where you're coming from. I also watched harry talk's tutorial and at first it worked but then I got the problem that it wont spawn more than one structure otherwise it'll overlap and only spawn the latest one added. I tried to follow this tutorial again and it just didnt seem to work at all now. When I get more time ill have to do it again and then afterwards try and fix the issues with spawning more than one structure. I'm currently trying to fix the issue where it causes cascading gen lag but I dont know how to fix that quite yet either.
    • Draco18s
      Distinguish singleplayer vs. multiplayer

      By Draco18s · Posted 1 hour ago

      No. Your client code is sending information to make the server do things. Your server code is telling the server to do those same things (again).
    • solitone
      Distinguish singleplayer vs. multiplayer

      By solitone · Posted 1 hour ago

      This isn’t an issue but normal behaviour, is it?
  • Topics

    • AdieCraft
      0
      Japanese Style Temple Base

      By AdieCraft
      Started 13 minutes ago

    • bitman
      1
      Forge crashes on start

      By bitman
      Started 2 hours ago

    • Merthew
      7
      [1.12.2] Multiple Structure Generation

      By Merthew
      Started November 7, 2018

    • solitone
      24
      Distinguish singleplayer vs. multiplayer

      By solitone
      Started December 5

    • TheGreenSquarez
      5
      Forge 28.1.10 won't show on launcher + 28.1.0 fails to work

      By TheGreenSquarez
      Started Wednesday at 11:21 AM

  • Who's Online (See full list)

    • Alpvax
    • thinkverse
    • AdieCraft
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [Almost Solved][1.8] Detect Player Using Furnace or Craft's an item
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community