Skip to content

Commit

Permalink
Add a cylinder filter
Browse files Browse the repository at this point in the history
  • Loading branch information
JustusJG authored and Gegy committed Oct 22, 2024
1 parent 79aa517 commit d635c38
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/main/java/xyz/nucleoid/stimuli/filter/CylinderFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package xyz.nucleoid.stimuli.filter;

import net.minecraft.registry.RegistryKey;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import xyz.nucleoid.stimuli.EventSource;

public record CylinderFilter(RegistryKey<World> dimension, BlockPos center, int radius, int height) implements EventFilter {
@Override
public boolean accepts(EventSource source) {
var pos = source.getPos();
var dimension = source.getDimension();
return (dimension == null || dimension == this.dimension) && (pos == null || this.containsPos(pos));
}

private boolean containsPos(BlockPos pos) {
var center = this.center;
var radius = this.radius;
var height = this.height;
var dx = pos.getX() - center.getX();
var dz = pos.getZ() - center.getZ();
return dx * dx + dz * dz <= radius * radius && pos.getY() >= center.getY() && pos.getY() <= center.getY() + height;
}
}
13 changes: 13 additions & 0 deletions src/main/java/xyz/nucleoid/stimuli/filter/EventFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ static EventFilter box(RegistryKey<World> dimension, BlockPos min, BlockPos max)
return new BoxFilter(dimension, min, max);
}

/**
* Returns an event filter that accepts only events from the given dimension and cylinder bounds.
*
* @param dimension the dimension to filter for
* @param center the center of the cylinder at bottom
* @param radius the radius of the cylinder
* @param height the height of the cylinder
* @return the result event filter
*/
static EventFilter cylinder(RegistryKey<World> dimension, BlockPos center, int radius, int height) {
return new CylinderFilter(dimension, center, radius, height);
}

/**
* Returns an event filter that accepts events from any of the given filters.
*
Expand Down

0 comments on commit d635c38

Please sign in to comment.