return statement error

Started by LeeLime5000 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Nov 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
return statement error

 

Hello! I have been having some issues with return statments!

 

For this code, it gives me an error that the last return can't be reached.

public class GrapeVineBlockValidPlacementConditionProcedure {
	public static boolean execute(LevelAccessor world, double x, double y, double z) {
		if ((world.getBlockState(new BlockPos((int) (Math.floor(x)), (int) (Math.floor(y)), (int) (Math.floor(z))))).getBlock() == Blocks.AIR) {
			return false;
		} else {
			return true;
		}
		return false;
	}
}
public class GrapeVineBlockValidPlacementConditionProcedure {
	public static boolean execute(LevelAccessor world, double x, double y, double z) {
		if ((world.getBlockState(new BlockPos((int) (Math.floor(x)), (int) (Math.floor(y)), (int) (Math.floor(z))))).getBlock() == Blocks.AIR) {
			return false;
		} else {
			return true;
		}
	}
}

But if I remove it, it will tell me that It needs to end in a valid return statement.

 

Joined Apr 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
for me it works to remove…
Tue, 11/23/2021 - 13:52

for me it works to remove the else block and putting an return there alone
because if you think about it if the return statement happened in the if-block then it wont get to the rest anyways.

It kind of treats the else like an else-if for some reason...