From 6d4b8762ee13f3941b9e95712070442bb729c03e Mon Sep 17 00:00:00 2001 From: tr7zw Date: Fri, 26 Jan 2024 19:40:12 +0100 Subject: [PATCH] More cleanup --- .../versionless/mixinbase/ModelPartBase.java | 6 +- .../firstperson/FirstPersonModelCore.java | 3 +- .../dev/tr7zw/firstperson/LogicHandler.java | 58 +++++++++---------- .../firstperson/access/PlayerModelAccess.java | 2 +- .../firstperson/api/ActivationHandler.java | 2 +- .../tr7zw/firstperson/api/FirstPersonAPI.java | 6 +- .../firstperson/api/PlayerOffsetHandler.java | 2 +- .../mixins/ArmorFeatureRendererMixin.java | 4 +- .../mixins/FishingBobberRendererMixin.java | 14 ++--- .../mixins/HeldItemRendererMixin.java | 9 +-- .../mixins/LivingEntityRendererMixin.java | 3 +- .../firstperson/mixins/ModelPartMixin.java | 5 +- .../firstperson/mixins/PlayerRenderMixin.java | 14 ++--- .../mixins/WorldRendererMixin.java | 7 ++- 14 files changed, 69 insertions(+), 66 deletions(-) diff --git a/FPVersionless/src/main/java/dev/tr7zw/firstperson/versionless/mixinbase/ModelPartBase.java b/FPVersionless/src/main/java/dev/tr7zw/firstperson/versionless/mixinbase/ModelPartBase.java index a264c85a..fc288ad7 100644 --- a/FPVersionless/src/main/java/dev/tr7zw/firstperson/versionless/mixinbase/ModelPartBase.java +++ b/FPVersionless/src/main/java/dev/tr7zw/firstperson/versionless/mixinbase/ModelPartBase.java @@ -2,10 +2,10 @@ public interface ModelPartBase { - public void setHidden(); + void setHidden(); - public void showAgain(); + void showAgain(); - public boolean isHidden(); + boolean isHidden(); } diff --git a/src/main/java/dev/tr7zw/firstperson/FirstPersonModelCore.java b/src/main/java/dev/tr7zw/firstperson/FirstPersonModelCore.java index 9b96ccae..996135a8 100644 --- a/src/main/java/dev/tr7zw/firstperson/FirstPersonModelCore.java +++ b/src/main/java/dev/tr7zw/firstperson/FirstPersonModelCore.java @@ -60,8 +60,9 @@ public void onTick() { lateInit(); } if (keyBinding.isDown()) { - if (isHeld) + if (isHeld) { return; + } isHeld = true; setEnabled(!isEnabled()); } else { diff --git a/src/main/java/dev/tr7zw/firstperson/LogicHandler.java b/src/main/java/dev/tr7zw/firstperson/LogicHandler.java index 84a30f17..70451f0f 100644 --- a/src/main/java/dev/tr7zw/firstperson/LogicHandler.java +++ b/src/main/java/dev/tr7zw/firstperson/LogicHandler.java @@ -34,30 +34,26 @@ public class LogicHandler { private Set autoVanillaHandItems = new HashSet<>(); void registerDefaultHandlers() { - FirstPersonAPI.registerPlayerHandler(new ActivationHandler() { - - @Override - public boolean preventFirstperson() { - if (client.player.isAutoSpinAttack()) - return true; - if (client.player.isFallFlying()) - return true; - if (client.player.getSwimAmount(1f) != 0 && !isCrawlingOrSwimming(client.player)) - return true; - // spotless:off - //#if MC >= 11700 - if (client.player.isScoping()) - return true; - //#endif - //spotless:on - return false; + FirstPersonAPI.registerPlayerHandler((ActivationHandler) () -> { + if (client.player.isAutoSpinAttack() || client.player.isFallFlying() + || (client.player.getSwimAmount(1f) != 0 && !isCrawlingOrSwimming(client.player))) { + return true; + } + // spotless:off + //#if MC >= 11700 + if (client.player.isScoping()) { + return true; } + //#endif + //spotless:on + return false; }); } public boolean shouldApplyThirdPerson(boolean thirdPerson) { - if (!fpm.isEnabled() || thirdPerson) + if (!fpm.isEnabled() || thirdPerson) { return false; + } for (ActivationHandler handler : FirstPersonAPI.getActivationHandlers()) { if (handler.preventFirstperson()) { return false; @@ -77,14 +73,13 @@ public void updatePositionOffset(Entity entity, Vec3 defValue) { double z = 0; AbstractClientPlayer player; double realYaw; - if (entity == client.player && client.options.getCameraType() == CameraType.FIRST_PERSON - && fpm.isRenderingPlayer()) { - player = (AbstractClientPlayer) entity; - realYaw = Mth.rotLerp(client.getFrameTime(), player.yBodyRotO, player.yBodyRot); - } else { + if ((entity != client.player) || (client.options.getCameraType() != CameraType.FIRST_PERSON) + || !fpm.isRenderingPlayer()) { offset = defValue; return; } + player = (AbstractClientPlayer) entity; + realYaw = Mth.rotLerp(client.getFrameTime(), player.yBodyRotO, player.yBodyRot); if (!player.isLocalPlayer() || client.getCameraEntity() == player) { float bodyOffset; if (isCrawlingOrSwimming(client.player)) { @@ -94,9 +89,9 @@ public void updatePositionOffset(Entity entity, Vec3 defValue) { } else { bodyOffset = Constants.SWIM_DOWN_BODY_OFFSET; } - // some mods seem to break the isCrouching method - } else if (player.isCrouching() || player.getPose() == Pose.CROUCHING) { - bodyOffset = Constants.SNEAK_BODY_OFFSET + (fpm.getConfig().sneakXOffset / 100f); + // some mods seem to break the isCrouching method + } else if (player.isCrouching() || player.getPose() == Pose.CROUCHING) { + 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); @@ -106,9 +101,9 @@ public void updatePositionOffset(Entity entity, Vec3 defValue) { realYaw = Mth.rotLerp(client.getFrameTime(), player.getVehicle().yRotO, NMSHelper.getYRot(player.getVehicle())); } - bodyOffset = Constants.IN_VEHICLE_BODY_OFFSET + (fpm.getConfig().sitXOffset / 100f); + bodyOffset = Constants.IN_VEHICLE_BODY_OFFSET + fpm.getConfig().sitXOffset / 100f; } else { - bodyOffset = 0.25f + (fpm.getConfig().xOffset / 100f); + bodyOffset = 0.25f + fpm.getConfig().xOffset / 100f; } x += bodyOffset * Math.sin(Math.toRadians(realYaw)); z -= bodyOffset * Math.cos(Math.toRadians(realYaw)); @@ -151,11 +146,11 @@ public boolean showVanillaHands() { } public void addAutoVanillaHandsItem(Item item) { - this.autoVanillaHandItems.add(item); + autoVanillaHandItems.add(item); } public void clearAutoVanillaHandsList() { - this.autoVanillaHandItems.clear(); + autoVanillaHandItems.clear(); } public void reloadAutoVanillaHandsSettings() { @@ -164,8 +159,9 @@ public void reloadAutoVanillaHandsSettings() { for (String itemId : fpm.getConfig().autoVanillaHands) { try { Item item = NMSHelper.getItem(new ResourceLocation(itemId.split(":")[0], itemId.split(":")[1])); - if (invalid != item) + if (invalid != item) { addAutoVanillaHandsItem(item); + } } catch (Exception ex) { FirstPersonBase.LOGGER.info("Unknown item to add to the auto vanilla hold list: {}", itemId); } diff --git a/src/main/java/dev/tr7zw/firstperson/access/PlayerModelAccess.java b/src/main/java/dev/tr7zw/firstperson/access/PlayerModelAccess.java index 873264a1..587063ae 100644 --- a/src/main/java/dev/tr7zw/firstperson/access/PlayerModelAccess.java +++ b/src/main/java/dev/tr7zw/firstperson/access/PlayerModelAccess.java @@ -4,6 +4,6 @@ public interface PlayerModelAccess { - public ModelPart getCloak(); + ModelPart getCloak(); } diff --git a/src/main/java/dev/tr7zw/firstperson/api/ActivationHandler.java b/src/main/java/dev/tr7zw/firstperson/api/ActivationHandler.java index 09538380..41ae3fab 100644 --- a/src/main/java/dev/tr7zw/firstperson/api/ActivationHandler.java +++ b/src/main/java/dev/tr7zw/firstperson/api/ActivationHandler.java @@ -2,5 +2,5 @@ public interface ActivationHandler { - public boolean preventFirstperson(); + boolean preventFirstperson(); } diff --git a/src/main/java/dev/tr7zw/firstperson/api/FirstPersonAPI.java b/src/main/java/dev/tr7zw/firstperson/api/FirstPersonAPI.java index c531a377..7404af8a 100644 --- a/src/main/java/dev/tr7zw/firstperson/api/FirstPersonAPI.java +++ b/src/main/java/dev/tr7zw/firstperson/api/FirstPersonAPI.java @@ -50,10 +50,12 @@ public static boolean isRenderingPlayer() { * @param handler */ public static void registerPlayerHandler(Object handler) { - if (handler instanceof PlayerOffsetHandler offset) + if (handler instanceof PlayerOffsetHandler offset) { playerOffsetHandlers.add(offset); - if (handler instanceof ActivationHandler activation) + } + if (handler instanceof ActivationHandler activation) { activationHandlers.add(activation); + } } /** diff --git a/src/main/java/dev/tr7zw/firstperson/api/PlayerOffsetHandler.java b/src/main/java/dev/tr7zw/firstperson/api/PlayerOffsetHandler.java index 3cb74a78..7d175bfe 100644 --- a/src/main/java/dev/tr7zw/firstperson/api/PlayerOffsetHandler.java +++ b/src/main/java/dev/tr7zw/firstperson/api/PlayerOffsetHandler.java @@ -17,6 +17,6 @@ public interface PlayerOffsetHandler { * @param current * @return */ - public Vec3 applyOffset(AbstractClientPlayer entity, float delta, Vec3 original, Vec3 current); + Vec3 applyOffset(AbstractClientPlayer entity, float delta, Vec3 original, Vec3 current); } diff --git a/src/main/java/dev/tr7zw/firstperson/mixins/ArmorFeatureRendererMixin.java b/src/main/java/dev/tr7zw/firstperson/mixins/ArmorFeatureRendererMixin.java index 11aaacdc..3d152fcf 100644 --- a/src/main/java/dev/tr7zw/firstperson/mixins/ArmorFeatureRendererMixin.java +++ b/src/main/java/dev/tr7zw/firstperson/mixins/ArmorFeatureRendererMixin.java @@ -39,8 +39,8 @@ private void renderArmor(PoseStack matrices, MultiBufferSource vertexConsumers, info.cancel(); } if (equipmentSlot == EquipmentSlot.CHEST && FirstPersonModelCore.instance.isRenderingPlayer() - && (livingEntity instanceof LocalPlayer player - && FirstPersonModelCore.instance.getLogicHandler().isSwimming(player))) { + && livingEntity instanceof LocalPlayer player + && FirstPersonModelCore.instance.getLogicHandler().isSwimming(player)) { info.cancel(); } if (equipmentSlot == EquipmentSlot.CHEST && FirstPersonModelCore.instance.isRenderingPlayer() diff --git a/src/main/java/dev/tr7zw/firstperson/mixins/FishingBobberRendererMixin.java b/src/main/java/dev/tr7zw/firstperson/mixins/FishingBobberRendererMixin.java index 0c889a59..75b74806 100644 --- a/src/main/java/dev/tr7zw/firstperson/mixins/FishingBobberRendererMixin.java +++ b/src/main/java/dev/tr7zw/firstperson/mixins/FishingBobberRendererMixin.java @@ -30,29 +30,29 @@ private boolean doCorrect() { @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Options;getCameraType()Lnet/minecraft/client/CameraType;")) private CameraType redirect(Options gameOptions) { - return (doCorrect()) ? CameraType.THIRD_PERSON_BACK : gameOptions.getCameraType(); + return doCorrect() ? CameraType.THIRD_PERSON_BACK : gameOptions.getCameraType(); } @Inject(method = "render", at = @At("HEAD")) private void calcOffset(FishingHook fishingBobberEntity, float f, float g, PoseStack matrixStack, MultiBufferSource vertexConsumerProvider, int i, CallbackInfo info) { if (fishingBobberEntity.getOwner() instanceof Player) { - this.offsetvec3d = FirstPersonModelCore.instance.getLogicHandler().getOffset();// getPositionOffset((Player) - // fishingBobberEntity.getOwner(), - // matrixStack); + offsetvec3d = FirstPersonModelCore.instance.getLogicHandler().getOffset();// getPositionOffset((Player) + // fishingBobberEntity.getOwner(), + // matrixStack); } else { - this.offsetvec3d = new Vec3(0, 0, 0); + offsetvec3d = new Vec3(0, 0, 0); } } @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;getX()D")) private double offsetX(Player playerEntity) { - return playerEntity.getX() + this.offsetvec3d.x(); + return playerEntity.getX() + offsetvec3d.x(); } @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;getZ()D")) private double offsetZ(Player playerEntity) { - return playerEntity.getZ() + this.offsetvec3d.z(); + return playerEntity.getZ() + offsetvec3d.z(); } @Redirect(method = "render", at = @At(value = "FIELD", target = "Lnet/minecraft/world/entity/player/Player;xo:D")) diff --git a/src/main/java/dev/tr7zw/firstperson/mixins/HeldItemRendererMixin.java b/src/main/java/dev/tr7zw/firstperson/mixins/HeldItemRendererMixin.java index a4aade33..9f0b6790 100644 --- a/src/main/java/dev/tr7zw/firstperson/mixins/HeldItemRendererMixin.java +++ b/src/main/java/dev/tr7zw/firstperson/mixins/HeldItemRendererMixin.java @@ -40,17 +40,18 @@ public void renderFirstPersonItem(AbstractClientPlayer player, float tickDelta, || player.getMainHandItem().getItem() == Items.FILLED_MAP // spotless:off //#if MC >= 11700 - || player.isScoping()) - //#else - //$$|| false) + || player.isScoping()) { + //#else + //$$|| false) { //#endif //spotless:on return; + } boolean bl = hand == InteractionHand.MAIN_HAND; HumanoidArm arm = bl ? player.getMainArm() : player.getMainArm().getOpposite(); matrices.pushPose(); if (item.isEmpty() && !bl && !player.isInvisible()) { - this.renderPlayerArm(matrices, vertexConsumers, light, equipProgress, swingProgress, arm); + renderPlayerArm(matrices, vertexConsumers, light, equipProgress, swingProgress, arm); } matrices.popPose(); } diff --git a/src/main/java/dev/tr7zw/firstperson/mixins/LivingEntityRendererMixin.java b/src/main/java/dev/tr7zw/firstperson/mixins/LivingEntityRendererMixin.java index c60e272a..d70ca500 100644 --- a/src/main/java/dev/tr7zw/firstperson/mixins/LivingEntityRendererMixin.java +++ b/src/main/java/dev/tr7zw/firstperson/mixins/LivingEntityRendererMixin.java @@ -25,8 +25,9 @@ public abstract class LivingEntityRendererMixin { @Inject(method = "render", at = @At("HEAD"), cancellable = true) public void renderHead(LivingEntity livingEntity, float f, float g, PoseStack matrixStack, MultiBufferSource vertexConsumerProvider, int i, CallbackInfo info) { - if (livingEntity instanceof Shulker) + if (livingEntity instanceof Shulker) { return;// No need to mess with + } // only run when the player is rendering, and it's not a "Humanoid" model(it // otherwise gets handeled in HumanoidModelMixin) if (FirstPersonModelCore.instance.isRenderingPlayer() && !(getModel() instanceof HumanoidModel)) { diff --git a/src/main/java/dev/tr7zw/firstperson/mixins/ModelPartMixin.java b/src/main/java/dev/tr7zw/firstperson/mixins/ModelPartMixin.java index 0a93a43b..be99cd0d 100644 --- a/src/main/java/dev/tr7zw/firstperson/mixins/ModelPartMixin.java +++ b/src/main/java/dev/tr7zw/firstperson/mixins/ModelPartMixin.java @@ -22,8 +22,9 @@ public class ModelPartMixin implements ModelPartBase { @Override public void setHidden() { - if (!moved) + if (!moved) { zCopy = z; + } z = 5000; moved = true; visible = false; @@ -50,7 +51,7 @@ public void setPivot(float x, float y, float z, CallbackInfo info) { public void copyTransform(ModelPart modelPart, CallbackInfo info) { if (moved) { zCopy = z; - this.z = 5000; + z = 5000; } } diff --git a/src/main/java/dev/tr7zw/firstperson/mixins/PlayerRenderMixin.java b/src/main/java/dev/tr7zw/firstperson/mixins/PlayerRenderMixin.java index a3fe03d4..1715a571 100644 --- a/src/main/java/dev/tr7zw/firstperson/mixins/PlayerRenderMixin.java +++ b/src/main/java/dev/tr7zw/firstperson/mixins/PlayerRenderMixin.java @@ -56,13 +56,13 @@ protected PlayerRenderMixin(Context ctx, PlayerModel model @Inject(method = "render", at = @At(value = "RETURN")) public void render(AbstractClientPlayer player, float f, float g, PoseStack matrixStack, MultiBufferSource vertexConsumerProvider, int i, CallbackInfo info) { - ((ModelPartBase) (Object) this.getModel().head).showAgain(); - ((ModelPartBase) (Object) this.getModel().hat).showAgain(); - ((ModelPartBase) (Object) this.getModel().leftArm).showAgain(); - ((ModelPartBase) (Object) this.getModel().rightArm).showAgain(); - ((ModelPartBase) (Object) this.getModel().leftSleeve).showAgain(); - ((ModelPartBase) (Object) this.getModel().rightSleeve).showAgain(); - ((ModelPartBase) (Object) this.getModel().body).showAgain(); + ((ModelPartBase) (Object) getModel().head).showAgain(); + ((ModelPartBase) (Object) getModel().hat).showAgain(); + ((ModelPartBase) (Object) getModel().leftArm).showAgain(); + ((ModelPartBase) (Object) getModel().rightArm).showAgain(); + ((ModelPartBase) (Object) getModel().leftSleeve).showAgain(); + ((ModelPartBase) (Object) getModel().rightSleeve).showAgain(); + ((ModelPartBase) (Object) getModel().body).showAgain(); ((ModelPartBase) (Object) ((PlayerModelAccess) model).getCloak()).showAgain(); FirstPersonModelCore.instance.setRenderingPlayer(false); } diff --git a/src/main/java/dev/tr7zw/firstperson/mixins/WorldRendererMixin.java b/src/main/java/dev/tr7zw/firstperson/mixins/WorldRendererMixin.java index dd435ea8..b0ddc08c 100644 --- a/src/main/java/dev/tr7zw/firstperson/mixins/WorldRendererMixin.java +++ b/src/main/java/dev/tr7zw/firstperson/mixins/WorldRendererMixin.java @@ -38,12 +38,13 @@ 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) { - if (camera.isDetached() || !FirstPersonModelCore.instance.getLogicHandler().shouldApplyThirdPerson(false)) + if (camera.isDetached() || !FirstPersonModelCore.instance.getLogicHandler().shouldApplyThirdPerson(false)) { return; + } Vec3 vec3d = camera.getPosition(); - MultiBufferSource.BufferSource immediate = this.renderBuffers.bufferSource(); + MultiBufferSource.BufferSource immediate = renderBuffers.bufferSource(); FirstPersonModelCore.instance.setRenderingPlayer(true); - this.renderEntity(camera.getEntity(), vec3d.x(), vec3d.y(), vec3d.z(), tickDelta, matrices, immediate); + renderEntity(camera.getEntity(), vec3d.x(), vec3d.y(), vec3d.z(), tickDelta, matrices, immediate); FirstPersonModelCore.instance.setRenderingPlayer(false); }