Skip to content

Commit

Permalink
Make <cu@cuboid.get_spawnable_blocks> ignore midair locations.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcernat committed Sep 18, 2013
1 parent d15a8c7 commit 70b99ab
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/main/java/net/aufdemrand/denizen/objects/dCuboid.java
Expand Up @@ -13,6 +13,7 @@
import net.aufdemrand.denizen.utilities.Utilities;
import net.aufdemrand.denizen.utilities.debugging.dB;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
Expand Down Expand Up @@ -282,8 +283,8 @@ public dList getBlocks() {
dList list = new dList();

for (int x = 0; x != x_distance + 1; x++) {
for (int y = 0; y != y_distance + 1; y++) {
for (int z = 0; z != z_distance + 1; z++) {
for (int z = 0; z != z_distance + 1; z++) {
for (int y = 0; y != y_distance + 1; y++) {
loc = new dLocation(loc_1.clone()
.add(x, y, z));
if (!filter.isEmpty()) {
Expand All @@ -303,27 +304,38 @@ public dList getBlocks() {

/**
* Returns a dList of dLocations with 2 vertical blocks of air
* that are safe for players and similar entities to spawn in
* that are safe for players and similar entities to spawn in,
* but ignoring blocks in midair
*
* @return The dList
*/

public dList getSpawnableBlocks() {
dLocation loc;
dList list = new dList();
boolean midair;

for (int x = 0; x != x_distance + 1; x++) {
for (int y = 0; y != y_distance; y++) {
for (int z = 0; z != z_distance + 1; z++) {
for (int z = 0; z != z_distance + 1; z++) {
midair = false;
for (int y = 0; y != y_distance; y++) {

loc = new dLocation(loc_1.clone()
.add(x, y, z));

if (loc.getBlock().getType().equals(Material.AIR)
&& loc.clone().add(0, 1, 0).getBlock().getType().equals(Material.AIR)) {

// Get the center of the block, so the entity won't suffocate
// inside the edges for a couple of seconds
loc.add(0.5, 0, 0.5);
list.add(loc.identify());
if (!midair) {
loc.add(0.5, 0, 0.5);
list.add(loc.identify());
}
midair = true;
}
else {
midair = false;
}
}
}
Expand Down

0 comments on commit 70b99ab

Please sign in to comment.