Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.hysky.skyblocker.annotations.Init;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.utils.BlockPosSet;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.render.WorldRenderExtractionCallback;
import de.hysky.skyblocker.utils.render.primitive.PrimitiveCollector;
Expand All @@ -18,9 +19,7 @@
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import java.util.ArrayDeque;
import java.util.HashSet;
import java.util.Queue;
import java.util.Set;

public class BuildersWandPreview {
private static final int MAX_BLOCKS = 241;
Expand Down Expand Up @@ -51,15 +50,15 @@ private static void extractBuildersWandPreview(PrimitiveCollector collector, Blo
Direction side = hitResult.getDirection();
if (!client.level.getBlockState(hitPos.relative(side)).isAir()) return;
BlockState state = client.level.getBlockState(hitPos);
for (BlockPos pos : findConnectedFaces(client.level, hitPos, side, state)) {
for (BlockPos pos : findConnectedFaces(client.level, hitPos, side, state).destroyAndIterateMut()) {
extractBlockPreview(collector, pos.relative(side), state);
}
}

private static Set<BlockPos> findConnectedFaces(Level world, BlockPos pos, Direction side, BlockState state) {
private static BlockPosSet findConnectedFaces(Level world, BlockPos pos, Direction side, BlockState state) {
// bfs connected block faces
Queue<BlockPos> q = new ArrayDeque<>();
Set<BlockPos> visited = new HashSet<>();
BlockPosSet visited = new BlockPosSet();
q.add(pos);
visited.add(pos);

Expand All @@ -83,7 +82,7 @@ private static Set<BlockPos> findConnectedFaces(Level world, BlockPos pos, Direc
mutable.move(dir.getOpposite());
}

if (visited.size() > MAX_BLOCKS) return Set.of();
if (visited.size() > MAX_BLOCKS) return new BlockPosSet();
}

return visited;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
import de.hysky.skyblocker.events.WorldEvents;
import de.hysky.skyblocker.skyblock.dungeon.DungeonBoss;
import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager;
import de.hysky.skyblocker.utils.BlockPosSet;
import de.hysky.skyblocker.utils.ColorUtils;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.render.RenderHelper;
import de.hysky.skyblocker.utils.render.WorldRenderExtractionCallback;
import de.hysky.skyblocker.utils.render.primitive.PrimitiveCollector;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectList;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import it.unimi.dsi.fastutil.objects.ObjectSet;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.minecraft.client.Minecraft;
Expand All @@ -40,8 +37,8 @@ public class SimonSays {
private static final BlockPos START_BUTTON = new BlockPos(110, 121, 91);
private static final float[] GREEN = ColorUtils.getFloatComponents(DyeColor.LIME);
private static final float[] YELLOW = ColorUtils.getFloatComponents(DyeColor.YELLOW);
private static final ObjectSet<BlockPos> CLICKED_BUTTONS = new ObjectOpenHashSet<>();
private static final ObjectList<BlockPos> SIMON_PATTERN = new ObjectArrayList<>();
private static final BlockPosSet CLICKED_BUTTONS = new BlockPosSet();
private static final BlockPosSet SIMON_PATTERN = new BlockPosSet();

@Init
public static void init() {
Expand All @@ -60,7 +57,7 @@ private static InteractionResult onBlockInteract(Player player, Level world, Int

if (block.equals(Blocks.STONE_BUTTON)) {
if (BUTTONS_AREA.contains(Vec3.atLowerCornerOf(pos))) {
CLICKED_BUTTONS.add(new BlockPos(pos)); //Copy just in case it becomes mutable in the future
CLICKED_BUTTONS.add(pos);
} else if (pos.equals(START_BUTTON)) {
reset();
}
Expand All @@ -80,7 +77,7 @@ private static void onBlockUpdate(BlockPos pos, @Nullable BlockState oldState, B
Block newBlock = newState.getBlock();

if (BOARD_AREA.contains(posVec) && newBlock.equals(Blocks.OBSIDIAN) && oldState != null && oldState.getBlock().equals(Blocks.SEA_LANTERN)) {
SIMON_PATTERN.add(pos.immutable()); //Convert to immutable because chunk delta updates use the mutable variant
SIMON_PATTERN.add(pos);
} else if (BUTTONS_AREA.contains(posVec) && newBlock.equals(Blocks.AIR)) {
//Upon reaching the showing of the next sequence we need to reset the state so that we don't show old data
//Otherwise, the nextIndex will go beyond 5 and that can cause bugs, it also helps with the other case noted above
Expand All @@ -93,7 +90,7 @@ private static void extractRendering(PrimitiveCollector collector) {
if (shouldProcess()) {
int buttonsRendered = 0;

for (BlockPos pos : SIMON_PATTERN) {
for (BlockPos pos : SIMON_PATTERN.iterateMut()) {
//Offset to west (x - 1) to get the position of the button from the sea lantern block
BlockPos buttonPos = pos.west();
ClientLevel world = Objects.requireNonNull(Minecraft.getInstance().level); //Should never be null here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package de.hysky.skyblocker.skyblock.dungeon.device;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import de.hysky.skyblocker.annotations.Init;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.events.WorldEvents;
import de.hysky.skyblocker.skyblock.dungeon.DungeonBoss;
import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager;
import de.hysky.skyblocker.utils.BlockPosSet;
import de.hysky.skyblocker.utils.ColorUtils;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.render.WorldRenderExtractionCallback;
Expand All @@ -24,12 +24,12 @@ public class TargetPractice {
private static final int ACTIVATION_THRESHOLD = 1;
private static final int UNACTIVATED = 0;
// In the order you see the grid in the world by row.
private static final List<BlockPos> POSSIBLE_TARGETS = List.of(
private static final Set<BlockPos> POSSIBLE_TARGETS = Set.of(
new BlockPos(68, 130, 50), new BlockPos(66, 130, 50), new BlockPos(64, 130, 50),
new BlockPos(68, 128, 50), new BlockPos(66, 128, 50), new BlockPos(64, 128, 50),
new BlockPos(68, 126, 50), new BlockPos(66, 126, 50), new BlockPos(64, 126, 50)
);
private static final List<BlockPos> HIT_TARGETS = new ArrayList<>();
);
private static final BlockPosSet HIT_TARGETS = new BlockPosSet();
private static final float[] RED = ColorUtils.getFloatComponents(DyeColor.RED);

@Init
Expand Down Expand Up @@ -68,16 +68,15 @@ private static void onBlockStateUpdate(BlockPos pos, BlockState oldState, BlockS
// player must shoot, so when that block turns back into Blue Terracotta it has either been successfully shot or the device reset.
if (POSSIBLE_TARGETS.contains(pos)) {
if (oldState.getBlock().equals(Blocks.EMERALD_BLOCK) && newState.getBlock().equals(Blocks.BLUE_TERRACOTTA)) {
// Convert position to immutable since it might be mutable and we can't have it changing
HIT_TARGETS.add(pos.immutable());
HIT_TARGETS.add(pos);
}
}
}

private static void extractRendering(PrimitiveCollector collector) {
if (!shouldProcess()) return;

for (BlockPos pos : HIT_TARGETS) {
for (BlockPos pos : HIT_TARGETS.iterateMut()) {
collector.submitFilledBox(pos, RED, 0.5f, false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.mojang.serialization.Codec;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.events.DungeonEvents;
import de.hysky.skyblocker.utils.BlockPosSet;
import de.hysky.skyblocker.utils.Constants;
import de.hysky.skyblocker.utils.Tickable;
import de.hysky.skyblocker.utils.Utils;
Expand Down Expand Up @@ -45,7 +46,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -91,7 +91,7 @@ public class Room implements Tickable, Renderable {
* Contains all blocks that have been checked to prevent checking the same block multiple times.
* This is null after the room is matched.
*/
private @Nullable Set<BlockPos> checkedBlocks = new HashSet<>();
private @Nullable BlockPosSet checkedBlocks = new BlockPosSet();
/**
* The task that is used to check blocks. This is used to ensure only one such task can run at a time.
*/
Expand Down Expand Up @@ -536,7 +536,7 @@ protected void reset() {
IntSortedSet segmentsX = IntSortedSets.unmodifiable(new IntRBTreeSet(segments.stream().mapToInt(Vector2ic::x).toArray()));
IntSortedSet segmentsY = IntSortedSets.unmodifiable(new IntRBTreeSet(segments.stream().mapToInt(Vector2ic::y).toArray()));
possibleRooms = getPossibleRooms(segmentsX, segmentsY);
checkedBlocks = new HashSet<>();
checkedBlocks = new BlockPosSet();
doubleCheckBlocks = 0;
secretWaypoints.clear();
name = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import de.hysky.skyblocker.annotations.Init;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.events.SkyblockEvents;
import de.hysky.skyblocker.utils.BlockPosSet;
import de.hysky.skyblocker.utils.Boxes;
import de.hysky.skyblocker.utils.Location;
import de.hysky.skyblocker.utils.Resettable;
import de.hysky.skyblocker.utils.render.Renderable;
import de.hysky.skyblocker.utils.render.WorldRenderExtractionCallback;
import de.hysky.skyblocker.utils.render.primitive.PrimitiveCollector;
import de.hysky.skyblocker.utils.scheduler.Scheduler;
import it.unimi.dsi.fastutil.objects.ObjectAVLTreeSet;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
Expand All @@ -30,7 +30,7 @@ public final class CarpetHighlighter implements Renderable, Resettable {
private static final Vec3 CARPET_BOUNDING_BOX = Boxes.getLengthVec(CarpetBlock.SHAPE.bounds());
private static final int SEARCH_RADIUS = 15;
private static final int TICK_INTERVAL = 15;
private static final ObjectAVLTreeSet<BlockPos> CARPET_LOCATIONS = new ObjectAVLTreeSet<>();
private static final BlockPosSet CARPET_LOCATIONS = new BlockPosSet();
private static float[] colorComponents;
private static boolean isLocationValid = false;

Expand All @@ -46,7 +46,7 @@ public static void init() {
@Override
public void extractRendering(PrimitiveCollector collector) {
if (!isLocationValid || !SkyblockerConfigManager.get().mining.dwarvenMines.enableCarpetHighlighter) return;
for (BlockPos carpetLocation : CARPET_LOCATIONS) {
for (BlockPos carpetLocation : CARPET_LOCATIONS.iterateMut()) {
collector.submitFilledBox(Vec3.atLowerCornerOf(carpetLocation), CARPET_BOUNDING_BOX, colorComponents, colorComponents[3], false);
}
}
Expand All @@ -59,9 +59,7 @@ public void tick() {
if (!isLocationValid || !SkyblockerConfigManager.get().mining.dwarvenMines.enableCarpetHighlighter || Minecraft.getInstance().level == null || Minecraft.getInstance().player == null) return;
Iterable<BlockPos> iterable = BlockPos.withinManhattan(Minecraft.getInstance().player.blockPosition(), SEARCH_RADIUS, SEARCH_RADIUS, SEARCH_RADIUS);
for (BlockPos blockPos : iterable) {
//The iterator contains a BlockPos.Mutable that it changes the position of to iterate over blocks,
// so it has to be converted to an immutable BlockPos or the position will change based on the player's position && the search radius
if (checkForCarpet(blockPos)) CARPET_LOCATIONS.add(blockPos.immutable());
if (checkForCarpet(blockPos)) CARPET_LOCATIONS.add(blockPos);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import de.hysky.skyblocker.events.ParticleEvents;
import de.hysky.skyblocker.events.PlaySoundEvents;
import de.hysky.skyblocker.events.WorldEvents;
import de.hysky.skyblocker.utils.BlockPosSet;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.render.WorldRenderExtractionCallback;
import de.hysky.skyblocker.utils.render.primitive.PrimitiveCollector;
Expand All @@ -27,8 +28,6 @@
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import java.util.HashSet;
import java.util.Set;

public class CrystalsChestHighlighter {

Expand All @@ -38,7 +37,7 @@ public class CrystalsChestHighlighter {
private static final Vec3 LOCK_HIGHLIGHT_SIZE = new Vec3(0.1, 0.1, 0.1);

private static int waitingForChest = 0;
private static final Set<BlockPos> activeChests = new HashSet<>();
private static final BlockPosSet activeChests = new BlockPosSet();
private static final Object2LongOpenHashMap<Vec3> activeParticles = new Object2LongOpenHashMap<>();
private static int currentLockCount = 0;
private static int neededLockCount = 0;
Expand Down Expand Up @@ -83,19 +82,17 @@ private static void onBlockUpdate(BlockPos pos, BlockState oldState, BlockState
return;
}

BlockPos immutable = pos.immutable();

if (waitingForChest > 0 && newState.is(Blocks.CHEST)) {
//make sure it is not too far from the player (more than 10 blocks away)
if (immutable.distToCenterSqr(CLIENT.player.position()) > 100) {
if (pos.distToCenterSqr(CLIENT.player.position()) > 100) {
return;
}
activeChests.add(immutable);
activeChests.add(pos);
currentLockCount = 0;
waitingForChest -= 1;
} else if (newState.isAir() && activeChests.contains(immutable)) {
} else if (newState.isAir() && activeChests.contains(pos)) {
currentLockCount = 0;
activeChests.remove(immutable);
activeChests.remove(pos);
}
}

Expand Down Expand Up @@ -159,7 +156,7 @@ private static void extractRendering(PrimitiveCollector collector) {
}
//render chest outline
float[] color = SkyblockerConfigManager.get().mining.crystalHollows.chestHighlightColor.getComponents(new float[]{0, 0, 0, 0});
for (BlockPos chest : activeChests) {
for (BlockPos chest : activeChests.iterateMut()) {
collector.submitOutlinedBox(AABB.ofSize(chest.getCenter().subtract(0, 0.0625, 0), 0.885, 0.885, 0.885), color, color[3], 3, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.tabhud.util.PlayerListManager;
import de.hysky.skyblocker.utils.Area;
import de.hysky.skyblocker.utils.BlockPosSet;
import de.hysky.skyblocker.utils.ColorUtils;
import de.hysky.skyblocker.utils.ItemAbility;
import de.hysky.skyblocker.utils.Utils;
Expand All @@ -13,7 +14,6 @@
import org.jspecify.annotations.Nullable;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import net.minecraft.ChatFormatting;
Expand Down Expand Up @@ -102,7 +102,7 @@ public class PickobulusHelper {
private static boolean shouldRender;
private static @Nullable Component errorMessage;
private static final BlockState[][][] blocks = new BlockState[8][8][8];
private static final Set<BlockPos> breakBlocks = new HashSet<>();
private static final BlockPosSet breakBlocks = new BlockPosSet();
private static final int[] drops = new int[MiningDrop.values().length];

public static boolean shouldRender() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.item.ItemCooldowns;
import de.hysky.skyblocker.skyblock.tabhud.util.PlayerListManager;
import de.hysky.skyblocker.utils.BlockPosSet;
import de.hysky.skyblocker.utils.Constants;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.render.WorldRenderExtractionCallback;
Expand All @@ -13,7 +14,6 @@

import java.awt.Color;
import java.util.ArrayDeque;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -241,7 +241,7 @@ private static void submitConnectedLogs(PrimitiveCollector collector, BlockHitRe
};
}

HashSet<BlockPos> visited = new HashSet<>();
BlockPosSet visited = new BlockPosSet();
ArrayDeque<BlockPos> queue = new ArrayDeque<>();
int woodCount = 0;
float toughness = getToughness(state);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package de.hysky.skyblocker.skyblock.galatea;

import de.hysky.skyblocker.events.WorldEvents;
import de.hysky.skyblocker.utils.BlockPosSet;
import de.hysky.skyblocker.utils.ColorUtils;
import de.hysky.skyblocker.utils.render.RenderHelper;
import de.hysky.skyblocker.utils.render.WorldRenderExtractionCallback;
import de.hysky.skyblocker.utils.render.primitive.PrimitiveCollector;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientChunkEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.minecraft.client.Minecraft;
Expand All @@ -18,15 +18,14 @@
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.phys.AABB;
import java.util.Iterator;
import java.util.Set;
import java.util.function.Predicate;

/**
* Abstract class for a simple feature that highlights a certain type of block.
*/
//TODO Move this to a more generic package since this is not Galatea specific (maybe make a world rendering utility package?)
public abstract class AbstractBlockHighlighter {
protected final Set<BlockPos> highlightedBlocks = new ObjectOpenHashSet<>();
protected final BlockPosSet highlightedBlocks = new BlockPosSet();
protected final float[] colour;
protected final Predicate<BlockState> statePredicate;

Expand Down Expand Up @@ -61,7 +60,7 @@ protected void onBlockUpdate(BlockPos pos, BlockState oldState, BlockState newSt
if (!shouldProcess()) return;

if (this.statePredicate.test(newState)) {
this.highlightedBlocks.add(pos.immutable());
this.highlightedBlocks.add(pos);
} else {
this.highlightedBlocks.remove(pos);
}
Expand All @@ -74,7 +73,7 @@ protected void onBlockUpdate(BlockPos pos, BlockState oldState, BlockState newSt
protected void onChunkLoad(ClientLevel world, LevelChunk chunk) {
if (!shouldProcess()) return;

chunk.findBlocks(statePredicate, (pos, state) -> this.highlightedBlocks.add(pos.immutable()));
chunk.findBlocks(statePredicate, (pos, state) -> this.highlightedBlocks.add(pos));
}

/**
Expand All @@ -98,7 +97,7 @@ private void extractRendering(PrimitiveCollector collector) {
Minecraft client = Minecraft.getInstance();
if (!shouldProcess() || client.level == null) return;

for (BlockPos highlight : this.highlightedBlocks) {
for (BlockPos highlight : this.highlightedBlocks.iterateMut()) {
AABB outline = RenderHelper.getBlockBoundingBox(client.level, highlight);

if (outline != null) {
Expand Down
Loading