]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/commitdiff
Change spawning sphere blocks logic
authorIrtimaled <irtimaled@gmail.com>
Sun, 10 May 2020 17:21:22 +0000 (10:21 -0700)
committerIrtimaled <irtimaled@gmail.com>
Mon, 18 May 2020 00:31:27 +0000 (17:31 -0700)
src/main/java/com/irtimaled/bbor/client/gui/SettingsScreen.java
src/main/java/com/irtimaled/bbor/client/interop/SpawningSphereHelper.java
src/main/java/com/irtimaled/bbor/client/models/BoundingBoxSpawningSphere.java
src/main/java/com/irtimaled/bbor/client/providers/SpawningSphereProvider.java
src/main/java/com/irtimaled/bbor/client/renderers/SpawningSphereRenderer.java
src/main/resources/assets/bbor/lang/en_us.json

index d336685c0ef11ea24b9b72d1eb70eed1edabf4b6..9a05b5d6721440e36e515c957b107bbd7058e560 100644 (file)
@@ -81,11 +81,7 @@ public class SettingsScreen extends ListScreen {
                                 .addDisplayValue(3, "32"))
                 .section(I18n.format("bbor.features.spawningSpheres"),
                         (x, width) -> new BoundingBoxTypeButton(width, I18n.format("bbor.features.spawningSpheres"), BoundingBoxType.AFKSphere),
-                        (x, width) -> new BoolSettingButton(width, I18n.format("bbor.features.spawningSpheres.spawnableBlocks"), ConfigManager.renderAFKSpawnableBlocks),
-                        (x, width) -> new IntSettingSlider(width, 1, 3, "bbor.options.distance", ConfigManager.afkSpawnableBlocksRenderDistance)
-                                .addDisplayValue(1, I18n.format("bbor.options.distance.nearest"))
-                                .addDisplayValue(2, I18n.format("bbor.options.distance.nearer"))
-                                .addDisplayValue(3, I18n.format("bbor.options.distance.normal")))
+                        (x, width) -> new BoolSettingButton(width, I18n.format("bbor.features.spawnableBlocks"), ConfigManager.renderAFKSpawnableBlocks))
                 .section(I18n.format("bbor.tabs.structures"),
                         (x, width) -> new BoundingBoxTypeButton(width, I18n.format("bbor.structures.desertTemples"), BoundingBoxType.DesertTemple),
                         (x, width) -> new BoundingBoxTypeButton(width, I18n.format("bbor.structures.jungleTemples"), BoundingBoxType.JungleTemple),
index 9485450dcfd15dcfe05b11a37218701f661211df..e9a5e6e82fbdbdaceb5e6e868cd3c46f57be92a6 100644 (file)
@@ -3,59 +3,44 @@ package com.irtimaled.bbor.client.interop;
 import com.irtimaled.bbor.client.models.BoundingBoxSpawningSphere;
 import com.irtimaled.bbor.common.models.Coords;
 import com.irtimaled.bbor.common.models.Point;
-import net.minecraft.block.Block;
 import net.minecraft.block.state.IBlockState;
 import net.minecraft.client.Minecraft;
-import net.minecraft.client.multiplayer.WorldClient;
-import net.minecraft.entity.EnumCreatureType;
-import net.minecraft.init.Blocks;
-import net.minecraft.tags.BlockTags;
-import net.minecraft.util.EnumFacing;
 import net.minecraft.util.math.BlockPos;
-import net.minecraft.world.EnumLightType;
-import net.minecraft.world.biome.Biome;
+import net.minecraft.world.World;
 
 public class SpawningSphereHelper {
     public static int findSpawnableSpaces(Point center, Coords coords, int width, int height, BlockProcessor blockProcessor) {
         int blockX = coords.getX();
         int minX = blockX - width;
-        int maxX = blockX + width;
+        int maxX = blockX + width + 1;
 
         int blockZ = coords.getZ();
         int minZ = blockZ - width;
-        int maxZ = blockZ + width;
+        int maxZ = blockZ + width + 1;
 
         int blockY = coords.getY();
-        int minY = blockY - height;
+        int minY = Math.max(1, blockY - height);
+        int maxY = Math.min(255, blockY + height);
 
-        int centerY = (int) center.getY();
-        int centerYby2 = 2 * centerY;
-
-        WorldClient world = Minecraft.getInstance().world;
+        World world = Minecraft.getInstance().world;
         int processed = 0;
         for (int x = minX; x < maxX; x++) {
             for (int z = minZ; z < maxZ; z++) {
-                if (!isWithinCircle(x, z, center)) continue;
+                double closestX = x + 0.5D;
+                double closestZ = z + 0.5D;
+                double distance = center.getDistance(new Point(closestX, center.getY(), closestZ));
+                if (distance > BoundingBoxSpawningSphere.SPAWN_RADIUS) continue;
 
-                if (!isBiomeHostileSpawnable(world, new BlockPos(x, 1, z))) continue;
+                if (SpawnableBlocksHelper.isBiomeHostileSpawnProof(world, new BlockPos(x, 1, z))) continue;
 
-                int bottom = centerY;
-                for (int y = minY; y < centerY; y++) {
-                    if (isWithinSpawnSphere(x, y, z, center)) {
-                        bottom = y;
-                        break;
-                    }
-                }
-                int top = (centerYby2 - bottom);
-                if (top > 255) top = 255;
-                if (bottom < 1) bottom = 1;
-
-                IBlockState upperBlockState = world.getBlockState(new BlockPos(x, bottom - 1, z));
-                for (int y = Math.max(1, bottom); y < top; y++) {
+                IBlockState upperBlockState = world.getBlockState(new BlockPos(x, minY - 1, z));
+                for (int y = minY; y < maxY; y++) {
                     IBlockState spawnBlockState = upperBlockState;
                     BlockPos pos = new BlockPos(x, y, z);
                     upperBlockState = world.getBlockState(pos);
-                    if (isSpawnable(world, pos, spawnBlockState, upperBlockState) &&
+                    distance = center.getDistance(new Point(closestX, y, closestZ));
+                    if (isWithinSpawnableZone(distance) &&
+                            SpawnableBlocksHelper.isSpawnable(world, pos, spawnBlockState, upperBlockState) &&
                             blockProcessor.process(x, y, z)) {
                         processed++;
                     }
@@ -65,43 +50,8 @@ public class SpawningSphereHelper {
         return processed;
     }
 
-    private static boolean isWithinSpawnSphere(int x, int y, int z, Point center) {
-        int x1 = x+1;
-        int z1 = z+1;
-        int y1 = y+1;
-        int closestX = Math.abs(center.getX()-x) < Math.abs(center.getX()-x1) ? x : x1;
-        int closestY = Math.abs(center.getY()-y) < Math.abs(center.getY()-y1) ? y : y1;
-        int closestZ = Math.abs(center.getZ()-z) < Math.abs(center.getZ()-z1) ? z : z1;
-        double distance = center.getDistance(new Point(closestX, closestY, closestZ));
-        return distance <= BoundingBoxSpawningSphere.SPAWN_RADIUS && distance >= (BoundingBoxSpawningSphere.SAFE_RADIUS-1);
-    }
-
-    private static boolean isWithinCircle(int x, int z, Point center) {
-        int x1 = x+1;
-        int z1 = z+1;
-        int closestX = Math.abs(center.getX()-x) < Math.abs(center.getX()-x1) ? x : x1;
-        int closestZ = Math.abs(center.getZ()-z) < Math.abs(center.getZ()-z1) ? z : z1;
-        double distance = center.getDistance(new Point(closestX, center.getY(), closestZ));
-        return distance <= BoundingBoxSpawningSphere.SPAWN_RADIUS;
-    }
-
-    private static boolean isBiomeHostileSpawnable(WorldClient world, BlockPos pos) {
-        Biome biome = world.getBiome(pos);
-        return biome.getSpawningChance() > 0 &&
-                !biome.getSpawns(EnumCreatureType.MONSTER).isEmpty();
-    }
-
-    private static boolean isSpawnable(WorldClient world, BlockPos pos, IBlockState spawnBlockState, IBlockState upperBlockState) {
-        Block spawnBlock = spawnBlockState.getBlock();
-        return spawnBlock != Blocks.AIR &&
-                spawnBlock != Blocks.BEDROCK &&
-                spawnBlock != Blocks.BARRIER &&
-                spawnBlockState.isTopSolid() &&
-                !upperBlockState.isBlockNormalCube() &&
-                !upperBlockState.canProvidePower() &&
-                !upperBlockState.isIn(BlockTags.RAILS) &&
-                upperBlockState.getCollisionShape(world, pos).getEnd(EnumFacing.Axis.Y) <= 0 &&
-                upperBlockState.getFluidState().isEmpty() &&
-                (world.dimension.isNether() || world.getLightFor(EnumLightType.BLOCK, pos) <= 7);
+    private static boolean isWithinSpawnableZone(double distance) {
+        return distance <= BoundingBoxSpawningSphere.SPAWN_RADIUS &&
+                distance > BoundingBoxSpawningSphere.SAFE_RADIUS;
     }
 }
index a7d5948cab3465405b964f5e65bb6098968dc966..b5bbd593fb120ef5150d282191ede2d1167b9b73 100644 (file)
@@ -2,18 +2,27 @@ package com.irtimaled.bbor.client.models;
 
 import com.irtimaled.bbor.common.BoundingBoxType;
 import com.irtimaled.bbor.common.models.BoundingBoxSphere;
+import com.irtimaled.bbor.common.models.Coords;
 import com.irtimaled.bbor.common.models.Point;
 
+import java.util.HashSet;
+import java.util.Set;
+
 public class BoundingBoxSpawningSphere extends BoundingBoxSphere {
     public static final int SAFE_RADIUS = 24;
     public static final int SPAWN_RADIUS = 128;
 
+    private final Set<Coords> blocks = new HashSet<>();
     private Integer spawnableCount;
 
     public BoundingBoxSpawningSphere(Point point) {
         super(point, SPAWN_RADIUS, BoundingBoxType.AFKSphere);
     }
 
+    public Set<Coords> getBlocks() {
+        return blocks;
+    }
+
     public boolean isWithinSphere(Point point) {
         return this.getPoint().getDistance(point) <= getRadius() + 0.5D;
     }
index 00c24827ee5bd8cfea3dbb5a4d254ae5299a960d..6b17475ea8762593a827bd8b48cac2d3cf09145f 100644 (file)
@@ -2,16 +2,23 @@ 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.SpawningSphereHelper;
 import com.irtimaled.bbor.client.models.BoundingBoxSpawningSphere;
 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<BoundingBoxSpawningSphere> {
+    public static final Minecraft minecraft = Minecraft.getInstance();
+    private static Long lastGameTime = null;
+
+    private static Set<BoundingBoxSpawningSphere> lastBoundingBox = null;
     private static BoundingBoxSpawningSphere spawningSphere;
     private static Integer dimensionId;
 
@@ -25,6 +32,7 @@ public class SpawningSphereProvider implements IBoundingBoxProvider<BoundingBoxS
 
         dimensionId = Player.getDimensionId();
         spawningSphere = new BoundingBoxSpawningSphere(point);
+        lastBoundingBox = null;
     }
 
     private static double snapToNearestHalf(double value) {
@@ -36,6 +44,7 @@ public class SpawningSphereProvider implements IBoundingBoxProvider<BoundingBoxS
 
     public static boolean clear() {
         if(spawningSphere != null) {
+            lastBoundingBox = null;
             spawningSphere = null;
             dimensionId = null;
             return true;
@@ -73,6 +82,24 @@ public class SpawningSphereProvider implements IBoundingBoxProvider<BoundingBoxS
 
     @Override
     public Iterable<BoundingBoxSpawningSphere> get(int dimensionId) {
+        long gameTime = minecraft.world.getGameTime();
+        if (lastBoundingBox == null || (!((Long) gameTime).equals(lastGameTime) && gameTime % 2L == 0L)) {
+            lastGameTime = gameTime;
+            lastBoundingBox = getSpawningSphere();
+        }
+        return lastBoundingBox;
+    }
+
+    private Set<BoundingBoxSpawningSphere> getSpawningSphere() {
+        Set<Coords> blocks = spawningSphere.getBlocks();
+        blocks.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,
+                    (x, y, z) -> blocks.add(new Coords(x, y, z)));
+        }
         Set<BoundingBoxSpawningSphere> boundingBoxes = new HashSet<>();
         boundingBoxes.add(spawningSphere);
         return boundingBoxes;
index ff5749c03bbe1c78f83d5920f6d63c2852bbb658..a4e9c1800acdb08b6b953e7e2915e8b52dfffd12 100644 (file)
@@ -2,10 +2,7 @@ package com.irtimaled.bbor.client.renderers;
 
 import com.irtimaled.bbor.client.Player;
 import com.irtimaled.bbor.client.config.ConfigManager;
-import com.irtimaled.bbor.client.interop.SpawningSphereHelper;
 import com.irtimaled.bbor.client.models.BoundingBoxSpawningSphere;
-import com.irtimaled.bbor.common.MathHelper;
-import com.irtimaled.bbor.common.models.Point;
 import net.minecraft.client.resources.I18n;
 
 import java.awt.*;
@@ -13,8 +10,7 @@ import java.awt.*;
 public class SpawningSphereRenderer extends AbstractRenderer<BoundingBoxSpawningSphere> {
     @Override
     public void render(BoundingBoxSpawningSphere boundingBox) {
-        Point point = boundingBox.getPoint();
-        OffsetPoint sphereCenter = new OffsetPoint(point);
+        OffsetPoint sphereCenter = new OffsetPoint(boundingBox.getPoint());
 
         OffsetBox offsetBox = new OffsetBox(sphereCenter, sphereCenter).grow(0.5, 0, 0.5);
         renderCuboid(offsetBox, Color.GREEN);
@@ -30,21 +26,18 @@ public class SpawningSphereRenderer extends AbstractRenderer<BoundingBoxSpawning
         renderSphere(sphereCenter, BoundingBoxSpawningSphere.SAFE_RADIUS, Color.GREEN, 5, 5);
         renderSphere(sphereCenter, BoundingBoxSpawningSphere.SPAWN_RADIUS, Color.RED, 5, 5);
 
-        if(ConfigManager.renderAFKSpawnableBlocks.get()) {
-            renderSpawnableSpaces(point);
+        if (ConfigManager.renderAFKSpawnableBlocks.get() && boundingBox.isWithinSphere(Player.getPoint())) {
+            renderSpawnableSpaces(boundingBox);
         }
     }
 
-    private void renderSpawnableSpaces(Point center) {
-        Integer renderDistance = ConfigManager.afkSpawnableBlocksRenderDistance.get();
-        int width = MathHelper.floor(Math.pow(2, 2 + renderDistance));
-        int height = MathHelper.floor(Math.pow(2, renderDistance));
-
-        SpawningSphereHelper.findSpawnableSpaces(center, Player.getCoords(), width, height,
-                (x, y, z) -> {
-                    OffsetBox offsetBox = new OffsetBox(x, y, z, x + 1, y, z + 1);
-                    renderCuboid(offsetBox, Color.RED);
-                    return false;
-                });
+    private void renderSpawnableSpaces(BoundingBoxSpawningSphere boundingBox) {
+        boundingBox.getBlocks().forEach(c -> {
+            int x = c.getX();
+            int y = c.getY();
+            int z = c.getZ();
+            OffsetBox offsetBox = new OffsetBox(x, y, z, x + 1, y, z + 1);
+            renderCuboid(offsetBox, boundingBox.getColor());
+        });
     }
 }
index 56dcbda9f7a7496ef5e7243a1862723530500a31..d345041c580152cfe24861b2dc4487e765c98f60 100644 (file)
@@ -27,7 +27,6 @@
   "bbor.features.mobSpawners.spawnArea": "Spawn Area",
   "bbor.features.mobSpawners.activationLines": "Activation Lines",
   "bbor.features.spawningSpheres": "Spawning Spheres",
-  "bbor.features.spawningSpheres.spawnableBlocks": "Spawnable Blocks",
   "bbor.features.spawnableBlocks": "Spawnable Blocks",
   "bbor.features.biomeBorders": "Biome Borders",