diff --git a/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/PlayerRendererMixin.java b/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/LivingEntityRendererMixin.java similarity index 91% rename from common/src/main/java/org/vivecraft/mixin/client/renderer/entity/PlayerRendererMixin.java rename to common/src/main/java/org/vivecraft/mixin/client/renderer/entity/LivingEntityRendererMixin.java index f991369f9..e4a10af7b 100644 --- a/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/PlayerRendererMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/LivingEntityRendererMixin.java @@ -6,6 +6,7 @@ import net.minecraft.client.model.PlayerModel; import net.minecraft.client.model.geom.EntityModelSet; import net.minecraft.client.model.geom.ModelLayers; +import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.client.renderer.entity.LivingEntityRenderer; import net.minecraft.client.renderer.entity.RenderLayerParent; @@ -14,7 +15,11 @@ import net.minecraft.client.renderer.entity.player.PlayerRenderer; import net.minecraft.world.entity.LivingEntity; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.vivecraft.client.extensions.EntityRenderDispatcherExtension; import org.vivecraft.client.extensions.RenderLayerExtension; import org.vivecraft.client.utils.RenderLayerTypes; @@ -31,16 +36,18 @@ * so mods could add it manually, but some mods hardcode only the slim/default model, * and that would mean the VRPlayerRenderers would be missing those layers completely */ -@Mixin(PlayerRenderer.class) -public abstract class PlayerRendererMixin> extends LivingEntityRenderer { +@Mixin(LivingEntityRenderer.class) +public abstract class LivingEntityRendererMixin> extends EntityRenderer { - // dummy constructor - public PlayerRendererMixin(EntityRendererProvider.Context context, M entityModel, float f) { - super(context, entityModel, f); + @Shadow + protected M model; + + protected LivingEntityRendererMixin(EntityRendererProvider.Context context) { + super(context); } - @Override - public boolean addLayer(RenderLayer renderLayer) { + @Inject(at = @At("HEAD"), method = "addLayer") + public void vivecraft$copyLayer(RenderLayer renderLayer, CallbackInfoReturnable cir) { // check if the layer gets added from the PlayerRenderer, we don't want to copy, if we add it to the VRPlayerRenderer // also check that the VRPlayerRenderers were created, this method also gets called in the constructor, // those default Layers already are added to the VRPlayerRenderer there @@ -91,7 +98,6 @@ public boolean addLayer(RenderLayer renderLayer) { } } } - return super.addLayer(renderLayer); } /** diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/MinecraftVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/MinecraftVRMixin.java index a1d1d72c3..97c983d5b 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/MinecraftVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/MinecraftVRMixin.java @@ -96,7 +96,7 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { private boolean vivecraft$lastClick; @Unique - private ItemStack vivecraft$itemInHand; //Captured item + private int vivecraft$currentHand = 0; @Unique private long vivecraft$mirroNotifyStart; @@ -570,22 +570,23 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { } } - @ModifyVariable(at = @At(value = "STORE", ordinal = 0), method = "startUseItem") - public ItemStack vivecraft$handItemStore(ItemStack itemInHand) { - this.vivecraft$itemInHand = itemInHand; - return itemInHand; - } - - @Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;hitResult:Lnet/minecraft/world/phys/HitResult;", ordinal = 1), method = "startUseItem", locals = LocalCapture.CAPTURE_FAILHARD) - public void vivecraft$activeHandSend(CallbackInfo ci, InteractionHand[] var1, int var2, int var3, InteractionHand interactionHand) { - if (VRState.vrRunning && (ClientDataHolderVR.getInstance().vrSettings.seated || !TelescopeTracker.isTelescope(vivecraft$itemInHand))) { - ClientNetworking.sendActiveHand((byte) interactionHand.ordinal()); - } + @Inject(at = @At("HEAD"), method = "startUseItem") + private void vivecraft$resetHand(CallbackInfo ci) { + vivecraft$currentHand = 0; } @Redirect(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;hitResult:Lnet/minecraft/world/phys/HitResult;", ordinal = 1), method = "startUseItem") - public HitResult vivecraft$activeHand2(Minecraft instance) { - if (!VRState.vrRunning || ClientDataHolderVR.getInstance().vrSettings.seated || !TelescopeTracker.isTelescope(vivecraft$itemInHand)) { + public HitResult vivecraft$activeHand(Minecraft instance) { + boolean isTelescope = false; + if (VRState.vrRunning) { + InteractionHand interactionHand = InteractionHand.values()[vivecraft$currentHand++]; + ItemStack itemInHand = this.player.getItemInHand(interactionHand); + isTelescope = TelescopeTracker.isTelescope(itemInHand); + if (ClientDataHolderVR.getInstance().vrSettings.seated || !isTelescope) { + ClientNetworking.sendActiveHand((byte) interactionHand.ordinal()); + } + } + if (!VRState.vrRunning || ClientDataHolderVR.getInstance().vrSettings.seated || !isTelescope) { return instance.hitResult; } return null; diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/GameRendererVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/GameRendererVRMixin.java index e29c50595..93ed5ce22 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/GameRendererVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/GameRendererVRMixin.java @@ -32,7 +32,6 @@ import org.spongepowered.asm.mixin.injection.At.Shift; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import org.vivecraft.client.Xevents; import org.vivecraft.client.Xplat; import org.vivecraft.client_vr.ClientDataHolderVR; @@ -158,6 +157,9 @@ public abstract class GameRendererVRMixin @Final private Camera mainCamera; + @Shadow + private int itemActivationTicks; + @Redirect(method = "", at = @At(value = "NEW", target = "net/minecraft/client/Camera")) public Camera vivecraft$replaceCamera() { return new XRCamera(); @@ -422,25 +424,27 @@ public abstract class GameRendererVRMixin } @Redirect(method = "renderItemActivationAnimation", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;scale(FFF)V")) - private void vivecraft$noScaleItem(PoseStack poseStack, float x, float y, float z) { + private void vivecraft$noScaleItem(PoseStack poseStack, float x, float y, float z, int width, int height, float partialTicks) { if (RenderPassType.isVanilla()) { poseStack.scale(x, y, z); - } - } - - @Inject(method = "renderItemActivationAnimation", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;scale(FFF)V"), locals = LocalCapture.CAPTURE_FAILHARD) - private void vivecraft$transformItem(int i, int j, float f, CallbackInfo ci, int k, float g, float h, float l, float m, float n, float o, float p, PoseStack posestack) { - if (!RenderPassType.isVanilla()) { + } else { + // need to do stuff twice, because redirects have no access to locals + int i = 40 - this.itemActivationTicks; + float g = ((float) i + partialTicks) / 40.0f; + float h = g * g; + float l = g * h; + float m = 10.25f * l * h - 24.95f * h * h + 25.5f * l - 13.8f * h + 4.0f * g; + float n = m * (float) Math.PI; float sinN = Mth.sin(n) * 0.5F; - posestack.translate(0, 0, sinN - 1.0); + poseStack.translate(0, 0, sinN - 1.0); if (ClientDataHolderVR.getInstance().currentPass == RenderPass.THIRD) { - sinN *= ClientDataHolderVR.getInstance().vrSettings.mixedRealityFov / 70.0; + sinN *= (float) (ClientDataHolderVR.getInstance().vrSettings.mixedRealityFov / 70.0); } - RenderHelper.applyVRModelView(ClientDataHolderVR.getInstance().currentPass, posestack); - RenderHelper.applyStereo(ClientDataHolderVR.getInstance().currentPass, posestack); - posestack.scale(sinN, sinN, sinN); - posestack.mulPose(Axis.YP.rotationDegrees(-ClientDataHolderVR.getInstance().vrPlayer.getVRDataWorld().getEye(ClientDataHolderVR.getInstance().currentPass).getYaw())); - posestack.mulPose(Axis.XP.rotationDegrees(-ClientDataHolderVR.getInstance().vrPlayer.getVRDataWorld().getEye(ClientDataHolderVR.getInstance().currentPass).getPitch())); + RenderHelper.applyVRModelView(ClientDataHolderVR.getInstance().currentPass, poseStack); + RenderHelper.applyStereo(ClientDataHolderVR.getInstance().currentPass, poseStack); + poseStack.scale(sinN, sinN, sinN); + poseStack.mulPose(Axis.YP.rotationDegrees(-ClientDataHolderVR.getInstance().vrPlayer.getVRDataWorld().getEye(ClientDataHolderVR.getInstance().currentPass).getYaw())); + poseStack.mulPose(Axis.XP.rotationDegrees(-ClientDataHolderVR.getInstance().vrPlayer.getVRDataWorld().getEye(ClientDataHolderVR.getInstance().currentPass).getPitch())); } } diff --git a/common/src/main/resources/vivecraft.accesswidener b/common/src/main/resources/vivecraft.accesswidener index 866b61e0e..abfb06579 100644 --- a/common/src/main/resources/vivecraft.accesswidener +++ b/common/src/main/resources/vivecraft.accesswidener @@ -12,7 +12,6 @@ extendable method net/minecraft/client/renderer/entity/player/PlayerRenderer set # modded layer supports accessible method net/minecraft/client/renderer/entity/LivingEntityRenderer addLayer (Lnet/minecraft/client/renderer/entity/layers/RenderLayer;)Z -extendable method net/minecraft/client/renderer/entity/LivingEntityRenderer addLayer (Lnet/minecraft/client/renderer/entity/layers/RenderLayer;)Z mutable field net/minecraft/client/renderer/entity/layers/RenderLayer renderer Lnet/minecraft/client/renderer/entity/RenderLayerParent; accessible field net/minecraft/client/renderer/entity/layers/RenderLayer renderer Lnet/minecraft/client/renderer/entity/RenderLayerParent; diff --git a/common/src/main/resources/vivecraft.mixins.json b/common/src/main/resources/vivecraft.mixins.json index 59dee5c16..5fcb2e64c 100644 --- a/common/src/main/resources/vivecraft.mixins.json +++ b/common/src/main/resources/vivecraft.mixins.json @@ -13,7 +13,7 @@ "client.renderer.block.LiquidBlockRendererMixin", "client.renderer.entity.EntityRenderDispatcherMixin", "client.renderer.entity.ItemRendererVRMixin", - "client.renderer.entity.PlayerRendererMixin", + "client.renderer.entity.LivingEntityRendererMixin", "client.renderer.entity.layers.RenderLayerMixin", "client_vr.ClientBrandRetrieverVRMixin", "client_vr.KeyboardHandlerVRMixin",