Jump to content

A line of code I do not understand

Maximation

While creating some mods for Minecraft I came across this line of code in the Minecraft "BlockWorkbench.class" file.

return p_149691_1_ == 1 ? this.field_150035_a : (p_149691_1_ == 0 ? Blocks.planks.getBlockTextureFromSide(p_149691_1_) : (p_149691_1_ != 2 && p_149691_1_ != 4 ? this.blockIcon : this.field_150034_b));

Are the ?'s and the :'s standard Java or is it something custom from Minecraft? In either way, what does this do?

Here is the full method where this return statement is positioned in:

/**     * Gets the block's texture. Args: side, meta     */    @SideOnly(Side.CLIENT)    public IIcon getIcon(int p_149691_1_, int p_149691_2_)    {        return p_149691_1_ == 1 ? this.field_150035_a : (p_149691_1_ == 0 ? Blocks.planks.getBlockTextureFromSide(p_149691_1_) : (p_149691_1_ != 2 && p_149691_1_ != 4 ? this.blockIcon : this.field_150034_b));    }

Has anyone made mods for Minecraft before? What mods did you create?

 

Thank you for hopefully another wise lesson :)

 

 

Learning

Link to comment
Share on other sites

Link to post
Share on other sites

What ta makin? Mod? What kind lols

Its all looks these days

Link to comment
Share on other sites

Link to post
Share on other sites

While creating some mods for Minecraft I came across this line of code in the Minecraft "BlockWorkbench.class" file.

return p_149691_1_ == 1 ? this.field_150035_a : (p_149691_1_ == 0 ? Blocks.planks.getBlockTextureFromSide(p_149691_1_) : (p_149691_1_ != 2 && p_149691_1_ != 4 ? this.blockIcon : this.field_150034_b));

Are the ?'s and the :'s standard Java or is it something custom from Minecraft? In either way, what does this do?

Here is the full method where this return statement is positioned in:

/**     * Gets the block's texture. Args: side, meta     */    @SideOnly(Side.CLIENT)    public IIcon getIcon(int p_149691_1_, int p_149691_2_)    {        return p_149691_1_ == 1 ? this.field_150035_a : (p_149691_1_ == 0 ? Blocks.planks.getBlockTextureFromSide(p_149691_1_) : (p_149691_1_ != 2 && p_149691_1_ != 4 ? this.blockIcon : this.field_150034_b));    }

Has anyone made mods for Minecraft before? What mods did you create?

 

Thank you for hopefully another wise lesson :)

Itis the ternary conditional operator.

 

Its very simple in the way it works.

 

In this example:

r = x > y ? i : n;

r would gain the value of i.

 

you could also write the above example as a if statement:

if(x>y){    r = i;}else{    r=n;}

or:

system.out.println(1>2 ? "No" : "Yes");

would print the string "No"

Link to comment
Share on other sites

Link to post
Share on other sites

Itis the ternary conditional operator.

Its very simple in the way it works.

In this example:

r = x > y ? i : n;
r would gain the value of i.

you could also write the above example as a if statement:

if(x>y){    r = i;}else{    r=n;}
or:

system.out.println(1>2 ? "No" : "Yes");
would print the string "No"
Thank you very much! It is very simple, but you have to understand it first. Thank you for the clear explanation!

Learning

Link to comment
Share on other sites

Link to post
Share on other sites

What ta makin? Mod? What kind lols

I do not understand what you say.

Learning

Link to comment
Share on other sites

Link to post
Share on other sites

I do not understand what you say.

he said whatcha making, is it a mod (for minecraft?)

Linux "nerd".  If I helped you please like my post and maybe add me as a friend :)  ^_^!

Link to comment
Share on other sites

Link to post
Share on other sites

he said whatcha making, is it a mod (for minecraft?)

 

Aha.. Well, he should definitely learn to formulate his questions better!

Learning

Link to comment
Share on other sites

Link to post
Share on other sites

Aha.. Well, he should definitely learn to formulate his questions better!

Aha.. Well, you should defiantly learn to read his questions better! Not like there complicated lols

Its all looks these days

Link to comment
Share on other sites

Link to post
Share on other sites

Aha.. Well, you should defiantly learn to read his questions better! Not like there complicated lols

English is not my native language, that is why I do not understand some of your sayings. Also, I do not like "internet language" as it isn't useful and not as understandable as "normal" English.

But if you want to reformulate your question I would be happy to answer it!

Learning

Link to comment
Share on other sites

Link to post
Share on other sites

English is not my native language, that is why I do not understand some of your sayings. Also, I do not like "internet language" as it isn't useful and not as understandable as "normal" English.

But if you want to reformulate your question I would be happy to answer it!

 

That really wasn't "internet language".. Seemed to me that he was simply trying to be cute. Perhaps he likes you in that way?

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

That really wasn't "internet language".. Seemed to me that he was simply trying to be cute. Perhaps he likes you in that way?

haha yeah right lol ;) dem jokes doe

Its all looks these days

Link to comment
Share on other sites

Link to post
Share on other sites

haha yeah right lol ;) dem jokes doe

:wub:

 

:P

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

haha yeah right lol ;) dem jokes doe

 

Haha it is all right, come give me a hug :D

Learning

Link to comment
Share on other sites

Link to post
Share on other sites

Haha it is all right, come give me a hug :D

Only a hug? :( Lols ROTFL 

Its all looks these days

Link to comment
Share on other sites

Link to post
Share on other sites

Wait what?

Urbandictionary.com might help you.... Personally I only use imo, iirc, and lol noticeably online. Anymore more than the mentioned would make me feel dumb.

Link to comment
Share on other sites

Link to post
Share on other sites

This kind of statement is called a Ternary Operator also known as no stop what're you doing

 

It is incredibly annoying to read and maintain and one of the core rules is to make code readable and maintainable.

 

For simple assignments it's ok, but the way it's used here is horrible.

Link to comment
Share on other sites

Link to post
Share on other sites

This kind of statement is called a Ternary Operator also known as no stop what're you doing

 

It is incredibly annoying to read and maintain and one of the core rules is to make code readable and maintainable.

 

For simple assignments it's ok, but the way it's used here is horrible.

 

The way and reason it's used there is due to obfuscation.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

The way and reason it's used there is due to obfuscation.

 

I thought so, but it's quite poorly obfuscated in that case. Just a bit of extra effort to read it.

 

Still, pls no long ternary operators in code, people. pls no pls

Link to comment
Share on other sites

Link to post
Share on other sites

I thought so, but it's quite poorly obfuscated in that case. Just a bit of extra effort to read it.

 

Still, pls no long ternary operators in code, people. pls no pls

 

I definitely agree with you, it is horrible!

This is just a line of code in the Minecraft Coder Pack.

Oh well..

Learning

Link to comment
Share on other sites

Link to post
Share on other sites

I definitely agree with you, it is horrible!

This is just a line of code in the Minecraft Coder Pack.

Oh well..

 

Yes they cannot deobfuscate certain things. They provide a couple of lookup tables for these (useful for core modding, i.e. intercepting and substituting byte code - XRay and so on).

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×