Skip to content

Commit

Permalink
Change invertedHitBox to a set
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerS1066 committed Sep 5, 2024
1 parent d52a942 commit 1afdc1a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void doUpdate() {
}
}
//The subtraction of the set of coordinates in the HitBox cube and the HitBox itself
final SetHitBox invertedHitBox = new SetHitBox(Sets.difference(craft.getHitBox().boundingHitBox().asSet(), craft.getHitBox().asSet()));
final Set<MovecraftLocation> invertedHitBox = Sets.difference(craft.getHitBox().boundingHitBox().asSet(), craft.getHitBox().asSet());
//A set of locations that are confirmed to be "exterior" locations
final SetHitBox exterior = new SetHitBox();
final SetHitBox interior = new SetHitBox();
Expand Down Expand Up @@ -139,10 +139,10 @@ public void doUpdate() {
}
}
exterior.addAll(visited);
interior.addAll(Sets.difference(invertedHitBox.asSet(), exterior.asSet()));
interior.addAll(Sets.difference(invertedHitBox, exterior.asSet()));

final WorldHandler handler = Movecraft.getInstance().getWorldHandler();
for (MovecraftLocation location : Sets.difference(invertedHitBox.asSet(), exterior.asSet())) {
for (MovecraftLocation location : Sets.difference(invertedHitBox, exterior.asSet())) {
var data = location.toBukkit(craft.getWorld()).getBlock().getBlockData();
if (!passthroughBlocks.contains(data.getMaterial())) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.*;

public class CollectionUtils {
/**
Expand Down Expand Up @@ -90,6 +86,18 @@ public static BitmapHitBox filter(@NotNull final HitBox collection, @NotNull fin
@NotNull
@Contract(pure = true)
public static Iterable<MovecraftLocation> neighbors(@NotNull HitBox hitbox, @NotNull MovecraftLocation location){
return neighbors(hitbox.asSet(), location);
}

/**
* finds the axial neighbors to a location. Neighbors are defined as locations that exist within one meter of a given
* location
* @param location the location to search for neighbors
* @return an iterable set of neighbors to the given location
*/
@NotNull
@Contract(pure = true)
public static Iterable<MovecraftLocation> neighbors(@NotNull Set<MovecraftLocation> hitbox, @NotNull MovecraftLocation location){
if(hitbox.isEmpty()){
return Collections.emptyList();
}
Expand Down

0 comments on commit 1afdc1a

Please sign in to comment.