0% found this document useful (0 votes)
16 views3 pages

Message

This Java code defines a procedure to place and break blocks in a sphere around a given position over time. It uses double loops to iterate through blocks in a radius, schedules tasks to place and break blocks with a delay, and schedules a final task to break all blocks after 10 seconds.

Uploaded by

exedrul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

Message

This Java code defines a procedure to place and break blocks in a sphere around a given position over time. It uses double loops to iterate through blocks in a radius, schedules tasks to place and break blocks with a delay, and schedules a final task to break all blocks after 10 seconds.

Uploaded by

exedrul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

package net.mcreator.jujutsufi.

procedures;

import net.minecraftforge.registries.ForgeRegistries;

import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.entity.Entity;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.network.chat.Component;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.CommandSource;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.Level;
import net.minecraft.core.BlockPos;

public class TestprocProcedure {

private static final ScheduledExecutorService scheduler =


Executors.newScheduledThreadPool(1);

private static class BlockPlace implements Runnable {


private final int x;
private final int y;
private final int z;
private final LevelAccessor world;
private final BlockState oldblock;

public BlockPlace(int x, int y, int z, LevelAccessor world, BlockState


oldblock) {
this.x = x;
this.y = y;
this.z = z;
this.world = world;
this.oldblock = oldblock;
}

@Override
public void run() {
if (world instanceof ServerLevel _level)
_level.getServer().getCommands().performPrefixedCommand(new
CommandSourceStack(CommandSource.NULL, new Vec3(x, y, z), Vec2.ZERO, _level, 4, "",
Component.literal(""), _level.getServer(), null).withSuppressedOutput(), "setblock
~ ~ ~ jujutsucraft:jujutsu_barrier");
}
}

private static class BlockBreak implements Runnable {


private final int x;
private final int y;
private final int z;
private final LevelAccessor world;
public BlockBreak(int x, int y, int z, LevelAccessor world) {
this.x = x;
this.y = y;
this.z = z;
this.world = world;
}

@Override
public void run() {
if (world instanceof ServerLevel _level)
_level.getServer().getCommands().performPrefixedCommand(new
CommandSourceStack(CommandSource.NULL, new Vec3(x, y, z), Vec2.ZERO, _level, 4, "",
Component.literal(""), _level.getServer(), null).withSuppressedOutput(), "setblock
~ ~ ~ minecraft:air");
}
}

public static void execute(LevelAccessor world, double x, double y, double z,


Entity entity) {
BlockState oldblock = Blocks.AIR.defaultBlockState();
int radius = 50;
long delay = 25;
for (int loopx = (int)Math.round(x) - radius; loopx <= (int)Math.round(x) +
radius; loopx++) {
for (int loopy = (int)Math.round(y) - radius; loopy <=
(int)Math.round(y) + radius; loopy++) {
for (int loopz = (int)Math.round(z) - radius; loopz <=
(int)Math.round(z) + radius; loopz++) {
double distance = Math.sqrt(Math.pow(loopx - x,
2) + Math.pow(loopy - y, 2) + Math.pow(loopz - z, 2));
oldblock =
(world.getBlockState(BlockPos.containing(loopx, loopy, loopz)));
if (distance <= radius && distance >= radius -
1) {
scheduler.schedule(new BlockPlace(loopx,
loopy, loopz, world, oldblock), delay, TimeUnit.MILLISECONDS);
}
}
}
}
scheduler.schedule(() -> {
for (int loopx = (int)Math.round(x) - radius; loopx <= (int)Math.round(x) +
radius; loopx++) {
for (int loopy = (int)Math.round(y) - radius; loopy <=
(int)Math.round(y) + radius; loopy++) {
for (int loopz = (int)Math.round(z) - radius; loopz <=
(int)Math.round(z) + radius; loopz++) {
double distance = Math.sqrt(Math.pow(loopx - x,
2) + Math.pow(loopy - y, 2) + Math.pow(loopz - z, 2));
if (distance <= radius && distance >= radius -
1) {
scheduler.schedule(new BlockBreak(loopx,
loopy, loopz, world), delay, TimeUnit.MILLISECONDS);
}
}
}
}
}, 10, TimeUnit.SECONDS);
}
}

You might also like