-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from Rebirth-of-the-Night/fix/ground-spawn
Add beneath spawn type, ground spawns top to bottom
- Loading branch information
Showing
6 changed files
with
93 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...ylor/mc/onslaught/modules/onslaught/invasion/sampler/predicate/SpawnPredicateBeneath.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.codetaylor.mc.onslaught.modules.onslaught.invasion.sampler.predicate; | ||
|
||
import java.util.function.Predicate; | ||
import net.minecraft.entity.EntityLiving; | ||
import net.minecraft.util.EnumFacing; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
/** Responsible for testing a pillar of blocks for a valid ground spawn location. */ | ||
public class SpawnPredicateBeneath implements Predicate<EntityLiving> { | ||
|
||
private final BlockPos.MutableBlockPos blockPos; | ||
private final int lightMin; | ||
private final int lightMax; | ||
private final int verticalRange; | ||
|
||
public SpawnPredicateBeneath(int lightMin, int lightMax, int verticalRange) { | ||
|
||
super(); | ||
this.blockPos = new BlockPos.MutableBlockPos(); | ||
this.lightMin = lightMin; | ||
this.lightMax = lightMax; | ||
this.verticalRange = verticalRange; | ||
} | ||
|
||
@Override | ||
public boolean test(EntityLiving entity) { | ||
|
||
double verticalMin = Math.max(0, -this.verticalRange + entity.posY); | ||
double verticalMax = Math.min(255, this.verticalRange + entity.posY); | ||
|
||
for (double y = verticalMin; y <= verticalMax; y++) { | ||
entity.setPosition(entity.posX, y, entity.posZ); | ||
|
||
if (this.testEntityPosition(entity)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private boolean testEntityPosition(EntityLiving entity) { | ||
|
||
this.blockPos.setPos(entity.posX, entity.posY, entity.posZ); | ||
|
||
if (!entity.world.isBlockLoaded(this.blockPos)) { | ||
return false; | ||
} | ||
|
||
// Ensure the light level isn't above the max | ||
int light = entity.world.getLightFromNeighbors(this.blockPos); | ||
|
||
if (light < this.lightMin || light > this.lightMax) { | ||
return false; | ||
} | ||
|
||
// Ensure we're testing an air block | ||
if (!entity.world.isAirBlock(this.blockPos)) { | ||
return false; | ||
} | ||
|
||
// Ensure the entity isn't colliding with blocks or fluids | ||
if (!entity.isNotColliding()) { | ||
return false; | ||
} | ||
|
||
// Ensure the block below the entity has a solid top | ||
this.blockPos.move(EnumFacing.DOWN); | ||
|
||
if (this.blockPos.getY() < 0 || this.blockPos.getY() > 255) { | ||
return false; | ||
} | ||
|
||
return entity.world.isSideSolid(this.blockPos, EnumFacing.UP); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,8 @@ public enum EnumSpawnType { | |
*/ | ||
|
||
ground, | ||
air | ||
air, | ||
beneath | ||
} | ||
|
||
public static class Group { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ | |
"type": "air", | ||
"light": [ | ||
0, | ||
14 | ||
15 | ||
], | ||
"rangeXZ": [ | ||
4, | ||
|