Created
March 20, 2012 01:36
-
-
Save pirogoeth/2129684 to your computer and use it in GitHub Desktop.
Attempt to write an algorithm that builds a small bedrock building.
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
package me.maiome.openauth.util; | |
// bukkit imports | |
import org.bukkit.Location; | |
import org.bukkit.World; | |
import org.bukkit.block.Block; | |
import org.bukkit.block.BlockState; | |
// internal imports | |
import me.maiome.openauth.util.ConfigInventory; | |
// java imports | |
import java.util.List; | |
import java.util.ArrayList; | |
import java.util.Iterator; | |
import java.lang.Math; | |
public class LockboxSupport { | |
public final static int area = ConfigInventory.MAIN.getConfig().getInt("actions.lockbox.area", 4); // floor size? | |
public final static boolean bed = ConfigInventory.MAIN.getConfig().getBoolean("actions.lockbox.bed", true); // place a bed? only if area > 4 | |
public final static double length = Math.sqrt(area); | |
private static List<Block> blocks = new ArrayList<Block>(); // this is the list of blocks that will be changed. | |
/* | |
* Data values: | |
* | |
* Bedrock : 07 | |
* Torch : 50 | |
* Wood Door : 64 | |
*/ | |
public static void buildXWall(Location sloc) { | |
World world = sloc.getWorld(); | |
int x_ = loc.getX(), y_ = loc.getY(), z = Location.locToBlock(loc.getZ()); | |
for (int x = Location.locToBlock(loc.getX()); x <= (x + (length + 1)); x++) { | |
for (int y = Location.locToBlock(loc.getY() + 1); y <= (y + 3); y++) { | |
blocks.append(world.getBlockAt(x, y, z)); | |
} | |
} | |
Iterator bxwi = blocks.iterator(); | |
while (bxwi.hasNext()) { | |
((Block) bxwi.next()).setTypeId(7, false); | |
} | |
blocks.clear(); | |
if (new Location(world, x_, y - 3, z_).getBlock().getTypeId() != 7) { | |
buildZWall(new Location(world, x, y - 3, z)); | |
} else { | |
buildFloorAndRoof(new Location(world, x - 1, y - 3, z)); | |
} | |
} | |
public static void buildZWall(Location sloc) { | |
World world = sloc.getWorld(); | |
int x = Location.locToBlock(loc.getX()); | |
for (int z = Location.locToBlock(loc.getZ()); z <= (z + (length + 1)); z++) { | |
for (int y = Location.locToBlock(loc.getY() + 1); y <= (y + 3); y++) { | |
blocks.append(world.getBlockAt(x, y, z)); | |
} | |
} | |
Iterator bzwi = blocks.iterator(); | |
while (bzwi.hasNext()) { | |
((Block) bzwi.next()).setTypeId(7, false); | |
} | |
blocks.clear(); | |
buildXWall(new Location(world, x, y - 3, z)); | |
} | |
public static void buildFloorAndRoof(Location sloc) { | |
World world = sloc.getWorld(); | |
int x = Location.locToBlock(loc.getX()), z = Location.locToBlock(loc.getZ()); | |
if (new Location(x, sloc.getY() + 1, z).getBlock().getTypeId() == 7) { | |
buildFloor(new Location(x + 1, y, z - 1)); | |
return; | |
} | |
for (xi = x; xi <= (x + length); xi++) { | |
for (zi = z; zi <= (z + length); zi++) { | |
blocks.append(world.getBlockAt(xi, y, zi)); | |
blocks.append(world.getBlockAt(xi, y + 3, zi)); | |
} | |
} | |
Iterator bfi = blocks.iterator(); | |
while (bfi.hasNext()) { | |
((Block) bfi.next()).setTypeId(7, false); | |
} | |
blocks.clear(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment