import com.irtimaled.bbor.common.MathHelper;
import com.irtimaled.bbor.common.models.AbstractBoundingBox;
import com.irtimaled.bbor.common.models.BoundingBoxCuboid;
+import com.irtimaled.bbor.common.models.BoundingBoxSphere;
import com.irtimaled.bbor.common.models.BoundingBoxVillage;
import org.lwjgl.opengl.GL11;
registerRenderer(BoundingBoxConduit.class, new ConduitRenderer());
registerRenderer(BoundingBoxSpawnableBlocks.class, new SpawnableBlocksRenderer());
registerRenderer(BoundingBoxLine.class, new LineRenderer());
+ registerRenderer(BoundingBoxSphere.class, new SphereRenderer());
registerProvider(new SlimeChunkProvider());
registerProvider(new WorldSpawnProvider());
registerProvider(new ConduitProvider());
registerProvider(new SpawnableBlocksProvider());
registerProvider(new CustomLineProvider());
+ registerProvider(new CustomSphereProvider());
}
public static <T extends AbstractBoundingBox> void registerProvider(IBoundingBoxProvider<T> provider) {
import com.irtimaled.bbor.client.providers.CustomBeaconProvider;
import com.irtimaled.bbor.client.providers.CustomBoxProvider;
import com.irtimaled.bbor.client.providers.CustomLineProvider;
+import com.irtimaled.bbor.client.providers.CustomSphereProvider;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.command.Commands;
private static final String BOX = "box";
private static final String BEACON = "beacon";
private static final String LINE = "line";
+ private static final String SPHERE = "sphere";
public static void register(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
LiteralArgumentBuilder command = Commands.literal(COMMAND)
.then(BoxCommandBuilder.build(BOX))
.then(BeaconCommandBuilder.build(BEACON))
.then(LineCommandBuilder.build(LINE))
+ .then(SphereCommandBuilder.build(SPHERE))
.then(Commands.literal(ArgumentNames.CLEAR)
.executes(context -> {
CustomBoxProvider.clear();
CustomBeaconProvider.clear();
CustomLineProvider.clear();
+ CustomSphereProvider.clear();
CommandHelper.feedback(context, "bbor.commands.custom.cleared.all");
return 0;
--- /dev/null
+package com.irtimaled.bbor.client.commands;
+
+import com.irtimaled.bbor.client.providers.CustomSphereProvider;
+import com.irtimaled.bbor.common.models.Point;
+import com.mojang.brigadier.builder.LiteralArgumentBuilder;
+import com.mojang.brigadier.context.CommandContext;
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
+import net.minecraft.command.CommandSource;
+import net.minecraft.command.Commands;
+
+class SphereCommandBuilder {
+ public static final String RADIUS = "radius";
+
+ static LiteralArgumentBuilder<CommandSource> build(String command) {
+ return Commands.literal(command)
+ .then(Commands.literal(ArgumentNames.ADD)
+ .then(Commands.argument(ArgumentNames.POS, Arguments.point())
+ .then(Commands.argument(RADIUS, Arguments.integer())
+ .executes(SphereCommandBuilder::addSphere)))
+ .then(Commands.argument(RADIUS, Arguments.integer())
+ .executes(SphereCommandBuilder::addSphere)))
+ .then(Commands.literal(ArgumentNames.CLEAR)
+ .executes(context -> {
+ CustomSphereProvider.clear();
+
+ CommandHelper.feedback(context, "bbor.commands.sphere.cleared.all");
+ return 0;
+ })
+ .then(Commands.argument(ArgumentNames.FROM, Arguments.coords())
+ .then(Commands.argument(ArgumentNames.TO, Arguments.coords())
+ .executes(context -> {
+ Point pos = Arguments.getPoint(context, ArgumentNames.POS).snapXZ(0.5d);
+ boolean removed = CustomSphereProvider.remove(pos);
+
+ String format = removed ? "bbor.commands.sphere.cleared" : "bbor.commands.sphere.notFound";
+ CommandHelper.feedback(context, format,
+ pos.getX(), pos.getY(), pos.getZ());
+ return 0;
+ }))));
+ }
+
+ private static int addSphere(CommandContext<CommandSource> context) throws CommandSyntaxException {
+ Point pos = Arguments.getPoint(context, ArgumentNames.POS).snapXZ(0.5d);
+ int radius = Arguments.getInteger(context, RADIUS);
+ CustomSphereProvider.add(pos, radius);
+
+ CommandHelper.feedback(context, "bbor.commands.sphere.added",
+ pos.getX(), pos.getY(), pos.getZ(), radius);
+ return 0;
+ }
+}
--- /dev/null
+package com.irtimaled.bbor.client.providers;
+
+import com.irtimaled.bbor.client.Player;
+import com.irtimaled.bbor.common.BoundingBoxType;
+import com.irtimaled.bbor.common.models.BoundingBoxSphere;
+import com.irtimaled.bbor.common.models.Point;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class CustomSphereProvider implements IBoundingBoxProvider<BoundingBoxSphere> {
+ private static final Map<Integer, Map<Integer, BoundingBoxSphere>> dimensionCache = new HashMap<>();
+
+ private static Map<Integer, BoundingBoxSphere> getCache(int dimensionId) {
+ return dimensionCache.computeIfAbsent(dimensionId, i -> new ConcurrentHashMap<>());
+ }
+
+ public static void add(Point center, double radius) {
+ int dimensionId = Player.getDimensionId();
+ int cacheKey = center.hashCode();
+ BoundingBoxSphere sphere = new BoundingBoxSphere(center, radius, BoundingBoxType.Custom);
+ getCache(dimensionId).put(cacheKey, sphere);
+ }
+
+ public static boolean remove(Point center) {
+ int dimensionId = Player.getDimensionId();
+ int cacheKey = center.hashCode();
+ return getCache(dimensionId).remove(cacheKey) != null;
+ }
+
+ public static void clear() {
+ dimensionCache.values().forEach(Map::clear);
+ }
+
+ public Iterable<BoundingBoxSphere> get(int dimensionId) {
+ return getCache(dimensionId).values();
+ }
+}
--- /dev/null
+package com.irtimaled.bbor.client.renderers;
+
+import com.irtimaled.bbor.common.models.BoundingBoxSphere;
+import com.irtimaled.bbor.common.models.Point;
+
+public class SphereRenderer extends AbstractRenderer<BoundingBoxSphere> {
+ @Override
+ public void render(BoundingBoxSphere boundingBox) {
+ Point point = boundingBox.getPoint();
+ double radius = boundingBox.getRadius();
+ renderSphere(point, radius, boundingBox.getColor(), 5, 5);
+ }
+}
private final double maxZ;
private final Point point;
- protected BoundingBoxSphere(Point point, double radius, BoundingBoxType type) {
+ public BoundingBoxSphere(Point point, double radius, BoundingBoxType type) {
super(type);
this.radius = radius;
this.point = point;
"bbor.commands.line.cleared.all": "Line cleared with start [x=%d, y=%d, z=%d] and end [x=%d, y=%d, z=%d]",
"bbor.commands.line.notFound": "No line found with start [x=%d, y=%d, z=%d] and end [x=%d, y=%d, z=%d]",
+ "bbor.commands.sphere.added": "Sphere added with center [x=%d, y=%d, z=%d] and radius %d",
+ "bbor.commands.sphere.cleared": "All spheres cleared",
+ "bbor.commands.sphere.cleared.all": "Sphere cleared with center [x=%d, y=%d, z=%d]",
+ "bbor.commands.sphere.notFound": "No sphere found with center [x=%d, y=%d, z=%d]",
+
"bbor.commands.spawningSphere.set": "Spawning sphere set",
"bbor.commands.spawningSphere.notSet": "No spawning sphere set",
"bbor.commands.spawningSphere.cleared": "Spawning sphere cleared",