Skip to content

Commit

Permalink
[feature] compatibility with origin
Browse files Browse the repository at this point in the history
  • Loading branch information
afoxxvi committed May 27, 2024
1 parent 7046e58 commit 47679a5
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Common/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java'
id 'fabric-loom' version '1.5-SNAPSHOT'
id 'fabric-loom' version '1.6.11'
}

group = 'com.afoxxvi'
Expand Down
2 changes: 2 additions & 0 deletions Common/src/main/java/com/afoxxvi/asteorbar/AsteorBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public static class Compatibility {
public boolean origins = false;
public boolean tfc = false;
public boolean arsNouveau = false;
public boolean apoli = false;


public void init() {
Expand All @@ -73,6 +74,7 @@ public void init() {
origins = platformAdapter.isModLoaded("origins");
tfc = platformAdapter.isModLoaded("tfc");
arsNouveau = platformAdapter.isModLoaded("ars_nouveau");
apoli = platformAdapter.isModLoaded("apoli");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,6 @@ public interface ConfigAdapter {
boolean hookTFC();

boolean hookArsNouveau();

boolean hookApoli();
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,5 @@ public class ConfigComment {
public static final String hookOrigins = "Whether to hook Origins.";
public static final String hookTFC = "Whether to hook TFC.";
public static final String hookArsNouveau = "Whether to hook Ars Nouveau.";
public static final String hookApoli = "Whether to hook Apoli(Origins).";
}
Original file line number Diff line number Diff line change
Expand Up @@ -522,4 +522,9 @@ public boolean hookTFC() {
public boolean hookArsNouveau() {
return true;
}

@Override
public boolean hookApoli() {
return true;
}
}
3 changes: 2 additions & 1 deletion Common/src/main/resources/assets/asteorbar/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,6 @@
"text.autoconfig.asteorbar.option.hook.hookBotania": "Botania",
"text.autoconfig.asteorbar.option.hook.hookOrigins": "Origins",
"text.autoconfig.asteorbar.option.hook.hookTFC": "TerraFirmaCraft",
"text.autoconfig.asteorbar.option.hook.hookArsNouveau": "Ars Nouveau"
"text.autoconfig.asteorbar.option.hook.hookArsNouveau": "Ars Nouveau",
"text.autoconfig.asteorbar.option.hook.hookApoli": "Apoli(Origins)"
}
15 changes: 11 additions & 4 deletions Fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.5-SNAPSHOT'
id 'fabric-loom' version '1.6.11'
id 'maven-publish'
}

Expand All @@ -11,9 +11,9 @@ repositories {
// for more information about repositories.
maven { url "https://maven.shedaniel.me/" }
maven { url "https://maven.terraformersmc.com/releases/" }
maven {
url "https://cursemaven.com"
}
maven { url "https://cursemaven.com" }
maven { url "https://jitpack.io" }
maven { url 'https://maven.ladysnake.org/releases' }
}

loom {
Expand Down Expand Up @@ -44,6 +44,13 @@ dependencies {
if (appleskin_version_fabric != "0") {
modImplementation "curse.maven:appleskin-248787:${appleskin_version_fabric}"
}
if (origins_apoli_version_fabric != "0") {
modImplementation("com.github.apace100:apoli:${origins_apoli_version_fabric}") {
exclude(group: "org.quiltmc.parsers")
exclude(group: "maven.modrinth")
exclude(group: "com.jamieswhiteshirt")
}
}
}

compileJava {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,11 @@ public boolean hookArsNouveau() {
return config.hook.hookArsNouveau;
}

@Override
public boolean hookApoli() {
return config.hook.hookApoli;
}

public static void init() {
AutoConfig.register(FabricConfigAdapter.AsteorBarConfig.class, JanksonConfigSerializer::new);
holder = AutoConfig.getConfigHolder(FabricConfigAdapter.AsteorBarConfig.class);
Expand Down Expand Up @@ -763,6 +768,8 @@ static class HookConfig {
public boolean hookTFC = DefaultConfigAdapter.I.hookTFC();
@Comment(ConfigComment.hookArsNouveau)
public boolean hookArsNouveau = DefaultConfigAdapter.I.hookArsNouveau();
@Comment(ConfigComment.hookApoli)
public boolean hookApoli = DefaultConfigAdapter.I.hookApoli();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.afoxxvi.asteorbar.mixin.third;

import com.afoxxvi.asteorbar.AsteorBar;
import io.github.apace100.apoli.screen.PowerHudRenderer;
import net.minecraft.client.gui.GuiGraphics;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(PowerHudRenderer.class)
public abstract class OriginPowerHudMixin {
@Inject(method = "render(Lnet/minecraft/client/gui/GuiGraphics;F)V", at = @At("HEAD"), cancellable = true)
void render(GuiGraphics context, float delta, CallbackInfo ci) {
if (AsteorBar.config.enableOverlay() && AsteorBar.compatibility.apoli && AsteorBar.config.hookApoli()) {
ci.cancel();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.afoxxvi.asteorbar.overlay;

import com.afoxxvi.asteorbar.overlay.parts.BaseOverlay;
import com.afoxxvi.asteorbar.overlay.parts.OriginsOverlay;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
Expand All @@ -18,6 +19,7 @@ public class FabricGuiRegistry {
REGISTRY.add(Overlays.AIR_LEVEL);
REGISTRY.add(Overlays.EXPERIENCE_BAR);
REGISTRY.add(Overlays.ARMOR_LEVEL);
REGISTRY.add(new OriginsOverlay());
REGISTRY.add(Overlays.STRING);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.afoxxvi.asteorbar.overlay.parts;

import com.afoxxvi.asteorbar.AsteorBar;
import com.afoxxvi.asteorbar.overlay.RenderGui;
import com.afoxxvi.asteorbar.utils.GuiHelper;
import com.afoxxvi.asteorbar.utils.Utils;
import com.mojang.blaze3d.systems.RenderSystem;
import io.github.apace100.apoli.component.PowerHolderComponent;
import io.github.apace100.apoli.power.HudRendered;
import io.github.apace100.apoli.util.HudRender;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.world.entity.player.Player;

import java.util.Comparator;
import java.util.Map;
import java.util.Optional;

public class OriginsOverlay extends BaseOverlay {
private SimpleBarOverlay subOverlay = null;
private static final int BAR_WIDTH = 71;
private static final int BAR_HEIGHT = 8;
private static final int ICON_SIZE = 8;

private static final int BAR_INDEX_OFFSET = BAR_HEIGHT + 2;
private static final int ICON_INDEX_OFFSET = ICON_SIZE + 1;

@Override
public void renderOverlay(RenderGui gui, GuiGraphics guiGraphics, float partialTick, int screenWidth, int screenHeight) {
if (!(AsteorBar.compatibility.apoli && AsteorBar.config.hookApoli())) {
return;
}
final var player = Minecraft.getInstance().player;
if (player == null) {
return;
}
PowerHolderComponent.KEY.get(player).getPowers().stream().filter(HudRendered.class::isInstance).map(p -> (HudRendered) p).filter(HudRendered::shouldRender).map(h -> Map.entry(h, h.getRenderSettings().getChildOrSelf(player))).filter(entry -> entry.getValue().isPresent()).sorted(Map.Entry.comparingByValue(Comparator.comparing(Optional::get))).forEach(entry -> {
HudRendered hudRendered = entry.getKey();
HudRender hudRender = entry.getValue().get();
if (subOverlay == null) {
subOverlay = new OriginSimpleBar();
}
final var originSimpleBar = (OriginSimpleBar) subOverlay;
originSimpleBar.hudRender = hudRender;
originSimpleBar.hudRendered = hudRendered;
subOverlay.render(gui, guiGraphics, partialTick, screenWidth, screenHeight);
});
}

private static class OriginSimpleBar extends SimpleBarOverlay {
protected HudRender hudRender;
protected HudRendered hudRendered;

private static int getFillColor(int index) {
switch (index) {
case 0 -> {
return 0xffc78c79;
}
case 1 -> {
return 0xff385fff;
}
case 2 -> {
return 0xfffaff35;
}
case 3 -> {
return 0xffff33ea;
}
case 4, 5 -> {
return 0xffffffff;
}
case 6 -> {
return 0xff608d6f;
}
case 7 -> {
return 0xffffc650;
}
case 8 -> {
return 0xff339127;
}
default -> {
return 0xffe0e0e0;
}
}
}

@Override
protected Parameters getParameters(Player player) {
if (hudRendered == null || hudRender == null || hudRendered.getFill() == 0.0) {
return null;
}
Parameters parameters = new Parameters();
parameters.value = hudRendered.getFill();
parameters.capacity = 1.0F;
parameters.fillColor = getFillColor(hudRender.getBarIndex());
parameters.boundColor = Utils.mixColor(0xff000000, parameters.fillColor, 0.5F);
parameters.emptyColor = 0xff202c25;
return parameters;
}

@Override
protected void drawDecorations(GuiGraphics guiGraphics, int left, int top, int right, int bottom, Parameters parameters, boolean flip) {
int iconU = (BAR_WIDTH + 2) + hudRender.getIconIndex() * ICON_INDEX_OFFSET;
int barV = BAR_HEIGHT + hudRender.getBarIndex() * BAR_INDEX_OFFSET;
RenderSystem.setShaderTexture(0, hudRender.getSpriteLocation());
GuiHelper.drawTexturedRect(guiGraphics, (right + left) / 2 - ICON_SIZE / 2, (top + bottom) / 2 - ICON_SIZE / 2, iconU, barV, ICON_SIZE, ICON_SIZE);
RenderSystem.setShaderTexture(0, LIGHTMAP_TEXTURE);
}

@Override
protected boolean shouldRender(Player player) {
return true;
}
}
}
3 changes: 2 additions & 1 deletion Fabric/src/main/resources/asteorbar.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"client": [
"EntityMixin",
"GuiMixin",
"RenderTypeMixin"
"RenderTypeMixin",
"third.OriginPowerHudMixin"
],
"server": [],
"injectors": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public static class Config {
public static final ForgeConfigSpec.BooleanValue HOOK_ORIGINS;
public static final ForgeConfigSpec.BooleanValue HOOK_TFC;
public static final ForgeConfigSpec.BooleanValue HOOK_ARS_NOUVEAU;
public static final ForgeConfigSpec.BooleanValue HOOK_APOLI;


static {
Expand Down Expand Up @@ -522,6 +523,10 @@ public static class Config {
.comment(ConfigComment.hookArsNouveau)
.translation("text.autoconfig.asteorbar.option.hook.hookArsNouveau")
.define("arsNouveau", DefaultConfigAdapter.I.hookArsNouveau());
HOOK_APOLI = BUILDER
.comment(ConfigComment.hookApoli)
.translation("text.autoconfig.asteorbar.option.hook.hookApoli")
.define("apoli", DefaultConfigAdapter.I.hookApoli());
BUILDER.pop();
}

Expand Down Expand Up @@ -1051,4 +1056,9 @@ public boolean hookArsNouveau() {
return Config.HOOK_ARS_NOUVEAU.get();
}

@Override
public boolean hookApoli() {
return Config.HOOK_APOLI.get();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public static class Config {
public static final ModConfigSpec.BooleanValue HOOK_ORIGINS;
public static final ModConfigSpec.BooleanValue HOOK_TFC;
public static final ModConfigSpec.BooleanValue HOOK_ARS_NOUVEAU;
public static final ModConfigSpec.BooleanValue HOOK_APOLI;

static {
BUILDER.push("overlay");
Expand Down Expand Up @@ -521,6 +522,10 @@ public static class Config {
.comment(ConfigComment.hookArsNouveau)
.translation("text.autoconfig.asteorbar.option.hook.hookArsNouveau")
.define("arsNouveau", DefaultConfigAdapter.I.hookArsNouveau());
HOOK_APOLI = BUILDER
.comment(ConfigComment.hookApoli)
.translation("text.autoconfig.asteorbar.option.hook.hookApoli")
.define("apoli", DefaultConfigAdapter.I.hookApoli());
BUILDER.pop();
}

Expand Down Expand Up @@ -1050,4 +1055,9 @@ public boolean hookArsNouveau() {
return Config.HOOK_ARS_NOUVEAU.get();
}

@Override
public boolean hookApoli() {
return Config.HOOK_APOLI.get();
}

}
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx1G
mod_id=asteorbar
mod_name=AsteorBar
mod_license=All-Rights-Reserved
mod_version=1.4.5
mod_version=1.4.6
mod_group_id=com.afoxxvi
mod_authors=AsteorFox(afoxxvi)
mod_description=
Expand Down Expand Up @@ -48,3 +48,4 @@ botania_version_forge=0
terrafirmacraft_version_forge=0
ars_nouveau_version_forge=0
origins_version_forge=0
origins_apoli_version_fabric=2.11.11
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Feb 17 16:06:01 GMT+08:00 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit 47679a5

Please sign in to comment.