|
||
---|---|---|
gradle/wrapper | ||
src | ||
.gitattributes | ||
.gitignore | ||
LICENSE | ||
README.md | ||
build.gradle | ||
gradle.properties | ||
gradlew | ||
gradlew.bat | ||
settings.gradle |
README.md
Presence
The ever-present range detection library for Java.
Features
- Simple, easy-to-use API
- Relies on no existing game libraries (e.g Fabric)
- No need to extend any classes
- Supports both integer and floating-point ranges
- Can implement own presence types with ease
- Uses spatial partitioning (chunk-based) for efficient range detection
- Uses Manhattan distance (in default implementations) for range detection
- Can be used in any Java project
- No dependencies (except for JUnit for testing)
Installation
To use the API, add the following to your build.gradle
:
repositories {
maven {
name = "Arzumify's Maven"
url = "https://maven.ailur.dev"
}
}
dependencies {
implementation "arzumify:presence:${version}"
}
To get the latest version, check the Maven repository.
Usage
Implementing a Presence Provider
import arzumify.presence.presences.IntegerPresence;
import arzumify.presence.presences.PresenceProvider;
public class ExampleIntegerPresence implements PresenceProvider<IntegerPresence> {
ExampleIntegerPresence(int range, Vec3i... points) {
this.presence = new IntegerPresence(range, points);
}
private final IntegerPresence presence;
public Presence<IntegerPresence> presence() {
return this.presence;
}
}
It's that simple! Even better, no extends, leaving you free to use that elsewhere.
Using that Presence Provider
public class Main {
private final Channel global = new Channel(true);
private final MatchMaker<FloatingPresence, ExampleFloatingPresence> matchMaker = new MatchMaker<>();
public static void main(String[] args) {
var presence = new ExampleIntegerPresence(5, new Vec3i(0, 0, 0));
var presence2 = new ExampleIntegerPresence(5, new Vec3i(1, 1, 1));
matchMaker.Add(presence, global); // Add to global channel
matchMaker.Add(presence2, global); // Add to global channel
var found = matchMaker.Search(presence, global); // Search on global channel
}
}
Implementing a Presence Type
Just implement the Presence
interface and you're good to go!
package arzumify.presence.presences;
import arzumify.presence.maths.Vec2i;
import java.util.Set;
public interface Presence<T extends Presence<T>> {
Set<Vec2i> GetChunks();
Set<Vec2i> GetCollisionChunks();
boolean Matches(Presence<T> presence);
}
A "Chunk" is defined as a 16x16 block area in the world. This is used for spatial partitioning. To calculate a chunk from a position, convert the position into an integer position, then shift right by 4.
public Set<Vec2i> getChunkPresence(Set<Vec3i> positions) {
var chunks = new Set<Vec2i>();
for (Vec3i position : positions) {
chunks.add(new Vec2i(position.x() >> 4, position.z() >> 4));
}
return chunks;
}
License
This library is licensed under the GPL-3.0 License. See the LICENSE file for more information.
TL;DR (not legal advice):
You CAN:
- Redistribute this library
- modify this library
- Use this library in a project
- Use this library in a video or stream
- Sell this library as part of a larger work
- Use this library for any purpose
You CANNOT:
- Hold the author liable
- Claim this library as your own
- Change the license of this library
- Redistribute the library without the source code
- modify the library without sharing the source code
You MUST:
- Share the source code of this library
- Include the license with any redistribution
- Include the source code with any redistribution
- Reproduce the below disclaimer in any redistribution
Thank you for keeping the Java community open and free!
Disclaimer
Presence - The ever-present range detection library for Java.
Copyright (C) 2025 Arzumify
This program is free software: you can redistribute it and/or libraryify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.