I have been into modding the popular Java based game Minecraft. I have created a few new weapons, including a battleaxe, and have given the weapons stronger damage and better durability.
I need your help Java programmers, because I am still newish at Java, and I haven't been able to found a tutorial on this upcoming question;

There are many .java files ( I'm using eclipse IDE with java sdk plugin ) within the Minecraft coding. One specific one I am looking at is EntityLiving.java. There is a public statement in there that goes;

Code:

public boolean canBreatheUnderWater()
     {
          return false;
     }

Now I could easily change that to true and breathe under water happily, but where's the fun? I want to create a SubaHelmet. I know how to create the crafting recipe, the graphics for it, assign durability, etc. When the helmet is worn though, I want the user to be able to breathe underwater. But the game looks at EntityLiving.java for the breathing attribute, and not Item(youritemhere).java for the attribute. So how could I change the coding to give the player the ability to breathe only when wearing this new helmet I am making? Thanks guys Smile

EDIT: I have tried using an If statement in the armor section basically saying;

Code:

if (variable == myhelmetsarmortype)
     {
          canBreatheUnderWater = true;
     }

But to no avail. Thanks.
if you can edit the EntityLiving.java file, I would add this attribute to the class:


Code:
private static boolean hasScubaHelmet = false;


Then, change the first method you shared to be this:


Code:
public boolean canBreatheUnderWater()
     {
          return this.hasScubaHelmet;
     }


And then, a setter for this attribute:


Code:
public void setHasScubaHelmet(boolean b) {
     this.hasScubaHelmet = b;
}


And finally, for that second block of code you gave, change it to this:


Code:
setHasScubaHelmet(variable == myhelmetsarmortype);




Keep in mind I'm just doing guesswork here, I haven't looked at any of these classes or have any experience minecraft modding; I'm just going with what seems logical to do for me.
That all makes a lot of sense, I'm going to open up eclipse right now and test this out. where would;

Code:

public void setHasScubaHelmet(boolean b) {
     this.hasScubaHelmet = b;
}

go? In EntityLiving.java or my custom item.java?
joshie75 wrote:
That all makes a lot of sense, I'm going to open up eclipse right now and test this out. where would;

Code:

public void setHasScubaHelmet(boolean b) {
     this.hasScubaHelmet = b;
}

go? In EntityLiving.java or my custom item.java?


It would have to go into the EntityLiving.java file's class, because it's referring to hasScubaHelmet as a local class variable within that scope.

Also, just realized I did something wrong. Change " this.hasScubaHelmet = b;" to "EntityLiving.hasScubaHelmet = b;".
A good idea to look for things is to find the code that deals with wearing a pumpkin, and then just adapt that to being a scuba mask, and modifying the hasScubaMask attribute. Unfortunately, I've never modded Minecraft before, so I don't know exactly what you need to do.
Are you sure it would be
EntityLiving.hasScubaHelmet = b;
and not
this.hasScubaHelmet = b;?
I thought it would be "this." because it was already in EntityLiving.java

@Player;
I've looked for the pumpkin wearing attributes and stuff, there's just so many.java files it could be under I haven't found it :\
joshie75 wrote:
Are you sure it would be
EntityLiving.hasScubaHelmet = b;
and not
this.hasScubaHelmet = b;?
I thought it would be "this." because it was already in EntityLiving.java


Yep, because "this" refers to a variable as a instance variable, and the class name ("EntityLiving:) refers to something being a class variable (static variable). I set it as static in case that EntityLiving had instances (I would assume it wouldn't, but either way this will ensure that there is only one hasScubaHelmet variable) Smile
Thanks Ashbad. I wasn't trying to question your programming ability or anything, I suck at programming, So I was just wondering, you cleared it up Very Happy
joshie75 wrote:
Thanks Ashbad. I wasn't trying to question your programming ability or anything, I suck at programming, So I was just wondering, you cleared it up Very Happy


Oh, I didn't take it that way Wink glad to help, and whilst helping it's a good idea to teach new concepts and clear misconceptions at the same time. Hope it works out!
Thanks man, I'm working on it now, and will be for an hour or two; I'll be sure to post once done and announce my success or failure, and If successful, I'll post some screenies Very Happy

Ashbad, for that final piece of code;

Code:

setHasScubaHelmet(variable == myhelmetsarmortype);

It's okay that piece is in a different .java file right?
joshie75 wrote:
Ashbad, for that final piece of code;

Code:

setHasScubaHelmet(variable == myhelmetsarmortype);

It's okay that piece is in a different .java file right?


That would be in whatever .java file that your new Scuba Helmet item's in, and would reside somewhere in the constructor Smile As for when you take off the helmet then (wherever the code is that handles item switching) would check if the scuba helmet was taken off, and set it back to false.

Another thing, one more mistake I made: plop a 'static' in the method signature of 'setHasScubaHelmet' (so, like 'public static void setHasScubaHelmet(boolean b)' ) and call to it like 'EntityLiving.setHasScubaHelmet'. Smile
Thanks Very Happy
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement