Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly handle generators with null spawns #536

Merged
merged 1 commit into from Jul 31, 2017
Merged

Properly handle generators with null spawns #536

merged 1 commit into from Jul 31, 2017

Conversation

mastercoms
Copy link
Member

@mastercoms mastercoms commented Jul 31, 2017

This fixes a null pointer exception when a generator returns a null spawn. This is valid according to the Bukkit spec and means that the server should find a random spawn point.

spawnX += random.nextInt(256) - 128;
spawnZ += random.nextInt(256) - 128;
}
setSpawnLocation(spawnX, getHighestBlockYAt(spawnX, spawnZ), spawnZ);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be getHighestBlockYAt(spawnX, spawnZ) + 1? Or is the 1 offset handled when actually spawning the player?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spawn point is a solid block

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? If you use /setworldspawn, it would set the spawn at the location of the executor which is 1 block above the surface.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, but I know that getHighestBlockYAt produces the correct Y value for the spawn point, whatever that value is supposed to be.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I guess the Y position doesn't really matter anyways because it is adjusted to the correct height when a player spawns (to avoid suffocation).

int spawnX = random.nextInt(256) - 128, spawnZ = random.nextInt(256) - 128;
getChunkAt(spawnX >> 4, spawnZ >> 4).load(true); // I'm not sure there's a sane way around this

for (int tries = 0; tries < 1000 && !generator.canSpawn(this, spawnX, spawnZ); ++tries) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1000 seems rather high, especially if all attempts going to fail because the spawn chunk is in the ocean or something.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure I'm missing something, but why not just use that method instead of duping the code? Also, that doesn't change that 1000 is a lot :P

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because that method isn't static.

I didn't change the value because that's outside of the scope of the PR. I could expand the scope to change the loop to a more appropriate value, and add a static helper method for default random spawn finding code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generator.getFixedSpawnLocation(this, random)? It wouldn't need to be static

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/GlowstoneMC/Glowstone/pull/536/files#diff-cea1d25e5518f2495b11e2d20021b0a0R767

The whole point of this PR is to add a case for when generator.getFixedSpawnLocation(this, random) returns null (as mentioned in the PR post "This fixes a null pointer exception when a generator returns a null spawn").

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. I should have read the PR description better then, my bad :)

@aramperes aramperes merged commit 4c70794 into master Jul 31, 2017
@mastercoms mastercoms deleted the spawn-fix branch August 1, 2017 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants