private static void pathto(World world, int i, int j, int k) { List<ChunkCoordinates> blocks = Lists.newLinkedList(); List<ChunkCoordinates> portals = Lists.newLinkedList(); List<ChunkCoordinates> repath = Lists.newLinkedList(); List<ChunkCoordinates> redraw = Lists.newLinkedList(); blocks.add(new ChunkCoordinates(i, j, k)); while ((portals.size() > 0) || (blocks.size() > 0)) { while (blocks.size() > 0) { ChunkCoordinates coords = blocks.remove(0); directPortal(world, coords.posX + 1, coords.posY, coords.posZ, 5, blocks, portals); directPortal(world, coords.posX, coords.posY + 1, coords.posZ, 1, blocks, portals); directPortal(world, coords.posX, coords.posY, coords.posZ + 1, 3, blocks, portals); directPortal(world, coords.posX - 1, coords.posY, coords.posZ, 6, blocks, portals); directPortal(world, coords.posX, coords.posY - 1, coords.posZ, 2, blocks, portals); directPortal(world, coords.posX, coords.posY, coords.posZ - 1, 4, blocks, portals); redraw.add(coords); } if (portals.size() > 0) { ChunkCoordinates coords = portals.remove(0); directPortal(world, coords.posX + 1, coords.posY, coords.posZ, 5, blocks, portals); directPortal(world, coords.posX, coords.posY + 1, coords.posZ, 1, blocks, portals); directPortal(world, coords.posX, coords.posY, coords.posZ + 1, 3, blocks, portals); directPortal(world, coords.posX - 1, coords.posY, coords.posZ, 6, blocks, portals); directPortal(world, coords.posX, coords.posY - 1, coords.posZ, 2, blocks, portals); directPortal(world, coords.posX, coords.posY, coords.posZ - 1, 4, blocks, portals); if (world.getBlock(coords.posX, coords.posY, coords.posZ) == NailedBlocks.portal) { repath.add(coords); } } } while (repath.size() > 0) { ChunkCoordinates coords = repath.remove(0); if (world.getBlock(coords.posX, coords.posY, coords.posZ) == NailedBlocks.portal) { if (!BlockPortal.isValidPortal(world, coords.posX, coords.posY, coords.posZ)) { repathNeighbors(world, coords.posX, coords.posY, coords.posZ); world.setBlock(coords.posX, coords.posY, coords.posZ, Blocks.air, 0, 0); addSurrounding(repath, coords.posX, coords.posY, coords.posZ); } else { redraw.add(coords); } } } for (ChunkCoordinates coords : redraw) { if (world.blockExists(coords.posX, coords.posY, coords.posZ)) { world.markBlockForUpdate(coords.posX, coords.posY, coords.posZ); world.notifyBlocksOfNeighborChange( coords.posX, coords.posY, coords.posZ, world.getBlock(coords.posX, coords.posY, coords.posZ)); } } }
public static void unpath(World world, int i, int j, int k) { List<ChunkCoordinates> blocks = Lists.newLinkedList(); List<ChunkCoordinates> notify = Lists.newLinkedList(); blocks.add(new ChunkCoordinates(i, j, k)); while (blocks.size() > 0) { ChunkCoordinates coords = blocks.remove(0); depolarize(world, coords.posX + 1, coords.posY, coords.posZ, blocks); depolarize(world, coords.posX, coords.posY + 1, coords.posZ, blocks); depolarize(world, coords.posX, coords.posY, coords.posZ + 1, blocks); depolarize(world, coords.posX - 1, coords.posY, coords.posZ, blocks); depolarize(world, coords.posX, coords.posY - 1, coords.posZ, blocks); depolarize(world, coords.posX, coords.posY, coords.posZ - 1, blocks); notify.add(coords); } for (ChunkCoordinates coords : notify) { if (world.blockExists(coords.posX, coords.posY, coords.posZ)) { world.markBlockForUpdate(coords.posX, coords.posY, coords.posZ); world.notifyBlocksOfNeighborChange( coords.posX, coords.posY, coords.posZ, world.getBlock(coords.posX, coords.posY, coords.posZ)); } } }
@Override public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, Block block) { ChunkCoordinates coord = getBase(par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4)); if (par1World.getBlock(coord.posX, coord.posY, coord.posZ) != NailedBlocks.portalCrystal) { this.dropBlockAsItem(par1World, par2, par3, par4, 0, 0); par1World.setBlockToAir(par2, par3, par4); } super.onNeighborBlockChange(par1World, par2, par3, par4, block); }
private static void directPortal( World world, int i, int j, int k, int meta, List<ChunkCoordinates> blocks, List<ChunkCoordinates> portals) { if (isValidLinkPortalBlock(world.getBlock(i, j, k)) == 0) { return; } if (world.getBlockMetadata(i, j, k) != 0) { return; } world.setBlockMetadataWithNotify(i, j, k, meta, 0); if (world.getBlock(i, j, k) == NailedBlocks.portal) { portals.add(new ChunkCoordinates(i, j, k)); } else { blocks.add(new ChunkCoordinates(i, j, k)); } }
private static void depolarize(World world, int i, int j, int k, List<ChunkCoordinates> blocks) { Block block = world.getBlock(i, j, k); if (isValidLinkPortalBlock(block) == 0) { return; } if (world.getBlockMetadata(i, j, k) == 0) { return; } world.setBlockMetadataWithNotify(i, j, k, 0, 0); if ((block == NailedBlocks.portal) && (!BlockPortal.isValidPortal(world, i, j, k))) { world.setBlock(i, j, k, Blocks.air, 0, 2); } blocks.add(new ChunkCoordinates(i, j, k)); }
private static void expandPortal( World world, int i, int j, int k, Collection<ChunkCoordinates> set, Stack<ChunkCoordinates> created) { if (!world.isAirBlock(i, j, k)) { return; } int score = isValidLinkPortalBlock(world.getBlock(i + 1, j, k)) + isValidLinkPortalBlock(world.getBlock(i - 1, j, k)) + isValidLinkPortalBlock(world.getBlock(i, j + 1, k)) + isValidLinkPortalBlock(world.getBlock(i, j - 1, k)) + isValidLinkPortalBlock(world.getBlock(i, j, k + 1)) + isValidLinkPortalBlock(world.getBlock(i, j, k - 1)); if (score > 1) { world.setBlock(i, j, k, NailedBlocks.portal, 0, 0); created.push(new ChunkCoordinates(i, j, k)); addSurrounding(set, i, j, k); } }
@Override public boolean canPlaceBlockOnSide(World world, int x, int y, int z, int side) { if ((side == 0) && (world.getBlock(x, y + 1, z) != NailedBlocks.portalCrystal)) { return false; } else if ((side == 1) && (world.getBlock(x, y - 1, z) != NailedBlocks.portalCrystal)) { return false; } else if ((side == 2) && (world.getBlock(x, y, z + 1) != NailedBlocks.portalCrystal)) { return false; } else if ((side == 3) && (world.getBlock(x, y, z - 1) != NailedBlocks.portalCrystal)) { return false; } else if ((side == 4) && (world.getBlock(x + 1, y, z) != NailedBlocks.portalCrystal)) { return false; } else if ((side == 5) && (world.getBlock(x - 1, y, z) != NailedBlocks.portalCrystal)) { return false; } else { return this.canPlaceBlockAt(world, x, y, z); } }
private static void redirectPortal( World world, TileEntity tileentity, int i, int j, int k, int meta, List<ChunkCoordinates> blocks) { if (isValidLinkPortalBlock(world.getBlock(i, j, k)) == 0) { return; } if (world.getBlockMetadata(i, j, k) == meta) { for (int m = 1; m < 7; m++) { if (m != meta) { world.setBlockMetadataWithNotify(i, j, k, m, 2); TileEntity local = getTileEntity(world, i, j, k); if ((local == tileentity) || ((local != null) && (tileentity == null))) { return; } } } world.setBlockMetadataWithNotify(i, j, k, 0, 2); } }