Need help understanding some Java

Questions about programming languages and debugging
Post Reply
reparto
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 288
Joined: 27 May 2013, 11:30
10

Need help understanding some Java

Post by reparto »

This is a snippet from Minecraft that I am trying to understand, there seems to be two conditionals which conflict each other

The labeled if statement requires var3 to be false and (this.movementInput.moveForward >= var2) to be true, but var3 is (this.movementInput.moveForward >= var2) so it reads as if the statement will always evaluate to false because the second and third conditionals will never be the same

Code: Select all

            boolean var3 = this.movementInput.moveForward >= var2; //evaluates to true if moving which I am for the purpose of this
            boolean var4 = true; //cut out bit which evaluates to true

            if (this.onGround && !var3 && this.movementInput.moveForward >= var2 && !this.isSprinting() && var4) //This line is confusing me since the second and third conditional conflict
            {

            }
Selling invisible pets:
Dogs - 0.5 Bitcoins
Cats - 0.7 Bitcoins
Unicorns - 10 Bitcoins
Chimpanzee - 2 Bitcoins

PM me if you are interested, will ship via priority airmail, will accept escrow services

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Re: Need help understanding some Java

Post by ayu »

hmmm yeah, that does look strange :S
Is it from a plugin or something?
"The best place to hide a tree, is in a forest"

reparto
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 288
Joined: 27 May 2013, 11:30
10

Re: Need help understanding some Java

Post by reparto »

No, its core code.

If the conditional evaluates true then it sets a counter to detect a double tap to enable sprint. Since sprint works then somehow this evaluates to true. I have seen this kind of code appear several times in Minecraft and I can't understand how on earth the same condition evaluates to true and false at the same time unless its the health of Schrodinger's cat.

There are also other several unnecessary lines of code and its weird because I thought Minecraft lagged because Java sucks.

Found another!

Code: Select all

boolean var1 = this.movementInput.jump;
if (this.capabilities.allowFlying && !var1 && this.movementInput.jump)
Selling invisible pets:
Dogs - 0.5 Bitcoins
Cats - 0.7 Bitcoins
Unicorns - 10 Bitcoins
Chimpanzee - 2 Bitcoins

PM me if you are interested, will ship via priority airmail, will accept escrow services

reparto
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 288
Joined: 27 May 2013, 11:30
10

Re: Need help understanding some Java

Post by reparto »

I looked at it in a debugger and it says that somehow it evaluates to true if the jump button is pressed, so I assume the input is being updated by another thread whilst this code running
Selling invisible pets:
Dogs - 0.5 Bitcoins
Cats - 0.7 Bitcoins
Unicorns - 10 Bitcoins
Chimpanzee - 2 Bitcoins

PM me if you are interested, will ship via priority airmail, will accept escrow services

Post Reply