diff options
author | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2023-10-23 14:51:57 -0400 |
---|---|---|
committer | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2023-10-28 00:51:23 -0400 |
commit | e00501cda9bec3da79896f098279c2f2a0f1a926 (patch) | |
tree | a141ae051f92203d60607c903806f1560d3fd82e /src/main/java/de/hysky | |
parent | 9edc4849a387aef3ac53d43573cfe53f5e06a5eb (diff) | |
download | Skyblocker-e00501cda9bec3da79896f098279c2f2a0f1a926.tar.gz Skyblocker-e00501cda9bec3da79896f098279c2f2a0f1a926.tar.bz2 Skyblocker-e00501cda9bec3da79896f098279c2f2a0f1a926.zip |
Abstract Waypoint
Diffstat (limited to 'src/main/java/de/hysky')
4 files changed, 112 insertions, 57 deletions
diff --git a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java index 51f3f098..8905644f 100644 --- a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java @@ -2,6 +2,7 @@ package de.hysky.skyblocker.config; import de.hysky.skyblocker.skyblock.item.CustomArmorTrims; import de.hysky.skyblocker.utils.chat.ChatFilterResult; +import de.hysky.skyblocker.utils.waypoint.Waypoint; import dev.isxander.yacl3.config.v2.api.SerialEntry; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; @@ -582,7 +583,7 @@ public class SkyblockerConfig { public boolean noInitSecretWaypoints = false; @SerialEntry - public WaypointType waypointType = WaypointType.WAYPOINT; + public Waypoint.Type waypointType = Waypoint.Type.WAYPOINT; @SerialEntry public boolean showSecretText = true; @@ -623,25 +624,6 @@ public class SkyblockerConfig { @SerialEntry public boolean enableDefaultWaypoints = true; } - - public enum WaypointType { - WAYPOINT, - OUTLINED_WAYPOINT, - HIGHLIGHT, - OUTLINED_HIGHLIGHT, - OUTLINE; - - @Override - public String toString() { - return switch (this) { - case WAYPOINT -> "Waypoint"; - case OUTLINED_WAYPOINT -> "Outlined Waypoint"; - case HIGHLIGHT -> "Highlight"; - case OUTLINED_HIGHLIGHT -> "Outlined Highlight"; - case OUTLINE -> "Outline"; - }; - } - } public static class DungeonChestProfit { @SerialEntry diff --git a/src/main/java/de/hysky/skyblocker/config/categories/DungeonsCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/DungeonsCategory.java index 2cdde89d..fdb13892 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/DungeonsCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/DungeonsCategory.java @@ -2,7 +2,7 @@ package de.hysky.skyblocker.config.categories; import de.hysky.skyblocker.config.ConfigUtils; import de.hysky.skyblocker.config.SkyblockerConfig; -import de.hysky.skyblocker.config.SkyblockerConfig.WaypointType; +import de.hysky.skyblocker.utils.waypoint.Waypoint.Type; import dev.isxander.yacl3.api.ButtonOption; import dev.isxander.yacl3.api.ConfigCategory; import dev.isxander.yacl3.api.Option; @@ -44,7 +44,7 @@ public class DungeonsCategory { .controller(ConfigUtils::createBooleanController) .flag(OptionFlag.GAME_RESTART) .build()) - .option(Option.<WaypointType>createBuilder() + .option(Option.<Type>createBuilder() .name(Text.translatable("text.autoconfig.skyblocker.option.locations.dungeons.secretWaypoints.waypointType")) .description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.locations.dungeons.secretWaypoints.waypointType.@Tooltip"))) .binding(defaults.locations.dungeons.secretWaypoints.waypointType, diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypoint.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypoint.java index a520c73f..72cc5ad8 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypoint.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypoint.java @@ -4,37 +4,35 @@ import com.google.gson.JsonObject; import de.hysky.skyblocker.config.SkyblockerConfig; import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.utils.render.RenderHelper; +import de.hysky.skyblocker.utils.waypoint.Waypoint; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.minecraft.client.MinecraftClient; import net.minecraft.entity.Entity; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Box; import net.minecraft.util.math.Vec3d; import java.util.List; import java.util.function.Predicate; +import java.util.function.Supplier; import java.util.function.ToDoubleFunction; -public class SecretWaypoint { - private static final float HIGHLIGHT_ALPHA = 0.5f; - private static final float LINE_WIDTH = 5f; +public class SecretWaypoint extends Waypoint { static final List<String> SECRET_ITEMS = List.of("Decoy", "Defuse Kit", "Dungeon Chest Key", "Healing VIII", "Inflatable Jerry", "Spirit Leap", "Training Weights", "Trap", "Treasure Talisman"); + private static final SkyblockerConfig.SecretWaypoints config = SkyblockerConfigManager.get().locations.dungeons.secretWaypoints; + private static final Supplier<Type> typeSupplier = () -> config.waypointType; final int secretIndex; final Category category; private final Text name; - private final BlockPos pos; private final Vec3d centerPos; - private boolean missing; SecretWaypoint(int secretIndex, JsonObject waypoint, String name, BlockPos pos) { + super(pos, typeSupplier, Category.get(waypoint).colorComponents); this.secretIndex = secretIndex; this.category = Category.get(waypoint); this.name = Text.of(name); - this.pos = pos; this.centerPos = pos.toCenterPos(); - this.missing = true; } static ToDoubleFunction<SecretWaypoint> getSquaredDistanceToFunction(Entity entity) { @@ -45,8 +43,9 @@ public class SecretWaypoint { return secretWaypoint -> entity.squaredDistanceTo(secretWaypoint.centerPos) <= 36D; } - boolean shouldRender() { - return category.isEnabled() && missing; + @Override + protected boolean shouldRender() { + return super.shouldRender() && category.isEnabled(); } boolean needsInteraction() { @@ -65,34 +64,13 @@ public class SecretWaypoint { return category.isBat(); } - void setFound() { - this.missing = false; - } - - void setMissing() { - this.missing = true; - } - /** * Renders the secret waypoint, including a filled cube, a beacon beam, the name, and the distance from the player. */ - void render(WorldRenderContext context) { - SkyblockerConfig.SecretWaypoints config = SkyblockerConfigManager.get().locations.dungeons.secretWaypoints; - - switch (config.waypointType) { - case WAYPOINT -> RenderHelper.renderFilledThroughWallsWithBeaconBeam(context, pos, category.colorComponents, HIGHLIGHT_ALPHA); - case OUTLINED_WAYPOINT -> { - RenderHelper.renderFilledThroughWallsWithBeaconBeam(context, pos, category.colorComponents, HIGHLIGHT_ALPHA); - RenderHelper.renderOutline(context, new Box(pos), category.colorComponents, LINE_WIDTH, true); - } - case HIGHLIGHT -> RenderHelper.renderFilledThroughWalls(context, pos, category.colorComponents, HIGHLIGHT_ALPHA); - case OUTLINED_HIGHLIGHT -> { - RenderHelper.renderFilledThroughWalls(context, pos, category.colorComponents, HIGHLIGHT_ALPHA); - RenderHelper.renderOutline(context, new Box(pos), category.colorComponents, LINE_WIDTH, true); - } - //TODO In the future, shrink the box for wither essence and items so its more realistic - case OUTLINE -> RenderHelper.renderOutline(context, new Box(pos), category.colorComponents, LINE_WIDTH, true); - } + @Override + protected void render(WorldRenderContext context) { + //TODO In the future, shrink the box for wither essence and items so its more realistic + super.render(context); if (config.showSecretText) { Vec3d posUp = centerPos.add(0, 1, 0); diff --git a/src/main/java/de/hysky/skyblocker/utils/waypoint/Waypoint.java b/src/main/java/de/hysky/skyblocker/utils/waypoint/Waypoint.java new file mode 100644 index 00000000..2cb37e6b --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/utils/waypoint/Waypoint.java @@ -0,0 +1,95 @@ +package de.hysky.skyblocker.utils.waypoint; + +import de.hysky.skyblocker.utils.render.RenderHelper; +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; + +import java.util.function.Supplier; + +public class Waypoint { + protected static final float DEFAULT_HIGHLIGHT_ALPHA = 0.5f; + protected static final float DEFAULT_LINE_WIDTH = 5f; + protected final BlockPos pos; + protected final Box box; + protected final Supplier<Type> typeSupplier; + protected final float[] colorComponents; + protected final float alpha; + protected final float lineWidth; + protected final boolean throughWalls; + protected boolean shouldRender; + + protected Waypoint(BlockPos pos, Supplier<Type> typeSupplier, float[] colorComponents) { + this(pos, typeSupplier, colorComponents, DEFAULT_HIGHLIGHT_ALPHA); + } + + protected Waypoint(BlockPos pos, Supplier<Type> typeSupplier, float[] colorComponents, float alpha) { + this(pos, typeSupplier, colorComponents, alpha, DEFAULT_LINE_WIDTH); + } + + protected Waypoint(BlockPos pos, Supplier<Type> typeSupplier, float[] colorComponents, float alpha, float lineWidth) { + this(pos, typeSupplier, colorComponents, alpha, lineWidth, true); + } + + protected Waypoint(BlockPos pos, Supplier<Type> typeSupplier, float[] colorComponents, float alpha, float lineWidth, boolean throughWalls) { + this(pos, typeSupplier, colorComponents, alpha, lineWidth, throughWalls, true); + } + + protected Waypoint(BlockPos pos, Supplier<Type> typeSupplier, float[] colorComponents, float alpha, float lineWidth, boolean throughWalls, boolean shouldRender) { + this.pos = pos; + this.box = new Box(pos); + this.typeSupplier = typeSupplier; + this.colorComponents = colorComponents; + this.alpha = alpha; + this.lineWidth = lineWidth; + this.throughWalls = throughWalls; + this.shouldRender = shouldRender; + } + + protected boolean shouldRender() { + return shouldRender; + } + + public void setFound() { + this.shouldRender = false; + } + + public void setMissing() { + this.shouldRender = true; + } + + protected void render(WorldRenderContext context) { + switch (typeSupplier.get()) { + case WAYPOINT -> RenderHelper.renderFilledThroughWallsWithBeaconBeam(context, pos, colorComponents, alpha); + case OUTLINED_WAYPOINT -> { + RenderHelper.renderFilledThroughWallsWithBeaconBeam(context, pos, colorComponents, alpha); + RenderHelper.renderOutline(context, box, colorComponents, lineWidth, throughWalls); + } + case HIGHLIGHT -> RenderHelper.renderFilledThroughWalls(context, pos, colorComponents, alpha); + case OUTLINED_HIGHLIGHT -> { + RenderHelper.renderFilledThroughWalls(context, pos, colorComponents, alpha); + RenderHelper.renderOutline(context, box, colorComponents, lineWidth, throughWalls); + } + case OUTLINE -> RenderHelper.renderOutline(context, box, colorComponents, lineWidth, throughWalls); + } + } + + public enum Type { + WAYPOINT, + OUTLINED_WAYPOINT, + HIGHLIGHT, + OUTLINED_HIGHLIGHT, + OUTLINE; + + @Override + public String toString() { + return switch (this) { + case WAYPOINT -> "Waypoint"; + case OUTLINED_WAYPOINT -> "Outlined Waypoint"; + case HIGHLIGHT -> "Highlight"; + case OUTLINED_HIGHLIGHT -> "Outlined Highlight"; + case OUTLINE -> "Outline"; + }; + } + } +} |