X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fcom%2Firtimaled%2Fbbor%2Fclient%2Fproviders%2FSpawningSphereProvider.java;h=056b18b3de7695c90ab400e3c88f4e4806c711c4;hb=4a3c58de58525061c3c07a6ab4b9ca5518f03ecb;hp=02a452a636e377bfff94eeb3d6ccec01ce1c9b00;hpb=eff4a632a409391647900f6d0579b4d92c15304b;p=BoundingBoxOutlineReloaded.git diff --git a/src/main/java/com/irtimaled/bbor/client/providers/SpawningSphereProvider.java b/src/main/java/com/irtimaled/bbor/client/providers/SpawningSphereProvider.java index 02a452a..056b18b 100644 --- a/src/main/java/com/irtimaled/bbor/client/providers/SpawningSphereProvider.java +++ b/src/main/java/com/irtimaled/bbor/client/providers/SpawningSphereProvider.java @@ -1,39 +1,39 @@ package com.irtimaled.bbor.client.providers; import com.irtimaled.bbor.client.Player; +import com.irtimaled.bbor.client.config.BoundingBoxTypeHelper; +import com.irtimaled.bbor.client.config.ConfigManager; +import com.irtimaled.bbor.client.interop.BlockProcessor; import com.irtimaled.bbor.client.interop.SpawningSphereHelper; import com.irtimaled.bbor.client.models.BoundingBoxSpawningSphere; -import com.irtimaled.bbor.client.models.Point; +import com.irtimaled.bbor.common.BoundingBoxType; import com.irtimaled.bbor.common.MathHelper; -import com.irtimaled.bbor.common.models.Coords; +import com.irtimaled.bbor.common.models.Point; +import net.minecraft.client.Minecraft; + +import java.util.HashSet; +import java.util.Set; public class SpawningSphereProvider implements IBoundingBoxProvider { + public static final Minecraft minecraft = Minecraft.getInstance(); + private static Long lastGameTime = null; + + private static Set lastBoundingBox = null; private static BoundingBoxSpawningSphere spawningSphere; private static Integer dimensionId; - public static void setSphere(double x, double y, double z) { - Coords coords = new Coords(x, y, z); - double xOffset = snapToNearestHalf(x -coords.getX()); - double yOffset = y- coords.getY(); - double zOffset = snapToNearestHalf(z-coords.getZ()); - - if(spawningSphere != null && spawningSphere.isCenter(coords, xOffset, yOffset, zOffset)) { - return; - } + public static void setSphere(Point point) { + if (spawningSphere != null && spawningSphere.getPoint().equals(point)) return; clear(); dimensionId = Player.getDimensionId(); - spawningSphere = new BoundingBoxSpawningSphere(coords, xOffset, yOffset, zOffset); - } - - private static double snapToNearestHalf(double value) { - int floor = MathHelper.floor(value * 4.0); - if(floor % 2 == 1) floor += 1; - return floor / 4.0; + spawningSphere = new BoundingBoxSpawningSphere(point); + lastBoundingBox = null; } public static boolean clear() { - if(spawningSphere != null) { + if (spawningSphere != null) { + lastBoundingBox = null; spawningSphere = null; dimensionId = null; return true; @@ -41,30 +41,53 @@ public class SpawningSphereProvider implements IBoundingBoxProvider true); + static boolean playerInsideSphere() { + return hasSpawningSphereInDimension(Player.getDimensionId()) && spawningSphere.isWithinSphere(Player.getPoint()); + } + + public static boolean hasSpawningSphereInDimension(int dimensionId) { + return spawningSphere != null && SpawningSphereProvider.dimensionId == dimensionId; } - private static final Iterable iterable = Iterators.singleton(() -> spawningSphere); + public static void setSpawnableSpacesCount(int count) { + if (spawningSphere != null) { + spawningSphere.setSpawnableCount(count); + } + } + + @Override + public boolean canProvide(int dimensionId) { + return hasSpawningSphereInDimension(dimensionId) && BoundingBoxTypeHelper.shouldRender(BoundingBoxType.AFKSphere); + } + @Override public Iterable get(int dimensionId) { - if(spawningSphere == null || SpawningSphereProvider.dimensionId != dimensionId) { - return Iterators.empty(); + long gameTime = minecraft.world.getGameTime(); + if (lastBoundingBox == null || (!((Long) gameTime).equals(lastGameTime) && gameTime % 2L == 0L)) { + lastGameTime = gameTime; + lastBoundingBox = getSpawningSphere(); + } + return lastBoundingBox; + } + + private Set getSpawningSphere() { + spawningSphere.getBlocks().clear(); + if (ConfigManager.renderAFKSpawnableBlocks.get()) { + int width = MathHelper.floor(Math.pow(2, 1 + ConfigManager.spawnableBlocksRenderWidth.get())); + int height = MathHelper.floor(Math.pow(2, ConfigManager.spawnableBlocksRenderHeight.get())); + + SpawningSphereHelper.findSpawnableSpaces(spawningSphere.getPoint(), Player.getCoords(), width, height, spawningSphere.getBlocks()::add); } - return iterable; + Set boundingBoxes = new HashSet<>(); + boundingBoxes.add(spawningSphere); + return boundingBoxes; } }