Skip to content

Commit

Permalink
Add Javadocs
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinthegreat1 committed Sep 21, 2024
1 parent dcd6c30 commit 00c33a8
Showing 1 changed file with 68 additions and 1 deletion.
69 changes: 68 additions & 1 deletion src/main/java/de/hysky/skyblocker/utils/waypoint/Waypoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,32 @@
import java.util.Objects;
import java.util.function.Supplier;

/**
* Represents a waypoint with a position, type, color, alpha, line width, through walls, and enabled state.
* <p>
* Extend this class and override at least the withers to create custom waypoint types and behavior.
*/
public class Waypoint implements Renderable {
protected static final float DEFAULT_HIGHLIGHT_ALPHA = 0.5f;
protected static final float DEFAULT_LINE_WIDTH = 5f;
public final BlockPos pos;
final Box box;
final Supplier<Type> typeSupplier;
/**
* The color components of the waypoint.
* <p>
* For custom color behavior, override {@link #getRenderColorComponents()}.
* This field must contain valid color components of the waypoint
* even if this is not being used for rendering (i.e. {@link #getRenderColorComponents()} is overridden)
* since this field is used for serialization.
*/
public final float[] colorComponents;
public final float alpha;
public final float lineWidth;
public final boolean throughWalls;
private boolean enabled;

// region Constructors
public Waypoint(BlockPos pos, Type type, float[] colorComponents) {
this(pos, type, colorComponents, DEFAULT_HIGHLIGHT_ALPHA);
}
Expand Down Expand Up @@ -58,37 +72,77 @@ public Waypoint(BlockPos pos, Supplier<Type> typeSupplier, float[] colorComponen
this.throughWalls = throughWalls;
this.enabled = enabled;
}
// endregion

// region Withers
/**
* Subclasses should override this method to return a new instance of the subclass with the specified x pos.
*/
public Waypoint withX(int x) {
return new Waypoint(new BlockPos(x, pos.getY(), pos.getZ()), typeSupplier, colorComponents, alpha, lineWidth, throughWalls, enabled);
}

/**
* Subclasses should override this method to return a new instance of the subclass with the specified y pos.
*/
public Waypoint withY(int y) {
return new Waypoint(pos.withY(y), typeSupplier, colorComponents, alpha, lineWidth, throughWalls, enabled);
}

/**
* Subclasses should override this method to return a new instance of the subclass with the specified z pos.
*/
public Waypoint withZ(int z) {
return new Waypoint(new BlockPos(pos.getX(), pos.getY(), z), typeSupplier, colorComponents, alpha, lineWidth, throughWalls, enabled);
}

/**
* Subclasses should override this method to return a new instance of the subclass with the specified color components and alpha.
*/
public Waypoint withColor(float[] colorComponents, float alpha) {
return new Waypoint(pos, typeSupplier, colorComponents, alpha, lineWidth, throughWalls, enabled);
}
// endregion

// region Getters and Setters
/**
* Whether the waypoint should be rendered.
* <p>
* Override this method for custom behavior.
*/
public boolean shouldRender() {
return enabled;
}

/**
* Sets the waypoint as found and enabled as false.
* <p>
* Override this method for custom behavior.
*/
public void setFound() {
this.enabled = false;
}

/**
* Sets the waypoint as missing and enabled as true.
* <p>
* Override this method for custom behavior.
*/
public void setMissing() {
this.enabled = true;
}

/**
* Toggles the enabled state of the waypoint.
* <p>
* Override this method for custom behavior.
*/
public void toggle() {
this.enabled = !this.enabled;
if (enabled) {
setFound();
} else {
setMissing();
}
}

public final boolean isEnabled() {
Expand All @@ -98,11 +152,24 @@ public final boolean isEnabled() {
public final void setEnabled(boolean enabled) {
this.enabled = enabled;
}
// endregion

/**
* Returns the render time color components of the waypoint.
* <p>
* Override this method for custom behavior.
*/
public float[] getRenderColorComponents() {
return colorComponents;
}

/**
* Renders the waypoint.
* <p>
* Does not check if the waypoint {@link #shouldRender() should be rendered}.
* <p>
* Override this method for custom behavior.
*/
@Override
public void render(WorldRenderContext context) {
switch (typeSupplier.get()) {
Expand Down

0 comments on commit 00c33a8

Please sign in to comment.