0

我对编码插件很陌生,但是有没有办法修改代码,所以球体各个方面的粗糙度都是一样的。目前,该代码使 4 面非常光滑,1 面粗糙,1 面半粗糙。我想让球体的所有 6 个面看起来都一样。

public class ExplosionManager {
    public static List<Block> getBlocksInSphere(final Location center, final int radius) {
        final List<Block> ret = new ArrayList<Block>();
        for (int dx = -radius; dx <= radius; ++dx) {
            for (int dy = -radius; dy <= radius; ++dy) {
                for (int dz = -radius; dz <= radius; ++dz) {
                    final double distance2 = dx * dx + dy * dy + dz * dz;
                    if (distance2 <= radius * radius) {
                        final Block block = center.clone().add((double) dx, (double) dy, (double) dz).getBlock();
                        if (!block.getType().isAir() && !block.getType().equals((Object) Material.BEDROCK) && !block.getType().equals((Object) Material.COMMAND_BLOCK) && !block.getType().equals((Object) Material.REPEATING_COMMAND_BLOCK) && !block.getType().equals((Object) Material.CHAIN_COMMAND_BLOCK) && !block.getType().equals((Object) Material.BARRIER) && !block.getType().equals((Object) Material.STRUCTURE_BLOCK) && !block.getType().equals((Object) Material.JIGSAW) && !block.getType().equals((Object) Material.END_PORTAL_FRAME)) {
                            ret.add(block);
                        }
                    }
                }
            }
        }
        return ret;
    }

    public static List<Block> getBlocksWithinSphericalShell(final List<Block> sphere, final Location center, final int innerRadius, int outerRadius, final Random random) {
        final List<Block> ret = new ArrayList<Block>();
        final int startingOuter = outerRadius;
        for (int dx = -outerRadius; dx <= outerRadius; ++dx) {
            for (int dy = -outerRadius; dy <= outerRadius; ++dy) {
                for (int dz = -outerRadius; dz <= outerRadius; ++dz) {
                    final double distance2 = dx * dx + dy * dy + dz * dz;
                    final boolean isWithinShell = distance2 >= innerRadius * innerRadius && distance2 <= outerRadius * outerRadius;
                    if (isWithinShell) {
                        outerRadius = startingOuter - random.nextInt(2);
                        final Block block = center.clone().add((double) dx, (double) dy, (double) dz).getBlock();
                        final boolean isNearOutermostShell = (int) block.getLocation().distance(center) >= outerRadius;
                        if (isNearOutermostShell) {

                        }
                        if (!block.getType().isAir() && !block.getType().equals((Object) Material.BEDROCK) && !block.getType().equals((Object) Material.COMMAND_BLOCK) && !block.getType().equals((Object) Material.REPEATING_COMMAND_BLOCK) && !block.getType().equals((Object) Material.CHAIN_COMMAND_BLOCK) && !block.getType().equals((Object) Material.BARRIER) && !block.getType().equals((Object) Material.STRUCTURE_BLOCK) && !block.getType().equals((Object) Material.JIGSAW) && !block.getType().equals((Object) Material.END_PORTAL_FRAME)) {
                            ret.add(block);
                        }
                    }
                }
            }
        }
        return ret;
    }

    public static List<Block> generateExplosionBlocksSlowest(final Location center, int radius, final Random random, final Particle particle) {
        final List<Block> explosionBlocks = new ArrayList<Block>();
        final int beginner = radius;
        for (int X = -radius; X < radius; ++X) {
            for (int Y = -radius; Y < radius; ++Y) {
                for (int Z = -radius; Z < radius; ++Z) {
                    if (Math.sqrt(X * X + Y * Y + Z * Z) <= radius) {
                        final Block block = center.getWorld().getBlockAt(X + center.getBlockX(), Y + center.getBlockY(), Z + center.getBlockZ());
                        if (generateRequiredChecks(10, random)) {

                        }
                        if (!block.getType().isAir()) {
                            explosionBlocks.add(block);
                            if (random.nextBoolean()) {
                                radius = beginner - random.nextInt(2);
                            }
                        }
                    }
                }
            }
        }
        return explosionBlocks;
    }

    private static void generateExplosionEffect(final Location center, final int radius, final Random random, final int loops) {
        for (int i = 0; i < loops; ++i) {
            final int randomX = random.nextInt(radius);
            final int randomY = random.nextInt(radius);
            final int randomZ = random.nextInt(radius);
            if (random.nextBoolean()) {

            } else {

            }
        }
    }

