Skip to content

Commit

Permalink
Update to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
tr7zw committed Jun 14, 2024
1 parent 68b9925 commit c360314
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 39 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,59 @@ jobs:
name: ${{github.ref_name}}-1.20.6 - Fabric
files: 'versions/1.20.6-fabric/build/libs/!(*-@(dev|sources|javadoc|all)).jar'
game-versions: 1.20.6
- name: Publish-1.21-forge-Curseforge
uses: Kir-Antipov/mc-publish@v3.3.0
with:
curseforge-id: 333287
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
loaders: forge
name: ${{github.ref_name}}-1.21 - Forge
version-type: beta
files: 'versions/1.21-forge/build/libs/!(*-@(dev|sources|javadoc|all)).jar'
game-versions: 1.21
- name: Publish-1.21-forge-Modrinth
uses: Kir-Antipov/mc-publish@v3.3.0
with:
modrinth-id: H5XMjpHi
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
loaders: forge
name: ${{github.ref_name}}-1.21 - Forge
files: 'versions/1.21-forge/build/libs/!(*-@(dev|sources|javadoc|all)).jar'
game-versions: 1.21
- name: Publish-1.21-neoforge-Curseforge
uses: Kir-Antipov/mc-publish@v3.3.0
with:
curseforge-id: 333287
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
loaders: neoforge
name: ${{github.ref_name}}-1.21 - NeoForge
version-type: beta
files: 'versions/1.21-neoforge/build/libs/!(*-@(dev|sources|javadoc|all)).jar'
game-versions: 1.21
- name: Publish-1.21-neoforge-Modrinth
uses: Kir-Antipov/mc-publish@v3.3.0
with:
modrinth-id: H5XMjpHi
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
loaders: neoforge
name: ${{github.ref_name}}-1.21 - NeoForge
files: 'versions/1.21-neoforge/build/libs/!(*-@(dev|sources|javadoc|all)).jar'
game-versions: 1.21
- name: Publish-1.21-fabric-Curseforge
uses: Kir-Antipov/mc-publish@v3.3.0
with:
curseforge-id: 333287
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
loaders: fabric
name: ${{github.ref_name}}-1.21 - Fabric
files: 'versions/1.21-fabric/build/libs/!(*-@(dev|sources|javadoc|all)).jar'
game-versions: 1.21
- name: Publish-1.21-fabric-Modrinth
uses: Kir-Antipov/mc-publish@v3.3.0
with:
modrinth-id: H5XMjpHi
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
loaders: fabric
name: ${{github.ref_name}}-1.21 - Fabric
files: 'versions/1.21-fabric/build/libs/!(*-@(dev|sources|javadoc|all)).jar'
game-versions: 1.21
5 changes: 4 additions & 1 deletion settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
"1.20.4-fabric",
"1.20.6-forge",
"1.20.6-neoforge",
"1.20.6-fabric"
"1.20.6-fabric",
"1.21-forge",
"1.21-neoforge",
"1.21-fabric"
]
}
35 changes: 20 additions & 15 deletions src/main/java/dev/tr7zw/firstperson/LogicHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import net.minecraft.client.CameraType;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
Expand Down Expand Up @@ -88,8 +87,9 @@ public boolean shouldApplyThirdPerson(boolean thirdPerson) {
*
* @param entity
* @param defValue
* @param delta
*/
public void updatePositionOffset(Entity entity, Vec3 defValue) {
public void updatePositionOffset(Entity entity, Vec3 defValue, float delta) {
offset = defValue;
// handle sleeping
if (entity == client.getCameraEntity() && client.player.isSleeping()) {
Expand All @@ -105,7 +105,7 @@ public void updatePositionOffset(Entity entity, Vec3 defValue) {
return;
}
player = (AbstractClientPlayer) entity;
realYaw = Mth.rotLerp(client.getFrameTime(), player.yBodyRotO, player.yBodyRot);
realYaw = Mth.rotLerp(delta, player.yBodyRotO, player.yBodyRot);
if (!player.isLocalPlayer() || client.getCameraEntity() == player) {
float bodyOffset;
if (isCrawlingOrSwimming(client.player)) {
Expand All @@ -120,9 +120,10 @@ public void updatePositionOffset(Entity entity, Vec3 defValue) {
bodyOffset = Constants.SNEAK_BODY_OFFSET + fpm.getConfig().sneakXOffset / 100f;
} else if (player.isPassenger()) {
if (player.getVehicle() instanceof Boat || player.getVehicle() instanceof Minecart) {
realYaw = Mth.rotLerp(client.getFrameTime(), player.yBodyRotO, player.yBodyRot);
realYaw = Mth.rotLerp(delta, player.yBodyRotO, player.yBodyRot);
} else if (player.getVehicle() instanceof LivingEntity living) {
realYaw = calculateBodyRot(Mth.rotLerp(client.getFrameTime(), living.yBodyRotO, living.yBodyRot), NMSHelper.getYRot(player));
realYaw = calculateBodyRot(Mth.rotLerp(delta, living.yBodyRotO, living.yBodyRot),
NMSHelper.getYRot(player));
} else {
// Non living entities don't use any custom rotation
// realYaw = Mth.rotLerp(client.getFrameTime(), player.getVehicle().yRotO,
Expand All @@ -145,23 +146,23 @@ public void updatePositionOffset(Entity entity, Vec3 defValue) {
}
offset = new Vec3(x, y, z);
}

private static float calculateBodyRot(float entityBodyRot, float riderHeadRot) {
// Wrap the head rotation to the range [-180, 180]
float wrappedHeadRot = Mth.wrapDegrees(riderHeadRot);

// Calculate the difference between the head and body rotation
float rotDiff = Mth.wrapDegrees(wrappedHeadRot - entityBodyRot);

// If the difference is more than 50 degrees, adjust the body rotation
if (Mth.abs(rotDiff) > 50.0F) {
// Pull the body along with the head
entityBodyRot = wrappedHeadRot - 50.0F * Math.signum(rotDiff);
}

// Ensure the body rotation is wrapped to [-180, 180]
entityBodyRot = Mth.wrapDegrees(entityBodyRot);

return entityBodyRot;
}

Expand Down Expand Up @@ -234,7 +235,8 @@ public boolean hideArmsAndItems(LivingEntity livingEntity) {
* @return
*/
public boolean hideArmsAndItems(LivingEntity livingEntity, ItemStack mainhand, ItemStack offhand) {
if (FirstPersonModelCore.instance.getConfig().vanillaHandsSkipSwimming && livingEntity instanceof Player player && isSwimming(player)) {
if (FirstPersonModelCore.instance.getConfig().vanillaHandsSkipSwimming && livingEntity instanceof Player player
&& isSwimming(player)) {
return false;
}
if (lookingDown()) {
Expand Down Expand Up @@ -265,7 +267,8 @@ public boolean dynamicHandsEnabled(LivingEntity livingEntity) {
* @return
*/
public boolean dynamicHandsEnabled(LivingEntity livingEntity, ItemStack mainhand, ItemStack offhand) {
if (FirstPersonModelCore.instance.getConfig().vanillaHandsSkipSwimming && livingEntity instanceof Player player && isSwimming(player)) {
if (FirstPersonModelCore.instance.getConfig().vanillaHandsSkipSwimming && livingEntity instanceof Player player
&& isSwimming(player)) {
return false;
}
return fpm.getConfig().dynamicMode && fpm.getConfig().vanillaHandsMode != VanillaHands.OFF
Expand Down Expand Up @@ -295,10 +298,11 @@ public void addAutoDisableItem(Item item) {
public void reloadAutoVanillaHandsSettings() {
autoVanillaHandItems.clear();
autoDisableItems.clear();
Item invalid = NMSHelper.getItem(new ResourceLocation("minecraft", "air"));
Item invalid = NMSHelper.getItem(NMSHelper.getResourceLocation("minecraft", "air"));
for (String itemId : fpm.getConfig().autoVanillaHands) {
try {
Item item = NMSHelper.getItem(new ResourceLocation(itemId.split(":")[0], itemId.split(":")[1]));
Item item = NMSHelper
.getItem(NMSHelper.getResourceLocation(itemId.split(":")[0], itemId.split(":")[1]));
if (invalid != item) {
addAutoVanillaHandsItem(item);
}
Expand All @@ -309,7 +313,8 @@ public void reloadAutoVanillaHandsSettings() {
FirstPersonBase.LOGGER.info("Loaded Vanilla Hands items: {}", autoVanillaHandItems);
for (String itemId : fpm.getConfig().autoToggleModItems) {
try {
Item item = NMSHelper.getItem(new ResourceLocation(itemId.split(":")[0], itemId.split(":")[1]));
Item item = NMSHelper
.getItem(NMSHelper.getResourceLocation(itemId.split(":")[0], itemId.split(":")[1]));
if (invalid != item) {
addAutoDisableItem(item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public void initialize() {
options.add(getOnOffOption("text.firstperson.option.firstperson.dynamicMode",
() -> fpm.getConfig().dynamicMode, b -> fpm.getConfig().dynamicMode = b));
options.add(getOnOffOption("text.firstperson.option.firstperson.vanillaHandsSkipSwimming",
() -> fpm.getConfig().vanillaHandsSkipSwimming, b -> fpm.getConfig().vanillaHandsSkipSwimming = b));
() -> fpm.getConfig().vanillaHandsSkipSwimming,
b -> fpm.getConfig().vanillaHandsSkipSwimming = b));

// spotless:off
//#if MC >= 11900
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public abstract class FeatureRendererMixin {
@Inject(method = "renderColoredCutoutModel", at = @At("HEAD"), cancellable = true)
// spotless:off
//#if MC >= 12100
private static <T extends LivingEntity> void removeHead(EntityModel<T> model, ResourceLocation texture,
PoseStack matrices, MultiBufferSource vertexConsumers, int light, T entity, float red, float green,
float blue, CallbackInfo ci) {
PoseStack matrices, MultiBufferSource vertexConsumers, int light, T entity, int color, CallbackInfo ci) {
//#else
//$$private static <T extends LivingEntity> void removeHead(EntityModel<T> model, ResourceLocation texture,
//$$ PoseStack matrices, MultiBufferSource vertexConsumers, int light, T entity, float red, float green,
//$$ float blue, CallbackInfo ci) {
//#endif
//spotless:on
if (FirstPersonModelCore.instance.isRenderingPlayer()) {
if (!(model instanceof HeadedModel)) {
ci.cancel();
Expand All @@ -39,9 +46,16 @@ private static <T extends LivingEntity> void removeHead(EntityModel<T> model, Re
}

@Inject(method = "renderColoredCutoutModel", at = @At("RETURN"), cancellable = true)
// spotless:off
//#if MC >= 12100
private static <T extends LivingEntity> void removeReturn(EntityModel<T> model, ResourceLocation texture,
PoseStack matrices, MultiBufferSource vertexConsumers, int light, T entity, float red, float green,
float blue, CallbackInfo ci) {
PoseStack matrices, MultiBufferSource vertexConsumers, int light, T entity, int color, CallbackInfo ci) {
//#else
//$$private static <T extends LivingEntity> void removeReturn(EntityModel<T> model, ResourceLocation texture,
//$$ PoseStack matrices, MultiBufferSource vertexConsumers, int light, T entity, float red, float green,
//$$ float blue, CallbackInfo ci) {
//#endif
//spotless:on
if (model instanceof HeadedModel) {
((ModelPartBase) (Object) ((HeadedModel) model).getHead()).showAgain();
if (model instanceof VillagerHeadModel villager) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public void renderFirstPersonItem(AbstractClientPlayer player, float tickDelta,
info.cancel();
return;
}
if(FirstPersonModelCore.instance.getConfig().vanillaHandsSkipSwimming && FirstPersonModelCore.instance.getLogicHandler().isSwimming(player)) {
if (FirstPersonModelCore.instance.getConfig().vanillaHandsSkipSwimming
&& FirstPersonModelCore.instance.getLogicHandler().isSwimming(player)) {
// while actively swimming, dont show the offhand item
info.cancel();
return;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/dev/tr7zw/firstperson/mixins/PlayerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public void getItemBySlot(EquipmentSlot slot, CallbackInfoReturnable<ItemStack>
ci.setReturnValue(ItemStack.EMPTY);
return;
}
if ((slot == EquipmentSlot.MAINHAND || slot == EquipmentSlot.OFFHAND) && FirstPersonModelCore.instance
.getLogicHandler().hideArmsAndItems(Minecraft.getInstance().player, this.inventory.getSelected(), this.inventory.offhand.get(0))) {
if ((slot == EquipmentSlot.MAINHAND || slot == EquipmentSlot.OFFHAND)
&& FirstPersonModelCore.instance.getLogicHandler().hideArmsAndItems(Minecraft.getInstance().player,
this.inventory.getSelected(), this.inventory.offhand.get(0))) {
ci.setReturnValue(ItemStack.EMPTY);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public class PlayerRendererMixin {
private static Minecraft fpmMcInstance = Minecraft.getInstance();

@Inject(method = "getRenderOffset", at = @At("RETURN"), cancellable = true)
public void getRenderOffset(AbstractClientPlayer entity, float f, CallbackInfoReturnable<Vec3> ci) {
public void getRenderOffset(AbstractClientPlayer entity, float delta, CallbackInfoReturnable<Vec3> ci) {
if (entity == fpmMcInstance.cameraEntity && FirstPersonModelCore.instance.isRenderingPlayer()) {
FirstPersonModelCore.instance.getLogicHandler().updatePositionOffset(entity, Vec3.ZERO);
FirstPersonModelCore.instance.getLogicHandler().updatePositionOffset(entity, Vec3.ZERO, delta);

Vec3 offset = ci.getReturnValue().add(FirstPersonModelCore.instance.getLogicHandler().getOffset());

for (PlayerOffsetHandler handler : FirstPersonAPI.getPlayerOffsetHandlers()) {
offset = handler.applyOffset(entity, f, ci.getReturnValue(), offset);
offset = handler.applyOffset(entity, delta, ci.getReturnValue(), offset);
}

ci.setReturnValue(offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,17 @@ private static void shadowMove(PoseStack matrices, MultiBufferSource vertexConsu

@Inject(method = "renderHitbox", at = @At(value = "HEAD"), cancellable = true)
// spotless:off
//#if MC >= 11700
//#if MC < 11700
//$$ private void renderHitbox(PoseStack poseStack, VertexConsumer vertexConsumer, Entity entity, float f, CallbackInfo ci) {
//#elseif MC < 12100
//$$ private static void renderHitbox(PoseStack poseStack, VertexConsumer vertexConsumer, Entity entity, float f,
//$$ CallbackInfo ci) {
//#else
private static void renderHitbox(PoseStack poseStack, VertexConsumer vertexConsumer, Entity entity, float f,
CallbackInfo ci) {
//#else
//$$ private void renderHitbox(PoseStack poseStack, VertexConsumer vertexConsumer, Entity entity, float f, CallbackInfo ci) {
//#endif
//spotless:on
float g, float h, float i,
CallbackInfo ci) {
//#endif
//spotless:on
if (entity == fpmMcInstance.cameraEntity && fpmMcInstance.options.getCameraType() == CameraType.FIRST_PERSON) {
ci.cancel();
}
Expand Down
22 changes: 18 additions & 4 deletions src/main/java/dev/tr7zw/firstperson/mixins/WorldRendererMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.Vec3;
// spotless:off
//#if MC >= 12100
import net.minecraft.client.DeltaTracker;
//#endif
//#if MC >= 11903
import org.joml.Matrix4f;
//#else
Expand All @@ -40,10 +43,15 @@ public class WorldRendererMixin {
//$$ @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;checkPoseStack(Lcom/mojang/blaze3d/vertex/PoseStack;)V", ordinal = 0))
//$$ public void render(PoseStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera,
//$$ GameRenderer gameRenderer, LightTexture lightmapTextureManager, Matrix4f matrix4f, CallbackInfo info) {
//#elseif MC < 12100
//$$ @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;checkPoseStack(Lcom/mojang/blaze3d/vertex/PoseStack;)V", ordinal = 0))
//$$ public void render(float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera,
//$$ GameRenderer gameRenderer, LightTexture lightmapTextureManager, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo info) {
//$$ PoseStack matrices = new PoseStack();
//#else
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;checkPoseStack(Lcom/mojang/blaze3d/vertex/PoseStack;)V", ordinal = 0))
public void render(float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera,
GameRenderer gameRenderer, LightTexture lightmapTextureManager, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo info) {
@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;checkPoseStack(Lcom/mojang/blaze3d/vertex/PoseStack;)V", ordinal = 0))
public void render(DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer,
LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo info) {
PoseStack matrices = new PoseStack();
//#endif
//spotless:on
Expand All @@ -53,7 +61,13 @@ public void render(float tickDelta, long limitTime, boolean renderBlockOutline,
Vec3 vec3d = camera.getPosition();
MultiBufferSource.BufferSource immediate = renderBuffers.bufferSource();
FirstPersonModelCore.instance.setRenderingPlayer(true);
renderEntity(camera.getEntity(), vec3d.x(), vec3d.y(), vec3d.z(), tickDelta, matrices, immediate);
// spotless:off
//#if MC < 12100
//$$ renderEntity(camera.getEntity(), vec3d.x(), vec3d.y(), vec3d.z(), tickDelta, matrices, immediate);
//#else
renderEntity(camera.getEntity(), vec3d.x(), vec3d.y(), vec3d.z(), deltaTracker.getGameTimeDeltaPartialTick(false), matrices, immediate);
//#endif
//spotless:on
FirstPersonModelCore.instance.setRenderingPlayer(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public Vec3 applyOffset(AbstractClientPlayer entity, float delta, Vec3 original,
relativeTranslation.translate(0, bodyOffset, 0); // Roll back the first [0,1,0] translation.

// calculate the actual rotations and
float realYaw = Mth.rotLerp(minecraft.getFrameTime(), entity.yBodyRotO, entity.yBodyRot);
float realYaw = Mth.rotLerp(delta, entity.yBodyRotO, entity.yBodyRot);

Matrix4f matrix = new Matrix4f(); // To multiply from LEFT, I have to create a new instance?!
matrix.mul(new Matrix4f().scale(-1, 1, 1)); // What is going on with this?!
Expand Down
2 changes: 1 addition & 1 deletion versions/mainProject
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.20.6-fabric
1.21-fabric

0 comments on commit c360314

Please sign in to comment.