Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.logging.Level;
- public class Craft
- {
- public static ArrayList<Craft> craftList = new ArrayList<Craft>();
- CraftType type;
- String name;
- short[][][] matrix;
- ArrayList<Craft.DataBlock> dataBlocks;
- ArrayList<Craft.CraftComplexBlock> complexBlocks;
- int sizeX = 0;
- int sizeZ = 0;
- int sizeY = 0;
- int posX;
- int posY;
- int posZ;
- int blockCount = 0;
- int flyBlockCount = 0;
- int maxBlocks;
- int waterLevel = -1;
- int newWaterLevel = -1;
- short waterType = 0;
- int minX = 0;
- int maxX = 0;
- int minY = 0;
- int maxY = 0;
- int minZ = 0;
- int maxZ = 0;
- static Player player;
- int speed = 1;
- long lastMove = System.currentTimeMillis();
- boolean haveControl = true;
- boolean isOnBoard = true;
- String customName = null;
- boolean blockPlaced = false;
- Craft(CraftType type, Player player, String customName)
- {
- this.type = type;
- name = type.name;
- this.customName = customName;
- Craft.player = player;
- }
- public static Craft getCraft(Player player)
- {
- if (craftList.isEmpty()) return null;
- for (Craft craft : craftList) {
- if (Craft.player.getName().equalsIgnoreCase(player.getName())) {
- return craft;
- }
- }
- return null;
- }
- public static Craft getCraft(int x, int y, int z)
- {
- if (craftList.isEmpty()) return null;
- for (Craft craft : craftList) {
- if (craft.isIn(x, y, z)) {
- return craft;
- }
- }
- return null;
- }
- public void addBlock(Block block)
- {
- int x = block.getX() - posX;
- int y = block.getY() - posY;
- int z = block.getZ() - posZ;
- if (((x < sizeX - 1) && (!isFree(matrix[(x + 1)][y][z]))) || ((x > 0) && (!isFree(matrix[(x - 1)][y][z]))) || ((y < sizeY - 1) && (!isFree(matrix[x][(y + 1)][z]))) || ((y > 0) && (!isFree(matrix[x][(y - 1)][z]))) || ((z < sizeZ - 1) && (!isFree(matrix[x][y][(z + 1)]))) || ((z > 0) && (!isFree(matrix[x][y][(z - 1)]))))
- {
- short blockId = (short)block.getType();
- if (blockId == 331) {
- blockId = 55;
- } else if (blockId == 323) {
- blockId = 68;
- } else if (blockId == 324) {
- blockId = 64;
- matrix[x][(y + 1)][z] = blockId;
- dataBlocks.add(new Craft.DataBlock(x, y + 1, z, block.getData() + 8));
- blockCount += 1;
- }
- else if (blockId == 330) {
- blockId = 71;
- matrix[x][(y + 1)][z] = blockId;
- dataBlocks.add(new Craft.DataBlock(x, y + 1, z, block.getData() + 8));
- blockCount += 1;
- }
- else if (blockId == 338) {
- blockId = 83;
- } else if (blockId >= 256) {
- return;
- }
- matrix[x][y][z] = blockId;
- if (BlocksInfo.isDataBlock(blockId)) {
- dataBlocks.add(new Craft.DataBlock(x, y, z, block.getData()));
- }
- blockCount += 1;
- }
- }
- public boolean isIn(int x, int y, int z)
- {
- return (x >= posX) && (x < posX + sizeX) && (y >= posY) && (y < posY + sizeY) && (z >= posZ) && (z < posZ + sizeZ);
- }
- static void addCraft(Craft craft) {
- craftList.add(craft);
- }
- static void removeCraft(Craft craft) {
- craftList.remove(craft);
- }
- private boolean canGoThrough(int blockId, int data)
- {
- if ((blockId == 0) || ((blockId >= 8) && (blockId <= 11) && (data != 0))) return true;
- if ((!type.canNavigate) && (!type.canDive)) return false;
- if (((blockId == 8) || (blockId == 9)) &&
- (waterType == 8)) return true;
- if (((blockId == 10) || (blockId == 11)) &&
- (waterType == 10)) return true;
- return (blockId == 79) && (type.iceBreaker) &&
- (waterType == 8);
- }
- private static boolean isFree(int blockId)
- {
- return (blockId == 0) || (blockId == -1);
- }
- @SuppressWarnings("unused")
- private static boolean isAirOrWater(int blockId)
- {
- return (blockId == 0) || ((blockId >= 8) && (blockId <= 11));
- }
- public boolean isOnCraft(Player player, boolean precise)
- {
- int x = (int)Math.floor(player.getX());
- int y = (int)Math.floor(player.getY());
- int z = (int)Math.floor(player.getZ());
- if (isIn(x, y - 1, z))
- {
- if (!precise) return true;
- if (matrix[(x - posX)][(y - posY - 1)][(z - posZ)] != -1) {
- return true;
- }
- }
- return false;
- }
- public static void setBlock(int id, int x, int y, int z)
- {
- if ((y < 0) || (y > 127) || (id < 0) || (id > 255)) {
- MoveCraft.log.log(Level.SEVERE, "Invalid setBlock : id=" + id + " x=" + x + " y=" + y + " z=" + z);
- return;
- }
- player.getWorld().setBlockAt(id, x, y, z);
- }
- private boolean isCraftBlock(int x, int y, int z)
- {
- if ((x >= 0) && (y >= 0) && (z >= 0) && (x < sizeX) && (y < sizeY) && (z < sizeZ))
- {
- return matrix[x][y][z] != -1;
- }
- return false;
- }
- public boolean canMove(int dx, int dy, int dz)
- {
- dx = speed * dx;
- dz = speed * dz;
- if (Math.abs(speed * dy) > 1) {
- dy = speed * dy / 2;
- if (Math.abs(dy) == 0) dy = (int)Math.signum(dy);
- }
- if ((posY + dy < 0) || (posY + sizeY + dy > 128)) {
- return false;
- }
- if (isOnCraft(player, true))
- {
- int X = (int)Math.floor(player.getX()) + dx;
- int Y = (int)Math.floor(player.getY()) + dy;
- int Z = (int)Math.floor(player.getZ()) + dz;
- if (((!isCraftBlock(X - posX, Y - posY, Z - posZ)) && (!canGoThrough(player.getWorld().getBlockIdAt(X, Y, Z), 0))) || ((!isCraftBlock(X - posX, Y + 1 - posY, Z - posZ)) && (!canGoThrough(player.getWorld().getBlockIdAt(X, Y + 1, Z), 0))))
- {
- return false;
- }
- }
- newWaterLevel = waterLevel;
- for (int x = 0; x < sizeX; x++) {
- for (int z = 0; z < sizeZ; z++) {
- for (int y = 0; y < sizeY; y++)
- {
- if ((isFree(matrix[x][y][z])) || (isCraftBlock(x + dx, y + dy, z + dz))) {
- continue;
- }
- int blockId = player.getWorld().getBlockIdAt(posX + x + dx, posY + y + dy, posZ + z + dz);
- int blockData = player.getWorld().getBlockData(posX + x + dx, posY + y + dy, posZ + z + dz);
- if ((dy < 0) && (blockId >= 8) && (blockId <= 11))
- {
- if (y > newWaterLevel) {
- newWaterLevel = y;
- }
- }
- else if ((dy > 0) && (blockId == 0))
- {
- if (y - 1 < newWaterLevel) {
- newWaterLevel = (y - 1);
- }
- }
- if (!canGoThrough(blockId, blockData))
- {
- return false;
- }
- }
- }
- }
- return true;
- }
- public void move(int dx, int dy, int dz)
- {
- dx = speed * dx;
- dz = speed * dz;
- if (Math.abs(speed * dy) > 1) {
- dy = speed * dy / 2;
- if (Math.abs(dy) == 0) dy = (int)Math.signum(dy);
- }
- for (int x = 0; x < sizeX; x++) {
- for (int y = 0; y < sizeY; y++) {
- for (int z = 0; z < sizeZ; z++) {
- int craftBlockId = matrix[x][y][z];
- if ((craftBlockId == -1) || (craftBlockId == 0) || ((craftBlockId >= 8) && (craftBlockId <= 11)))
- continue;
- int blockId = player.getWorld().getBlockIdAt(posX + x, posY + y, posZ + z);
- if ((craftBlockId == 46) && (type.bomber)) {
- continue;
- }
- if ((blockId == 0) || ((blockId >= 8) && (blockId <= 11))) {
- if ((waterType != 0) && (y <= waterLevel))
- matrix[x][y][z] = 0;
- else {
- matrix[x][y][z] = -1;
- }
- blockCount -= 1;
- }
- }
- }
- }
- for (Craft.CraftComplexBlock complexBlock : complexBlocks)
- {
- complexBlock.data = player.getWorld().getComplexBlock(posX + complexBlock.x, posY + complexBlock.y, posZ + complexBlock.z);
- }
- for (int x = 0; x < sizeX; x++) {
- for (int z = 0; z < sizeZ; z++) {
- for (int y = 0; y < sizeY; y++)
- {
- short blockId = matrix[x][y][z];
- if (!BlocksInfo.needsSupport(blockId))
- {
- continue;
- }
- if (((blockId == 64) || (blockId == 71)) &&
- (player.getWorld().getBlockData(posX + x, posY + y, posZ + z) >= 8))
- {
- continue;
- }
- setBlock(0, posX + x, posY + y, posZ + z);
- }
- }
- }
- for (int x = 0; x < sizeX; x++) {
- for (int z = 0; z < sizeZ; z++) {
- for (int y = 0; y < sizeY; y++)
- {
- short blockId = matrix[x][y][z];
- if (blockId == -1) {
- continue;
- }
- if ((x - dx >= 0) && (y - dy >= 0) && (z - dz >= 0) && (x - dx < sizeX) && (y - dy < sizeY) && (z - dz < sizeZ))
- {
- if ((matrix[(x - dx)][(y - dy)][(z - dz)] == -1) || (BlocksInfo.needsSupport(matrix[(x - dx)][(y - dy)][(z - dz)]))) {
- if ((y > waterLevel) || ((!type.canNavigate) && (!type.canDive)))
- setBlock(0, posX + x, posY + y, posZ + z);
- else {
- setBlock(waterType, posX + x, posY + y, posZ + z);
- }
- }
- }
- else if ((y > waterLevel) || ((!type.canNavigate) && (!type.canDive)))
- setBlock(0, posX + x, posY + y, posZ + z);
- else {
- setBlock(waterType, posX + x, posY + y, posZ + z);
- }
- if (BlocksInfo.needsSupport(blockId)) {
- continue;
- }
- if ((x + dx >= 0) && (y + dy >= 0) && (z + dz >= 0) && (x + dx < sizeX) && (y + dy < sizeY) && (z + dz < sizeZ)) {
- if (matrix[x][y][z] != matrix[(x + dx)][(y + dy)][(z + dz)]) {
- setBlock(blockId, posX + dx + x, posY + dy + y, posZ + dz + z);
- }
- }
- else
- {
- setBlock(blockId, posX + dx + x, posY + dy + y, posZ + dz + z);
- }
- }
- }
- }
- Block block = new Block();
- for (Craft.DataBlock dataBlock : dataBlocks)
- {
- if (BlocksInfo.needsSupport(matrix[dataBlock.x][dataBlock.y][dataBlock.z])) {
- block.setX(posX + dx + dataBlock.x);
- block.setY(posY + dy + dataBlock.y);
- block.setZ(posZ + dz + dataBlock.z);
- block.setType(matrix[dataBlock.x][dataBlock.y][dataBlock.z]);
- block.setData(dataBlock.data);
- block.update();
- }
- else
- {
- block.getWorld().setBlockData(posX + dx + dataBlock.x, posY + dy + dataBlock.y, posZ + dz + dataBlock.z, dataBlock.data);
- }
- }
- for (int x = 0; x < sizeX; x++) {
- for (int z = 0; z < sizeZ; z++) {
- for (int y = 0; y < sizeY; y++)
- {
- short blockId = matrix[x][y][z];
- if ((!BlocksInfo.needsSupport(blockId)) || (BlocksInfo.isDataBlock(blockId)))
- continue;
- setBlock(blockId, posX + dx + x, posY + dy + y, posZ + dz + z);
- }
- }
- }
- for (Craft.CraftComplexBlock complexBlock : complexBlocks)
- {
- if ((complexBlock.data instanceof Sign))
- {
- Sign sign = (Sign)block.getWorld().getComplexBlock(posX + dx + complexBlock.x, posY + dy + complexBlock.y, posZ + dz + complexBlock.z);
- sign.setText(0, ((Sign)(Sign)complexBlock.data).getText(0));
- sign.setText(1, ((Sign)(Sign)complexBlock.data).getText(1));
- sign.setText(2, ((Sign)(Sign)complexBlock.data).getText(2));
- sign.setText(3, ((Sign)(Sign)complexBlock.data).getText(3));
- sign.update();
- }
- }
- for (Player p : etc.getServer().getPlayerList()) {
- if ((p.getX() >= posX) && (p.getX() < posX + sizeX) && (p.getY() >= posY) && (p.getY() <= posY + sizeY) && (p.getZ() >= posZ) && (p.getZ() < posZ + sizeZ)) {
- p.teleportTo(p.getX() + dx, p.getY() + dy, p.getZ() + dz, p.getRotation(), p.getPitch());
- }
- }
- posX += dx;
- posY += dy;
- posZ += dz;
- minX = posX;
- minY = posY;
- minZ = posZ;
- maxX = (posX + sizeX - 1);
- maxY = (posY + sizeY - 1);
- maxZ = (posZ + sizeZ - 1);
- if ((waterLevel == sizeY - 1) && (newWaterLevel < waterLevel))
- {
- waterLevel = newWaterLevel;
- }
- else if ((waterLevel <= -1) && (newWaterLevel > waterLevel))
- {
- waterLevel = newWaterLevel;
- } else if ((waterLevel >= 0) && (waterLevel < sizeY - 1))
- {
- waterLevel -= dy;
- }
- lastMove = System.currentTimeMillis();
- }
- public void setSpeed(int speed)
- {
- if (speed < 1)
- this.speed = speed;
- else if (speed > type.maxSpeed)
- speed = type.maxSpeed;
- else
- this.speed = speed;
- }
- public int getSpeed() {
- return speed;
- }
- public static class CraftComplexBlock
- {
- int x;
- int y;
- int z;
- ComplexBlock data;
- CraftComplexBlock(int x, int y, int z, ComplexBlock data)
- {
- this.x = x;
- this.y = y;
- this.z = z;
- this.data = data;
- }
- }
- public static class DataBlock
- {
- int x;
- int y;
- int z;
- int data;
- DataBlock(int x, int y, int z, int data)
- {
- this.x = x;
- this.y = y;
- this.z = z;
- this.data = data;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment