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 net.minecraft.client.Minecraft;
12 import java.util.HashSet;
15 public class SpawnableBlocksProvider implements IBoundingBoxProvider<BoundingBoxSpawnableBlocks> {
16 public static final Minecraft minecraft = Minecraft.getInstance();
17 private static Long lastGameTime = null;
19 private static Set<BoundingBoxSpawnableBlocks> lastBoundingBox = null;
21 public static void clear() {
22 lastBoundingBox = null;
25 private boolean isWithinActiveSpawningSphere() {
26 return BoundingBoxTypeHelper.shouldRender(BoundingBoxType.AFKSphere) &&
27 ConfigManager.renderAFKSpawnableBlocks.get() &&
28 SpawningSphereProvider.playerInsideSphere();
32 public boolean canProvide(int dimensionId) {
33 return BoundingBoxTypeHelper.shouldRender(BoundingBoxType.SpawnableBlocks) &&
34 !isWithinActiveSpawningSphere();
38 public Iterable<BoundingBoxSpawnableBlocks> get(int dimensionId) {
39 long gameTime = minecraft.world.getGameTime();
40 if (lastBoundingBox == null || (!((Long) gameTime).equals(lastGameTime) && gameTime % 2L == 0L)) {
41 lastGameTime = gameTime;
42 lastBoundingBox = getSpawnableBlocks();
44 return lastBoundingBox;
47 private Set<BoundingBoxSpawnableBlocks> getSpawnableBlocks() {
48 BoundingBoxSpawnableBlocks boundingBox = new BoundingBoxSpawnableBlocks();
50 int width = MathHelper.floor(Math.pow(2, 1 + ConfigManager.spawnableBlocksRenderWidth.get()));
51 int height = MathHelper.floor(Math.pow(2, ConfigManager.spawnableBlocksRenderHeight.get()));
53 SpawnableBlocksHelper.findSpawnableBlocks(Player.getCoords(), width, height, boundingBox.getBlocks()::add);
55 Set<BoundingBoxSpawnableBlocks> boundingBoxes = new HashSet<>();
56 boundingBoxes.add(boundingBox);