Skip to content

Commit

Permalink
Possible 1.21 port
Browse files Browse the repository at this point in the history
  • Loading branch information
KosmX committed Jul 6, 2024
1 parent e0925e0 commit 3e15d59
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ architectury {
minecraft = rootProject.minecraft_version
}

project.mod_version = mod_version + "+1.20.6"
project.mod_version = mod_version + "+" + minecraft_version

allprojects {
apply plugin: "java"
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
org.gradle.jvmargs=-Xmx4G

minecraft_version=1.20.6
minecraft_version=1.21

archives_base_name=player-animation-lib
#Major: API break, Minor: non-breaking but significant, Patch: minor bugfix/change + MC implementation fix
Expand All @@ -9,9 +9,9 @@ maven_group=dev.kosmx.player-anim


fabric_loader_version=0.15.11
fabric_api_version=0.100.2+1.20.6
fabric_api_version=0.100.4+1.21

forge_version=20.6.119
forge_version=21.0.61-beta

# from localmaven TODO change
bendy_lib=4.1.0
bendy_lib=5.0-rc2
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static void resourceLoaderCallback(@NotNull ResourceManager manager, Logg
for (var animation : AnimationSerializing.deserializeAnimation(input)) {

//Save the animation for later use.
animations.put(new ResourceLocation(resource.getKey().getNamespace(), PlayerAnimationRegistry.serializeTextToString((String) animation.extraData.get("name")).toLowerCase(Locale.ROOT)), animation);
animations.put(ResourceLocation.fromNamespaceAndPath(resource.getKey().getNamespace(), PlayerAnimationRegistry.serializeTextToString((String) animation.extraData.get("name")).toLowerCase(Locale.ROOT)), animation);
}
} catch(IOException e) {
logger.error("Error while loading payer animation: " + resource.getKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ private void copyMutatedAttributes(HumanoidModel<T> bipedEntityModel, CallbackIn

@Intrinsic(displace = true)
@Override
public void renderToBuffer(PoseStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha){
public void renderToBuffer(PoseStack matrices, VertexConsumer vertices, int light, int overlay, int color){
if(Helper.isBendEnabled() && this.animation.get() != null && this.animation.get().isActive()){
this.headParts().forEach((part)->{
if(! ((IUpperPartHelper) part).isUpperPart()){
part.render(matrices, vertices, light, overlay, red, green, blue, alpha);
part.render(matrices, vertices, light, overlay, color);
}
});
this.bodyParts().forEach((part)->{
if(! ((IUpperPartHelper) part).isUpperPart()){
part.render(matrices, vertices, light, overlay, red, green, blue, alpha);
part.render(matrices, vertices, light, overlay, color);
}
});

Expand All @@ -78,16 +78,16 @@ public void renderToBuffer(PoseStack matrices, VertexConsumer vertices, int ligh
IBendHelper.rotateMatrixStack(matrices, emoteSupplier.get().getBend("body"));
this.headParts().forEach((part)->{
if(((IUpperPartHelper) part).isUpperPart()){
part.render(matrices, vertices, light, overlay, red, green, blue, alpha);
part.render(matrices, vertices, light, overlay, color);
}
});
this.bodyParts().forEach((part)->{
if(((IUpperPartHelper) part).isUpperPart()){
part.render(matrices, vertices, light, overlay, red, green, blue, alpha);
part.render(matrices, vertices, light, overlay, color);
}
});
matrices.popPose();
} else super.renderToBuffer(matrices, vertices, light, overlay, red, green, blue, alpha);
} else super.renderToBuffer(matrices, vertices, light, overlay, color);
}

@Final
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.kosmx.playerAnim.api.firstPerson.FirstPersonMode;
import dev.kosmx.playerAnim.impl.IAnimatedPlayer;
import net.minecraft.client.Camera;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.LevelRenderer;
Expand All @@ -27,7 +28,7 @@ public class LevelRendererMixin {
// @Redirect(at = @At(target = "Lnet/minecraft/client/Camera;isDetached()Z")) is forbidden

@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;isDetached()Z"))
private void fakeThirdPersonMode(float f, long l, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) {
private void fakeThirdPersonMode(DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) {
// mods may need to redirect that method, I want to avoid compatibility issues as long as possible
defaultCameraState = camera.isDetached();
if (camera.getEntity() instanceof IAnimatedPlayer player && player.playerAnimator_getAnimation().getFirstPersonMode() == FirstPersonMode.THIRD_PERSON_MODEL) {
Expand All @@ -36,7 +37,7 @@ private void fakeThirdPersonMode(float f, long l, boolean bl, Camera camera, Gam
}
}
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;isDetached()Z", shift = At.Shift.AFTER))
private void resetThirdPerson(float f, long l, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) {
private void resetThirdPerson(DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) {
((CameraAccessor)camera).setDetached(defaultCameraState);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void onInitializeClient() {
ResourceManagerHelper.get(PackType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public ResourceLocation getFabricId() {
return new ResourceLocation("playeranimator", "animation");
return ResourceLocation.fromNamespaceAndPath("playeranimator", "animation");
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion minecraft/fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"playerAnimator-common.mixins.json"
],
"depends": {
"minecraft": "~1.20",
"minecraft": "~1.21",
"fabric-resource-loader-v0": "*"
},
"breaks": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void onInitializeClient() {
LOGGER.warn("Testmod is loading :D");

//You might use the EVENT to register new animations, or you can use Mixin.
PlayerAnimationFactory.ANIMATION_DATA_FACTORY.registerFactory(new ResourceLocation("testmod", "animation"), 42, (player) -> {
PlayerAnimationFactory.ANIMATION_DATA_FACTORY.registerFactory(ResourceLocation.fromNamespaceAndPath("testmod", "animation"), 42, (player) -> {
if (player instanceof LocalPlayer) {
//animationStack.addAnimLayer(42, testAnimation); //Add and save the animation container for later use.
ModifierLayer<IAnimation> testAnimation = new ModifierLayer<>();
Expand All @@ -56,7 +56,7 @@ public void onInitializeClient() {
PlayerAnimationAccess.REGISTER_ANIMATION_EVENT.register((player, animationStack) -> {
ModifierLayer<IAnimation> layer = new ModifierLayer<>();
animationStack.addAnimLayer(69, layer);
PlayerAnimationAccess.getPlayerAssociatedData(player).set(new ResourceLocation("testmod", "test"), layer);
PlayerAnimationAccess.getPlayerAssociatedData(player).set(ResourceLocation.fromNamespaceAndPath("testmod", "test"), layer);
});
//You can add modifiers to the ModifierLayer.

Expand All @@ -69,9 +69,9 @@ public static void playTestAnimation() {

ModifierLayer<IAnimation> testAnimation;
if (new Random().nextBoolean()) {
testAnimation = (ModifierLayer<IAnimation>) PlayerAnimationAccess.getPlayerAssociatedData(Minecraft.getInstance().player).get(new ResourceLocation("testmod", "animation"));
testAnimation = (ModifierLayer<IAnimation>) PlayerAnimationAccess.getPlayerAssociatedData(Minecraft.getInstance().player).get(ResourceLocation.fromNamespaceAndPath("testmod", "animation"));
} else {
testAnimation = (ModifierLayer<IAnimation>) PlayerAnimationAccess.getPlayerAssociatedData(Minecraft.getInstance().player).get(new ResourceLocation("testmod", "test"));
testAnimation = (ModifierLayer<IAnimation>) PlayerAnimationAccess.getPlayerAssociatedData(Minecraft.getInstance().player).get(ResourceLocation.fromNamespaceAndPath("testmod", "test"));
}

if (testAnimation.getAnimation() != null && new Random().nextBoolean()) {
Expand All @@ -81,7 +81,7 @@ public static void playTestAnimation() {
//Fade from current animation to a new one.
//Will not fade if there is no animation currently.
testAnimation.replaceAnimationWithFade(AbstractFadeModifier.functionalFadeIn(20, (modelName, type, value) -> value),
new KeyframeAnimationPlayer(PlayerAnimationRegistry.getAnimation(new ResourceLocation("testmod", "two_handed_slash_vertical_right")))
new KeyframeAnimationPlayer(PlayerAnimationRegistry.getAnimation(ResourceLocation.fromNamespaceAndPath("testmod", "two_handed_slash_vertical_right")))
.setFirstPersonMode(FirstPersonMode.THIRD_PERSON_MODEL)
.setFirstPersonConfiguration(new FirstPersonConfiguration().setShowRightArm(true).setShowLeftItem(false))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ config = "playerAnimator-common.mixins.json"
modId = "minecraft"
type = "required"
mandatory = true
versionRange = "[1.20.6,)"
versionRange = "[1.21,)"
ordering = "NONE"
side = "BOTH"

0 comments on commit 3e15d59

Please sign in to comment.