Skip to content

Commit

Permalink
Add renderer support for GeoEntity entities from GeckoLib
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita51bot committed Nov 19, 2024
1 parent 47af00f commit a217f85
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 15 deletions.
11 changes: 11 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ repositories {
name "Modrinth"
url "https://api.modrinth.com/maven"
} // Needs for Replay Mod

maven {
name = 'GeckoLib'
url 'https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/'
content {
includeGroupByRegex("software\\.bernie.*")
includeGroup("com.eliotlash.mclib")
}
}
}

dependencies {
Expand Down Expand Up @@ -92,6 +101,8 @@ dependencies {
exclude(group: "net.fabricmc.fabric-api")
}

modImplementation("software.bernie.geckolib:geckolib-fabric-${mcVersion}:${prop("dep.geckolib")}")

if (!(stonecutter.compare("1.20.5", mcVersion) == 0)) {
// Replay Mod
modImplementation("maven.modrinth:replaymod:${findProperty("dep.replaymod")}")
Expand Down
6 changes: 5 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ lombok_version = 1.18.32

# Multi-Versions Properties
# Verified version: 1.20 1.20.1 1.20.2 1.20.3 1.20.4 1.20.5 1.20.6 1.21
multi_versions = 1.16.5 1.17 1.17.1 1.18 1.18.1 1.18.2 1.19 1.19.1 1.19.2 1.19.3 1.19.4 1.20 1.20.1 1.20.3 1.20.4 1.20.5 1.20.6 1.21 1.21.1 1.21.2 1.21.3
# multi_versions = 1.16.5 1.17 1.17.1 1.18 1.18.1 1.18.2 1.19 1.19.1 1.19.2 1.19.3 1.19.4 1.20 1.20.1 1.20.3 1.20.4 1.20.5 1.20.6 1.21 1.21.1 1.21.2 1.21.3
multi_versions = 1.20.1 1.21.3

# Build Dependencies
build.yarn = [VERSIONED]
Expand All @@ -35,6 +36,9 @@ dep.yacl = [VERSIONED]
dep.modmenu = [VERSIONED]
dep.cloth-config = [VERSIONED]
dep.replaymod = [VERSIONED]
dep.geckolib = [VERSIONED]

# TODO ?????? GeckoLib ?? ??????, ? ??????? ?? ?? ?????? (???????? 1.21.2)

# # # # # # # # # # # # # #
# Publication Properties #
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package net.lopymine.patpat.mixin;

// TODO Отключить класс из версий, в которых GeckoLib не создан (например 1.21.2)

import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.*;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import software.bernie.geckolib.renderer.GeoEntityRenderer;

import net.lopymine.patpat.renderer.PatAnimationRenderer;


//? >=1.21.2 {
import net.minecraft.client.render.entity.state.EntityRenderState;
import net.lopymine.patpat.utils.mixin.EntityRenderStateWithParent;
//?}

@Mixin(GeoEntityRenderer.class)
public abstract class GeoEntityRendererMixin {

//? <1.21.2 {
/*@Inject(at=@At(value = "HEAD"), method = "render")
private void render(Entity entity, float entityYaw, float partialTick, MatrixStack matrixStack, VertexConsumerProvider bufferSource, int packedLight, CallbackInfo ci) {
*///?} else {
@Inject(at = @At(value = "HEAD"), method = "render")
private void render(EntityRenderState entityRenderState, MatrixStack matrixStack, VertexConsumerProvider bufferSource, int packedLight, CallbackInfo ci) {
Entity entity = ((EntityRenderStateWithParent) entityRenderState).patPat$getEntity();
//?}
if (!(entity instanceof LivingEntity livingEntity)) {
return;
}
PatAnimationRenderer.scaleEntityIfPatted(livingEntity, matrixStack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.lopymine.patpat.entity.PatEntity;
import net.lopymine.patpat.manager.client.PatPatClientManager;
import net.lopymine.patpat.renderer.PatAnimationRenderer;

//? >=1.21.2 {
import net.minecraft.entity.Entity;
Expand All @@ -31,16 +30,6 @@ private void render(LivingEntityRenderState livingEntityRenderState, MatrixStack
return;
}
//?}
PatEntity patEntity = PatPatClientManager.getPatEntity(livingEntity);
if (patEntity == null) {
return;
}

if (PatPatClientManager.expired(patEntity)) {
PatPatClientManager.removePatEntity(patEntity);
return;
}

matrixStack.scale(1F, PatPatClientManager.getAnimationProgress(patEntity), 1F);
PatAnimationRenderer.scaleEntityIfPatted(livingEntity, matrixStack);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.lopymine.patpat.renderer;

import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity;

import net.lopymine.patpat.entity.PatEntity;
import net.lopymine.patpat.manager.client.PatPatClientManager;

public class PatAnimationRenderer {

public static void scaleEntityIfPatted(LivingEntity livingEntity, MatrixStack matrixStack){
PatEntity patEntity = PatPatClientManager.getPatEntity(livingEntity);
if (patEntity == null) {
return;
}

if (PatPatClientManager.expired(patEntity)) {
PatPatClientManager.removePatEntity(patEntity);
return;
}

matrixStack.scale(1F, PatPatClientManager.getAnimationProgress(patEntity), 1F);
}
}
1 change: 1 addition & 0 deletions src/main/resources/patpat.mixins.json5
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/*? >=1.21.2*/
"EntityRenderStateMixin",
"MinecraftClientMixin",
"GeoEntityRendererMixin",
"CameraMixin"
],
"injectors": {
Expand Down
2 changes: 2 additions & 0 deletions versions/1.20.1/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ dep.modmenu=7.2.2
dep.yacl=3.6.1+1.20.1-fabric
# replaymod, check https://modrinth.com/mod/replaymod/versions?g=1.20.1
dep.replaymod=1.20.1-2.6.20
# geckolib, check https://modrinth.com/mod/geckolib/versions?g=1.20.1
dep.geckolib=4.4.9
4 changes: 3 additions & 1 deletion versions/1.21.3/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Fabric Properties, check https://fabricmc.net/develop/
build.yarn=1.21.3+build.2
build.fabric_api=0.107.0+1.21.3
build.fabric_api=0.109.0+1.21.3

# Additional Dependencies Properties
# cloth-config, check https://modrinth.com/mod/cloth-config/versions?g=1.21.3
Expand All @@ -13,3 +13,5 @@ dep.modmenu=12.0.0-beta.1
dep.yacl=3.6.1+1.21.2-fabric
# replaymod, check https://modrinth.com/mod/replaymod/versions?g=1.21.3
dep.replaymod=1.21.2-2.6.20
# geckolib, check https://modrinth.com/mod/geckolib/versions?g=1.21.3
dep.geckolib=4.7.1

0 comments on commit a217f85

Please sign in to comment.