Hey, I'm trying to find out, within my block's class, if the player is holding the block, so that way a variable can be set for use in other areas in that block's class if that is true. I already know where I want to use this, and how I'll implement it, (I'm going to be using it to determine if the code in onDisplayTick will run by if checking if the player is holding the block, be it directly or through a variable, however I can get this done) just my only roadblock is getting that crucial held item check.
Will I need to create a class for its ItemBlock and modify that, or can this be done solely within the block class? Any help is appreciated.
On a slightly less important note, is there a way to get a block's texture from the items folder or vice versa? (I didn't make this a separate thread to avoid double posting, and also this isn't big enough of an issue to me to make a new thread, so I just slapped this extra question right here.)
UPDATE: Okay, so I found out that Minecraft.getMinecraft() has thePlayer which is nothing new, but I learned that this allows me to basically do the same thing as EntityPlayer. (I was under the impression it was missing a few things.) However...
(If you're wondering why there's a variable for checking what's in the hand instead of it just being where the last if statement is, I did this just as a placeholder to see what sets the holdingBarrier to true or false for testing. Once I get things working, I'll be cleaning this up.)
So, here's a little snippet of code I'm having trouble with. The if statement with checking the item crashes the game. If I remove the .getItem() part, and the item.getItemFromBlock parts, instead of crashing, it will just ignore what the player is holding and always return false. If I remove the holding check completely, it'll successfully check the player's game mode but that's only half of what I want.
If it helps, the block of code this is in, is in onDisplayTick in a block's code, and is marked with @SideOnly(Side.CLIENT). Please go easy on me if I'm missing something obvious; I'm new to code, but I want to get better.
I managed to solve it while waiting. If anyone else was wondering, I was checking if getCurrentItem().getItem() was null, instead of if getCurrentItem was null, so by that time the game would already be running null code and crashing when I held nothing.
As you can see, I don't let heldItem ever be set if getCurrentItem() is null unlike the old code, instead of going to .getItem(), since by then the getCurrentItem() will be null.
Hey, I'm trying to find out, within my block's class, if the player is holding the block, so that way a variable can be set for use in other areas in that block's class if that is true. I already know where I want to use this, and how I'll implement it, (I'm going to be using it to determine if the code in onDisplayTick will run by if checking if the player is holding the block, be it directly or through a variable, however I can get this done) just my only roadblock is getting that crucial held item check.
Will I need to create a class for its ItemBlock and modify that, or can this be done solely within the block class? Any help is appreciated.
On a slightly less important note, is there a way to get a block's texture from the items folder or vice versa? (I didn't make this a separate thread to avoid double posting, and also this isn't big enough of an issue to me to make a new thread, so I just slapped this extra question right here.)
UPDATE: Okay, so I found out that Minecraft.getMinecraft() has thePlayer which is nothing new, but I learned that this allows me to basically do the same thing as EntityPlayer. (I was under the impression it was missing a few things.) However...
(If you're wondering why there's a variable for checking what's in the hand instead of it just being where the last if statement is, I did this just as a placeholder to see what sets the holdingBarrier to true or false for testing. Once I get things working, I'll be cleaning this up.)
So, here's a little snippet of code I'm having trouble with. The if statement with checking the item crashes the game. If I remove the .getItem() part, and the item.getItemFromBlock parts, instead of crashing, it will just ignore what the player is holding and always return false. If I remove the holding check completely, it'll successfully check the player's game mode but that's only half of what I want.
If it helps, the block of code this is in, is in onDisplayTick in a block's code, and is marked with @SideOnly(Side.CLIENT). Please go easy on me if I'm missing something obvious; I'm new to code, but I want to get better.
I managed to solve it while waiting. If anyone else was wondering, I was checking if getCurrentItem().getItem() was null, instead of if getCurrentItem was null, so by that time the game would already be running null code and crashing when I held nothing.
Here's how I fixed it:
As you can see, I don't let heldItem ever be set if getCurrentItem() is null unlike the old code, instead of going to .getItem(), since by then the getCurrentItem() will be null.