    public static List<Block> generateExplosionBlocks(final Location center, int radius, final Random random, final Particle particle) {
        final List<Block> explosionBlocks = new ArrayList<Block>();
        final int beginner = radius;
        for (int X = -radius; X < radius; ++X) {
            for (int Y = -radius; Y < radius; ++Y) {
                for (int Z = -radius; Z < radius; ++Z) {
                    if (Math.sqrt(X * X + Y * Y + Z * Z) <= radius) {
                        final Block block = center.getWorld().getBlockAt(X + center.getBlockX(), Y + center.getBlockY(), Z + center.getBlockZ());
                        if (!block.getType().isAir()) {
                            explosionBlocks.add(block);
                            if (random.nextBoolean()) {
                                radius = beginner - random.nextInt(2);
                            }
                        }
                    }
                }
            }
        }
        return explosionBlocks;
    }

    public static void animateExplosionOptimized(final int radius, final Location center, final Random random, final Player player) {
        Bukkit.broadcastMessage("Animating explosions: optimized way");
        final List<Block> sphereBlocks = getBlocksInSphere(center, radius);
        final int RADIUS_STEP = 1;
        final long TICKS_BETWEEN_STEPS = 1L;
        for (int i = 0; i < radius - 1; ++i) {
            final int currentRadius = i;
            new BukkitRunnable() {
                public void run() {
                    final List<Block> shellBlocks = ExplosionManager.getBlocksWithinSphericalShell(sphereBlocks, center, currentRadius, currentRadius + 2, random);
                    ItemStack storedItemStack = null;
                    for (final Block block : shellBlocks) {
                        final boolean isNearOutermostShell = (int)block.getLocation().distance(center) >= radius - 1 - 2;
                        if (!isNearOutermostShell) {
                            block.setType(Material.AIR, false);
                        }
                        else {
                            try {
                                final Collection<ItemStack> dropItems = (Collection<ItemStack>)block.getDrops();
                                for (final ItemStack itemStack : dropItems) {
                                    if (itemStack != null) {
                                        if (storedItemStack == null) {
                                            storedItemStack = itemStack;
                                        }
                                        else if (storedItemStack.getType().equals((Object)itemStack.getType())) {
                                            storedItemStack.setAmount(itemStack.getAmount() + storedItemStack.getAmount());
                                            if (storedItemStack.getAmount() < 32) {
                                                continue;
                                            }
                                            block.getWorld().dropItemNaturally(block.getLocation(), storedItemStack);
                                        }
                                        else {
                                            if (storedItemStack.getType().isAir()) {
                                                storedItemStack.setType(itemStack.getType());
                                            }
                                            block.getWorld().dropItemNaturally(block.getLocation(), storedItemStack);
                                            storedItemStack = itemStack;
                                        }
                                    }
                                }
                                block.setType(Material.AIR, true);
                            }
                            catch (IllegalArgumentException ex) {}
                        }
                    }
                }
            }.runTaskLater((Plugin)CustomTNT.plugin, i * 0L);
        }
    }

    public static void animateExplosion(final int radius, final Location center, final Random random, final Particle particle, final int dropCheckCount) {
        int starting;
        int loops;
        for (starting = radius, loops = 0; starting > 2; starting -= 2, ++loops) {}
        for (int i = 0; i < loops; ++i) {
            final int amount = i + 1;
            new BukkitRunnable() {
                public void run() {
                    final List<Block> explosionBlocks = ExplosionManager.generateExplosionBlocksSlowest(center, amount * 2, random, particle);
                    for (final Block block : explosionBlocks) {
                        if (ExplosionManager.generateRequiredChecks(dropCheckCount, random)) {
                            block.breakNaturally(new ItemStack(Material.DIAMOND_PICKAXE));
                        }
                        else {
                            block.setType(Material.AIR);
                        }
                        block.setType(Material.AIR);
                    }
                }
            }.runTaskLater((Plugin)CustomTNT.plugin, i * 0L);
        }
    }

    public static boolean generateRequiredChecks(final int checks, final Random random) {
        int correct = 0;
        for (int i = 0; i < checks; ++i) {
            if (random.nextBoolean()) {
                ++correct;
            }
        }
        return correct == checks;
    }
}

代码中的当前球体

我希望它看起来像我的球体的目标

4

0 回答 0