Skip to content
This repository has been archived by the owner on Feb 9, 2025. It is now read-only.

Commit

Permalink
cherry-pick from 1.20 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
LucunJi committed Jul 17, 2023
1 parent c16cc48 commit 5441e49
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .gitmessage
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [ ] update dependencies in gradle.properties
- [ ] update mod version in src/resources/fabric.mod.json
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
![](logo.png)

[![Quick Fabric Release](https://github.com/LucunJi/ExtraPlayerRenderer/actions/workflows/quick-fabric-release.yml/badge.svg)](https://github.com/LucunJi/ExtraPlayerRenderer/actions/workflows/quick-fabric-release.yml)
![](https://img.shields.io/badge/dynamic/json?color=5da545&label=modrinth&prefix=downloads%20&query=hits.0.downloads&url=https://api.modrinth.com/v2/search?query=extraplayerrenderer&limit=1&index=relevance)
[![](https://img.shields.io/badge/dynamic/json?color=5da545&label=modrinth&prefix=downloads%20&query=hits.0.downloads&url=https://api.modrinth.com/v2/search?query=extraplayerrenderer&limit=1&index=relevance)](https://modrinth.com/mod/7q8r8AtY)
![](https://cf.way2muchnoise.eu/extraplayerrenderer.svg)
![](https://cf.way2muchnoise.eu/versions/extraplayerrenderer.svg)

Expand Down Expand Up @@ -38,12 +38,11 @@ Explore the tabs and buttons, there are a lot for you to config: the scale, posi

## Downloads & Dependencies

Downloading this mod from [CurseForge](https://www.curseforge.com/minecraft/mc-mods/extraplayerrenderer) or [Modrinth](https://modrinth.com/mod/extraplayerrenderer) is recommended, as this can help me gain some rewards.
Downloading this mod from [CurseForge](https://www.curseforge.com/minecraft/mc-mods/extraplayerrenderer) or [Modrinth](https://modrinth.com/mod/7q8r8AtY) is recommended, as this can help me gain some rewards.

You can also download from [GitHub](https://github.com/LucunJi/ExtraPlayerRenderer) or [mcmod](https://www.mcmod.cn/class/2374.html).

This mod in all versions, except Minecraft 1.20.0, requires masa's [malilib](https://www.curseforge.com/minecraft/mc-mods/malilib).
The alpha versions for Minecraft 1.20.0 requires [Kosmolot's unofficial port of malilib](https://kosma.pl/masamods-1.20/), as masa has not finished porting.
This mod requires masa's [malilib](https://www.curseforge.com/minecraft/mc-mods/malilib).

[Mod Menu](https://modrinth.com/mod/modmenu/) is an optional dependency for the latest versions.

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ loader_version=0.14.21
maven_group=github.io.lucunji
# Dependencies
# Fabric api
fabric_version=0.83.0+1.19.4
fabric_version=0.85.0+1.19.4
# malilib
malilib_minecraft_version=1.19.4
malilib_version=0.15.4
Expand Down
Empty file modified gradlew
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public final void save() {
this.data.replaceAll((k, v) -> k.saver.apply(target));
}

@SuppressWarnings("unchecked")
public final void restore() {
//noinspection unchecked
this.data.forEach((key, val) -> ((BiConsumer<Object, Object>) key.restorer).accept(target, val));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,35 @@
import net.minecraft.world.World;
import org.joml.*;

import java.lang.Math;
import java.util.List;


public class PlayerHUDRenderer implements IRenderer {
private static final MinecraftClient client = MinecraftClient.getInstance();
private static final List<DataBackupEntry<LivingEntity, ?>> LIVINGENTITY_BACKUP_ENTRIES = ImmutableList.of(
new DataBackupEntry<>(LivingEntity::getPose, LivingEntity::setPose),
new DataBackupEntry<>(Entity::isInSneakingPose, (e, flag) -> {
new DataBackupEntry<LivingEntity, EntityPose>(LivingEntity::getPose, LivingEntity::setPose),
new DataBackupEntry<LivingEntity, Boolean>(Entity::isInSneakingPose, (e, flag) -> {
if (e instanceof ClientPlayerEntity) ((ClientPlayerEntityAccessor) e).setInSneakingPose(flag);
}),
new DataBackupEntry<>(e -> ((LivingEntityAccessor) e).getLeaningPitch(), (e, pitch) -> ((LivingEntityAccessor) e).setLeaningPitch(pitch)),
new DataBackupEntry<>(e -> ((LivingEntityAccessor) e).getLastLeaningPitch(), (e, pitch) -> ((LivingEntityAccessor) e).setLastLeaningPitch(pitch)),
new DataBackupEntry<>(LivingEntity::isFallFlying, (e, flag) -> ((EntityMixin) e).callSetFlag(7, flag)),
new DataBackupEntry<>(LivingEntity::getRoll, (e, roll) -> ((LivingEntityAccessor) e).setRoll(roll)),
new DataBackupEntry<>(LivingEntity::getVehicle, (e, vehicle) -> ((EntityMixin) e).setVehicle(vehicle)),

new DataBackupEntry<>(e -> e.prevBodyYaw, (e, yaw) -> e.prevBodyYaw = yaw),
new DataBackupEntry<>(e -> e.bodyYaw, (e, yaw) -> e.bodyYaw = yaw),
new DataBackupEntry<>(e -> e.prevHeadYaw, (e, yaw) -> e.prevHeadYaw = yaw),
new DataBackupEntry<>(e -> e.headYaw, (e, yaw) -> e.headYaw = yaw),
new DataBackupEntry<>(e -> e.prevPitch, (e, pitch) -> e.prevPitch = pitch),
new DataBackupEntry<>(LivingEntity::getPitch, LivingEntity::setPitch),

new DataBackupEntry<>(e -> e.handSwingProgress, (e, prog) -> e.handSwingProgress = prog),
new DataBackupEntry<>(e -> e.lastHandSwingProgress, (e, prog) -> e.lastHandSwingProgress = prog),
new DataBackupEntry<>(e -> e.hurtTime, (e, time) -> e.hurtTime = time),
new DataBackupEntry<>(LivingEntity::getFireTicks, LivingEntity::setFireTicks),
new DataBackupEntry<>(e -> ((EntityMixin) e).callGetFlag(0), (e, flag) -> ((EntityMixin) e).callSetFlag(0,flag)) // on fire
new DataBackupEntry<LivingEntity, Float>(e -> ((LivingEntityAccessor) e).getLeaningPitch(), (e, pitch) -> ((LivingEntityAccessor) e).setLeaningPitch(pitch)),
new DataBackupEntry<LivingEntity, Float>(e -> ((LivingEntityAccessor) e).getLastLeaningPitch(), (e, pitch) -> ((LivingEntityAccessor) e).setLastLeaningPitch(pitch)),
new DataBackupEntry<LivingEntity, Boolean>(LivingEntity::isFallFlying, (e, flag) -> ((EntityMixin) e).callSetFlag(7, flag)),
new DataBackupEntry<LivingEntity, Integer>(LivingEntity::getRoll, (e, roll) -> ((LivingEntityAccessor) e).setRoll(roll)),
new DataBackupEntry<LivingEntity, Entity>(LivingEntity::getVehicle, (e, vehicle) -> ((EntityMixin) e).setVehicle(vehicle)),

new DataBackupEntry<LivingEntity, Float>(e -> e.prevBodyYaw, (e, yaw) -> e.prevBodyYaw = yaw),
new DataBackupEntry<LivingEntity, Float>(e -> e.bodyYaw, (e, yaw) -> e.bodyYaw = yaw),
new DataBackupEntry<LivingEntity, Float>(e -> e.prevHeadYaw, (e, yaw) -> e.prevHeadYaw = yaw),
new DataBackupEntry<LivingEntity, Float>(e -> e.headYaw, (e, yaw) -> e.headYaw = yaw),
new DataBackupEntry<LivingEntity, Float>(e -> e.prevPitch, (e, pitch) -> e.prevPitch = pitch),
new DataBackupEntry<LivingEntity, Float>(LivingEntity::getPitch, LivingEntity::setPitch),

new DataBackupEntry<LivingEntity, Float>(e -> e.handSwingProgress, (e, prog) -> e.handSwingProgress = prog),
new DataBackupEntry<LivingEntity, Float>(e -> e.lastHandSwingProgress, (e, prog) -> e.lastHandSwingProgress = prog),
new DataBackupEntry<LivingEntity, Integer>(e -> e.hurtTime, (e, time) -> e.hurtTime = time),
new DataBackupEntry<LivingEntity, Integer>(LivingEntity::getFireTicks, LivingEntity::setFireTicks),
new DataBackupEntry<LivingEntity, Boolean>(e -> ((EntityMixin) e).callGetFlag(0), (e, flag) -> ((EntityMixin) e).callSetFlag(0, flag)) // on fire

);

Expand Down Expand Up @@ -102,6 +103,8 @@ public void doRender(float partialTicks) {
DataBackup<LivingEntity> vehicleBackup = null;
if (Configs.RENDER_VEHICLE.getBooleanValue() && poseOffsetMethod != PoseOffsetMethod.FORCE_STANDING && targetEntity.hasVehicle()) {
var vehicle = targetEntity.getVehicle();
assert vehicle != null;

if (vehicle instanceof LivingEntity livingVehicle) {
vehicleBackup = new DataBackup<>(livingVehicle, LIVINGENTITY_BACKUP_ENTRIES);
vehicleBackup.save();
Expand Down Expand Up @@ -186,12 +189,16 @@ private void transformEntity(LivingEntity targetEntity, float partialTicks, bool
((LivingEntityAccessor) targetEntity).setRoll(0);
}

float headLerp = MathHelper.lerp(partialTicks, targetEntity.prevHeadYaw, targetEntity.headYaw);
float headClamp = (float) MathHelper.clamp(headLerp,
Configs.HEAD_YAW_MIN.getDoubleValue(), Configs.HEAD_YAW_MAX.getDoubleValue());
float bodyLerp = MathHelper.lerp(partialTicks, targetEntity.prevBodyYaw, targetEntity.bodyYaw);
float diff = headLerp - bodyLerp;

targetEntity.prevHeadYaw = targetEntity.headYaw = 180 - headClamp;
targetEntity.prevBodyYaw = targetEntity.bodyYaw = 180 - (float) MathHelper.clamp(
MathHelper.lerp(partialTicks, targetEntity.prevBodyYaw, targetEntity.bodyYaw),
wrapDegree180(headClamp - diff),
Configs.BODY_YAW_MIN.getDoubleValue(), Configs.BODY_YAW_MAX.getDoubleValue());
targetEntity.prevHeadYaw = targetEntity.headYaw = 180 - (float) MathHelper.clamp(
MathHelper.lerp(partialTicks, targetEntity.prevHeadYaw, targetEntity.headYaw),
Configs.HEAD_YAW_MIN.getDoubleValue(), Configs.HEAD_YAW_MAX.getDoubleValue());
targetEntity.setPitch(targetEntity.prevPitch = (float) (MathHelper.clamp(
MathHelper.lerp(partialTicks, targetEntity.prevPitch, targetEntity.getPitch()),
Configs.PITCH_MIN.getDoubleValue(), Configs.PITCH_MAX.getDoubleValue())
Expand All @@ -211,6 +218,7 @@ private void transformEntity(LivingEntity targetEntity, float partialTicks, bool
((EntityMixin) targetEntity).callSetFlag(0, false);
}

@SuppressWarnings("deprecation")
private void performRendering(Entity targetEntity, double posX, double posY, double size, boolean mirror,
double poseOffsetY, IConfigOptionListEntry poseOffsetMethod, double lightDegree,
float partialTicks) {
Expand Down Expand Up @@ -252,7 +260,6 @@ private void performRendering(Entity targetEntity, double posX, double posY, dou
entityRenderDispatcher.setRenderShadows(false);

VertexConsumerProvider.Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
//noinspection deprecation
RenderSystem.runAsFancy(() ->
entityRenderDispatcher.render(targetEntity, 0, 0, 0, 0, partialTicks, matrixStack2, immediate, getLight(targetEntity, partialTicks))
);
Expand Down Expand Up @@ -287,4 +294,13 @@ private static float getFallFlyingLeaning(LivingEntity entity, float partialTick
float ticks = partialTicks + entity.getRoll();
return MathHelper.clamp(ticks * ticks / 100f, 0f, 1f);
}

/**
* Wrap angle between [-180, 180] in degrees.
*/
private static float wrapDegree180(float x) {
x += 180;
if (x < 0) x += 360 * Math.ceil(-x / 360);
return (x % 360) - 180;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "explayerenderer",
"version": "2.3.0",
"version": "2.3.1",

"name": "ExtraPlayerRenderer",
"description": "Render an extra player figure on your screen. Made for game streaming and recordings.",
Expand Down

0 comments on commit 5441e49

Please sign in to comment.