Skip to content

Commit

Permalink
Add the HUD further
Browse files Browse the repository at this point in the history
  • Loading branch information
sddsd2332 committed Jan 9, 2025
1 parent 0d29871 commit 73a7671
Show file tree
Hide file tree
Showing 43 changed files with 2,285 additions and 86 deletions.
16 changes: 16 additions & 0 deletions src/main/java/mekanism/api/AutomationType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package mekanism.api;

public enum AutomationType {
/**
* External interaction (third party interacting with a machine)
*/
EXTERNAL,
/**
* Internal interaction (machine interacting with its own contents)
*/
INTERNAL,
/**
* Manual interaction (player interacting manually, such as in a GUI)
*/
MANUAL;
}
36 changes: 18 additions & 18 deletions src/main/java/mekanism/api/EnumColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@
* @author AidanBrady
*/
public enum EnumColor implements IStringSerializable {
BLACK("\u00a70", "black", "Black", new int[]{0, 0, 0}, 0, TextFormatting.BLACK),
DARK_BLUE("\u00a71", "darkBlue", "Blue", new int[]{0, 0, 170}, 4, TextFormatting.DARK_BLUE),
DARK_GREEN("\u00a72", "darkGreen", "Green", new int[]{0, 170, 0}, 2, TextFormatting.DARK_GREEN),
DARK_AQUA("\u00a73", "darkAqua", "Cyan", new int[]{0, 255, 255}, 6, TextFormatting.DARK_AQUA),
DARK_RED("\u00a74", "darkRed", null, new int[]{170, 0, 0}, -1, TextFormatting.DARK_RED),
PURPLE("\u00a75", "purple", "Purple", new int[]{170, 0, 170}, 5, TextFormatting.DARK_PURPLE),
ORANGE("\u00a76", "orange", "Orange", new int[]{255, 170, 0}, 14, TextFormatting.GOLD),
GREY("\u00a77", "grey", "LightGray", new int[]{170, 170, 170}, 7, TextFormatting.GRAY),
DARK_GREY("\u00a78", "darkGrey", "Gray", new int[]{85, 85, 85}, 8, TextFormatting.DARK_GRAY),
INDIGO("\u00a79", "indigo", "LightBlue", new int[]{85, 85, 255}, 12, TextFormatting.BLUE),
BRIGHT_GREEN("\u00a7a", "brightGreen", "Lime", new int[]{85, 255, 85}, 10, TextFormatting.GREEN),
AQUA("\u00a7b", "aqua", null, new int[]{85, 255, 255}, -1, TextFormatting.AQUA),
RED("\u00a7c", "red", "Red", new int[]{255, 0, 0}, 1, TextFormatting.RED),
PINK("\u00a7d", "pink", "Magenta", new int[]{255, 85, 255}, 13, TextFormatting.LIGHT_PURPLE),
YELLOW("\u00a7e", "yellow", "Yellow", new int[]{255, 255, 85}, 11, TextFormatting.YELLOW),
WHITE("\u00a7f", "white", "White", new int[]{255, 255, 255}, 15, TextFormatting.WHITE),
BLACK("§0", "black", "Black", new int[]{0, 0, 0}, 0, TextFormatting.BLACK),
DARK_BLUE("§1", "darkBlue", "Blue", new int[]{0, 0, 170}, 4, TextFormatting.DARK_BLUE),
DARK_GREEN("§2", "darkGreen", "Green", new int[]{0, 170, 0}, 2, TextFormatting.DARK_GREEN),
DARK_AQUA("§3", "darkAqua", "Cyan", new int[]{0, 255, 255}, 6, TextFormatting.DARK_AQUA),
DARK_RED("§4", "darkRed", null, new int[]{170, 0, 0}, -1, TextFormatting.DARK_RED),
PURPLE("§5", "purple", "Purple", new int[]{170, 0, 170}, 5, TextFormatting.DARK_PURPLE),
ORANGE("§6", "orange", "Orange", new int[]{255, 170, 0}, 14, TextFormatting.GOLD),
GREY("§7", "grey", "LightGray", new int[]{170, 170, 170}, 7, TextFormatting.GRAY),
DARK_GREY("§8", "darkGrey", "Gray", new int[]{85, 85, 85}, 8, TextFormatting.DARK_GRAY),
INDIGO("§9", "indigo", "LightBlue", new int[]{85, 85, 255}, 12, TextFormatting.BLUE),
BRIGHT_GREEN("§a", "brightGreen", "Lime", new int[]{85, 255, 85}, 10, TextFormatting.GREEN),
AQUA("§b", "aqua", null, new int[]{85, 255, 255}, -1, TextFormatting.AQUA),
RED("§c", "red", "Red", new int[]{255, 0, 0}, 1, TextFormatting.RED),
PINK("§d", "pink", "Magenta", new int[]{255, 85, 255}, 13, TextFormatting.LIGHT_PURPLE),
YELLOW("§e", "yellow", "Yellow", new int[]{255, 255, 85}, 11, TextFormatting.YELLOW),
WHITE("§f", "white", "White", new int[]{255, 255, 255}, 15, TextFormatting.WHITE),
//Extras for dye-completeness
BROWN("\u00a76", "brown", "Brown", new int[]{150, 75, 0}, 3, TextFormatting.GOLD),
BRIGHT_PINK("\u00a7d", "brightPink", "Pink", new int[]{255, 192, 203}, 9, TextFormatting.LIGHT_PURPLE);
BROWN("§6", "brown", "Brown", new int[]{150, 75, 0}, 3, TextFormatting.GOLD),
BRIGHT_PINK("§d", "brightPink", "Pink", new int[]{255, 192, 203}, 9, TextFormatting.LIGHT_PURPLE);

public static EnumColor[] DYES = new EnumColor[]{BLACK, RED, DARK_GREEN, BROWN, DARK_BLUE, PURPLE, DARK_AQUA, GREY, DARK_GREY, BRIGHT_PINK, BRIGHT_GREEN, YELLOW,
INDIGO, PINK, ORANGE, WHITE};
Expand Down
114 changes: 114 additions & 0 deletions src/main/java/mekanism/api/IIncrementalEnum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package mekanism.api;

import java.util.function.Predicate;
import mekanism.api.annotations.NothingNullByDefault;
import mekanism.api.functions.ConstantPredicates;

/**
* Interface for enum's to make them easily incremental
*/
@NothingNullByDefault
public interface IIncrementalEnum<TYPE extends Enum<TYPE> & IIncrementalEnum<TYPE>> {

/**
* Gets the next "valid" element
*
* @param isValid Predicate defining if an element is valid
*
* @return The next "valid" element
*/
default TYPE getNext(Predicate<TYPE> isValid) {
TYPE next = byIndex(ordinal() + 1);
while (!isValid.test(next)) {
if (next == this) {
//Don't loop forever, and just return our self instead given we got back to our self
return next;
}
next = byIndex(next.ordinal() + 1);
}
//Once we break out of the loop we know we have a valid entry
return next;
}

/**
* Gets the previous "valid" element
*
* @param isValid Predicate defining if an element is valid
*
* @return The previous "valid" element
*/
default TYPE getPrevious(Predicate<TYPE> isValid) {
TYPE previous = byIndex(ordinal() - 1);
while (!isValid.test(previous)) {
if (previous == this) {
//Don't loop forever, and just return our self instead given we got back to our self
return previous;
}
previous = byIndex(previous.ordinal() - 1);
}
//Once we break out of the loop we know we have a valid entry
return previous;
}

/**
* Helper method to get a value by index rather than having to duplicate all the previous/next logic.
*/
TYPE byIndex(int index);

/**
* {@link Enum#ordinal()}
*/
int ordinal();

/**
* Gets the next "valid" element
*
* @return The next "valid" element
*/
default TYPE getNext() {
return getNext(ConstantPredicates.alwaysTrue());
}

/**
* Gets the previous "valid" element
*
* @return The previous "valid" element
*/
default TYPE getPrevious() {
return getPrevious(ConstantPredicates.alwaysTrue());
}

/**
* Gets the "valid" element that is offset by the given shift
*
* @param shift Shift to perform, may be negative to indicate going backwards
*
* @return The "valid" element that is offset by the given shift
*
* @implNote Default implementation assumes all elements are "valid", override this if that is not the case.
*/
default TYPE adjust(int shift) {
return shift == 0 ? (TYPE) this : byIndex(ordinal() + shift);
}

/**
* Gets the "valid" element that is offset by the given shift with the given validity predicate.
*
* @param shift Shift to perform, may be negative to indicate going backwards
* @param isValid Predicate defining if an element is valid
*
* @return The "valid" element that is offset by the given shift. If no elements are "valid" returns the current element.
*/
default TYPE adjust(int shift, Predicate<TYPE> isValid) {
TYPE result = (TYPE) this;
while (shift < 0) {
shift++;
result = result.getPrevious(isValid);
}
while (shift > 0) {
shift--;
result = result.getNext(isValid);
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package mekanism.api.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierDefault;
import org.jetbrains.annotations.NotNull;

/**
* Interface to declare that all fields in a class are {@link @NotNull}
*/
@NotNull
@Nonnull//Note: Must use the javax nonnull for intellij to recognize it properly in warnings
@TypeQualifierDefault(ElementType.FIELD)
@Retention(RetentionPolicy.CLASS)
public @interface FieldsAreNotNullByDefault {
}
15 changes: 15 additions & 0 deletions src/main/java/mekanism/api/annotations/NonNullSupplier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package mekanism.api.annotations;

import org.jetbrains.annotations.NotNull;
import java.util.function.Supplier;

/**
* Equivalent to {@link Supplier}, except with nonnull contract.
*
* @see Supplier
*/
@FunctionalInterface
public interface NonNullSupplier<T>
{
@NotNull T get();
}
18 changes: 18 additions & 0 deletions src/main/java/mekanism/api/annotations/NothingNullByDefault.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package mekanism.api.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierDefault;
import org.jetbrains.annotations.NotNull;

/**
* Interface to declare that all fields, methods, and parameters in a class are {@link @NotNull}
*/
@NotNull
@Nonnull//Note: Must use the javax nonnull for intellij to recognize it properly in override warnings
@TypeQualifierDefault({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
@Retention(RetentionPolicy.CLASS)
public @interface NothingNullByDefault {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package mekanism.api.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierDefault;
import org.jetbrains.annotations.NotNull;

/**
* Interface to declare that all parameters in a class are {@link @NotNull}
*/
@NotNull
@Nonnull//Note: Must use the javax nonnull for intellij to recognize it properly in warnings
@TypeQualifierDefault(ElementType.PARAMETER)
@Retention(RetentionPolicy.CLASS)
public @interface ParametersAreNotNullByDefault {
}
4 changes: 4 additions & 0 deletions src/main/java/mekanism/api/energy/IEnergizedItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ public interface IEnergizedItem {
* @return if the item can send energy
*/
boolean canSend(ItemStack itemStack);

default double getEnergyRatio(ItemStack stack) {
return getEnergy(stack) / getMaxEnergy(stack);
}
}
87 changes: 87 additions & 0 deletions src/main/java/mekanism/api/functions/ConstantPredicates.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package mekanism.api.functions;

import java.util.function.BiPredicate;
import java.util.function.Predicate;
import mekanism.api.AutomationType;
import org.jetbrains.annotations.NotNull;

/**
* Helper class to reduce having to create duplicate objects for constant predicates.
*/
@SuppressWarnings("unchecked")
public class ConstantPredicates {

private ConstantPredicates() {
}

private static final Predicate<Object> alwaysTrue = t -> true;
private static final BiPredicate<Object, Object> alwaysTrueBi = (t, u) -> true;
private static final TriPredicate<Object, Object, Object> alwaysTrueTri = (t, u, v) -> true;

private static final Predicate<Object> alwaysFalse = t -> false;
private static final BiPredicate<Object, Object> alwaysFalseBi = (t, u) -> false;
private static final TriPredicate<Object, Object, Object> alwaysFalseTri = (t, u, v) -> false;

private static final BiPredicate<Object, @NotNull AutomationType> internalOnly = (t, automationType) -> automationType == AutomationType.INTERNAL;
private static final BiPredicate<Object, @NotNull AutomationType> notExternal = (t, automationType) -> automationType != AutomationType.EXTERNAL;

/**
* Returns a predicate that returns {@code true} for any input.
*/
public static <T> Predicate<T> alwaysTrue() {
return (Predicate<T>) alwaysTrue;
}

/**
* Returns a bi predicate that returns {@code true} for any input.
*/
public static <T, U> BiPredicate<T, U> alwaysTrueBi() {
return (BiPredicate<T, U>) alwaysTrueBi;
}

/**
* Returns a tri predicate that returns {@code true} for any input.
*/
public static <T, U, V> TriPredicate<T, U, V> alwaysTrueTri() {
return (TriPredicate<T, U, V>) alwaysTrueTri;
}

/**
* Returns a predicate that returns {@code false} for any input.
*/
public static <T> Predicate<T> alwaysFalse() {
return (Predicate<T>) alwaysFalse;
}

/**
* Returns a bi predicate that returns {@code false} for any input.
*/
public static <T, V> BiPredicate<T, V> alwaysFalseBi() {
return (BiPredicate<T, V>) alwaysFalseBi;
}

/**
* Returns a tri predicate that returns {@code false} for any input.
*/
public static <T, U, V> TriPredicate<T, U, V> alwaysFalseTri() {
return (TriPredicate<T, U, V>) alwaysFalseTri;
}

/**
* Returns a bi predicate that returns {@code true} for any input when the automation type is internal.
*
* @since 10.3.3
*/
public static <T> BiPredicate<T, @NotNull AutomationType> internalOnly() {
return (BiPredicate<T, @NotNull AutomationType>) internalOnly;
}

/**
* Returns a bi predicate that returns {@code true} for any input when the automation type is not external.
*
* @since 10.3.3
*/
public static <T> BiPredicate<T, @NotNull AutomationType> notExternal() {
return (BiPredicate<T, @NotNull AutomationType>) notExternal;
}
}
23 changes: 23 additions & 0 deletions src/main/java/mekanism/api/functions/FloatSupplier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package mekanism.api.functions;

import java.util.function.Supplier;

/**
* Represents a supplier of {@code float}-valued results. This is the {@code float}-producing primitive specialization of {@link Supplier}.
*
* <p>There is no requirement that a new or distinct result be returned each time the supplier is invoked.
*
* <p>This is a <a href="package-summary.html">functional interface</a> whose functional method is {@link #getAsFloat()}.
*
* @see Supplier
*/
@FunctionalInterface
public interface FloatSupplier {

/**
* Gets a result.
*
* @return a result
*/
float getAsFloat();
}
Loading

0 comments on commit 73a7671

Please sign in to comment.