1 package com.irtimaled.bbor.client.providers;
3 import com.irtimaled.bbor.client.Player;
4 import com.irtimaled.bbor.client.config.BoundingBoxTypeHelper;
5 import com.irtimaled.bbor.client.config.ConfigManager;
6 import com.irtimaled.bbor.client.interop.SpawnableBlocksHelper;
7 import com.irtimaled.bbor.client.models.BoundingBoxSpawnableBlocks;
8 import com.irtimaled.bbor.common.BoundingBoxType;
9 import com.irtimaled.bbor.common.MathHelper;
10 import com.irtimaled.bbor.common.models.Coords;
11 import net.minecraft.client.Minecraft;
13 import java.util.HashSet;
16 public class SpawnableBlocksProvider implements IBoundingBoxProvider<BoundingBoxSpawnableBlocks> {
17 public static final Minecraft minecraft = Minecraft.getInstance();
18 private static Long lastGameTime = null;
20 private static Set<BoundingBoxSpawnableBlocks> lastBoundingBox = null;
22 public static void clear() {
23 lastBoundingBox = null;
26 private boolean isWithinActiveSpawningSphere() {
27 return BoundingBoxTypeHelper.shouldRender(BoundingBoxType.AFKSphere) &&
28 ConfigManager.renderAFKSpawnableBlocks.get() &&
29 SpawningSphereProvider.playerInsideSphere();
33 public boolean canProvide(int dimensionId) {
34 return BoundingBoxTypeHelper.shouldRender(BoundingBoxType.SpawnableBlocks) &&
35 !isWithinActiveSpawningSphere();
39 public Iterable<BoundingBoxSpawnableBlocks> get(int dimensionId) {
40 long gameTime = minecraft.world.getGameTime();
41 if (lastBoundingBox == null || (!((Long) gameTime).equals(lastGameTime) && gameTime % 2L == 0L)) {
42 lastGameTime = gameTime;
43 lastBoundingBox = getSpawnableBlocks();
45 return lastBoundingBox;
48 private Set<BoundingBoxSpawnableBlocks> getSpawnableBlocks() {
49 BoundingBoxSpawnableBlocks boundingBox = new BoundingBoxSpawnableBlocks();
50 Set<Coords> blocks = boundingBox.getBlocks();
52 int width = MathHelper.floor(Math.pow(2, 1 + ConfigManager.spawnableBlocksRenderWidth.get()));
53 int height = MathHelper.floor(Math.pow(2, ConfigManager.spawnableBlocksRenderHeight.get()));
55 SpawnableBlocksHelper.findSpawnableBlocks(Player.getCoords(), width, height,
56 (x, y, z) -> blocks.add(new Coords(x, y, z)));
58 Set<BoundingBoxSpawnableBlocks> boundingBoxes = new HashSet<>();
59 boundingBoxes.add(boundingBox);