Skip to content

Commit

Permalink
Add Pehkui API event bridge
Browse files Browse the repository at this point in the history
Relates to #829
  • Loading branch information
Su5eD committed Mar 5, 2024
1 parent 5b22b01 commit 9a9680e
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 20 deletions.
4 changes: 0 additions & 4 deletions architectury-bridge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ repositories {
name = "Architectury"
url = uri("https://maven.architectury.dev")
}
maven {
name = "Cursemaven"
url = uri("https://cursemaven.com")
}
}

dependencies {
Expand Down
17 changes: 10 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ allprojects {
name = "Sinytra"
url = uri("https://maven.su5ed.dev/releases")
}
maven {
name = "CurseMaven"
url = uri("https://cursemaven.com")
content {
includeGroup("curse.maven")
}
}
}

dependencies {
Expand Down Expand Up @@ -92,13 +99,6 @@ configurations.runtimeElements {
setExtendsFrom(listOf(configurations.include.get()))
}

repositories {
maven {
name = "Cursemaven"
url = uri("https://cursemaven.com")
}
}

dependencies {
mappings(loom.officialMojangMappings())
forge("net.minecraftforge:forge:$versionMc-$versionForge")
Expand All @@ -117,6 +117,7 @@ dependencies {
includeProject("extras-utils")
includeProject("kubejs-bridge")
includeProject("jei-bridge")
includeProject("pehkui-bridge")

// Misc
modImplementation("curse.maven:mcpitanlibarch-682213:4723157")
Expand Down Expand Up @@ -201,6 +202,7 @@ publishMods {
optional { slug.set("continuity") }
optional { slug.set("kubejs") }
optional { slug.set("jei") }
optional { slug.set("pehkui") }
}
modrinth {
accessToken.set(providers.environmentVariable("MODRINTH_TOKEN"))
Expand All @@ -217,5 +219,6 @@ publishMods {
optional { id.set("1IjD5062") } // Continuity
optional { id.set("umyGl7zF") } // KubeJS
optional { id.set("u6dRKJwZ") } // JEI
optional { id.set("t5W7Jfwy") } // Pehkui
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fabric.loom.multiProjectOptimisation=true
# Versions
versionMc=1.20.1
versionForge=47.1.3
versionConnectorExtras=1.9.3
versionConnectorExtras=1.10.0
versionYarn=1.20.1+build.1

# Publishing
Expand Down
7 changes: 0 additions & 7 deletions intermediary-deobf/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ repositories {
name = "GeckoLib"
url = uri("https://dl.cloudsmith.io/public/geckolib3/geckolib/maven")
}
maven {
name = "CurseMaven"
url = uri("https://cursemaven.com")
content {
includeGroup("curse.maven")
}
}
}

dependencies {
Expand Down
24 changes: 24 additions & 0 deletions pehkui-bridge/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
plugins {
id("dev.architectury.loom")
}

val versionMc: String by rootProject
val versionForge: String by rootProject

loom {
forge {
mixinConfig("mixins.pehkuibridge.json")
}
mixin {
defaultRefmapName.set("refmap.pehkuibridge.json")
}
}

dependencies {
mappings(loom.officialMojangMappings())
forge("net.minecraftforge:forge:$versionMc-$versionForge")

modImplementation(group = "dev.su5ed.sinytra.fabric-api", name = "fabric-api-base", version = "0.4.31+ef105b4977")

modImplementation(group = "curse.maven", name = "pehkui-319596", version = "4974824")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dev.su5ed.sinytra.connectorextras.pehkuibridge;

import net.minecraftforge.fml.common.Mod;

@Mod("connectorextras_pehkui_bridge")
public class PehkuiBridge {
public static final String PEHKUI_MODID = "pehkui";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package dev.su5ed.sinytra.connectorextras.pehkuibridge;

import com.google.common.base.Suppliers;
import net.minecraftforge.fml.loading.LoadingModList;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.List;
import java.util.Set;
import java.util.function.Supplier;

public class PehkuiBridgeMixinPlugin implements IMixinConfigPlugin {
private static final Supplier<Boolean> PEHKUI_LOADED = Suppliers.memoize(() -> LoadingModList.get().getModFileById(PehkuiBridge.PEHKUI_MODID) != null);

@Override
public void onLoad(String mixinPackage) {}

@Override
public String getRefMapperConfig() {
return null;
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return PEHKUI_LOADED.get();
}

@Override
public List<String> getMixins() {
return null;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package dev.su5ed.sinytra.connectorextras.pehkuibridge.mixin;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import virtuoel.pehkui.api.ScaleEventCallback;
import virtuoel.pehkui.api.ScaleType;

@Mixin(ScaleType.class)
public class ScaleTypeMixin {
@Unique
private Event<ScaleEventCallback> connectorextras_scaleTypeChangedEvent;
@Unique
private Event<ScaleEventCallback> connectorextras_preTickChangedEvent = connector_createScaleEvent();
@Unique
private Event<ScaleEventCallback> connectorextras_postTickChangedEvent = connector_createScaleEvent();

@Inject(method = "<init>", at = @At("TAIL"))
private void onInit(ScaleType.Builder builder, CallbackInfo ci) {
this.connectorextras_scaleTypeChangedEvent = connector_createScaleEvent();
this.connectorextras_preTickChangedEvent = connector_createScaleEvent();
this.connectorextras_postTickChangedEvent = connector_createScaleEvent();
((ScaleType) (Object) this).getScaleChangedEvent().add(data -> connectorextras_scaleTypeChangedEvent.invoker().onEvent(data));
((ScaleType) (Object) this).getPreTickEvent().add(data -> connectorextras_preTickChangedEvent.invoker().onEvent(data));
((ScaleType) (Object) this).getPostTickEvent().add(data -> connectorextras_postTickChangedEvent.invoker().onEvent(data));
}

@Unique
public Event<ScaleEventCallback> getScaleChangedEvent() {
return this.connectorextras_scaleTypeChangedEvent;
}

@Unique
public Event<ScaleEventCallback> getPreTickEvent() {
return this.connectorextras_preTickChangedEvent;
}

@Unique
public Event<ScaleEventCallback> getPostTickEvent() {
return this.connectorextras_postTickChangedEvent;
}

@Unique
private static Event<ScaleEventCallback> connector_createScaleEvent() {
return EventFactory.createArrayBacked(
ScaleEventCallback.class,
data -> {
},
callbacks -> data ->
{
for (ScaleEventCallback callback : callbacks) {
callback.onEvent(data);
}
}
);
}
}
27 changes: 27 additions & 0 deletions pehkui-bridge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
modLoader="javafml"
loaderVersion="[47,)"
license="MIT"
issueTrackerURL="https://github.com/Sinytra/ConnectorExtras/issues"

[[mods]]
modId="connectorextras_pehkui_bridge"
version="${file.jarVersion}"
displayName="Connector Extras Pehkui Bridge"
authors="Su5eD"
displayURL="https://github.com/Sinytra/ConnectorExtras"
description='''
Compatibility bridge for Pehkui's Fabric API on Forge
'''
displayTest = 'IGNORE_ALL_VERSION'
[[dependencies.connectorextras_pehkui_bridge]]
modId="forge"
mandatory=true
versionRange="[47,)"
ordering="NONE"
side="BOTH"
[[dependencies.connectorextras_pehkui_bridge]]
modId="minecraft"
mandatory=true
versionRange="[1.20.1,1.21)"
ordering="NONE"
side="BOTH"
10 changes: 10 additions & 0 deletions pehkui-bridge/src/main/resources/mixins.pehkuibridge.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"minVersion": "0.8",
"compatibilityLevel": "JAVA_16",
"required": true,
"package": "dev.su5ed.sinytra.connectorextras.pehkuibridge.mixin",
"plugin": "dev.su5ed.sinytra.connectorextras.pehkuibridge.PehkuiBridgeMixinPlugin",
"mixins": [
"ScaleTypeMixin"
]
}
6 changes: 6 additions & 0 deletions pehkui-bridge/src/main/resources/pack.mcmeta
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pack": {
"description": "The default data for pehkuibridge",
"pack_format": 15
}
}
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ include(
"forgeconfigapiport",
"extras-utils",
"kubejs-bridge",
"jei-bridge"
"jei-bridge",
"pehkui-bridge"
)

0 comments on commit 9a9680e

Please sign in to comment.