The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Re: Using a String[] in a Void or INT???

Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

I assume you're talking about this statement and others like it:

if (var4 = "stone")

'=' is an assignment operator. The value to the right is assigned to or stored in the variable on the left.

In the if statement, if ( condition ), condition must resolve to a boolean, either true or false. Since the condition var4 = "stone" does not resolve to true or false, the statement

if (var4 = "stone")

is incorrect.

'==' is an equality operator, but it is not used to determine if the value or contents of one object (a String object, for example) is equal to another object's value or contents. Instead, the equals() method is used which is (or can be) customized to be specific for each Java type. Thus,

if (var4 = "stone")

is correctly written:

if ( var4.equals( "stone" ) )

as long as var4 is a String object.

That's more about Java than you probably wanted to know. If you decide to continue your use of Java to enhance your Minecraft experience, please pick up a book and study Java basics a bit.

Re: Using a String[] in a Void or INT???

Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

I assume you're talking about this statement and others like it:

if (var4 = "stone")

'=' is an assignment operator. The value to the right is assigned to or stored in the variable on the left.

In the if statement, if ( condition ), condition must resolve to a boolean, either true or false. Since the condition var4 = "stone" does not resolve to true or false, the statement

if (var4 = "stone")

is incorrect.

'==' is an equality operator, but it is not used to determine if the value or contents of one object (a String object, for example) is equal to another object's value or contents. Instead, the equals() method is used which is (or can be) customized to be specific for each Java type. Thus,

if (var4 = "stone")

is correctly written:

if ( var4.equals( "stone" ) )

as long as var4 is a String object.

That's more about Java than you probably wanted to know. If you decide to continue your use of Java to enhance your Minecraft experience, please pick up a book and study Java basics a bit.

I know naming the variables to things like var1, or par1 is not usually what people like, it's just easier for me at the moment...

But yeah, where I am stuck might be a bit obvious, but its at "var1" in "textureType". I'm not sure how to set up something to do what I'm wanting her, but I am trying to get it to assign a number to each type based off the types in "stoneType".

Setting "var1 = 0" to "var1 = 1" does work as I wanted when I test it, and changes the texture of the block from Stone to Sand as intended, so I know at least that works. So I think it just needs some math... I don't really know since I'm still a beginner with Java.

Re: Using a String[] in a Void or INT???

You have a couple "lists" of if statements that could be simplified by using loops and combining actions. There's no reason that I can see to separately assign values to the variables varX and then do another action based on the value of varX. Why not do it all at once? You can also make better use of arrays to simplify the design.

These optimizations will occur to you as you gain more experience and confidence, ask questions, and review how others do similar things.

I'm not sure what you mean by "needs some math." Each type in the array stoneType[] already has a value - the item's index in the array.

Re: Using a String[] in a Void or INT???

Originally Posted by GregBrannon

You have a couple "lists" of if statements that could be simplified by using loops and combining actions. There's no reason that I can see to separately assign values to the variables varX and then do another action based on the value of varX. Why not do it all at once? You can also make better use of arrays to simplify the design.

These optimizations will occur to you as you gain more experience and confidence, ask questions, and review how others do similar things.

I'm not sure what you mean by "needs some math." Each type in the array stoneType[] already has a value - the item's index in the array.

Keep coding!

I'm not sure really... I just know that this seems to really be the only thing that works for the codes I am using it for, and that if this loop worked out as I wanted then I'd be able to fix other parts of my code, as "stoneType.equals("stone")" doesn't seem to work in some applications I am trying to use it for, but if it's set up as an Int then it works better.

Re: Using a String[] in a Void or INT???

I don't see any loops. The loops in Java are for, while, and do/while. Did you mean there are loops in the code you didn't post?

When using "stoneType.equals("stone")" the block does not register in the menus . . . So I'm not really sure what else to do at the moment.

I don't know what problem you're trying to solve. I don't know what "the block does not register in the menus" means. Describe what "it works" and "it doesn't work" mean. Show a sample run if possible, and describe how the sample run would look if it did "work."

Rather than posting ALL of your code, post a short runnable example that demonstrates the problem you're trying to solve.

Re: Using a String[] in a Void or INT???

Originally Posted by GregBrannon

I don't see any loops. The loops in Java are for, while, and do/while. Did you mean there are loops in the code you didn't post?

I don't know what problem you're trying to solve. I don't know what "the block does not register in the menus" means. Describe what "it works" and "it doesn't work" mean. Show a sample run if possible, and describe how the sample run would look if it did "work."

Rather than posting ALL of your code, post a short runnable example that demonstrates the problem you're trying to solve.

Well I mean like, without the "textureType" then the things don't correctly and that it's making it a little easier to handle the "stoneTypes" data.

getSubBlocks, Is what registers the blocks into menus in Minecraft.

Colored codes are referenced from earlier post.

int var3 = this.textureType();

if (par1 != Block.stoneVerticalDoubleSlab.blockID)
Tells the game to not register a block.

if (var3 == 0) par3List.add(new ItemStack(par1, 1, 0));
Tells the game to register a block. And it's getting the data from "textureType"

if (stoneType.equals("stone")) par3List.add(new ItemStack(par1, 1, 0));
This is using the code you tipped me off to, but it's not taking the data from stoneTypes, so I used the texureType that I setup as an attempt to a loop hole, which I think shall help me register that data for other codes when I add them.

if (var3 == 0) par3List.add(new ItemStack(par1, 1, 0));
Can be registered as many times as desired and it tells the game to add the block to the list.

And, if (stoneType.equals("stone")) par3List.add(new ItemStack(par1, 1, 0));
Is not getting data from the stoneType as I thought it would. Which is why I made the whole textureType as a loop hole for my code.

Re: Using a String[] in a Void or INT???

This is a loop that collapses your string of 'if' statements into a more compact form:

// returns the index number for the argumentprotectedint getElementNumber(String slabType ){// STONE_TYPES is an array that contains the possible stone typesfor(int i =0; i < STONE_TYPES.length; i++){if( slabType.equals( STONE_TYPES[i])){return i;}}// default to indicate the specified value was not foundreturn-1;}// end method get ElementNumber()

Loops and arrays are basic programming tools common to most every programming language. If you're interested in programming, you should pick up a book and learn the basic tools.

Re: Using a String[] in a Void or INT???

I'm not really sure what to do for the STONE_TYPES as the stoneTypes referenced before was changed to slabType, just a name change with the same codes.

But yeah, I'd love to learn Java, not only for Minecraft but for applications I want to try to make in the future, or even Windows Apps.

One thing is that I can't really do books to well, I don't really have a way to go to the nearest library, and Idon't know of any near by book stores.
But any online resources should help just as much, right?