Skip to content

Commit

Permalink
add figura integration (closes #44)
Browse files Browse the repository at this point in the history
  • Loading branch information
UpcraftLP committed Apr 20, 2024
1 parent 342740f commit 32b6dd1
Show file tree
Hide file tree
Showing 13 changed files with 197 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ dependencies {
implementation libs.resourcefulconfig
implementation libs.commonnetworking

compileOnly libs.figura
compileOnly libs.bundles.figura.runtime

// compileOnly "${libs.emi.asProvider().get()}:api"
}
13 changes: 13 additions & 0 deletions Common/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ commonnetworking = "1.0.2-1.20.1"
resourcefulconfig = "2.1.2"
emi = "1.1.4+1.20.1"

figura = "0.1.4+1.20.1"
luaj = "3.0.8-figura"
nv_websocket = "2.14"

[libraries]
minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" }
parchment_mappings = { module = "org.parchmentmc.data:parchment-1.20.1", version.ref = "parchment" }
Expand All @@ -39,8 +43,17 @@ emi = { module = "dev.emi:emi-xplat-mojmap", version.ref = "emi" }
emi_neoforge = { module = "dev.emi:emi-neoforge", version.ref = "emi" }
emi_fabric = { module = "dev.emi:emi-fabric", version.ref = "emi" }

figura = { module = "org.figuramc:figura-common-mojmap", version.ref = "figura" }
figura_forge = { module = "org.figuramc:figura-forge", version.ref = "figura" }
figura_fabric = { module = "org.figuramc:figura-fabric", version.ref = "figura" }

luaj_core = { module = "com.github.FiguraMC.luaj:luaj-core", version.ref = "luaj" }
luaj_jse = { module = "com.github.FiguraMC.luaj:luaj-jse", version.ref = "luaj" }
nv_websocket = { module = "com.neovisionaries:nv-websocket-client", version.ref = "nv_websocket" }

[bundles]
mixin = ["mixin", "mixin_extras", "asm", "asm_analysis", "asm_commons", "asm_tree", "asm_util"]
figura_runtime = ["luaj_core", "luaj_jse", "nv_websocket"]

[plugins]
vanilla_gradle = { id = "org.spongepowered.gradle.vanilla", version.ref = "vanilla_gradle" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.cammiescorner.icarus.api.client;

import dev.cammiescorner.icarus.client.IcarusClient;
import net.minecraft.world.entity.LivingEntity;

import java.util.function.Predicate;

public class IcarusAPIClient {

public static void addRenderPredicate(Predicate<LivingEntity> predicate) {
IcarusClient.addRenderPredicate(predicate);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package dev.cammiescorner.icarus.client;

import dev.cammiescorner.icarus.util.IcarusHelper;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import org.jetbrains.annotations.ApiStatus;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

public class IcarusClient {
public static float wingSpeed;
public static float maxSlowedMultiplier;
public static boolean armorSlows;
public static boolean canLoopDeLoop;

private static final List<Predicate<LivingEntity>> renderPredicates = new ArrayList<>();

public static void onPlayerTick(Player player) {
if (player.isFallFlying() && IcarusHelper.hasWings.test(player) && player.zza > 0) {
var rotation = player.getLookAngle();
Expand All @@ -21,4 +29,20 @@ public static void onPlayerTick(Player player) {
rotation.z * speed + (rotation.z * 1.5D - velocity.z) * speed));
}
}

@ApiStatus.Internal
public static void addRenderPredicate(Predicate<LivingEntity> predicate) {
renderPredicates.add(predicate);
}

public static boolean shouldRenderWings(LivingEntity entity) {
if (!renderPredicates.isEmpty()) {
for (Predicate<LivingEntity> predicate : renderPredicates) {
if (!predicate.test(entity)) {
return false;
}
}
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import dev.cammiescorner.icarus.client.IcarusClient;
import dev.cammiescorner.icarus.client.IcarusModels;
import dev.cammiescorner.icarus.client.models.*;
import dev.cammiescorner.icarus.init.IcarusItems;
Expand Down Expand Up @@ -43,7 +44,7 @@ public WingsLayer(RenderLayerParent<T, M> context, EntityModelSet loader) {
public void render(PoseStack matrices, MultiBufferSource vertexConsumers, int light, T entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
var stack = IcarusHelper.getEquippedWings.apply(entity);

if (stack.getItem() instanceof WingItem wingItem) {
if (stack.getItem() instanceof WingItem wingItem && IcarusClient.shouldRenderWings(entity)) {
float[] primaryColour = wingItem.getPrimaryColor(stack).getTextureDiffuseColors();
float[] secondaryColour = wingItem.getSecondaryColor(stack).getTextureDiffuseColors();
float r1 = primaryColour[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dev.cammiescorner.icarus.integration.figura;

import com.mojang.datafixers.util.Pair;
import dev.cammiescorner.icarus.Icarus;
import dev.cammiescorner.icarus.client.models.WingEntityModel;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.model.geom.ModelPart;
import org.figuramc.figura.entries.FiguraVanillaPart;
import org.figuramc.figura.entries.annotations.FiguraVanillaPartPlugin;

import java.util.Collection;
import java.util.List;
import java.util.function.Function;

@SuppressWarnings("unused")
@FiguraVanillaPartPlugin
public class IcarusFiguraModelPartsPlugin implements FiguraVanillaPart {

@Override
public String getID() {
return Icarus.MODID;
}

@Override
public Collection<Pair<String, Function<EntityModel<?>, ModelPart>>> getParts() {
return List.of(
new Pair<>("right_wing", model -> model instanceof WingEntityModel<?> wingModel ? wingModel.rightWing : null),
new Pair<>("left_wing", model -> model instanceof WingEntityModel<?> wingModel ? wingModel.leftWing : null)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package dev.cammiescorner.icarus.integration.figura;

import dev.cammiescorner.icarus.Icarus;
import dev.cammiescorner.icarus.api.client.IcarusAPIClient;
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
import net.minecraft.world.entity.LivingEntity;
import org.figuramc.figura.avatar.Avatar;
import org.figuramc.figura.entries.FiguraAPI;
import org.figuramc.figura.entries.annotations.FiguraAPIPlugin;
import org.figuramc.figura.lua.LuaWhitelist;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.List;
import java.util.UUID;

@SuppressWarnings("unused")
@LuaWhitelist
@FiguraAPIPlugin
public class IcarusFiguraPlugin implements FiguraAPI {

private static final Object2BooleanMap<UUID> WINGS_VISIBLE = new Object2BooleanOpenHashMap<>();
@NotNull
private final Avatar avatar;

// needed because this class is instantiated via reflection.
// honestly this API is pretty bad.
@SuppressWarnings({"unused", "DataFlowIssue"})
public IcarusFiguraPlugin() {
this.avatar = null;
}

static {
IcarusAPIClient.addRenderPredicate(IcarusFiguraPlugin::shouldRenderWings);
}

public IcarusFiguraPlugin(Avatar avatar) {
this.avatar = avatar;
}

@LuaWhitelist
public boolean areWingsVisible() {
return WINGS_VISIBLE.getOrDefault(avatar.owner, true);
}

@LuaWhitelist
public void setWingsVisible(boolean visible) {
WINGS_VISIBLE.put(avatar.owner, visible);
}

@Override
public FiguraAPI build(Avatar avatar) {
return new IcarusFiguraPlugin(avatar);
}

@Override
public String getName() {
return Icarus.MODID;
}

@Override
public Collection<Class<?>> getWhitelistedClasses() {
return List.of(IcarusFiguraPlugin.class);
}

@Override
public Collection<Class<?>> getDocsClasses() {
return List.of();
}

private static boolean shouldRenderWings(LivingEntity entity) {
return WINGS_VISIBLE.getOrDefault(entity.getUUID(), true);
}
}
4 changes: 4 additions & 0 deletions Fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ dependencies {
// modLocalRuntime fabric.cameraoverhaul
// modLocalRuntime fabric.cloth

modCompileOnly libs.figura.fabric
modLocalRuntime libs.figura.fabric
localRuntime libs.bundles.figura.runtime

// modCompileOnly "${libs.emi.fabric.get()}:api"
}

Expand Down
6 changes: 6 additions & 0 deletions Fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
],
"modmenu": [
"dev.cammiescorner.icarus.fabric.entrypoints.Modmenu"
],
"figura_api": [
"dev.cammiescorner.icarus.integration.figura.IcarusFiguraPlugin"
],
"figura_vanilla_part": [
"dev.cammiescorner.icarus.integration.figura.IcarusFiguraModelPartsPlugin"
]
},
"mixins": [
Expand Down
3 changes: 3 additions & 0 deletions NeoForge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ dependencies {
// NOT UPDATED YET!
// runtimeOnly fg.deobf(neoforge.cameraoverhaul.get())

compileOnly fg.deobf(libs.figura.forge.get())
// runtimeOnly fg.deobf(libs.figura.forge.get())

// compileOnly "${libs.emi.neoforge.get()}:api"

minecraftLibrary(libs.mixin.extras.asProvider().get())
Expand Down
8 changes: 6 additions & 2 deletions Quilt/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ dependencies {
modImplementation libs.commonnetworking.fabric
modImplementation quilt.trinkets

modCompileOnly quilt.modmenu
modLocalRuntime quilt.modmenu

modCompileOnly quilt.cameraoverhaul
// modLocalRuntime quilt.cameraoverhaul
// modLocalRuntime quilt.cloth

modCompileOnly quilt.modmenu
modLocalRuntime quilt.modmenu
modCompileOnly libs.figura.fabric
modLocalRuntime libs.figura.fabric
localRuntime libs.bundles.figura.runtime

// modCompileOnly "${libs.emi.fabric.get()}:api"
}
Expand Down
4 changes: 3 additions & 1 deletion Quilt/src/main/resources/quilt.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"entrypoints": {
"init": "dev.cammiescorner.icarus.quilt.entrypoints.Main",
"client_init": "dev.cammiescorner.icarus.quilt.entrypoints.Client",
"modmenu": "dev.cammiescorner.icarus.quilt.entrypoints.Modmenu"
"modmenu": "dev.cammiescorner.icarus.quilt.entrypoints.Modmenu",
"figura_api": "dev.cammiescorner.icarus.integration.figura.IcarusFiguraPlugin",
"figura_vanilla_part": "dev.cammiescorner.icarus.integration.figura.IcarusFiguraModelPartsPlugin"
},
"depends": [
{
Expand Down
14 changes: 14 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ subprojects {
url = "https://maven.shedaniel.me"
}

maven {
name = "FiguraMC"
url = "https://maven.figuramc.org/releases"
}

maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
Expand All @@ -147,6 +152,15 @@ subprojects {
includeGroup "curse.maven"
}
}

maven {
name = "JitPack"
url = "https://jitpack.io"
content {
includeGroupByRegex("com\\.github\\..*")
includeGroupByRegex("io\\.github\\..*")
}
}
}

tasks.withType(JavaCompile).configureEach {
Expand Down

0 comments on commit 32b6dd1

Please sign in to comment.