diff --git a/common/build.gradle b/common/build.gradle index a1080f25d..edee0596b 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -45,7 +45,7 @@ dependencies { compileOnly('com.electronwill.night-config:toml:3.6.6') //LaunchPopup - implementation 'com.github.Vivecraft:LaunchPopup:master-SNAPSHOT' + implementation 'com.github.Vivecraft:LaunchPopup:1.1.1' } // extract the LaunchPopup classes jar { diff --git a/common/src/main/java/org/vivecraft/client/VRPlayersClient.java b/common/src/main/java/org/vivecraft/client/VRPlayersClient.java index 84ddffd3b..c1cf862c2 100644 --- a/common/src/main/java/org/vivecraft/client/VRPlayersClient.java +++ b/common/src/main/java/org/vivecraft/client/VRPlayersClient.java @@ -180,7 +180,7 @@ public RotInfo getRotationsForPlayer(UUID uuid) { if (playermodelcontroller$rotinfo != null && this.vivePlayersLast.containsKey(uuid)) { RotInfo playermodelcontroller$rotinfo1 = this.vivePlayersLast.get(uuid); RotInfo playermodelcontroller$rotinfo2 = new RotInfo(); - float f = Minecraft.getInstance().getTimer().getGameTimeDeltaPartialTick(false); + float f = Minecraft.getInstance().getDeltaTracker().getGameTimeDeltaPartialTick(false); playermodelcontroller$rotinfo2.reverse = playermodelcontroller$rotinfo.reverse; playermodelcontroller$rotinfo2.seated = playermodelcontroller$rotinfo.seated; playermodelcontroller$rotinfo2.hmd = playermodelcontroller$rotinfo.hmd; diff --git a/common/src/main/java/org/vivecraft/client/extensions/EntityRenderStateExtension.java b/common/src/main/java/org/vivecraft/client/extensions/EntityRenderStateExtension.java new file mode 100644 index 000000000..4cfb1ea73 --- /dev/null +++ b/common/src/main/java/org/vivecraft/client/extensions/EntityRenderStateExtension.java @@ -0,0 +1,15 @@ +package org.vivecraft.client.extensions; + +import java.util.UUID; + +public interface EntityRenderStateExtension { + /** + * @return the uuid this state was created for + */ + UUID vivecraft$getEntityUUID(); + + /** + * set the uuid this state was created for + */ + void vivecraft$setEntityUUID(UUID uuid); +} diff --git a/common/src/main/java/org/vivecraft/client/extensions/RenderTargetExtension.java b/common/src/main/java/org/vivecraft/client/extensions/RenderTargetExtension.java index e4a8423f8..58aa2af09 100644 --- a/common/src/main/java/org/vivecraft/client/extensions/RenderTargetExtension.java +++ b/common/src/main/java/org/vivecraft/client/extensions/RenderTargetExtension.java @@ -1,6 +1,6 @@ package org.vivecraft.client.extensions; -import net.minecraft.client.renderer.ShaderInstance; +import net.minecraft.client.renderer.ShaderProgram; import org.lwjgl.opengl.GL30; public interface RenderTargetExtension { @@ -19,5 +19,5 @@ public interface RenderTargetExtension { void vivecraft$isLinearFilter(boolean linearFilter); - void vivecraft$blitFovReduction(ShaderInstance instance, int width, int height); + void vivecraft$blitFovReduction(ShaderProgram instance, int width, int height); } diff --git a/common/src/main/java/org/vivecraft/client/network/ClientNetworking.java b/common/src/main/java/org/vivecraft/client/network/ClientNetworking.java index 05a115e18..3da8341b3 100644 --- a/common/src/main/java/org/vivecraft/client/network/ClientNetworking.java +++ b/common/src/main/java/org/vivecraft/client/network/ClientNetworking.java @@ -6,6 +6,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.client.player.LocalPlayer; +import net.minecraft.core.Holder; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; @@ -207,7 +208,7 @@ public static void overrideLook(Player player, Vec3 view) { capturedYaw = player.getYRot(); float f = (float) Math.toDegrees(Math.asin(-view.y / view.length())); float f1 = (float) Math.toDegrees(Math.atan2(-view.x, view.z)); - ((LocalPlayer) player).connection.send(new ServerboundMovePlayerPacket.Rot(f1, f, player.onGround())); + ((LocalPlayer) player).connection.send(new ServerboundMovePlayerPacket.Rot(f1, f, player.onGround(), player.horizontalCollision)); overrideActive = true; } } @@ -215,7 +216,7 @@ public static void overrideLook(Player player, Vec3 view) { public static void restoreLook(Player player) { if (!serverWantsData) { if (overrideActive) { - ((LocalPlayer) player).connection.send(new ServerboundMovePlayerPacket.Rot(capturedYaw, capturedPitch, player.onGround())); + ((LocalPlayer) player).connection.send(new ServerboundMovePlayerPacket.Rot(capturedYaw, capturedPitch, player.onGround(), player.horizontalCollision)); overrideActive = false; } } @@ -256,11 +257,11 @@ public static void handlePacket(CommonNetworkHelper.PacketDiscriminators packetI while (buffer.readableBytes() > 0) { String s12 = buffer.readUtf(16384); - Block block = BuiltInRegistries.BLOCK.get(ResourceLocation.parse(s12)); + Holder.Reference block = BuiltInRegistries.BLOCK.get(ResourceLocation.parse(s12)).orElse(null); // if the block is not there AIR is returned - if (block != Blocks.AIR) { - dataholder.climbTracker.blocklist.add(block); + if (block != null && block.value() != Blocks.AIR) { + dataholder.climbTracker.blocklist.add(block.value()); } } } diff --git a/common/src/main/java/org/vivecraft/client/render/HMDLayer.java b/common/src/main/java/org/vivecraft/client/render/HMDLayer.java index 6c10c2f6e..0406d39e8 100644 --- a/common/src/main/java/org/vivecraft/client/render/HMDLayer.java +++ b/common/src/main/java/org/vivecraft/client/render/HMDLayer.java @@ -3,29 +3,30 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import net.minecraft.client.model.PlayerModel; -import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.RenderLayerParent; import net.minecraft.client.renderer.entity.layers.RenderLayer; +import net.minecraft.client.renderer.entity.state.PlayerRenderState; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.resources.ResourceLocation; import org.vivecraft.client.VRPlayersClient; +import org.vivecraft.client.extensions.EntityRenderStateExtension; -public class HMDLayer extends RenderLayer> { +public class HMDLayer extends RenderLayer { ResourceLocation DIAMOND_HMD = ResourceLocation.parse("vivecraft:textures/diamond_hmd.png"); ResourceLocation GOLD_HMD = ResourceLocation.parse("vivecraft:textures/gold_hmd.png"); ResourceLocation BLACK_HMD = ResourceLocation.parse("vivecraft:textures/black_hmd.png"); - public HMDLayer(RenderLayerParent> renderLayerParent) { + public HMDLayer(RenderLayerParent renderLayerParent) { super(renderLayerParent); } @Override - public void render(PoseStack poseStack, MultiBufferSource multiBufferSource, int i, AbstractClientPlayer entity, float f, float g, float h, float j, float k, float l) { - if (this.getParentModel().head.visible && this.getParentModel() instanceof VRPlayerModel vrPlayerModel) { - VRPlayersClient.RotInfo rotinfo = VRPlayersClient.getInstance().getRotationsForPlayer(entity.getUUID()); + public void render(PoseStack poseStack, MultiBufferSource multiBufferSource, int i, PlayerRenderState entityState, float f, float g) { + if (this.getParentModel().head.visible && this.getParentModel() instanceof VRPlayerModel vrPlayerModel) { + VRPlayersClient.RotInfo rotinfo = VRPlayersClient.getInstance().getRotationsForPlayer(((EntityRenderStateExtension)entityState).vivecraft$getEntityUUID()); ResourceLocation hmd; switch (rotinfo.hmd) { default -> hmd = null; diff --git a/common/src/main/java/org/vivecraft/client/render/VRPlayerModel.java b/common/src/main/java/org/vivecraft/client/render/VRPlayerModel.java index 931136b16..35b6e23ea 100644 --- a/common/src/main/java/org/vivecraft/client/render/VRPlayerModel.java +++ b/common/src/main/java/org/vivecraft/client/render/VRPlayerModel.java @@ -9,10 +9,11 @@ import net.minecraft.client.model.geom.builders.CubeListBuilder; import net.minecraft.client.model.geom.builders.MeshDefinition; import net.minecraft.client.model.geom.builders.PartDefinition; -import net.minecraft.world.entity.LivingEntity; +import net.minecraft.client.renderer.entity.state.PlayerRenderState; import org.vivecraft.client.VRPlayersClient; +import org.vivecraft.client.extensions.EntityRenderStateExtension; -public class VRPlayerModel extends PlayerModel { +public class VRPlayerModel extends PlayerModel { private final boolean slim; public ModelPart vrHMD; VRPlayersClient.RotInfo rotInfo; @@ -21,41 +22,43 @@ public class VRPlayerModel extends PlayerModel { public VRPlayerModel(ModelPart modelPart, boolean isSlim) { super(modelPart, isSlim); this.slim = isSlim; - this.vrHMD = modelPart.getChild("vrHMD"); + this.vrHMD = this.head.getChild("vrHMD"); } public static MeshDefinition createMesh(CubeDeformation p_170826_, boolean p_170827_) { MeshDefinition meshdefinition = PlayerModel.createMesh(p_170826_, p_170827_); PartDefinition partdefinition = meshdefinition.getRoot(); - partdefinition.addOrReplaceChild("vrHMD", CubeListBuilder.create().texOffs(0, 0).addBox(-3.5F, -6.0F, -7.5F, 7.0F, 4.0F, 5.0F, p_170826_), PartPose.ZERO); + partdefinition.getChild("head").addOrReplaceChild("vrHMD", CubeListBuilder.create().texOffs(0, 0).addBox(-3.5F, -6.0F, -7.5F, 7.0F, 4.0F, 5.0F, p_170826_), PartPose.ZERO); return meshdefinition; } - public void setupAnim(T pEntity, float pLimbSwing, float pLimbSwingAmount, float pAgeInTicks, float pNetHeadYaw, float pHeadPitch) { - super.setupAnim(pEntity, pLimbSwing, pLimbSwingAmount, pAgeInTicks, pNetHeadYaw, pHeadPitch); - this.rotInfo = VRPlayersClient.getInstance().getRotationsForPlayer(pEntity.getUUID()); - VRPlayersClient.RotInfo rotinfo = VRPlayersClient.getInstance().getRotationsForPlayer(pEntity.getUUID()); + public void setupAnim(PlayerRenderState playerRenderState) { + playerRenderState.isCrouching &= !playerRenderState.isVisuallySwimming; - if (rotinfo == null) { + super.setupAnim(playerRenderState); + + this.rotInfo = VRPlayersClient.getInstance().getRotationsForPlayer(((EntityRenderStateExtension)playerRenderState).vivecraft$getEntityUUID()); + + if (this.rotInfo == null) { return; //how } - double d0 = -1.501F * rotinfo.heightScale; - float f = (float) Math.toRadians(pEntity.getYRot()); - float f1 = (float) Math.atan2(-rotinfo.headRot.x, -rotinfo.headRot.z); - float f2 = (float) Math.asin(rotinfo.headRot.y / rotinfo.headRot.length()); - double d1 = rotinfo.getBodyYawRadians(); + double d0 = -1.501F * this.rotInfo.heightScale; + float f = (float) Math.toRadians(playerRenderState.yRot); + float f1 = (float) Math.atan2(-this.rotInfo.headRot.x, -this.rotInfo.headRot.z); + float f2 = (float) Math.asin(this.rotInfo.headRot.y / this.rotInfo.headRot.length()); + double d1 = this.rotInfo.getBodyYawRadians(); this.head.xRot = -f2; this.head.yRot = (float) (Math.PI - (double) f1 - d1); - this.laying = this.swimAmount > 0.0F || pEntity.isFallFlying() && !pEntity.isAutoSpinAttack(); + this.laying = playerRenderState.swimAmount > 0.0F || playerRenderState.isFallFlying && !playerRenderState.isAutoSpinAttack; if (this.laying) { this.head.z = 0.0F; this.head.x = 0.0F; this.head.y = -4.0F; this.head.xRot = (float) ((double) this.head.xRot - (Math.PI / 2D)); - } else if (this.crouching) { + } else if (playerRenderState.isCrouching) { // move head down when crouching this.head.z = 0.0F; this.head.x = 0.0F; @@ -66,13 +69,12 @@ public void setupAnim(T pEntity, float pLimbSwing, float pLimbSwingAmount, float this.head.y = 0.0F; } - this.vrHMD.visible = true; - - this.vrHMD.copyFrom(this.head); - this.hat.copyFrom(this.head); + this.vrHMD.visible = false; } public void renderHMDR(PoseStack poseStack, VertexConsumer vertexConsumer, int i, int noOverlay) { + this.vrHMD.visible = true; this.vrHMD.render(poseStack, vertexConsumer, i, noOverlay); + this.vrHMD.visible = false; } } diff --git a/common/src/main/java/org/vivecraft/client/render/VRPlayerModel_WithArms.java b/common/src/main/java/org/vivecraft/client/render/VRPlayerModel_WithArms.java index 49c5586fe..90f3a6008 100644 --- a/common/src/main/java/org/vivecraft/client/render/VRPlayerModel_WithArms.java +++ b/common/src/main/java/org/vivecraft/client/render/VRPlayerModel_WithArms.java @@ -12,82 +12,82 @@ import net.minecraft.client.model.geom.builders.CubeListBuilder; import net.minecraft.client.model.geom.builders.MeshDefinition; import net.minecraft.client.model.geom.builders.PartDefinition; +import net.minecraft.client.renderer.entity.state.PlayerRenderState; import net.minecraft.util.Mth; import net.minecraft.world.entity.HumanoidArm; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.phys.Vec3; -import org.vivecraft.client.VRPlayersClient; -import org.vivecraft.client_vr.utils.ScaleHelper; +import org.vivecraft.client.extensions.EntityRenderStateExtension; +import org.vivecraft.client_vr.ClientDataHolderVR; +import org.vivecraft.client_vr.render.RenderPass; import org.vivecraft.mod_compat_vr.optifine.OptifineHelper; import org.vivecraft.mod_compat_vr.sodium.SodiumHelper; -public class VRPlayerModel_WithArms extends VRPlayerModel { +public class VRPlayerModel_WithArms extends VRPlayerModel { private final boolean slim; - public ModelPart leftShoulder; - public ModelPart rightShoulder; - public ModelPart leftShoulder_sleeve; - public ModelPart rightShoulder_sleeve; public ModelPart leftHand; public ModelPart rightHand; - VRPlayersClient.RotInfo rotInfo; + public ModelPart leftHandSleeve; + public ModelPart rightHandSleeve; + private boolean laying; + // TODO 1.21.3 check if that can be solved a different way + private float attackTime; + public VRPlayerModel_WithArms(ModelPart modelPart, boolean isSlim) { super(modelPart, isSlim); this.slim = isSlim; // use left/right arm as shoulders - this.leftShoulder = modelPart.getChild("left_arm"); - this.rightShoulder = modelPart.getChild("right_arm"); - this.leftShoulder_sleeve = modelPart.getChild("leftShoulder_sleeve"); - this.rightShoulder_sleeve = modelPart.getChild("rightShoulder_sleeve"); - this.rightHand = modelPart.getChild("rightHand"); - this.leftHand = modelPart.getChild("leftHand"); + this.rightHand = modelPart.getChild("right_hand"); + this.leftHand = modelPart.getChild("left_hand"); + this.rightHandSleeve = rightHand.getChild("right_hand_sleeve"); + this.leftHandSleeve = leftHand.getChild("left_hand_sleeve"); //finger hax // some mods remove the base parts - if (!leftShoulder.cubes.isEmpty()) { - copyUV(leftShoulder.cubes.get(0).polygons[1], leftHand.cubes.get(0).polygons[1]); - copyUV(leftShoulder.cubes.get(0).polygons[1], leftHand.cubes.get(0).polygons[0]); + if (!leftArm.cubes.isEmpty()) { + copyUV(leftArm.cubes.get(0).polygons[1], leftHand.cubes.get(0).polygons[1]); + copyUV(leftArm.cubes.get(0).polygons[1], leftHand.cubes.get(0).polygons[0]); if (SodiumHelper.isLoaded()) { - SodiumHelper.copyModelCuboidUV(leftShoulder, leftHand, 3, 3); - SodiumHelper.copyModelCuboidUV(leftShoulder, leftHand, 3, 2); + SodiumHelper.copyModelCuboidUV(leftArm, leftHand, 3, 3); + SodiumHelper.copyModelCuboidUV(leftArm, leftHand, 3, 2); } } - if (!rightShoulder.cubes.isEmpty()) { - copyUV(rightShoulder.cubes.get(0).polygons[1], this.rightHand.cubes.get(0).polygons[1]); - copyUV(rightShoulder.cubes.get(0).polygons[1], this.rightHand.cubes.get(0).polygons[0]); + if (!rightArm.cubes.isEmpty()) { + copyUV(rightArm.cubes.get(0).polygons[1], this.rightHand.cubes.get(0).polygons[1]); + copyUV(rightArm.cubes.get(0).polygons[1], this.rightHand.cubes.get(0).polygons[0]); if (SodiumHelper.isLoaded()) { - SodiumHelper.copyModelCuboidUV(rightShoulder, rightHand, 3, 3); - SodiumHelper.copyModelCuboidUV(rightShoulder, rightHand, 3, 2); + SodiumHelper.copyModelCuboidUV(rightArm, rightHand, 3, 3); + SodiumHelper.copyModelCuboidUV(rightArm, rightHand, 3, 2); } } - if (!rightSleeve.cubes.isEmpty()) { - copyUV(rightShoulder_sleeve.cubes.get(0).polygons[1], this.rightSleeve.cubes.get(0).polygons[1]); - copyUV(rightShoulder_sleeve.cubes.get(0).polygons[1], this.rightSleeve.cubes.get(0).polygons[0]); + if (!rightHandSleeve.cubes.isEmpty()) { + copyUV(rightSleeve.cubes.get(0).polygons[1], this.rightHandSleeve.cubes.get(0).polygons[1]); + copyUV(rightSleeve.cubes.get(0).polygons[1], this.rightHandSleeve.cubes.get(0).polygons[0]); if (SodiumHelper.isLoaded()) { - SodiumHelper.copyModelCuboidUV(rightShoulder_sleeve, rightSleeve, 3, 3); - SodiumHelper.copyModelCuboidUV(rightShoulder_sleeve, rightSleeve, 3, 2); + SodiumHelper.copyModelCuboidUV(rightSleeve, rightHandSleeve, 3, 3); + SodiumHelper.copyModelCuboidUV(rightSleeve, rightHandSleeve, 3, 2); } } - if (!leftSleeve.cubes.isEmpty()) { - copyUV(leftShoulder_sleeve.cubes.get(0).polygons[1], leftSleeve.cubes.get(0).polygons[1]); - copyUV(leftShoulder_sleeve.cubes.get(0).polygons[1], leftSleeve.cubes.get(0).polygons[0]); + if (!leftHandSleeve.cubes.isEmpty()) { + copyUV(leftSleeve.cubes.get(0).polygons[1], leftHandSleeve.cubes.get(0).polygons[1]); + copyUV(leftSleeve.cubes.get(0).polygons[1], leftHandSleeve.cubes.get(0).polygons[0]); if (SodiumHelper.isLoaded()) { - SodiumHelper.copyModelCuboidUV(leftShoulder_sleeve, leftSleeve, 3, 3); - SodiumHelper.copyModelCuboidUV(leftShoulder_sleeve, leftSleeve, 3, 2); + SodiumHelper.copyModelCuboidUV(leftSleeve, leftHandSleeve, 3, 3); + SodiumHelper.copyModelCuboidUV(leftSleeve, leftHandSleeve, 3, 2); } } } private void copyUV(Polygon source, Polygon dest) { - for (int i = 0; i < source.vertices.length; i++) { - Vertex newVertex = new Vertex(dest.vertices[i].pos, source.vertices[i].u, source.vertices[i].v); + for (int i = 0; i < source.vertices().length; i++) { + Vertex newVertex = new Vertex(dest.vertices()[i].pos(), source.vertices()[i].u(), source.vertices()[i].v()); if (OptifineHelper.isOptifineLoaded()) { - OptifineHelper.copyRenderPositions(dest.vertices[i], newVertex); + OptifineHelper.copyRenderPositions(dest.vertices()[i], newVertex); } - dest.vertices[i] = newVertex; + dest.vertices()[i] = newVertex; } } @@ -96,138 +96,146 @@ public static MeshDefinition createMesh(CubeDeformation p_170826_, boolean p_170 PartDefinition partdefinition = meshdefinition.getRoot(); if (p_170827_) { - partdefinition.addOrReplaceChild("leftHand", CubeListBuilder.create().texOffs(32, 55).addBox(-1.0F, -2.0F, -2.0F, 3.0F, 5.0F, 4.0F, p_170826_), PartPose.offset(5.0F, 2.5F, 0.0F)); - partdefinition.addOrReplaceChild("left_sleeve", CubeListBuilder.create().texOffs(48, 55).addBox(-1.0F, -2.0F, -2.0F, 3.0F, 5.0F, 4.0F, p_170826_.extend(0.25f)), PartPose.offset(5.0F, 2.5F, 0.0F)); - partdefinition.addOrReplaceChild("rightHand", CubeListBuilder.create().texOffs(40, 23).addBox(-2.0F, -2.0F, -2.0F, 3.0F, 5.0F, 4.0F, p_170826_), PartPose.offset(-5.0F, 2.5F, 0.0F)); - partdefinition.addOrReplaceChild("right_sleeve", CubeListBuilder.create().texOffs(40, 39).addBox(-2.0F, -2.0F, -2.0F, 3.0F, 5.0F, 4.0F, p_170826_.extend(0.25f)), PartPose.offset(-5.0F, 2.5F, 0.0F)); - partdefinition.addOrReplaceChild("left_arm", CubeListBuilder.create().texOffs(32, 48).addBox(-1.0F, -2.0F, -2.0F, 3.0F, 5.0F, 4.0F, p_170826_), PartPose.offset(5.0F, 2.5F, 0.0F)); - partdefinition.addOrReplaceChild("right_arm", CubeListBuilder.create().texOffs(40, 16).addBox(-2.0F, -2.0F, -2.0F, 3.0F, 5.0F, 4.0F, p_170826_), PartPose.offset(-5.0F, 2.5F, 0.0F)); - partdefinition.addOrReplaceChild("leftShoulder_sleeve", CubeListBuilder.create().texOffs(48, 48).addBox(-1.0F, -2.0F, -2.0F, 3.0F, 5.0F, 4.0F, p_170826_.extend(0.25f)), PartPose.offset(5.0F, 2.5F, 0.0F)); - partdefinition.addOrReplaceChild("rightShoulder_sleeve", CubeListBuilder.create().texOffs(40, 32).addBox(-2.0F, -2.0F, -2.0F, 3.0F, 5.0F, 4.0F, p_170826_.extend(0.25f)), PartPose.offset(-5.0F, 2.5F, 0.0F)); + PartDefinition leftHand = partdefinition.addOrReplaceChild("left_hand", CubeListBuilder.create().texOffs(32, 55).addBox(-1.0F, -2.0F, -2.0F, 3.0F, 5.0F, 4.0F, p_170826_), PartPose.offset(5.0F, 2.5F, 0.0F)); + leftHand.addOrReplaceChild("left_hand_sleeve", CubeListBuilder.create().texOffs(48, 55).addBox(-1.0F, -2.0F, -2.0F, 3.0F, 5.0F, 4.0F, p_170826_.extend(0.25f)), PartPose.ZERO); + PartDefinition rightHand = partdefinition.addOrReplaceChild("right_hand", CubeListBuilder.create().texOffs(40, 23).addBox(-2.0F, -2.0F, -2.0F, 3.0F, 5.0F, 4.0F, p_170826_), PartPose.offset(-5.0F, 2.5F, 0.0F)); + rightHand.addOrReplaceChild("right_hand_sleeve", CubeListBuilder.create().texOffs(40, 39).addBox(-2.0F, -2.0F, -2.0F, 3.0F, 5.0F, 4.0F, p_170826_.extend(0.25f)), PartPose.ZERO); + PartDefinition leftShoulder = partdefinition.addOrReplaceChild("left_arm", CubeListBuilder.create().texOffs(32, 48).addBox(-1.0F, -2.0F, -2.0F, 3.0F, 5.0F, 4.0F, p_170826_), PartPose.offset(5.0F, 2.5F, 0.0F)); + PartDefinition rightShoulder = partdefinition.addOrReplaceChild("right_arm", CubeListBuilder.create().texOffs(40, 16).addBox(-2.0F, -2.0F, -2.0F, 3.0F, 5.0F, 4.0F, p_170826_), PartPose.offset(-5.0F, 2.5F, 0.0F)); + leftShoulder.addOrReplaceChild("left_sleeve", CubeListBuilder.create().texOffs(48, 48).addBox(-1.0F, -2.0F, -2.0F, 3.0F, 5.0F, 4.0F, p_170826_.extend(0.25f)), PartPose.ZERO); + rightShoulder.addOrReplaceChild("right_sleeve", CubeListBuilder.create().texOffs(40, 32).addBox(-2.0F, -2.0F, -2.0F, 3.0F, 5.0F, 4.0F, p_170826_.extend(0.25f)), PartPose.ZERO); } else { - partdefinition.addOrReplaceChild("leftHand", CubeListBuilder.create().texOffs(32, 55).addBox(-1.0F, -2.0F, -2.0F, 4.0F, 5.0F, 4.0F, p_170826_), PartPose.offset(5.0F, 2.5F, 0.0F)); - partdefinition.addOrReplaceChild("left_sleeve", CubeListBuilder.create().texOffs(48, 55).addBox(-1.0F, -2.0F, -2.0F, 4.0F, 5.0F, 4.0F, p_170826_.extend(0.25f)), PartPose.offset(5.0F, 2.5F, 0.0F)); - partdefinition.addOrReplaceChild("rightHand", CubeListBuilder.create().texOffs(40, 23).addBox(-2.0F, -2.0F, -2.0F, 4.0F, 5.0F, 4.0F, p_170826_), PartPose.offset(-5.0F, 2.5F, 0.0F)); - partdefinition.addOrReplaceChild("right_sleeve", CubeListBuilder.create().texOffs(40, 39).addBox(-2.0F, -2.0F, -2.0F, 4.0F, 5.0F, 4.0F, p_170826_.extend(0.25f)), PartPose.offset(-5.0F, 2.5F, 0.0F)); - partdefinition.addOrReplaceChild("left_arm", CubeListBuilder.create().texOffs(32, 48).addBox(-1.0F, -2.0F, -2.0F, 4.0F, 5.0F, 4.0F, p_170826_), PartPose.offset(5.0F, 2.5F, 0.0F)); - partdefinition.addOrReplaceChild("right_arm", CubeListBuilder.create().texOffs(40, 16).addBox(-2.0F, -2.0F, -2.0F, 4.0F, 5.0F, 4.0F, p_170826_), PartPose.offset(-5.0F, 2.5F, 0.0F)); - partdefinition.addOrReplaceChild("leftShoulder_sleeve", CubeListBuilder.create().texOffs(48, 48).addBox(-1.0F, -2.0F, -2.0F, 4.0F, 5.0F, 4.0F, p_170826_.extend(0.25f)), PartPose.offset(5.0F, 2.5F, 0.0F)); - partdefinition.addOrReplaceChild("rightShoulder_sleeve", CubeListBuilder.create().texOffs(40, 32).addBox(-2.0F, -2.0F, -2.0F, 4.0F, 5.0F, 4.0F, p_170826_.extend(0.25f)), PartPose.offset(-5.0F, 2.5F, 0.0F)); + PartDefinition leftHand = partdefinition.addOrReplaceChild("left_hand", CubeListBuilder.create().texOffs(32, 55).addBox(-1.0F, -2.0F, -2.0F, 4.0F, 5.0F, 4.0F, p_170826_), PartPose.offset(5.0F, 2.5F, 0.0F)); + leftHand.addOrReplaceChild("left_hand_sleeve", CubeListBuilder.create().texOffs(48, 55).addBox(-1.0F, -2.0F, -2.0F, 4.0F, 5.0F, 4.0F, p_170826_.extend(0.25f)), PartPose.ZERO); + PartDefinition rightHand = partdefinition.addOrReplaceChild("right_hand", CubeListBuilder.create().texOffs(40, 23).addBox(-2.0F, -2.0F, -2.0F, 4.0F, 5.0F, 4.0F, p_170826_), PartPose.offset(-5.0F, 2.5F, 0.0F)); + rightHand.addOrReplaceChild("right_hand_sleeve", CubeListBuilder.create().texOffs(40, 39).addBox(-2.0F, -2.0F, -2.0F, 4.0F, 5.0F, 4.0F, p_170826_.extend(0.25f)), PartPose.ZERO); + PartDefinition leftShoulder = partdefinition.addOrReplaceChild("left_arm", CubeListBuilder.create().texOffs(32, 48).addBox(-1.0F, -2.0F, -2.0F, 4.0F, 5.0F, 4.0F, p_170826_), PartPose.offset(5.0F, 2.5F, 0.0F)); + PartDefinition rightShoulder = partdefinition.addOrReplaceChild("right_arm", CubeListBuilder.create().texOffs(40, 16).addBox(-2.0F, -2.0F, -2.0F, 4.0F, 5.0F, 4.0F, p_170826_), PartPose.offset(-5.0F, 2.5F, 0.0F)); + leftShoulder.addOrReplaceChild("left_sleeve", CubeListBuilder.create().texOffs(48, 48).addBox(-1.0F, -2.0F, -2.0F, 4.0F, 5.0F, 4.0F, p_170826_.extend(0.25f)), PartPose.ZERO); + rightShoulder.addOrReplaceChild("right_sleeve", CubeListBuilder.create().texOffs(40, 32).addBox(-2.0F, -2.0F, -2.0F, 4.0F, 5.0F, 4.0F, p_170826_.extend(0.25f)), PartPose.ZERO); } return meshdefinition; } protected Iterable bodyParts() { - return ImmutableList.of(this.body, this.leftHand, this.rightHand, this.leftShoulder, this.rightShoulder, this.leftShoulder_sleeve, this.rightShoulder_sleeve, this.rightLeg, this.leftLeg, this.hat, this.leftPants, this.rightPants, this.leftSleeve, this.rightSleeve, this.jacket); + return ImmutableList.of(this.body, this.leftHand, this.rightHand, this.leftArm, this.rightArm, this.leftSleeve, this.rightSleeve, this.rightLeg, this.leftLeg, this.hat, this.leftPants, this.rightPants, this.leftHandSleeve, this.rightHandSleeve, this.jacket); } - public void setupAnim(T pEntity, float pLimbSwing, float pLimbSwingAmount, float pAgeInTicks, float pNetHeadYaw, float pHeadPitch) { - super.setupAnim(pEntity, pLimbSwing, pLimbSwingAmount, pAgeInTicks, pNetHeadYaw, pHeadPitch); - this.rotInfo = VRPlayersClient.getInstance().getRotationsForPlayer(pEntity.getUUID()); - VRPlayersClient.RotInfo rotinfo = VRPlayersClient.getInstance().getRotationsForPlayer(pEntity.getUUID()); + public void setupAnim(PlayerRenderState playerRenderState) { + super.setupAnim(playerRenderState); + + this.attackTime = playerRenderState.attackTime; - if (rotinfo == null) { + if (Minecraft.getInstance().player != null && Minecraft.getInstance().player.getUUID().equals(((EntityRenderStateExtension) playerRenderState).vivecraft$getEntityUUID()) && ClientDataHolderVR.getInstance().currentPass == RenderPass.CAMERA && ClientDataHolderVR.getInstance().cameraTracker.isQuickMode() && ClientDataHolderVR.getInstance().grabScreenShot) { + // player hands block the camera, so disable them for the screenshot + this.leftHand.visible = false; + this.rightHand.visible = false; + this.leftHandSleeve.visible = false; + this.rightHandSleeve.visible = false; + } + + if (this.rotInfo == null) { return; } - double d0 = -1.501F * rotinfo.heightScale; - float f = (float) Math.toRadians(pEntity.getYRot()); - float f1 = (float) Math.atan2(-rotinfo.headRot.x, -rotinfo.headRot.z); - float f2 = (float) Math.asin(rotinfo.headRot.y / rotinfo.headRot.length()); - float f3 = (float) Math.atan2(-rotinfo.leftArmRot.x, -rotinfo.leftArmRot.z); - float f4 = (float) Math.asin(rotinfo.leftArmRot.y / rotinfo.leftArmRot.length()); - float f5 = (float) Math.atan2(-rotinfo.rightArmRot.x, -rotinfo.rightArmRot.z); - float f6 = (float) Math.asin(rotinfo.rightArmRot.y / rotinfo.rightArmRot.length()); - double d1 = rotinfo.getBodyYawRadians(); - - this.laying = this.swimAmount > 0.0F || pEntity.isFallFlying() && !pEntity.isAutoSpinAttack(); - - if (!rotinfo.reverse) { - this.rightShoulder.setPos(-Mth.cos(this.body.yRot) * 5.0F, this.slim ? 2.5F : 2.0F, Mth.sin(this.body.yRot) * 5.0F); - this.leftShoulder.setPos(Mth.cos(this.body.yRot) * 5.0F, this.slim ? 2.5F : 2.0F, -Mth.sin(this.body.yRot) * 5.0F); + double d0 = -1.501F * this.rotInfo.heightScale; + float f = (float) Math.toRadians(playerRenderState.yRot); + float f1 = (float) Math.atan2(-this.rotInfo.headRot.x, -this.rotInfo.headRot.z); + float f2 = (float) Math.asin(this.rotInfo.headRot.y / this.rotInfo.headRot.length()); + float f3 = (float) Math.atan2(-this.rotInfo.leftArmRot.x, -this.rotInfo.leftArmRot.z); + float f4 = (float) Math.asin(this.rotInfo.leftArmRot.y / this.rotInfo.leftArmRot.length()); + float f5 = (float) Math.atan2(-this.rotInfo.rightArmRot.x, -this.rotInfo.rightArmRot.z); + float f6 = (float) Math.asin(this.rotInfo.rightArmRot.y / this.rotInfo.rightArmRot.length()); + double d1 = this.rotInfo.getBodyYawRadians(); + + this.laying = playerRenderState.swimAmount > 0.0F || playerRenderState.isFallFlying && !playerRenderState.isAutoSpinAttack; + + if (!this.rotInfo.reverse) { + this.rightArm.setPos(-Mth.cos(this.body.yRot) * 5.0F, this.slim ? 2.5F : 2.0F, Mth.sin(this.body.yRot) * 5.0F); + this.leftArm.setPos(Mth.cos(this.body.yRot) * 5.0F, this.slim ? 2.5F : 2.0F, -Mth.sin(this.body.yRot) * 5.0F); } else { - this.leftShoulder.setPos(-Mth.cos(this.body.yRot) * 5.0F, this.slim ? 2.5F : 2.0F, Mth.sin(this.body.yRot) * 5.0F); - this.rightShoulder.setPos(Mth.cos(this.body.yRot) * 5.0F, this.slim ? 2.5F : 2.0F, -Mth.sin(this.body.yRot) * 5.0F); + this.leftArm.setPos(-Mth.cos(this.body.yRot) * 5.0F, this.slim ? 2.5F : 2.0F, Mth.sin(this.body.yRot) * 5.0F); + this.rightArm.setPos(Mth.cos(this.body.yRot) * 5.0F, this.slim ? 2.5F : 2.0F, -Mth.sin(this.body.yRot) * 5.0F); } - if (this.crouching) { - this.rightShoulder.y += 3.2F; - this.leftShoulder.y += 3.2F; + if (playerRenderState.isCrouching) { + this.rightArm.y += 3.2F; + this.leftArm.y += 3.2F; } // remove entity scale from that - float scale = 1.0F / ScaleHelper.getEntityScale(pEntity, Minecraft.getInstance().getTimer().getGameTimeDeltaPartialTick(false)); - Vec3 vec3 = rotinfo.leftArmPos.scale(scale); - Vec3 vec32 = rotinfo.rightArmPos.scale(scale); + float scale = 1.0F / playerRenderState.scale; + Vec3 vec3 = this.rotInfo.leftArmPos.scale(scale); + Vec3 vec32 = this.rotInfo.rightArmPos.scale(scale); vec3 = vec3.add(0.0D, d0, 0.0D); vec3 = vec3.yRot((float) (-Math.PI + d1)); - vec3 = vec3.scale(16.0F / rotinfo.heightScale); + vec3 = vec3.scale(16.0F / this.rotInfo.heightScale); this.leftHand.setPos((float) (-vec3.x), (float) (-vec3.y), (float) vec3.z); this.leftHand.xRot = (float) ((double) (-f4) + (Math.PI * 1.5D)); this.leftHand.yRot = (float) (Math.PI - (double) f3 - d1); this.leftHand.zRot = 0.0F; - Vec3 vec31 = new Vec3((double) this.leftShoulder.x + vec3.x, (double) this.leftShoulder.y + vec3.y, (double) this.leftShoulder.z - vec3.z); + Vec3 vec31 = new Vec3((double) this.leftArm.x + vec3.x, (double) this.leftArm.y + vec3.y, (double) this.leftArm.z - vec3.z); float f7 = (float) Math.atan2(vec31.x, vec31.z); float f8 = (float) ((Math.PI * 1.5D) - Math.asin(vec31.y / vec31.length())); - this.leftShoulder.zRot = 0.0F; - this.leftShoulder.xRot = f8; - this.leftShoulder.yRot = f7; + this.leftArm.zRot = 0.0F; + this.leftArm.xRot = f8; + this.leftArm.yRot = f7; - if (this.leftShoulder.yRot > 0.0F) { - this.leftShoulder.yRot = 0.0F; + if (this.leftArm.yRot > 0.0F) { + this.leftArm.yRot = 0.0F; } - if (this.leftArmPose == ArmPose.THROW_SPEAR) { + if (getArmPose(playerRenderState, HumanoidArm.RIGHT) == ArmPose.THROW_SPEAR) { this.leftHand.xRot = (float) ((double) this.leftHand.xRot - (Math.PI / 2D)); } vec32 = vec32.add(0.0D, d0, 0.0D); vec32 = vec32.yRot((float) (-Math.PI + d1)); - vec32 = vec32.scale(16.0F / rotinfo.heightScale); + vec32 = vec32.scale(16.0F / this.rotInfo.heightScale); this.rightHand.setPos((float) (-vec32.x), -((float) vec32.y), (float) vec32.z); this.rightHand.xRot = (float) ((double) (-f6) + (Math.PI * 1.5D)); this.rightHand.yRot = (float) (Math.PI - (double) f5 - d1); this.rightHand.zRot = 0.0F; - Vec3 vec33 = new Vec3((double) this.rightShoulder.x + vec32.x, (double) this.rightShoulder.y + vec32.y, (double) this.rightShoulder.z - vec32.z); + Vec3 vec33 = new Vec3((double) this.rightArm.x + vec32.x, (double) this.rightArm.y + vec32.y, (double) this.rightArm.z - vec32.z); float f9 = (float) Math.atan2(vec33.x, vec33.z); float f10 = (float) ((Math.PI * 1.5D) - Math.asin(vec33.y / vec33.length())); - this.rightShoulder.zRot = 0.0F; - this.rightShoulder.xRot = f10; - this.rightShoulder.yRot = f9; + this.rightArm.zRot = 0.0F; + this.rightArm.xRot = f10; + this.rightArm.yRot = f9; - if (this.rightShoulder.yRot < 0.0F) { - this.rightShoulder.yRot = 0.0F; + if (this.rightArm.yRot < 0.0F) { + this.rightArm.yRot = 0.0F; } - if (this.rightArmPose == ArmPose.THROW_SPEAR) { + if (this.getArmPose(playerRenderState, HumanoidArm.RIGHT) == ArmPose.THROW_SPEAR) { this.rightHand.xRot = (float) ((double) this.rightHand.xRot - (Math.PI / 2D)); } if (this.laying) { - this.rightShoulder.xRot = (float) ((double) this.rightShoulder.xRot - (Math.PI / 2D)); - this.leftShoulder.xRot = (float) ((double) this.leftShoulder.xRot - (Math.PI / 2D)); + this.rightArm.xRot = (float) ((double) this.rightArm.xRot - (Math.PI / 2D)); + this.leftArm.xRot = (float) ((double) this.leftArm.xRot - (Math.PI / 2D)); } - this.leftSleeve.copyFrom(this.leftHand); - this.rightSleeve.copyFrom(this.rightHand); - this.leftShoulder_sleeve.copyFrom(this.leftShoulder); - this.rightShoulder_sleeve.copyFrom(this.rightShoulder); - this.leftShoulder_sleeve.visible = this.leftSleeve.visible; - this.rightShoulder_sleeve.visible = this.rightSleeve.visible; + //this.leftHandSleeve.copyFrom(this.leftHand); + //this.rightHandSleeve.copyFrom(this.rightHand); + //this.leftShoulder_sleeve.copyFrom(this.leftShoulder); + //this.rightShoulder_sleeve.copyFrom(this.rightShoulder); + this.leftSleeve.visible = this.leftHandSleeve.visible; + this.rightSleeve.visible = this.rightHandSleeve.visible; + setAllVisible(true); } public void setAllVisible(boolean pVisible) { super.setAllVisible(pVisible); - - this.rightShoulder.visible = pVisible; - this.leftShoulder.visible = pVisible; - this.rightShoulder_sleeve.visible = pVisible; - this.leftShoulder_sleeve.visible = pVisible; + this.rightArm.visible = pVisible; + this.leftArm.visible = pVisible; + this.rightSleeve.visible = pVisible; + this.leftSleeve.visible = pVisible; this.rightHand.visible = pVisible; this.leftHand.visible = pVisible; } @@ -280,8 +288,8 @@ public void translateToHand(HumanoidArm pSide, PoseStack pMatrixStack) { // this.leftHand.render(pMatrixStack, pBuffer, pPackedLight, pPackedOverlay, pRed, pGreen, pBlue, pAlpha); // } // -// this.leftSleeve.render(pMatrixStack, pBuffer, pPackedLight, pPackedOverlay, pRed, pGreen, pBlue, pAlpha); -// this.rightSleeve.render(pMatrixStack, pBuffer, pPackedLight, pPackedOverlay, pRed, pGreen, pBlue, pAlpha); +// this.leftHandSleeve.render(pMatrixStack, pBuffer, pPackedLight, pPackedOverlay, pRed, pGreen, pBlue, pAlpha); +// this.rightHandSleeve.render(pMatrixStack, pBuffer, pPackedLight, pPackedOverlay, pRed, pGreen, pBlue, pAlpha); // pMatrixStack.popPose(); // } } diff --git a/common/src/main/java/org/vivecraft/client/render/VRPlayerRenderer.java b/common/src/main/java/org/vivecraft/client/render/VRPlayerRenderer.java index 2fb170db9..d84564bbe 100644 --- a/common/src/main/java/org/vivecraft/client/render/VRPlayerRenderer.java +++ b/common/src/main/java/org/vivecraft/client/render/VRPlayerRenderer.java @@ -1,16 +1,16 @@ package org.vivecraft.client.render; import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.Minecraft; import net.minecraft.client.model.geom.builders.CubeDeformation; import net.minecraft.client.model.geom.builders.LayerDefinition; -import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.client.renderer.entity.layers.RenderLayer; import net.minecraft.client.renderer.entity.player.PlayerRenderer; +import net.minecraft.client.renderer.entity.state.PlayerRenderState; import net.minecraft.world.phys.Vec3; import org.vivecraft.client.VRPlayersClient; +import org.vivecraft.client.extensions.EntityRenderStateExtension; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.render.RenderPass; @@ -26,11 +26,11 @@ public VRPlayerRenderer(EntityRendererProvider.Context context, boolean slim, bo super(context, slim); model = !slim ? (seated ? - new VRPlayerModel<>(VRLayerDef.bakeRoot(), slim) : - new VRPlayerModel_WithArms<>(VRLayerDef_arms.bakeRoot(), slim)) : + new VRPlayerModel(VRLayerDef.bakeRoot(), slim) : + new VRPlayerModel_WithArms(VRLayerDef_arms.bakeRoot(), slim)) : (seated ? - new VRPlayerModel<>(VRLayerDef_slim.bakeRoot(), slim) : - new VRPlayerModel_WithArms<>(VRLayerDef_arms_slim.bakeRoot(), slim)); + new VRPlayerModel(VRLayerDef_slim.bakeRoot(), slim) : + new VRPlayerModel_WithArms(VRLayerDef_arms_slim.bakeRoot(), slim)); this.addLayer(new HMDLayer(this)); } @@ -40,48 +40,21 @@ public boolean hasLayerType(RenderLayer renderLayer) { } @Override - public void render(AbstractClientPlayer entityIn, float pEntityYaw, float pPartialTicks, PoseStack matrixStackIn, MultiBufferSource pBuffer, int pPackedLight) { - - VRPlayersClient.RotInfo playermodelcontroller$rotinfo = VRPlayersClient.getInstance().getRotationsForPlayer(entityIn.getUUID()); - - if (playermodelcontroller$rotinfo != null) { - matrixStackIn.scale(playermodelcontroller$rotinfo.heightScale, playermodelcontroller$rotinfo.heightScale, playermodelcontroller$rotinfo.heightScale); - super.render(entityIn, pEntityYaw, pPartialTicks, matrixStackIn, pBuffer, pPackedLight); - matrixStackIn.scale(1.0F, 1.0F / playermodelcontroller$rotinfo.heightScale, 1.0F); - } - } - - @Override - public Vec3 getRenderOffset(AbstractClientPlayer pEntity, float pPartialTicks) { + public Vec3 getRenderOffset(PlayerRenderState playerRenderState) { //idk why we do this anymore - return pEntity.isVisuallySwimming() ? new Vec3(0.0D, -0.125D, 0.0D) : Vec3.ZERO; + return playerRenderState.isVisuallySwimming ? new Vec3(0.0D, -0.125D, 0.0D) : Vec3.ZERO; // return pEntity.isCrouching() ? new Vec3(0.0D, -0.125D, 0.0D) : super.getRenderOffset(pEntity, pPartialTicks); } @Override - public void setModelProperties(AbstractClientPlayer pClientPlayer) { - super.setModelProperties(pClientPlayer); - - this.getModel().crouching &= !pClientPlayer.isVisuallySwimming(); - - if (pClientPlayer == Minecraft.getInstance().player && this.getModel() instanceof VRPlayerModel_WithArms armsModel && ClientDataHolderVR.getInstance().currentPass == RenderPass.CAMERA && ClientDataHolderVR.getInstance().cameraTracker.isQuickMode() && ClientDataHolderVR.getInstance().grabScreenShot) { - // player hands block the camera, so disable them for the screenshot - armsModel.leftHand.visible = false; - armsModel.rightHand.visible = false; - armsModel.leftSleeve.visible = false; - armsModel.rightSleeve.visible = false; - } - } - - @Override - protected void setupRotations(AbstractClientPlayer pEntityLiving, PoseStack pMatrixStack, float pAgeInTicks, float pRotationYaw, float pPartialTicks, float entityScale) { - UUID uuid = pEntityLiving.getUUID(); + protected void setupRotations(PlayerRenderState playerRenderState, PoseStack poseStack, float yRot, float scale) { + UUID uuid = ((EntityRenderStateExtension) playerRenderState).vivecraft$getEntityUUID(); if (ClientDataHolderVR.getInstance().currentPass != RenderPass.GUI && VRPlayersClient.getInstance().isTracked(uuid)) { VRPlayersClient.RotInfo playermodelcontroller$rotinfo = VRPlayersClient.getInstance().getRotationsForPlayer(uuid); - pRotationYaw = (float) Math.toDegrees(playermodelcontroller$rotinfo.getBodyYawRadians()); + yRot = (float) Math.toDegrees(playermodelcontroller$rotinfo.getBodyYawRadians()); } //vanilla below here - super.setupRotations(pEntityLiving, pMatrixStack, pAgeInTicks, pRotationYaw, pPartialTicks, entityScale); + super.setupRotations(playerRenderState, poseStack, yRot, scale); } } diff --git a/common/src/main/java/org/vivecraft/client_vr/ClientDataHolderVR.java b/common/src/main/java/org/vivecraft/client_vr/ClientDataHolderVR.java index 0c3f1e201..d6bfc1c4e 100644 --- a/common/src/main/java/org/vivecraft/client_vr/ClientDataHolderVR.java +++ b/common/src/main/java/org/vivecraft/client_vr/ClientDataHolderVR.java @@ -18,8 +18,8 @@ public class ClientDataHolderVR { public static boolean katvr; public static boolean infinadeck; public static boolean viewonly; - public static ModelResourceLocation thirdPersonCameraModel = new ModelResourceLocation(ResourceLocation.fromNamespaceAndPath("vivecraft", "camcorder"), "standalone"); - public static ModelResourceLocation thirdPersonCameraDisplayModel = new ModelResourceLocation(ResourceLocation.fromNamespaceAndPath("vivecraft", "camcorder_display"), "standalone"); + public static ModelResourceLocation thirdPersonCameraModel = ModelResourceLocation.inventory(ResourceLocation.fromNamespaceAndPath("vivecraft", "camcorder")); + public static ModelResourceLocation thirdPersonCameraDisplayModel = ModelResourceLocation.inventory(ResourceLocation.fromNamespaceAndPath("vivecraft", "camcorder_display")); private static ClientDataHolderVR INSTANCE; public VRPlayer vrPlayer; diff --git a/common/src/main/java/org/vivecraft/client_vr/MultiPassRenderTarget.java b/common/src/main/java/org/vivecraft/client_vr/MultiPassRenderTarget.java new file mode 100644 index 000000000..ae9733724 --- /dev/null +++ b/common/src/main/java/org/vivecraft/client_vr/MultiPassRenderTarget.java @@ -0,0 +1,132 @@ +package org.vivecraft.client_vr; + +import com.mojang.blaze3d.pipeline.RenderTarget; +import org.vivecraft.client_vr.render.RenderPass; +import org.vivecraft.client_xr.render_pass.RenderPassType; + +import java.util.EnumMap; +import java.util.function.Consumer; +import java.util.function.Function; + +/** + * A RenderTarget that holds multiple RenderTargets for each RenderPass, and delegates calls to the current active one + */ +public class MultiPassRenderTarget extends RenderTarget { + + private final RenderTarget mainTarget; + private final EnumMap vrTargets; + + public MultiPassRenderTarget(RenderTarget mainTarget, EnumMap vrTargets) { + super(mainTarget.useDepth); + this.mainTarget = mainTarget; + this.vrTargets = vrTargets; + + // use the default vanilla target for those + this.width = mainTarget.width; + this.height = mainTarget.height; + this.viewWidth = mainTarget.viewWidth; + this.viewHeight = mainTarget.viewHeight; + this.frameBufferId = mainTarget.frameBufferId; + this.filterMode = mainTarget.filterMode; + } + + @Override + public void resize(int width, int height) { + callOnTarget(r -> r.resize(width, height)); + } + + @Override + public void destroyBuffers() { + // this one should be called on all RenderTargets + this.mainTarget.destroyBuffers(); + for (RenderTarget renderTarget : this.vrTargets.values()) { + renderTarget.destroyBuffers(); + } + } + + @Override + public void copyDepthFrom(RenderTarget otherTarget) { + callOnTarget(r -> r.copyDepthFrom(otherTarget)); + } + + @Override + public void createBuffers(int width, int height) { + callOnTarget(r -> r.createBuffers(width, height)); + } + + @Override + public void setFilterMode(int filterMode) { + callOnTarget(r -> r.setFilterMode(filterMode)); + } + + @Override + public void checkStatus() { + callOnTarget(RenderTarget::checkStatus); + } + + @Override + public void bindRead() { + callOnTarget(RenderTarget::bindRead); + } + + @Override + public void unbindRead() { + callOnTarget(RenderTarget::unbindRead); + } + + @Override + public void bindWrite(boolean setViewport) { + callOnTarget(r -> r.bindWrite(setViewport)); + } + + @Override + public void unbindWrite() { + callOnTarget(RenderTarget::unbindWrite); + } + + @Override + public void setClearColor(float red, float green, float blue, float alpha) { + callOnTarget(r -> r.setClearColor(red, green, blue, alpha)); + } + + @Override + public void blitToScreen(int width, int height) { + callOnTarget(r -> r.blitToScreen(width, height)); + } + + @Override + public void blitAndBlendToScreen(int width, int height) { + callOnTarget(r -> r.blitAndBlendToScreen(width, height)); + } + + @Override + public void clear() { + callOnTarget(RenderTarget::clear); + } + + @Override + public int getColorTextureId() { + return callOnTargetInt(RenderTarget::getColorTextureId); + } + + @Override + public int getDepthTextureId() { + return callOnTargetInt(RenderTarget::getDepthTextureId); + } + + private void callOnTarget(Consumer consumer) { + if (RenderPassType.isVanilla()) { + consumer.accept(this.mainTarget); + } else { + consumer.accept(this.vrTargets.get(ClientDataHolderVR.getInstance().currentPass)); + } + } + + private int callOnTargetInt(Function function) { + if (RenderPassType.isVanilla()) { + return function.apply(this.mainTarget); + } else { + return function.apply(this.vrTargets.get(ClientDataHolderVR.getInstance().currentPass)); + } + } +} diff --git a/common/src/main/java/org/vivecraft/client_vr/VRTextureTarget.java b/common/src/main/java/org/vivecraft/client_vr/VRTextureTarget.java index 150e848bf..590944501 100644 --- a/common/src/main/java/org/vivecraft/client_vr/VRTextureTarget.java +++ b/common/src/main/java/org/vivecraft/client_vr/VRTextureTarget.java @@ -9,7 +9,7 @@ public class VRTextureTarget extends RenderTarget { private final String name; - public VRTextureTarget(String name, int width, int height, boolean usedepth, boolean onMac, int texid, boolean depthtex, boolean linearFilter, boolean useStencil) { + public VRTextureTarget(String name, int width, int height, boolean usedepth, int texid, boolean depthtex, boolean linearFilter, boolean useStencil) { super(usedepth); this.name = name; RenderSystem.assertOnRenderThreadOrInit(); @@ -20,11 +20,12 @@ public VRTextureTarget(String name, int width, int height, boolean usedepth, boo this.viewWidth = width; this.viewHeight = height; + if (useStencil && !Xplat.enableRenderTargetStencil(this)) { // use our stencil only if the modloader doesn't support it ((RenderTargetExtension) this).vivecraft$setUseStencil(true); } - this.resize(width, height, onMac); + this.resize(width, height); this.setClearColor(0, 0, 0, 0); } diff --git a/common/src/main/java/org/vivecraft/client_vr/extensions/FrustumExtension.java b/common/src/main/java/org/vivecraft/client_vr/extensions/FrustumExtension.java index 74826717c..e0c2e1b7d 100644 --- a/common/src/main/java/org/vivecraft/client_vr/extensions/FrustumExtension.java +++ b/common/src/main/java/org/vivecraft/client_vr/extensions/FrustumExtension.java @@ -1,10 +1,7 @@ package org.vivecraft.client_vr.extensions; -import net.minecraft.world.phys.AABB; public interface FrustumExtension { void vivecraft$setCameraPosition(double var1, double var3, double var5); - - boolean vivecraft$isBoundingBoxInFrustum(AABB var1); } diff --git a/common/src/main/java/org/vivecraft/client_vr/extensions/LevelRendererExtension.java b/common/src/main/java/org/vivecraft/client_vr/extensions/LevelRendererExtension.java index 12aaa38a6..e169afb7a 100644 --- a/common/src/main/java/org/vivecraft/client_vr/extensions/LevelRendererExtension.java +++ b/common/src/main/java/org/vivecraft/client_vr/extensions/LevelRendererExtension.java @@ -1,16 +1,7 @@ package org.vivecraft.client_vr.extensions; -import com.mojang.blaze3d.pipeline.RenderTarget; import net.minecraft.world.entity.Entity; public interface LevelRendererExtension { Entity vivecraft$getRenderedEntity(); - - RenderTarget vivecraft$getAlphaSortVROccludedFramebuffer(); - - RenderTarget vivecraft$getAlphaSortVRUnoccludedFramebuffer(); - - RenderTarget vivecraft$getAlphaSortVRHandsFramebuffer(); - - void vivecraft$restoreVanillaPostChains(); } diff --git a/common/src/main/java/org/vivecraft/client_vr/extensions/LevelTargetBundleExtension.java b/common/src/main/java/org/vivecraft/client_vr/extensions/LevelTargetBundleExtension.java new file mode 100644 index 000000000..eb78adc1f --- /dev/null +++ b/common/src/main/java/org/vivecraft/client_vr/extensions/LevelTargetBundleExtension.java @@ -0,0 +1,22 @@ +package org.vivecraft.client_vr.extensions; + +import com.mojang.blaze3d.pipeline.RenderTarget; +import com.mojang.blaze3d.resource.ResourceHandle; +import net.minecraft.client.renderer.LevelTargetBundle; +import net.minecraft.resources.ResourceLocation; + +import java.util.Set; + +public interface LevelTargetBundleExtension { + ResourceLocation OCCLUDED_TARGET_ID = ResourceLocation.fromNamespaceAndPath("vivecraft", "vroccluded"); + ResourceLocation UNOCCLUDED_TARGET_ID = ResourceLocation.fromNamespaceAndPath("vivecraft", "vrunoccluded"); + ResourceLocation HANDS_TARGET_ID = ResourceLocation.fromNamespaceAndPath("vivecraft", "vrhands"); + + Set VR_TARGETS = Set.of(LevelTargetBundle.MAIN_TARGET_ID, LevelTargetBundle.TRANSLUCENT_TARGET_ID, LevelTargetBundle.ITEM_ENTITY_TARGET_ID, LevelTargetBundle.PARTICLES_TARGET_ID, LevelTargetBundle.WEATHER_TARGET_ID, LevelTargetBundle.CLOUDS_TARGET_ID, OCCLUDED_TARGET_ID, UNOCCLUDED_TARGET_ID, HANDS_TARGET_ID); + + ResourceHandle vivecraft$getOccluded(); + + ResourceHandle vivecraft$getUnoccluded(); + + ResourceHandle vivecraft$getHands(); +} diff --git a/common/src/main/java/org/vivecraft/client_vr/extensions/MinecraftExtension.java b/common/src/main/java/org/vivecraft/client_vr/extensions/MinecraftExtension.java index 6f0d36c6b..975250b11 100644 --- a/common/src/main/java/org/vivecraft/client_vr/extensions/MinecraftExtension.java +++ b/common/src/main/java/org/vivecraft/client_vr/extensions/MinecraftExtension.java @@ -3,5 +3,4 @@ public interface MinecraftExtension { void vivecraft$notifyMirror(String buttonDisplayString, boolean b, int i); - void vivecraft$drawProfiler(); } diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/VRPlayer.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/VRPlayer.java index 9bce8779e..dffd899b3 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/VRPlayer.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/VRPlayer.java @@ -147,7 +147,7 @@ public void preTick() { this.worldScale = rawWorldScale; // scale world with player size - this.worldScale *= ScaleHelper.getEntityScale(mc.player, mc.getTimer().getGameTimeDeltaPartialTick(false)); + this.worldScale *= ScaleHelper.getEntityScale(mc.player, mc.getDeltaTracker().getGameTimeDeltaPartialTick(false)); // limit scale if (this.worldScale > 100F) { this.worldScale = 100F; @@ -543,7 +543,7 @@ public void doPermanantLookOverride(LocalPlayer entity, VRData data) { entity.setYHeadRot(entity.getYRot()); entity.setXRot(-data.getController(1).getPitch()); } - } else if (entity.isSprinting() && (entity.input.jumping || mc.options.keyJump.isDown()) || entity.isFallFlying() || entity.isSwimming() && entity.zza > 0.0F) { + } else if (entity.isSprinting() && (entity.input.keyPresses.jump() || mc.options.keyJump.isDown()) || entity.isFallFlying() || entity.isSwimming() && entity.zza > 0.0F) { //Server-side movement VRSettings.FreeMove freeMoveType = entity.isFallFlying() && this.dh.vrSettings.vrFreeMoveFlyMode != VRSettings.FreeMove.AUTO ? this.dh.vrSettings.vrFreeMoveFlyMode : this.dh.vrSettings.vrFreeMoveMode; diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/screenhandlers/GuiHandler.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/screenhandlers/GuiHandler.java index 6c40e2b6b..99837a619 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/screenhandlers/GuiHandler.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/screenhandlers/GuiHandler.java @@ -12,6 +12,7 @@ import net.minecraft.client.gui.screens.inventory.BookEditScreen; import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; +import net.minecraft.util.profiling.Profiler; import net.minecraft.world.entity.vehicle.ContainerEntity; import net.minecraft.world.phys.*; import org.joml.Vector2f; @@ -429,7 +430,7 @@ public static void onScreenChanged(Screen previousGuiScreen, Screen newScreen, b } public static Vec3 applyGUIModelView(RenderPass currentPass, org.joml.Matrix4f pMatrixStack) { - mc.getProfiler().push("applyGUIModelView"); + Profiler.get().push("applyGUIModelView"); Vec3 vec3 = RenderHelper.getSmoothCameraPosition(currentPass, dh.vrPlayer.vrdata_world_render); if (mc.screen != null && guiPos_room == null) { @@ -560,7 +561,7 @@ public static Vec3 applyGUIModelView(RenderPass currentPass, org.joml.Matrix4f p float f2 = scale * dh.vrPlayer.vrdata_world_render.worldScale; pMatrixStack.scale(f2, f2, f2); guiScaleApplied = f2; - mc.getProfiler().pop(); + Profiler.get().pop(); return guipos; } } diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/BowTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/BowTracker.java index 2ba04064e..d9406c2f5 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/BowTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/BowTracker.java @@ -9,7 +9,7 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.item.UseAnim; +import net.minecraft.world.item.ItemUseAnimation; import net.minecraft.world.phys.Vec3; import org.vivecraft.client.VivecraftVRMod; import org.vivecraft.client.network.ClientNetworking; @@ -70,7 +70,7 @@ public static boolean isBow(ItemStack itemStack) { } else if (ClientDataHolderVR.getInstance().vrSettings.bowMode == VRSettings.BowMode.VANILLA) { return itemStack.getItem() == Items.BOW; } else { - return itemStack.getItem().getUseAnimation(itemStack) == UseAnim.BOW && !itemStack.is(org.vivecraft.client_vr.ItemTags.VIVECRAFT_BOW_EXCLUSION); + return itemStack.getItem().getUseAnimation(itemStack) == ItemUseAnimation.BOW && !itemStack.is(org.vivecraft.client_vr.ItemTags.VIVECRAFT_BOW_EXCLUSION); } } @@ -128,7 +128,7 @@ public void doProcess(LocalPlayer player) { this.lastcanDraw = this.canDraw; // this is meant to be relative to the base Bb height, not the scaled one - this.maxDraw = (double) this.mc.player.getBbHeight() * 0.22D / ScaleHelper.getEntityBbScale(player, mc.getTimer().getGameTimeDeltaPartialTick(false)); + this.maxDraw = (double) this.mc.player.getBbHeight() * 0.22D / ScaleHelper.getEntityBbScale(player, mc.getDeltaTracker().getGameTimeDeltaPartialTick(false)); Vec3 vec3 = vrdata.getController(0).getPosition(); Vec3 vec31 = vrdata.getController(1).getPosition(); diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/CameraTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/CameraTracker.java index c0a575b55..4d32f1351 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/CameraTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/CameraTracker.java @@ -14,8 +14,8 @@ import org.vivecraft.common.utils.math.Vector3; public class CameraTracker extends Tracker { - public static final ModelResourceLocation cameraModel = new ModelResourceLocation(ResourceLocation.fromNamespaceAndPath("vivecraft", "camera"), "standalone"); - public static final ModelResourceLocation cameraDisplayModel = new ModelResourceLocation(ResourceLocation.fromNamespaceAndPath("vivecraft", "camera_display"), "standalone"); + public static final ModelResourceLocation cameraModel = ModelResourceLocation.inventory(ResourceLocation.fromNamespaceAndPath("vivecraft", "camera")); + public static final ModelResourceLocation cameraDisplayModel = ModelResourceLocation.inventory(ResourceLocation.fromNamespaceAndPath("vivecraft", "camera_display")); private boolean visible = false; private Vec3 position = new Vec3(0.0D, 0.0D, 0.0D); private Quaternion rotation = new Quaternion(); diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/ClimbTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/ClimbTracker.java index 4a34ef488..9abc04801 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/ClimbTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/ClimbTracker.java @@ -31,7 +31,7 @@ import java.util.*; public class ClimbTracker extends Tracker { - public static final ModelResourceLocation clawsModel = new ModelResourceLocation(ResourceLocation.fromNamespaceAndPath("vivecraft", "item/climb_claws"), "standalone"); + public static final ModelResourceLocation clawsModel = ModelResourceLocation.inventory(ResourceLocation.fromNamespaceAndPath("vivecraft", "climb_claws")); private final boolean[] latched = new boolean[2]; private final boolean[] wasinblock = new boolean[2]; private final boolean[] wasbutton = new boolean[2]; diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/CrawlTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/CrawlTracker.java index fa252da9b..91a8b55d1 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/CrawlTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/CrawlTracker.java @@ -43,7 +43,7 @@ public void reset(LocalPlayer player) { } public void doProcess(LocalPlayer player) { - float scaleMultiplier = 1.0F / ScaleHelper.getEntityScale(player, mc.getTimer().getGameTimeDeltaPartialTick(false)); + float scaleMultiplier = 1.0F / ScaleHelper.getEntityScale(player, mc.getDeltaTracker().getGameTimeDeltaPartialTick(false)); this.crawling = this.dh.vr.hmdPivotHistory.averagePosition(0.2F).y * (double) this.dh.vrPlayer.worldScale * scaleMultiplier + (double) 0.1F < (double) this.dh.vrSettings.crawlThreshold; this.updateState(player); } diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/EatingTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/EatingTracker.java index 2a1ced52c..65e7391df 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/EatingTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/EatingTracker.java @@ -5,7 +5,7 @@ import net.minecraft.client.player.LocalPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.UseAnim; +import net.minecraft.world.item.ItemUseAnimation; import net.minecraft.world.phys.Vec3; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.gameplay.VRPlayer; @@ -41,17 +41,17 @@ public boolean isActive(LocalPlayer p) { return false; } else { if (p.getMainHandItem() != null) { - UseAnim useanim = p.getMainHandItem().getUseAnimation(); + ItemUseAnimation useanim = p.getMainHandItem().getUseAnimation(); - if (useanim == UseAnim.EAT || useanim == UseAnim.DRINK || useanim == UseAnim.TOOT_HORN) { + if (useanim == ItemUseAnimation.EAT || useanim == ItemUseAnimation.DRINK || useanim == ItemUseAnimation.TOOT_HORN) { return true; } } if (p.getOffhandItem() != null) { - UseAnim useanim1 = p.getOffhandItem().getUseAnimation(); + ItemUseAnimation useanim1 = p.getOffhandItem().getUseAnimation(); - return useanim1 == UseAnim.EAT || useanim1 == UseAnim.DRINK || useanim1 == UseAnim.TOOT_HORN; + return useanim1 == ItemUseAnimation.EAT || useanim1 == ItemUseAnimation.DRINK || useanim1 == ItemUseAnimation.TOOT_HORN; } return false; @@ -81,13 +81,13 @@ public void doProcess(LocalPlayer player) { int crunchiness = 0; - if (itemstack.getUseAnimation() == UseAnim.DRINK) {//thats how liquid works. + if (itemstack.getUseAnimation() == ItemUseAnimation.DRINK) {//thats how liquid works. if (vrplayer.vrdata_room_pre.getController(c).getCustomVector(new Vec3(0, 1, 0)).y > 0) { continue; } - } else if (itemstack.getUseAnimation() == UseAnim.EAT) { + } else if (itemstack.getUseAnimation() == ItemUseAnimation.EAT) { crunchiness = 2; - } else if (itemstack.getUseAnimation() == UseAnim.TOOT_HORN) { + } else if (itemstack.getUseAnimation() == ItemUseAnimation.TOOT_HORN) { crunchiness = 1; } else { continue; diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/SwingTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/SwingTracker.java index 5d723b5aa..9a698321f 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/SwingTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/SwingTracker.java @@ -5,7 +5,9 @@ import net.minecraft.core.BlockPos; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; +import net.minecraft.util.profiling.Profiler; import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.player.Player; @@ -107,7 +109,7 @@ public void doProcess(LocalPlayer player) { this.speedthresh *= 1.5D; } - this.mc.getProfiler().push("updateSwingAttack"); + Profiler.get().push("updateSwingAttack"); for (int c = 0; c < 2; c++) { if (!this.dh.climbTracker.isGrabbingLadder(c)) { @@ -258,10 +260,10 @@ public void doProcess(LocalPlayer player) { || blockstate.getBlock() instanceof AttachedStemBlock || blockstate.is(BlockTags.VIVECRAFT_CROPS) // check if the item can use the block - || item.useOn(new UseOnContext(player, c == 0 ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND, blockHit)).shouldSwing())) { + || (item.useOn(new UseOnContext(player, c == 0 ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND, blockHit)) instanceof InteractionResult.Success success && success.swingSource() == InteractionResult.SwingSource.CLIENT))) { // don't try to break crops with hoes // actually use the item on the block - boolean useSuccessful = this.mc.gameMode.useItemOn(player, c == 0 ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND, blockHit).shouldSwing(); + boolean useSuccessful = this.mc.gameMode.useItemOn(player, c == 0 ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND, blockHit) instanceof InteractionResult.Success success && success.swingSource() == InteractionResult.SwingSource.CLIENT; if (itemstack.is(ItemTags.VIVECRAFT_SCYTHES) && !useSuccessful) { // some scythes just need to be used this.mc.gameMode.useItem(player, c == 0 ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND); @@ -319,7 +321,7 @@ else if (blockstate.getBlock() instanceof NoteBlock || blockstate.is(BlockTags.V } } - this.mc.getProfiler().pop(); + Profiler.get().pop(); } private boolean getIsHittingBlock() { diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/TeleportTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/TeleportTracker.java index ed49906f4..d0470eb4e 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/TeleportTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/TeleportTracker.java @@ -5,6 +5,7 @@ import net.minecraft.client.renderer.GameRenderer; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.util.profiling.Profiler; import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; @@ -204,7 +205,7 @@ public void doProcess(LocalPlayer player) { } public void updateTeleportDestinations(GameRenderer renderer, Minecraft mc, LocalPlayer player) { - mc.getProfiler().push("updateTeleportDestinations"); + Profiler.get().push("updateTeleportDestinations"); if (this.vrMovementStyle.arcAiming) { this.movementTeleportDestination = new Vec3(0.0D, 0.0D, 0.0D); @@ -214,7 +215,7 @@ public void updateTeleportDestinations(GameRenderer renderer, Minecraft mc, Loca } } - mc.getProfiler().pop(); + Profiler.get().pop(); } private void updateTeleportArc(Minecraft mc, LocalPlayer player) { diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/TelescopeTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/TelescopeTracker.java index 51b774ffe..c886a1376 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/TelescopeTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/TelescopeTracker.java @@ -16,7 +16,7 @@ public class TelescopeTracker extends Tracker { //public static final ResourceLocation scopeResource = new ResourceLocation("vivecraft:trashbin"); - public static final ModelResourceLocation scopeModel = new ModelResourceLocation(ResourceLocation.fromNamespaceAndPath("vivecraft", "item/spyglass_in_hand"), "standalone"); + public static final ModelResourceLocation scopeModel = ModelResourceLocation.inventory(ResourceLocation.fromNamespaceAndPath("vivecraft", "spyglass_in_hand")); private static final double lensDistMax = 0.05D; private static final double lensDistMin = 0.185D; private static final double lensDotMax = 0.9D; diff --git a/common/src/main/java/org/vivecraft/client_vr/gui/PhysicalKeyboard.java b/common/src/main/java/org/vivecraft/client_vr/gui/PhysicalKeyboard.java index ce37af7e6..e6d1c7fba 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gui/PhysicalKeyboard.java +++ b/common/src/main/java/org/vivecraft/client_vr/gui/PhysicalKeyboard.java @@ -6,6 +6,7 @@ import com.mojang.blaze3d.vertex.VertexFormat.Mode; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; +import net.minecraft.client.renderer.CoreShaders; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.resources.sounds.SimpleSoundInstance; @@ -483,7 +484,7 @@ public void render(Matrix4fStack poseStack) { if (this.easterEggActive) { // https://qimg.techjargaming.com/i/UkG1cWAh.png for (KeyButton button : this.keys) { - RGBAColor color = RGBAColor.fromHSB(((float) this.dh.tickCounter + this.mc.getTimer().getGameTimeDeltaPartialTick(false)) / 100.0F + (float) (button.boundingBox.minX + (button.boundingBox.maxX - button.boundingBox.minX) / 2.0D) / 2.0F, 1.0F, 1.0F); + RGBAColor color = RGBAColor.fromHSB(((float) this.dh.tickCounter + this.mc.getDeltaTracker().getGameTimeDeltaPartialTick(false)) / 100.0F + (float) (button.boundingBox.minX + (button.boundingBox.maxX - button.boundingBox.minX) / 2.0D) / 2.0F, 1.0F, 1.0F); button.color.r = color.r; button.color.g = color.g; button.color.b = color.b; @@ -503,11 +504,11 @@ public void render(Matrix4fStack poseStack) { }); } - RenderSystem.setShader(GameRenderer::getPositionTexColorShader); + RenderSystem.setShader(CoreShaders.POSITION_TEX_COLOR); // TODO: does this still do the right thing for shaders? - mc.getTextureManager().bindForSetup(ResourceLocation.parse("vivecraft:textures/white.png")); RenderSystem.setShaderTexture(0, ResourceLocation.parse("vivecraft:textures/white.png")); + RenderSystem.bindTexture(RenderSystem.getShaderTexture(0)); // We need to ignore depth so we can see the back faces and text RenderSystem.depthFunc(GL11.GL_ALWAYS); @@ -553,7 +554,7 @@ public void render(Matrix4fStack poseStack) { poseStack.pushMatrix(); poseStack.translate((label.getB()).x, (label.getB()).y, (label.getB()).z); poseStack.scale(textScale, textScale, 1.0F); - font.drawInBatch(label.getA(), 0.0F, 0.0F, 0xFFFFFFFF, false, poseStack, mc.renderBuffers().bufferSource(), Font.DisplayMode.NORMAL, 0, 15728880, font.isBidirectional()); + font.drawInBatch(label.getA(), 0.0F, 0.0F, 0xFFFFFFFF, false, poseStack, mc.renderBuffers().bufferSource(), Font.DisplayMode.NORMAL, 0, 15728880); poseStack.popMatrix(); } diff --git a/common/src/main/java/org/vivecraft/client_vr/menuworlds/FakeBlockAccess.java b/common/src/main/java/org/vivecraft/client_vr/menuworlds/FakeBlockAccess.java index c8ffba4d6..5d6283169 100644 --- a/common/src/main/java/org/vivecraft/client_vr/menuworlds/FakeBlockAccess.java +++ b/common/src/main/java/org/vivecraft/client_vr/menuworlds/FakeBlockAccess.java @@ -153,7 +153,7 @@ public double getVoidFogYFactor() { } public double getHorizon() { - return isFlat ? -effectiveGround : 63.0D - effectiveGround + getMinBuildHeight(); + return isFlat ? -effectiveGround : 63.0D - effectiveGround + getMinY(); } @Override @@ -344,7 +344,7 @@ public boolean isClientSide() { @Override public int getSeaLevel() { - return (int) (63 - effectiveGround + getMinBuildHeight()); // magic number + return (int) (63 - effectiveGround + getMinY()); // magic number } @Override diff --git a/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldExporter.java b/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldExporter.java index f11d8b622..95b6de44d 100644 --- a/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldExporter.java +++ b/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldExporter.java @@ -7,6 +7,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; import net.minecraft.core.RegistryAccess; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleType; @@ -49,7 +50,7 @@ public static byte[] saveArea(Level level, int xMin, int zMin, int xSize, int zS BlockStateMapper blockStateMapper = new BlockStateMapper(); PaletteBiomeMapper biomeMapper = new PaletteBiomeMapper(); - int yMin = level.getMinBuildHeight(); + int yMin = level.getMinY(); int ySize = level.getHeight(); int[] blocks = new int[xSize * ySize * zSize]; byte[] skylightmap = new byte[xSize * ySize * zSize]; @@ -390,7 +391,7 @@ void readPalette(DataInputStream dis, int dataVersion) throws IOException { for (int i = 0; i < size; i++) { CompoundTag tag = CompoundTag.TYPE.load(dis, NbtAccounter.unlimitedHeap()); tag = (CompoundTag) dataFixer.update(References.BLOCK_STATE, new Dynamic<>(NbtOps.INSTANCE, tag), dataVersion, SharedConstants.getCurrentVersion().getDataVersion().getVersion()).getValue(); - this.paletteMap.add(NbtUtils.readBlockState(BuiltInRegistries.BLOCK.asLookup(), tag)); + this.paletteMap.add(NbtUtils.readBlockState(BuiltInRegistries.BLOCK, tag)); } } @@ -461,11 +462,13 @@ void readPalette(DataInputStream dis) throws IOException { decodeEnum(BiomeSpecialEffects.GrassColorModifier.class, dis.readUTF()).ifPresent(effectsBuilder::grassColorModifier); if (dis.readBoolean()) { - ParticleType particleType = BuiltInRegistries.PARTICLE_TYPE.get(ResourceLocation.parse(dis.readUTF())); + Optional>> particleTypeRef = BuiltInRegistries.PARTICLE_TYPE.get(ResourceLocation.parse(dis.readUTF())); float probability = dis.readFloat(); - if (particleType instanceof ParticleOptions) { - effectsBuilder.ambientParticle(new AmbientParticleSettings((ParticleOptions) particleType, probability)); - } + particleTypeRef.ifPresent(particleType -> { + if (particleType.value() instanceof ParticleOptions) { + effectsBuilder.ambientParticle(new AmbientParticleSettings((ParticleOptions) particleType.value(), probability)); + } + }); } Biome biome = builder.specialEffects(effectsBuilder.build()).generationSettings(dummyGenerationSettings).mobSpawnSettings(dummyMobSpawnSettings).build(); @@ -479,7 +482,7 @@ void writePalette(DataOutputStream dos, RegistryAccess registryAccess) throws IO for (int i = 0; i < this.paletteMap.size(); i++) { Biome biome = this.paletteMap.byId(i); - dos.writeUTF(registryAccess.registryOrThrow(Registries.BIOME).getKey(biome).toString()); + dos.writeUTF(registryAccess.lookupOrThrow(Registries.BIOME).getKey(biome).toString()); Biome.ClimateSettings climateSettings = Xplat.getBiomeClimateSettings(biome); @@ -676,13 +679,13 @@ private static class LegacyBiomeMapper implements BiomeMapper { // bamboo_jungle_hills map.put(169, new Biome.BiomeBuilder().hasPrecipitation(true).temperature(0.950000f).downfall(0.900000f).specialEffects(new BiomeSpecialEffects.Builder().fogColor(12638463).waterColor(4159204).waterFogColor(329011).skyColor(7842047).build()).generationSettings(dummyGenerationSettings).mobSpawnSettings(dummyMobSpawnSettings).build()); // soul_sand_valley - map.put(170, new Biome.BiomeBuilder().hasPrecipitation(false).temperature(2.000000f).downfall(0.000000f).specialEffects(new BiomeSpecialEffects.Builder().fogColor(1787717).waterColor(4159204).waterFogColor(329011).skyColor(7254527).ambientParticle(new AmbientParticleSettings((ParticleOptions) BuiltInRegistries.PARTICLE_TYPE.get(ResourceLocation.parse("minecraft:ash")), 0.006250f)).build()).generationSettings(dummyGenerationSettings).mobSpawnSettings(dummyMobSpawnSettings).build()); + map.put(170, new Biome.BiomeBuilder().hasPrecipitation(false).temperature(2.000000f).downfall(0.000000f).specialEffects(new BiomeSpecialEffects.Builder().fogColor(1787717).waterColor(4159204).waterFogColor(329011).skyColor(7254527).ambientParticle(new AmbientParticleSettings((ParticleOptions) BuiltInRegistries.PARTICLE_TYPE.get(ResourceLocation.parse("minecraft:ash")).orElseThrow().value(), 0.006250f)).build()).generationSettings(dummyGenerationSettings).mobSpawnSettings(dummyMobSpawnSettings).build()); // crimson_forest - map.put(171, new Biome.BiomeBuilder().hasPrecipitation(false).temperature(2.000000f).downfall(0.000000f).specialEffects(new BiomeSpecialEffects.Builder().fogColor(3343107).waterColor(4159204).waterFogColor(329011).skyColor(7254527).ambientParticle(new AmbientParticleSettings((ParticleOptions) BuiltInRegistries.PARTICLE_TYPE.get(ResourceLocation.parse("minecraft:crimson_spore")), 0.025000f)).build()).generationSettings(dummyGenerationSettings).mobSpawnSettings(dummyMobSpawnSettings).build()); + map.put(171, new Biome.BiomeBuilder().hasPrecipitation(false).temperature(2.000000f).downfall(0.000000f).specialEffects(new BiomeSpecialEffects.Builder().fogColor(3343107).waterColor(4159204).waterFogColor(329011).skyColor(7254527).ambientParticle(new AmbientParticleSettings((ParticleOptions) BuiltInRegistries.PARTICLE_TYPE.get(ResourceLocation.parse("minecraft:crimson_spore")).orElseThrow().value(), 0.025000f)).build()).generationSettings(dummyGenerationSettings).mobSpawnSettings(dummyMobSpawnSettings).build()); // warped_forest - map.put(172, new Biome.BiomeBuilder().hasPrecipitation(false).temperature(2.000000f).downfall(0.000000f).specialEffects(new BiomeSpecialEffects.Builder().fogColor(1705242).waterColor(4159204).waterFogColor(329011).skyColor(7254527).ambientParticle(new AmbientParticleSettings((ParticleOptions) BuiltInRegistries.PARTICLE_TYPE.get(ResourceLocation.parse("minecraft:warped_spore")), 0.014280f)).build()).generationSettings(dummyGenerationSettings).mobSpawnSettings(dummyMobSpawnSettings).build()); + map.put(172, new Biome.BiomeBuilder().hasPrecipitation(false).temperature(2.000000f).downfall(0.000000f).specialEffects(new BiomeSpecialEffects.Builder().fogColor(1705242).waterColor(4159204).waterFogColor(329011).skyColor(7254527).ambientParticle(new AmbientParticleSettings((ParticleOptions) BuiltInRegistries.PARTICLE_TYPE.get(ResourceLocation.parse("minecraft:warped_spore")).orElseThrow().value(), 0.014280f)).build()).generationSettings(dummyGenerationSettings).mobSpawnSettings(dummyMobSpawnSettings).build()); // basalt_deltas - map.put(173, new Biome.BiomeBuilder().hasPrecipitation(false).temperature(2.000000f).downfall(0.000000f).specialEffects(new BiomeSpecialEffects.Builder().fogColor(6840176).waterColor(4159204).waterFogColor(4341314).skyColor(7254527).ambientParticle(new AmbientParticleSettings((ParticleOptions) BuiltInRegistries.PARTICLE_TYPE.get(ResourceLocation.parse("minecraft:white_ash")), 0.118093f)).build()).generationSettings(dummyGenerationSettings).mobSpawnSettings(dummyMobSpawnSettings).build()); + map.put(173, new Biome.BiomeBuilder().hasPrecipitation(false).temperature(2.000000f).downfall(0.000000f).specialEffects(new BiomeSpecialEffects.Builder().fogColor(6840176).waterColor(4159204).waterFogColor(4341314).skyColor(7254527).ambientParticle(new AmbientParticleSettings((ParticleOptions) BuiltInRegistries.PARTICLE_TYPE.get(ResourceLocation.parse("minecraft:white_ash")).orElseThrow().value(), 0.118093f)).build()).generationSettings(dummyGenerationSettings).mobSpawnSettings(dummyMobSpawnSettings).build()); } private LegacyBiomeMapper() { diff --git a/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldRenderer.java b/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldRenderer.java index 5a2c93a27..31fbc7bcd 100644 --- a/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldRenderer.java +++ b/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldRenderer.java @@ -1,19 +1,18 @@ package org.vivecraft.client_vr.menuworlds; +import com.mojang.blaze3d.buffers.BufferUsage; +import com.mojang.blaze3d.pipeline.TextureTarget; import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.platform.NativeImage; import com.mojang.blaze3d.shaders.FogShape; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.*; import com.mojang.math.Axis; -import it.unimi.dsi.fastutil.objects.Reference2ObjectArrayMap; import net.minecraft.Util; import net.minecraft.client.CloudStatus; import net.minecraft.client.GraphicsStatus; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.block.BlockRenderDispatcher; -import net.minecraft.client.renderer.texture.DynamicTexture; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; @@ -23,6 +22,7 @@ import net.minecraft.tags.BiomeTags; import net.minecraft.tags.FluidTags; import net.minecraft.tags.TagKey; +import net.minecraft.util.ARGB; import net.minecraft.util.CubicSampler; import net.minecraft.util.Mth; import net.minecraft.util.RandomSource; @@ -33,7 +33,6 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.properties.Property; import net.minecraft.world.level.dimension.BuiltinDimensionTypes; import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.FluidState; @@ -45,7 +44,6 @@ import org.joml.Matrix4fStack; import org.joml.Quaternionf; import org.joml.Vector3f; -import org.lwjgl.opengl.GL11; import org.vivecraft.client.Xplat; import org.vivecraft.client.extensions.BufferBuilderExtension; import org.vivecraft.client.utils.Utils; @@ -53,7 +51,6 @@ import org.vivecraft.client_vr.extensions.StateHolderExtension; import org.vivecraft.client_vr.settings.VRSettings; import org.vivecraft.mixin.client.renderer.RenderStateShardAccessor; -import org.vivecraft.mod_compat_vr.ShadersHelper; import org.vivecraft.mod_compat_vr.iris.IrisHelper; import org.vivecraft.mod_compat_vr.optifine.OptifineHelper; import org.vivecraft.mod_compat_vr.sodium.SodiumHelper; @@ -79,9 +76,7 @@ public class MenuWorldRenderer { private final Minecraft mc; private DimensionSpecialEffects dimensionInfo; private FakeBlockAccess blockAccess; - private final DynamicTexture lightTexture; - private final NativeImage lightPixels; - private final ResourceLocation lightTextureLocation; + private final TextureTarget lightMap; private boolean lightmapUpdateNeeded; private float blockLightRedFlicker; private int waterVisionTime; @@ -93,19 +88,12 @@ public class MenuWorldRenderer { private VertexBuffer starVBO; private VertexBuffer skyBuffer; private VertexBuffer darkBuffer; - private VertexBuffer cloudVBO; private int renderDistance; private int renderDistanceChunks; public MenuFogRenderer fogRenderer; public Set animatedSprites; private final Random rand; private boolean ready; - private CloudStatus prevCloudsType; - private int prevCloudX; - private int prevCloudY; - private int prevCloudZ; - private Vec3 prevCloudColor; - private boolean generateClouds = true; private int skyFlashTime; private float rainLevel; private float thunderLevel; @@ -135,9 +123,12 @@ public class MenuWorldRenderer { public MenuWorldRenderer() { this.mc = Minecraft.getInstance(); - this.lightTexture = new DynamicTexture(16, 16, false); - this.lightTextureLocation = mc.getTextureManager().register("vivecraft_light_map", this.lightTexture); - this.lightPixels = this.lightTexture.getPixels(); + + this.lightMap = new TextureTarget(16, 16, false); + this.lightMap.setFilterMode(9729); + this.lightMap.setClearColor(1.0F, 1.0F, 1.0F, 1.0F); + this.lightMap.clear(); + this.fogRenderer = new MenuFogRenderer(this); this.rand = new Random(); this.rand.nextInt(); // toss some bits in the bin @@ -210,7 +201,7 @@ public void render(Matrix4fStack poseStack) { Vec3 offset = new Vec3(0.5, -blockAccess.getGround() + (int) blockAccess.getGround(), 0.5).yRot(worldRotation * 0.0174533f); Vec3 eyePosition = getEyePos().add(offset).yRot(-worldRotation * 0.0174533f); - fogRenderer.levelFogColor(); + fogRenderer.setupFog(FogRenderer.FogMode.FOG_SKY); renderSky(poseStack, eyePosition); @@ -234,15 +225,15 @@ public void render(Matrix4fStack poseStack) { cloudHeight += OptifineHelper.getCloudHeight() * 128.0; } - if (eyePosition.y + blockAccess.getGround() + blockAccess.getMinBuildHeight() < cloudHeight) { - renderClouds(poseStack, eyePosition.x, eyePosition.y + blockAccess.getGround() + blockAccess.getMinBuildHeight(), eyePosition.z); + if (eyePosition.y + blockAccess.getGround() + blockAccess.getMinY() < cloudHeight) { + renderClouds(poseStack, eyePosition.x, eyePosition.y + blockAccess.getGround() + blockAccess.getMinY(), eyePosition.z); } renderChunkLayer(RenderType.translucent(), poseStack, projection); renderChunkLayer(RenderType.tripwire(), poseStack, projection); - if (eyePosition.y + blockAccess.getGround() + blockAccess.getMinBuildHeight() >= cloudHeight) { - renderClouds(poseStack, eyePosition.x, eyePosition.y + blockAccess.getGround() + blockAccess.getMinBuildHeight(), eyePosition.z); + if (eyePosition.y + blockAccess.getGround() + blockAccess.getMinY() >= cloudHeight) { + renderClouds(poseStack, eyePosition.x, eyePosition.y + blockAccess.getGround() + blockAccess.getMinY(), eyePosition.z); } RenderSystem.depthMask(false); @@ -261,7 +252,7 @@ private void renderChunkLayer(RenderType layer, Matrix4f modelView, Matrix4f Pro } layer.setupRenderState(); - ShaderInstance shaderInstance = RenderSystem.getShader(); + CompiledShaderProgram shaderInstance = RenderSystem.getShader(); shaderInstance.apply(); turnOnLightLayer(); for (VertexBuffer vertexBuffer : buffers) { @@ -506,7 +497,7 @@ private void handleError() { } private void uploadGeometry(RenderType layer, MeshData meshData) { - VertexBuffer buffer = new VertexBuffer(VertexBuffer.Usage.STATIC); + VertexBuffer buffer = new VertexBuffer(BufferUsage.STATIC_WRITE); buffer.bind(); buffer.upload(meshData); VertexBuffer.unbind(); @@ -553,9 +544,9 @@ public void completeDestroy() { if (darkBuffer != null) { darkBuffer.close(); } - if (cloudVBO != null) { + /*if (cloudVBO != null) { cloudVBO.close(); - } + }*/ ready = false; } @@ -652,10 +643,10 @@ public void pushVisibleTextures() { public void renderSky(Matrix4fStack poseStack, Vec3 position) { if (this.dimensionInfo.skyType() == DimensionSpecialEffects.SkyType.END) { this.renderEndSky(poseStack); - } else if (this.dimensionInfo.skyType() == DimensionSpecialEffects.SkyType.NORMAL) { - RenderSystem.setShader(GameRenderer::getPositionShader); + } else if (this.dimensionInfo.skyType() == DimensionSpecialEffects.SkyType.OVERWORLD) { + RenderSystem.setShader(CoreShaders.POSITION); fogRenderer.setupFog(FogRenderer.FogMode.FOG_SKY); - ShaderInstance skyShader = RenderSystem.getShader(); + CompiledShaderProgram skyShader = RenderSystem.getShader(); //RenderSystem.disableTexture(); Vec3 skyColor = this.getSkyColor(position); @@ -664,8 +655,6 @@ public void renderSky(Matrix4fStack poseStack, Vec3 position) { skyColor = OptifineHelper.getCustomSkyColor(skyColor, blockAccess, position.x, position.y, position.z); } - fogRenderer.levelFogColor(); - RenderSystem.depthMask(false); RenderSystem.setShaderColor((float) skyColor.x, (float) skyColor.y, (float) skyColor.z, 1.0f); @@ -679,11 +668,11 @@ public void renderSky(Matrix4fStack poseStack, Vec3 position) { RenderSystem.enableBlend(); RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); - float[] sunriseColor = this.dimensionInfo.getSunriseColor(this.getTimeOfDay(), 0); // calcSunriseSunsetColors + int sunriseColor = this.dimensionInfo.getSunriseOrSunsetColor(this.getTimeOfDay()); // calcSunriseSunsetColors - if (sunriseColor != null && (!OptifineHelper.isOptifineLoaded() || OptifineHelper.isSunMoonEnabled())) { + if (this.dimensionInfo.isSunriseOrSunset(this.getTimeOfDay()) && (!OptifineHelper.isOptifineLoaded() || OptifineHelper.isSunMoonEnabled())) { //RenderSystem.disableTexture(); - RenderSystem.setShader(GameRenderer::getPositionColorShader); + RenderSystem.setShader(CoreShaders.POSITION_COLOR); RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); poseStack.pushMatrix(); @@ -695,15 +684,15 @@ public void renderSky(Matrix4fStack poseStack, Vec3 position) { BufferBuilder bufferBuilder = Tesselator.getInstance().begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR); bufferBuilder .addVertex(modelView, 0.0f, 100.0f, 0.0f) - .setColor(sunriseColor[0], sunriseColor[1], sunriseColor[2], sunriseColor[3]); + .setColor(sunriseColor); for (int j = 0; j <= 16; ++j) { float f6 = (float) j * ((float) Math.PI * 2F) / 16.0F; float f7 = Mth.sin(f6); float f8 = Mth.cos(f6); bufferBuilder - .addVertex(modelView, f7 * 120.0F, f8 * 120.0F, -f8 * 40.0F * sunriseColor[3]) - .setColor(sunriseColor[0], sunriseColor[1], sunriseColor[2], 0.0F); + .addVertex(modelView, f7 * 120.0F, f8 * 120.0F, -f8 * 40.0F *ARGB.from8BitChannel(ARGB.alpha(sunriseColor))) + .setColor(ARGB.transparent(sunriseColor)); } BufferUploader.drawWithShader(bufferBuilder.buildOrThrow()); @@ -729,7 +718,7 @@ public void renderSky(Matrix4fStack poseStack, Vec3 position) { float size = 30.0F; if (!OptifineHelper.isOptifineLoaded() || OptifineHelper.isSunMoonEnabled()) { - RenderSystem.setShader(GameRenderer::getPositionTexShader); + RenderSystem.setShader(CoreShaders.POSITION_TEX); RenderSystem.setShaderTexture(0, SUN_LOCATION); BufferBuilder bufferBuilder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); bufferBuilder.addVertex(modelView, -size, 100.0F, -size).setUv(0.0F, 0.0F); @@ -765,7 +754,7 @@ public void renderSky(Matrix4fStack poseStack, Vec3 position) { RenderSystem.setShaderColor(starBrightness, starBrightness, starBrightness, starBrightness); fogRenderer.setupNoFog(); this.starVBO.bind(); - this.starVBO.drawWithShader(poseStack, RenderSystem.getProjectionMatrix(), GameRenderer.getPositionShader()); + this.starVBO.drawWithShader(poseStack, RenderSystem.getProjectionMatrix(), RenderSystem.setShader(CoreShaders.POSITION)); VertexBuffer.unbind(); fogRenderer.setupFog(FogRenderer.FogMode.FOG_SKY); } @@ -799,7 +788,7 @@ private void renderEndSky(Matrix4fStack poseStack) { RenderSystem.enableBlend(); RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); RenderSystem.depthMask(false); - RenderSystem.setShader(GameRenderer::getPositionTexColorShader); + RenderSystem.setShader(CoreShaders.POSITION_TEX_COLOR); RenderSystem.setShaderTexture(0, END_SKY_LOCATION); for (int i = 0; i < 6; ++i) { @@ -842,170 +831,11 @@ public void renderClouds(Matrix4fStack poseStack, double x, double y, double z) float cloudHeight = this.dimensionInfo.getCloudHeight(); if (!Float.isNaN(cloudHeight) && this.mc.options.getCloudsType() != CloudStatus.OFF) { - // setup clouds - - RenderSystem.disableCull(); - RenderSystem.enableBlend(); - RenderSystem.enableDepthTest(); - RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); - RenderSystem.depthMask(true); - - float cloudSizeXZ = 12.0f; - float cloudSizeY = 4.0f; - double cloudOffset = ((float) ticks + mc.getTimer().getGameTimeDeltaPartialTick(false)) * 0.03f; - double cloudX = (x + cloudOffset) / 12.0; - double cloudY = cloudHeight - y + 0.33; - if (OptifineHelper.isOptifineLoaded()) { - cloudY = cloudY + OptifineHelper.getCloudHeight() * 128.0; - } - - double cloudZ = z / 12.0 + 0.33; - cloudX -= Mth.floor(cloudX / 2048.0) * 2048; - cloudZ -= Mth.floor(cloudZ / 2048.0) * 2048; - float cloudXfract = (float) (cloudX - (double) Mth.floor(cloudX)); - float cloudYfract = (float) (cloudY / 4.0 - (double) Mth.floor(cloudY / 4.0)) * 4.0f; - float cloudZfract = (float) (cloudZ - (double) Mth.floor(cloudZ)); - - Vec3 cloudColor = this.getCloudColour(); - int cloudXfloor = (int) Math.floor(cloudX); - int cloudYfloor = (int) Math.floor(cloudY / 4.0); - int cloudZfloor = (int) Math.floor(cloudZ); - if (cloudXfloor != this.prevCloudX || - cloudYfloor != this.prevCloudY || - cloudZfloor != this.prevCloudZ || - this.mc.options.getCloudsType() != this.prevCloudsType || - this.prevCloudColor.distanceToSqr(cloudColor) > 2.0E-4) { - this.prevCloudX = cloudXfloor; - this.prevCloudY = cloudYfloor; - this.prevCloudZ = cloudZfloor; - this.prevCloudColor = cloudColor; - this.prevCloudsType = this.mc.options.getCloudsType(); - this.generateClouds = true; - } - if (this.generateClouds) { - this.generateClouds = false; - if (this.cloudVBO != null) { - this.cloudVBO.close(); - } - this.cloudVBO = new VertexBuffer(VertexBuffer.Usage.STATIC); - this.cloudVBO.bind(); - this.cloudVBO.upload(this.buildClouds(Tesselator.getInstance(), cloudX, cloudY, cloudZ, cloudColor)); - VertexBuffer.unbind(); - } - - // render - RenderSystem.setShader(GameRenderer::getRendertypeCloudsShader); - RenderSystem.setShaderTexture(0, CLOUDS_LOCATION); - fogRenderer.levelFogColor(); - poseStack.pushMatrix(); - poseStack.scale(12.0f, 1.0f, 12.0f); - poseStack.translate(-cloudXfract, cloudYfract, -cloudZfract); - if (this.cloudVBO != null) { - this.cloudVBO.bind(); - // probably rendered twice, so only the front faces are there? - for (int w = this.prevCloudsType == CloudStatus.FANCY ? 0 : 1; w < 2; ++w) { - if (w == 0) { - RenderSystem.colorMask(false, false, false, false); - } else { - RenderSystem.colorMask(true, true, true, true); - } - this.cloudVBO.drawWithShader(poseStack, RenderSystem.getProjectionMatrix(), RenderSystem.getShader()); - } - VertexBuffer.unbind(); - } - poseStack.popMatrix(); - RenderSystem.enableCull(); - RenderSystem.disableBlend(); - RenderSystem.defaultBlendFunc(); + // use the LevelRenderer CloudRenderer for the clouds + this.mc.levelRenderer.getCloudRenderer().render(getCloudColour(), this.mc.options.getCloudsType(), cloudHeight + 0.35F, poseStack, RenderSystem.getProjectionMatrix(), new Vec3(x, y, z), this.ticks + this.mc.getDeltaTracker().getGameTimeDeltaPartialTick(false)); } } - private MeshData buildClouds(Tesselator tesselator, double cloudX, double cloudY, double cloudZ, Vec3 cloudColor) { - float l = (float) Mth.floor(cloudX) * 0.00390625f; - float m = (float) Mth.floor(cloudZ) * 0.00390625f; - float redTop = (float) cloudColor.x; - float greenTop = (float) cloudColor.y; - float blueTop = (float) cloudColor.z; - float redX = redTop * 0.9f; - float greenX = greenTop * 0.9f; - float blueX = blueTop * 0.9f; - float redBottom = redTop * 0.7f; - float greenBottom = greenTop * 0.7f; - float blueBottom = blueTop * 0.7f; - float redZ = redTop * 0.8f; - float greenZ = greenTop * 0.8f; - float blueZ = blueTop * 0.8f; - RenderSystem.setShader(GameRenderer::getRendertypeCloudsShader); - BufferBuilder bufferBuilder = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR_NORMAL); - float z = (float) Math.floor(cloudY / 4.0) * 4.0f; - if (this.prevCloudsType == CloudStatus.FANCY) { - for (int aa = -3; aa <= 4; ++aa) { - for (int ab = -3; ab <= 4; ++ab) { - int ae; - float ac = aa * 8; - float ad = ab * 8; - if (z > -5.0f) { - bufferBuilder.addVertex(ac + 0.0f, z + 0.0f, ad + 8.0f).setUv((ac + 0.0f) * 0.00390625f + l, (ad + 8.0f) * 0.00390625f + m).setColor(redBottom, greenBottom, blueBottom, 0.8f).setNormal(0.0f, -1.0f, 0.0f); - bufferBuilder.addVertex(ac + 8.0f, z + 0.0f, ad + 8.0f).setUv((ac + 8.0f) * 0.00390625f + l, (ad + 8.0f) * 0.00390625f + m).setColor(redBottom, greenBottom, blueBottom, 0.8f).setNormal(0.0f, -1.0f, 0.0f); - bufferBuilder.addVertex(ac + 8.0f, z + 0.0f, ad + 0.0f).setUv((ac + 8.0f) * 0.00390625f + l, (ad + 0.0f) * 0.00390625f + m).setColor(redBottom, greenBottom, blueBottom, 0.8f).setNormal(0.0f, -1.0f, 0.0f); - bufferBuilder.addVertex(ac + 0.0f, z + 0.0f, ad + 0.0f).setUv((ac + 0.0f) * 0.00390625f + l, (ad + 0.0f) * 0.00390625f + m).setColor(redBottom, greenBottom, blueBottom, 0.8f).setNormal(0.0f, -1.0f, 0.0f); - } - if (z <= 5.0f) { - bufferBuilder.addVertex(ac + 0.0f, z + 4.0f - 9.765625E-4f, ad + 8.0f).setUv((ac + 0.0f) * 0.00390625f + l, (ad + 8.0f) * 0.00390625f + m).setColor(redTop, greenTop, blueTop, 0.8f).setNormal(0.0f, 1.0f, 0.0f); - bufferBuilder.addVertex(ac + 8.0f, z + 4.0f - 9.765625E-4f, ad + 8.0f).setUv((ac + 8.0f) * 0.00390625f + l, (ad + 8.0f) * 0.00390625f + m).setColor(redTop, greenTop, blueTop, 0.8f).setNormal(0.0f, 1.0f, 0.0f); - bufferBuilder.addVertex(ac + 8.0f, z + 4.0f - 9.765625E-4f, ad + 0.0f).setUv((ac + 8.0f) * 0.00390625f + l, (ad + 0.0f) * 0.00390625f + m).setColor(redTop, greenTop, blueTop, 0.8f).setNormal(0.0f, 1.0f, 0.0f); - bufferBuilder.addVertex(ac + 0.0f, z + 4.0f - 9.765625E-4f, ad + 0.0f).setUv((ac + 0.0f) * 0.00390625f + l, (ad + 0.0f) * 0.00390625f + m).setColor(redTop, greenTop, blueTop, 0.8f).setNormal(0.0f, 1.0f, 0.0f); - } - if (aa > -1) { - for (ae = 0; ae < 8; ++ae) { - bufferBuilder.addVertex(ac + (float) ae + 0.0f, z + 0.0f, ad + 8.0f).setUv((ac + (float) ae + 0.5f) * 0.00390625f + l, (ad + 8.0f) * 0.00390625f + m).setColor(redX, greenX, blueX, 0.8f).setNormal(-1.0f, 0.0f, 0.0f); - bufferBuilder.addVertex(ac + (float) ae + 0.0f, z + 4.0f, ad + 8.0f).setUv((ac + (float) ae + 0.5f) * 0.00390625f + l, (ad + 8.0f) * 0.00390625f + m).setColor(redX, greenX, blueX, 0.8f).setNormal(-1.0f, 0.0f, 0.0f); - bufferBuilder.addVertex(ac + (float) ae + 0.0f, z + 4.0f, ad + 0.0f).setUv((ac + (float) ae + 0.5f) * 0.00390625f + l, (ad + 0.0f) * 0.00390625f + m).setColor(redX, greenX, blueX, 0.8f).setNormal(-1.0f, 0.0f, 0.0f); - bufferBuilder.addVertex(ac + (float) ae + 0.0f, z + 0.0f, ad + 0.0f).setUv((ac + (float) ae + 0.5f) * 0.00390625f + l, (ad + 0.0f) * 0.00390625f + m).setColor(redX, greenX, blueX, 0.8f).setNormal(-1.0f, 0.0f, 0.0f); - } - } - if (aa <= 1) { - for (ae = 0; ae < 8; ++ae) { - bufferBuilder.addVertex(ac + (float) ae + 1.0f - 9.765625E-4f, z + 0.0f, ad + 8.0f).setUv((ac + (float) ae + 0.5f) * 0.00390625f + l, (ad + 8.0f) * 0.00390625f + m).setColor(redX, greenX, blueX, 0.8f).setNormal(1.0f, 0.0f, 0.0f); - bufferBuilder.addVertex(ac + (float) ae + 1.0f - 9.765625E-4f, z + 4.0f, ad + 8.0f).setUv((ac + (float) ae + 0.5f) * 0.00390625f + l, (ad + 8.0f) * 0.00390625f + m).setColor(redX, greenX, blueX, 0.8f).setNormal(1.0f, 0.0f, 0.0f); - bufferBuilder.addVertex(ac + (float) ae + 1.0f - 9.765625E-4f, z + 4.0f, ad + 0.0f).setUv((ac + (float) ae + 0.5f) * 0.00390625f + l, (ad + 0.0f) * 0.00390625f + m).setColor(redX, greenX, blueX, 0.8f).setNormal(1.0f, 0.0f, 0.0f); - bufferBuilder.addVertex(ac + (float) ae + 1.0f - 9.765625E-4f, z + 0.0f, ad + 0.0f).setUv((ac + (float) ae + 0.5f) * 0.00390625f + l, (ad + 0.0f) * 0.00390625f + m).setColor(redX, greenX, blueX, 0.8f).setNormal(1.0f, 0.0f, 0.0f); - } - } - if (ab > -1) { - for (ae = 0; ae < 8; ++ae) { - bufferBuilder.addVertex(ac + 0.0f, z + 4.0f, ad + (float) ae + 0.0f).setUv((ac + 0.0f) * 0.00390625f + l, (ad + (float) ae + 0.5f) * 0.00390625f + m).setColor(redZ, greenZ, blueZ, 0.8f).setNormal(0.0f, 0.0f, -1.0f); - bufferBuilder.addVertex(ac + 8.0f, z + 4.0f, ad + (float) ae + 0.0f).setUv((ac + 8.0f) * 0.00390625f + l, (ad + (float) ae + 0.5f) * 0.00390625f + m).setColor(redZ, greenZ, blueZ, 0.8f).setNormal(0.0f, 0.0f, -1.0f); - bufferBuilder.addVertex(ac + 8.0f, z + 0.0f, ad + (float) ae + 0.0f).setUv((ac + 8.0f) * 0.00390625f + l, (ad + (float) ae + 0.5f) * 0.00390625f + m).setColor(redZ, greenZ, blueZ, 0.8f).setNormal(0.0f, 0.0f, -1.0f); - bufferBuilder.addVertex(ac + 0.0f, z + 0.0f, ad + (float) ae + 0.0f).setUv((ac + 0.0f) * 0.00390625f + l, (ad + (float) ae + 0.5f) * 0.00390625f + m).setColor(redZ, greenZ, blueZ, 0.8f).setNormal(0.0f, 0.0f, -1.0f); - } - } - if (ab > 1) { - continue; - } - for (ae = 0; ae < 8; ++ae) { - bufferBuilder.addVertex(ac + 0.0f, z + 4.0f, ad + (float) ae + 1.0f - 9.765625E-4f).setUv((ac + 0.0f) * 0.00390625f + l, (ad + (float) ae + 0.5f) * 0.00390625f + m).setColor(redZ, greenZ, blueZ, 0.8f).setNormal(0.0f, 0.0f, 1.0f); - bufferBuilder.addVertex(ac + 8.0f, z + 4.0f, ad + (float) ae + 1.0f - 9.765625E-4f).setUv((ac + 8.0f) * 0.00390625f + l, (ad + (float) ae + 0.5f) * 0.00390625f + m).setColor(redZ, greenZ, blueZ, 0.8f).setNormal(0.0f, 0.0f, 1.0f); - bufferBuilder.addVertex(ac + 8.0f, z + 0.0f, ad + (float) ae + 1.0f - 9.765625E-4f).setUv((ac + 8.0f) * 0.00390625f + l, (ad + (float) ae + 0.5f) * 0.00390625f + m).setColor(redZ, greenZ, blueZ, 0.8f).setNormal(0.0f, 0.0f, 1.0f); - bufferBuilder.addVertex(ac + 0.0f, z + 0.0f, ad + (float) ae + 1.0f - 9.765625E-4f).setUv((ac + 0.0f) * 0.00390625f + l, (ad + (float) ae + 0.5f) * 0.00390625f + m).setColor(redZ, greenZ, blueZ, 0.8f).setNormal(0.0f, 0.0f, 1.0f); - } - } - } - } else { - boolean aa = true; - int ab = 32; - for (int af = -32; af < 32; af += 32) { - for (int ag = -32; ag < 32; ag += 32) { - bufferBuilder.addVertex(af, z, ag + 32).setUv((float) (af) * 0.00390625f + l, (float) (ag + 32) * 0.00390625f + m).setColor(redTop, greenTop, blueTop, 0.8f).setNormal(0.0f, -1.0f, 0.0f); - bufferBuilder.addVertex(af + 32, z, ag + 32).setUv((float) (af + 32) * 0.00390625f + l, (float) (ag + 32) * 0.00390625f + m).setColor(redTop, greenTop, blueTop, 0.8f).setNormal(0.0f, -1.0f, 0.0f); - bufferBuilder.addVertex(af + 32, z, ag).setUv((float) (af + 32) * 0.00390625f + l, (float) (ag) * 0.00390625f + m).setColor(redTop, greenTop, blueTop, 0.8f).setNormal(0.0f, -1.0f, 0.0f); - bufferBuilder.addVertex(af, z, ag).setUv((float) (af) * 0.00390625f + l, (float) (ag) * 0.00390625f + m).setColor(redTop, greenTop, blueTop, 0.8f).setNormal(0.0f, -1.0f, 0.0f); - } - } - } - return bufferBuilder.buildOrThrow(); - } - private void renderSnowAndRain(Matrix4fStack poseStack, double inX, double inY, double inZ) { if (getRainLevel() <= 0.0f) { return; @@ -1013,7 +843,6 @@ private void renderSnowAndRain(Matrix4fStack poseStack, double inX, double inY, RenderSystem.getModelViewStack().pushMatrix(); RenderSystem.getModelViewStack().mul(poseStack); - RenderSystem.applyModelViewMatrix(); int xFloor = Mth.floor(inX); int yFloor = Mth.floor(inY); @@ -1029,8 +858,8 @@ private void renderSnowAndRain(Matrix4fStack poseStack, double inX, double inY, } RenderSystem.depthMask(true); int count = -1; - float rainAnimationTime = this.ticks + mc.getTimer().getGameTimeDeltaPartialTick(false); - RenderSystem.setShader(GameRenderer::getParticleShader); + float rainAnimationTime = this.ticks + mc.getDeltaTracker().getGameTimeDeltaPartialTick(false); + RenderSystem.setShader(CoreShaders.PARTICLE); turnOnLightLayer(); BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos(); for (int rainZ = zFloor - rainDistance; rainZ <= zFloor + rainDistance; ++rainZ) { @@ -1056,7 +885,7 @@ private void renderSnowAndRain(Matrix4fStack poseStack, double inX, double inY, RandomSource randomSource = RandomSource.create(rainX * rainX * 3121L + rainX * 45238971L ^ rainZ * rainZ * 418711L + rainZ * 13761L); mutableBlockPos.setY(lower); - Biome.Precipitation precipitation = biome.getPrecipitationAt(mutableBlockPos); + Biome.Precipitation precipitation = biome.getPrecipitationAt(mutableBlockPos, blockAccess.getSeaLevel()); if (precipitation == Biome.Precipitation.NONE) { continue; } @@ -1085,7 +914,7 @@ private void renderSnowAndRain(Matrix4fStack poseStack, double inX, double inY, blend = ((1.0f - distance * distance) * 0.5f + 0.5f); int x = this.ticks + rainX * rainX * 3121 + rainX * 45238971 + rainZ * rainZ * 418711 + rainZ * 13761 & 0x1F; - yOffset = -((float) x + mc.getTimer().getGameTimeDeltaPartialTick(false)) / 32.0f * (3.0f + randomSource.nextFloat()); + yOffset = -((float) x + mc.getDeltaTracker().getGameTimeDeltaPartialTick(false)) / 32.0f * (3.0f + randomSource.nextFloat()); } else if (precipitation == Biome.Precipitation.SNOW) { if (count != 1) { if (count >= 0) { @@ -1098,7 +927,7 @@ private void renderSnowAndRain(Matrix4fStack poseStack, double inX, double inY, blend = ((1.0f - distance * distance) * 0.3f + 0.5f); xOffset = (float) (randomSource.nextDouble() + (double) rainAnimationTime * 0.01 * (double) ((float) randomSource.nextGaussian())); - float ae = -((float) (this.ticks & 0x1FF) + mc.getTimer().getGameTimeDeltaPartialTick(false)) / 512.0f; + float ae = -((float) (this.ticks & 0x1FF) + mc.getDeltaTracker().getGameTimeDeltaPartialTick(false)) / 512.0f; float af = (float) (randomSource.nextDouble() + (double) (rainAnimationTime * (float) randomSource.nextGaussian()) * 0.001); yOffset = ae + af; @@ -1130,7 +959,6 @@ private void renderSnowAndRain(Matrix4fStack poseStack, double inX, double inY, BufferUploader.drawWithShader(bufferBuilder.buildOrThrow()); } RenderSystem.getModelViewStack().popMatrix(); - RenderSystem.applyModelViewMatrix(); RenderSystem.enableCull(); RenderSystem.disableBlend(); turnOffLightLayer(); @@ -1210,7 +1038,7 @@ public Vec3 getSkyColor(Vec3 position) { skyColorB = skyColorB * darkening + luminance * (1.0f - darkening); } if (!mc.options.hideLightningFlash().get() && this.skyFlashTime > 0) { - float flash = (float) this.skyFlashTime - mc.getTimer().getGameTimeDeltaPartialTick(false); + float flash = (float) this.skyFlashTime - mc.getDeltaTracker().getGameTimeDeltaPartialTick(false); if (flash > 1.0f) { flash = 1.0f; } @@ -1227,8 +1055,8 @@ public Vec3 getFogColor(Vec3 pos) { return CubicSampler.gaussianSampleVec3(scaledPos, (x, y, z) -> this.dimensionInfo.getBrightnessDependentFogColor(Vec3.fromRGB24(this.blockAccess.getBiomeManager().getNoiseBiomeAtQuart(x, y, z).value().getFogColor()), f)); } - public Vec3 getCloudColour() { - float dayTime = this.getTimeOfDay(); + public int getCloudColour() { + /*float dayTime = this.getTimeOfDay(); float f1 = Mth.cos(dayTime * ((float) Math.PI * 2F)) * 2.0F + 0.5F; f1 = Mth.clamp(f1, 0.0F, 1.0F); float r = 1.0F; @@ -1257,14 +1085,32 @@ public Vec3 getCloudColour() { b = b * dark + luma * (1.0F - dark); } - return new Vec3(r, g, b); + return new Vec3(r, g, b);*/ + int color = -1; + float rain = this.getRainLevel(); + if (rain > 0.0F) { + int j = ARGB.scaleRGB(ARGB.greyscale(color), 0.6F); + color = ARGB.lerp(rain * 0.95F, color, j); + } + + float dayTime = this.getTimeOfDay(); + float k = Mth.cos(dayTime * ((float)Math.PI * 2F)) * 2.0F + 0.5F; + k = Mth.clamp(k, 0.0F, 1.0F); + color = ARGB.multiply(color, ARGB.colorFromFloat(1.0F, k * 0.9F + 0.1F, k * 0.9F + 0.1F, k * 0.85F + 0.15F)); + float thunder = this.getThunderLevel(); + if (thunder > 0.0F) { + int m = ARGB.scaleRGB(ARGB.greyscale(color), 0.2F); + color = ARGB.lerp(thunder * 0.95F, color, m); + } + + return color; } private void generateLightSky() { if (this.skyBuffer != null) { this.skyBuffer.close(); } - this.skyBuffer = new VertexBuffer(VertexBuffer.Usage.STATIC); + this.skyBuffer = new VertexBuffer(BufferUsage.STATIC_WRITE); this.skyBuffer.bind(); this.skyBuffer.upload(buildSkyDisc(Tesselator.getInstance(), 16.0f)); VertexBuffer.unbind(); @@ -1274,7 +1120,7 @@ private void generateDarkSky() { if (this.darkBuffer != null) { this.darkBuffer.close(); } - this.darkBuffer = new VertexBuffer(VertexBuffer.Usage.STATIC); + this.darkBuffer = new VertexBuffer(BufferUsage.STATIC_WRITE); this.darkBuffer.bind(); this.darkBuffer.upload(buildSkyDisc(Tesselator.getInstance(), -16.0f)); VertexBuffer.unbind(); @@ -1283,7 +1129,7 @@ private void generateDarkSky() { private static MeshData buildSkyDisc(Tesselator tesselator, float posY) { float g = Math.signum(posY) * 512.0f; float h = 512.0f; - RenderSystem.setShader(GameRenderer::getPositionShader); + RenderSystem.setShader(CoreShaders.POSITION); BufferBuilder bufferBuilder = tesselator.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION); bufferBuilder.addVertex(0.0F, posY, 0.0F); for (int i = -180; i <= 180; i += 45) { @@ -1293,11 +1139,11 @@ private static MeshData buildSkyDisc(Tesselator tesselator, float posY) { } private void createStars() { - RenderSystem.setShader(GameRenderer::getPositionShader); + RenderSystem.setShader(CoreShaders.POSITION); if (this.starVBO != null) { this.starVBO.close(); } - this.starVBO = new VertexBuffer(VertexBuffer.Usage.STATIC); + this.starVBO = new VertexBuffer(BufferUsage.STATIC_WRITE); this.starVBO.bind(); this.starVBO.upload(this.drawStars(Tesselator.getInstance())); VertexBuffer.unbind(); @@ -1336,10 +1182,7 @@ public void turnOffLightLayer() { } public void turnOnLightLayer() { - RenderSystem.setShaderTexture(2, this.lightTextureLocation); - mc.getTextureManager().bindForSetup(this.lightTextureLocation); - RenderSystem.texParameter(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); - RenderSystem.texParameter(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); + RenderSystem.setShaderTexture(2, this.lightMap.getColorTextureId()); } public void updateTorchFlicker() { @@ -1383,60 +1226,27 @@ public void updateLightmap() { Vector3f skylightColor = new Vector3f(skyLight, skyLight, 1.0f).lerp(new Vector3f(1.0f, 1.0f, 1.0f), 0.35f); - Vector3f finalColor = new Vector3f(); - for (int i = 0; i < 16; ++i) { - for (int j = 0; j < 16; ++j) { - float skyBrightness = LightTexture.getBrightness(this.blockAccess.dimensionType(), i) * effectiveSkyLight; - float blockBrightnessRed = LightTexture.getBrightness(this.blockAccess.dimensionType(), j) * (blockLightRedFlicker + 1.5f); - float blockBrightnessGreen = blockBrightnessRed * ((blockBrightnessRed * 0.6f + 0.4f) * 0.6f + 0.4f); - float blockBrightnessBlue = blockBrightnessRed * (blockBrightnessRed * blockBrightnessRed * 0.6f + 0.4f); - - finalColor.set(blockBrightnessRed, blockBrightnessGreen, blockBrightnessBlue); - - if (dimensionInfo.forceBrightLightmap()) { - finalColor.lerp(new Vector3f(0.99f, 1.12f, 1.0f), 0.25f); - finalColor.set(Mth.clamp(finalColor.x, 0.0f, 1.0f), Mth.clamp(finalColor.y, 0.0f, 1.0f), Mth.clamp(finalColor.z, 0.0f, 1.0f)); - } else { - finalColor.add(new Vector3f(skylightColor).mul(skyBrightness)); - finalColor.lerp(new Vector3f(0.75f, 0.75f, 0.75f), 0.04f); - // no darkening from bosses -// if (getDarkenWorldAmount() > 0.0f) { -// finalColor.lerp(new Vector3f(finalColor).mul(0.7f, 0.6f, 0.6f), getDarkenWorldAmount()); -// } - } - - /* no night vision, no player - if (nightVision > 0.0f && (w = Math.max(finalColor.x(), Math.max(finalColor.y(), finalColor.z()))) < 1.0f) { - v = 1.0f / w; - vector3f4 = new Vector3f(finalColor).mul(v); - finalColor.lerp(vector3f4, nightVision); - } - */ - - if (!dimensionInfo.forceBrightLightmap()) { - /* no darkness, no player - if (effectiveDarknessScale > 0.0f) { - finalColor.add(-effectiveDarknessScale, -effectiveDarknessScale, -effectiveDarknessScale); - } - */ - finalColor.set(Mth.clamp(finalColor.x, 0.0f, 1.0f), Mth.clamp(finalColor.y, 0.0f, 1.0f), Mth.clamp(finalColor.z, 0.0f, 1.0f)); - } - - float gamma = this.mc.options.gamma().get().floatValue(); - Vector3f vector3f5 = new Vector3f(this.notGamma(finalColor.x), this.notGamma(finalColor.y), this.notGamma(finalColor.z)); - finalColor.lerp(vector3f5, Math.max(0.0f, gamma /*- darknessGamma*/)); - finalColor.lerp(new Vector3f(0.75f, 0.75f, 0.75f), 0.04f); - finalColor.set(Mth.clamp(finalColor.x, 0.0f, 1.0f), Mth.clamp(finalColor.y, 0.0f, 1.0f), Mth.clamp(finalColor.z, 0.0f, 1.0f)); - finalColor.mul(255.0f); - - int r = (int) finalColor.x(); - int g = (int) finalColor.y(); - int b = (int) finalColor.z(); - this.lightPixels.setPixelRGBA(j, i, 0xFF000000 | b << 16 | g << 8 | r); - } - } + CompiledShaderProgram compiledShaderProgram = Objects.requireNonNull(RenderSystem.setShader(CoreShaders.LIGHTMAP), "Lightmap shader not loaded"); + compiledShaderProgram.safeGetUniform("AmbientLightFactor").set(this.blockAccess.dimensionType().ambientLight()); + compiledShaderProgram.safeGetUniform("SkyFactor").set(effectiveSkyLight); + compiledShaderProgram.safeGetUniform("BlockFactor").set(blockLightRedFlicker + 1.5f); + compiledShaderProgram.safeGetUniform("UseBrightLightmap").set(0); + compiledShaderProgram.safeGetUniform("SkyLightColor").set(skylightColor); + compiledShaderProgram.safeGetUniform("NightVisionFactor").set(nightVision); + compiledShaderProgram.safeGetUniform("DarknessScale").set(0F); + compiledShaderProgram.safeGetUniform("DarkenWorldFactor").set(0F); + compiledShaderProgram.safeGetUniform("BrightnessFactor").set(Math.max(0.0F, this.mc.options.gamma().get().floatValue())); + + this.lightMap.bindWrite(true); + BufferBuilder bufferBuilder = RenderSystem.renderThreadTesselator().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLIT_SCREEN); + bufferBuilder.addVertex(0.0F, 0.0F, 0.0F); + bufferBuilder.addVertex(1.0F, 0.0F, 0.0F); + bufferBuilder.addVertex(1.0F, 1.0F, 0.0F); + bufferBuilder.addVertex(0.0F, 1.0F, 0.0F); + BufferUploader.drawWithShader(bufferBuilder.buildOrThrow()); + this.lightMap.unbindWrite(); + mc.mainRenderTarget.bindWrite(true); - this.lightTexture.upload(); this.lightmapUpdateNeeded = false; } } @@ -1625,15 +1435,13 @@ private void updateSurfaceFog() { f5 = 0.0F; } - if (f5 > 0.0F) { - float[] afloat = this.menuWorldRenderer.dimensionInfo.getSunriseColor(this.menuWorldRenderer.getTimeOfDay(), 0); + if (f5 > 0.0F && this.menuWorldRenderer.dimensionInfo.isSunriseOrSunset(this.menuWorldRenderer.getTimeOfDay())) { + int color = this.menuWorldRenderer.dimensionInfo.getSunriseOrSunsetColor(this.menuWorldRenderer.getTimeOfDay()); - if (afloat != null) { - f5 = f5 * afloat[3]; - fogRed = fogRed * (1.0F - f5) + afloat[0] * f5; - fogGreen = fogGreen * (1.0F - f5) + afloat[1] * f5; - fogBlue = fogBlue * (1.0F - f5) + afloat[2] * f5; - } + f5 = f5 * ARGB.from8BitChannel(ARGB.alpha(color)); + fogRed = fogRed * (1.0f - f5) + ARGB.from8BitChannel(ARGB.red(color)) * f5; + fogGreen = fogGreen * (1.0f - f5) + ARGB.from8BitChannel(ARGB.green(color)) * f5; + fogBlue = fogBlue * (1.0f - f5) + ARGB.from8BitChannel(ARGB.blue(color)) * f5; } } @@ -1729,9 +1537,7 @@ public void setupFog(FogRenderer.FogMode fogMode) { fogEnd = menuWorldRenderer.renderDistance; fogShape = FogShape.CYLINDER; } - RenderSystem.setShaderFogStart(fogStart); - RenderSystem.setShaderFogEnd(fogEnd); - RenderSystem.setShaderFogShape(fogShape); + RenderSystem.setShaderFog(new FogParameters(fogStart, fogEnd, fogShape, fogRed, fogGreen, fogBlue, 1F)); } private FogType getEyeFogType() { @@ -1747,11 +1553,7 @@ private FogType getEyeFogType() { } public void setupNoFog() { - RenderSystem.setShaderFogStart(Float.MAX_VALUE); - } - - public void levelFogColor() { - RenderSystem.setShaderFogColor(fogRed, fogGreen, fogBlue); + RenderSystem.setShaderFog(FogParameters.NO_FOG); } } diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/MCVR.java b/common/src/main/java/org/vivecraft/client_vr/provider/MCVR.java index a3e901b1c..461a4cfcb 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/MCVR.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/MCVR.java @@ -2,11 +2,13 @@ import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; +import net.minecraft.client.ScrollWheelHandler; import net.minecraft.client.gui.screens.ChatScreen; import net.minecraft.client.gui.screens.WinScreen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; +import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.TorchBlock; @@ -1157,7 +1159,7 @@ protected void changeHotbar(int dir) { if (this.mc.screen == null) { InputSimulator.scrollMouse(0.0D, dir * 4); } else { - this.mc.player.getInventory().swapPaint(dir); + this.mc.player.getInventory().setSelectedHotbarSlot(ScrollWheelHandler.getNextScrollWheelSelection(dir, this.mc.player.getInventory().selected, Inventory.getSelectionSize())); } } } diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java b/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java index 858f83444..645f85fbc 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java @@ -1,15 +1,17 @@ package org.vivecraft.client_vr.provider; +import com.mojang.blaze3d.ProjectionType; import com.mojang.blaze3d.pipeline.RenderTarget; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlUtil; -import com.mojang.blaze3d.shaders.ProgramManager; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.*; import net.minecraft.ChatFormatting; import net.minecraft.Util; import net.minecraft.client.GraphicsStatus; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.CompiledShaderProgram; +import net.minecraft.client.renderer.CoreShaders; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.CommonComponents; @@ -48,6 +50,7 @@ import java.nio.FloatBuffer; import java.util.ArrayList; import java.util.List; +import java.util.Objects; public abstract class VRRenderer { public static final String RENDER_SETUP_FAILURE_MESSAGE = "Failed to initialise stereo rendering plugin: "; @@ -127,9 +130,11 @@ public void doStencil(boolean inverse) { ClientDataHolderVR dataholder = ClientDataHolderVR.getInstance(); //setup stencil for writing - GL11.glEnable(GL11.GL_STENCIL_TEST); - RenderSystem.stencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_REPLACE); - RenderSystem.stencilMask(0xFF); // Write to stencil buffer + if (dataholder.vrSettings.useStencilBuffer) { + GL11.glEnable(GL11.GL_STENCIL_TEST); + RenderSystem.stencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_REPLACE); + RenderSystem.stencilMask(0xFF); // Write to stencil buffer + } if (inverse) { //clear whole image for total mask in color, stencil, depth @@ -147,7 +152,7 @@ public void doStencil(boolean inverse) { RenderSystem.colorMask(true, true, true, true); } - RenderSystem.clear(GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT, false); + RenderSystem.clear(GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT); RenderSystem.clearStencil(0); RenderSystem.clearDepth(1); @@ -162,15 +167,15 @@ public void doStencil(boolean inverse) { RenderTarget fb = minecraft.getMainRenderTarget(); RenderSystem.backupProjectionMatrix(); - RenderSystem.setProjectionMatrix(new Matrix4f().setOrtho(0.0F, fb.viewWidth, 0.0F, fb.viewHeight, 0.0F, 20.0F), VertexSorting.ORTHOGRAPHIC_Z); + RenderSystem.setProjectionMatrix(new Matrix4f().setOrtho(0.0F, fb.viewWidth, 0.0F, fb.viewHeight, 0.0F, 20.0F), ProjectionType.ORTHOGRAPHIC); RenderSystem.getModelViewStack().pushMatrix(); RenderSystem.getModelViewStack().identity(); if (inverse) //draw on far clip { RenderSystem.getModelViewStack().translate(0, 0, -20); } - RenderSystem.applyModelViewMatrix(); - int s = GlStateManager._getInteger(GL43.GL_CURRENT_PROGRAM); + + CompiledShaderProgram s = RenderSystem.getShader(); if (dataholder.currentPass == RenderPass.SCOPEL || dataholder.currentPass == RenderPass.SCOPER) { drawCircle(fb.viewWidth, fb.viewHeight); @@ -187,10 +192,13 @@ public void doStencil(boolean inverse) { RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.enableCull(); - ProgramManager.glUseProgram(s); - RenderSystem.stencilFunc(GL11.GL_NOTEQUAL, 255, 1); - RenderSystem.stencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP); - RenderSystem.stencilMask(0); // Dont Write to stencil buffer + + RenderSystem.setShader(s); + if (dataholder.vrSettings.useStencilBuffer) { + RenderSystem.stencilFunc(GL11.GL_NOTEQUAL, 255, 1); + RenderSystem.stencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP); + RenderSystem.stencilMask(0); // Dont Write to stencil buffer + } RenderSystem.depthFunc(GL11.GL_LEQUAL); } @@ -205,6 +213,9 @@ public void doFSAA(boolean hasShaders) { // set to always, so that we can skip the clear RenderSystem.depthFunc(GL43.GL_ALWAYS); + CompiledShaderProgram shader = Objects.requireNonNull( + RenderSystem.setShader(VRShaders.lanczosShader), "lanczos shader not loaded"); + // first pass this.fsaaFirstPassResultFBO.bindWrite(true); @@ -217,11 +228,11 @@ public void doFSAA(boolean hasShaders) { RenderSystem.bindTexture(framebufferVrRender.getDepthTextureId()); RenderSystem.activeTexture(GL43.GL_TEXTURE0); - VRShaders.lanczosShader.setSampler("Sampler0", RenderSystem.getShaderTexture(0)); - VRShaders.lanczosShader.setSampler("Sampler1", RenderSystem.getShaderTexture(1)); + shader.bindSampler("Sampler0", RenderSystem.getShaderTexture(0)); + shader.bindSampler("Sampler1", RenderSystem.getShaderTexture(1)); VRShaders._Lanczos_texelWidthOffsetUniform.set(1.0F / (3.0F * (float) this.fsaaFirstPassResultFBO.viewWidth)); VRShaders._Lanczos_texelHeightOffsetUniform.set(0.0F); - VRShaders.lanczosShader.apply(); + shader.apply(); this.drawQuad(); @@ -236,16 +247,16 @@ public void doFSAA(boolean hasShaders) { RenderSystem.bindTexture(fsaaFirstPassResultFBO.getDepthTextureId()); RenderSystem.activeTexture(GL43.GL_TEXTURE0); - VRShaders.lanczosShader.setSampler("Sampler0", RenderSystem.getShaderTexture(0)); - VRShaders.lanczosShader.setSampler("Sampler1", RenderSystem.getShaderTexture(1)); + shader.bindSampler("Sampler0", RenderSystem.getShaderTexture(0)); + shader.bindSampler("Sampler1", RenderSystem.getShaderTexture(1)); VRShaders._Lanczos_texelWidthOffsetUniform.set(0.0F); VRShaders._Lanczos_texelHeightOffsetUniform.set(1.0F / (3.0F * (float) this.fsaaLastPassResultFBO.viewHeight)); - VRShaders.lanczosShader.apply(); + shader.apply(); this.drawQuad(); // Clean up time - VRShaders.lanczosShader.clear(); + shader.clear(); this.fsaaLastPassResultFBO.unbindWrite(); RenderSystem.depthFunc(GL43.GL_LEQUAL); RenderSystem.enableBlend(); @@ -276,13 +287,14 @@ private void drawMask() { BufferBuilder builder = Tesselator.getInstance().begin(VertexFormat.Mode.TRIANGLES, DefaultVertexFormat.POSITION); - mc.getTextureManager().bindForSetup(ResourceLocation.parse("vivecraft:textures/black.png")); + RenderSystem.setShaderTexture(0, ResourceLocation.parse("vivecraft:textures/black.png")); + RenderSystem.bindTexture(RenderSystem.getShaderTexture(0)); for (int i = 0; i < verts.length; i += 2) { builder.addVertex(verts[i] * dh.vrRenderer.renderScale, verts[i + 1] * dh.vrRenderer.renderScale, 0.0F); } - RenderSystem.setShader(GameRenderer::getPositionShader); + RenderSystem.setShader(CoreShaders.POSITION); BufferUploader.drawWithShader(builder.buildOrThrow()); } @@ -488,13 +500,14 @@ public void setupRenderConfiguration() throws Exception { Tuple cameraSize = getCameraTextureSize(eyeFBWidth, eyeFBHeight); // main render target - if (dataholder.vrSettings.vrUseStencil) { + + if (dataholder.vrSettings.vrUseStencil && dataholder.vrSettings.useStencilBuffer) { ((RenderTargetExtension) WorldRenderPass.stereoXR.target) .vivecraft$setUseStencil(!Xplat.enableRenderTargetStencil(WorldRenderPass.stereoXR.target)); } WorldRenderPass.stereoXR.resize(eyeFBWidth, eyeFBHeight); if (dataholder.vrSettings.useFsaa) { - this.fsaaFirstPassResultFBO.resize(eyew, eyeFBHeight, Minecraft.ON_OSX); + this.fsaaFirstPassResultFBO.resize(eyew, eyeFBHeight); } // mirror @@ -512,7 +525,7 @@ public void setupRenderConfiguration() throws Exception { WorldRenderPass.rightTelescope.resize(telescopeSize.getA(), telescopeSize.getB()); // camera - cameraFramebuffer.resize(cameraSize.getA(), cameraSize.getB(), Minecraft.ON_OSX); + cameraFramebuffer.resize(cameraSize.getA(), cameraSize.getB()); if (ShadersHelper.needsSameSizeBuffers()) { WorldRenderPass.camera.resize(eyeFBWidth, eyeFBHeight); } else { @@ -521,7 +534,7 @@ public void setupRenderConfiguration() throws Exception { // resize gui, if changed if (GuiHandler.updateResolution()) { - GuiHandler.guiFramebuffer.resize(GuiHandler.guiWidth, GuiHandler.guiHeight, Minecraft.ON_OSX); + GuiHandler.guiFramebuffer.resize(GuiHandler.guiWidth, GuiHandler.guiHeight); if (minecraft.screen != null) { int l2 = minecraft.getWindow().getGuiScaledWidth(); int j3 = minecraft.getWindow().getGuiScaledHeight(); @@ -583,13 +596,13 @@ public void setupRenderConfiguration() throws Exception { this.checkGLError("Render Texture setup"); if (this.framebufferEye0 == null) { - this.framebufferEye0 = new VRTextureTarget("L Eye", eyew, eyeh, false, false, this.LeftEyeTextureId, false, true, false); + this.framebufferEye0 = new VRTextureTarget("L Eye", eyew, eyeh, false, this.LeftEyeTextureId, false, true, false); dataholder.print(this.framebufferEye0.toString()); this.checkGLError("Left Eye framebuffer setup"); } if (this.framebufferEye1 == null) { - this.framebufferEye1 = new VRTextureTarget("R Eye", eyew, eyeh, false, false, this.RightEyeTextureId, false, true, false); + this.framebufferEye1 = new VRTextureTarget("R Eye", eyew, eyeh, false, this.RightEyeTextureId, false, true, false); dataholder.print(this.framebufferEye1.toString()); this.checkGLError("Right Eye framebuffer setup"); } @@ -600,7 +613,7 @@ public void setupRenderConfiguration() throws Exception { int eyeFBWidth = (int) Math.ceil(eyew * this.renderScale); int eyeFBHeight = (int) Math.ceil(eyeh * this.renderScale); - this.framebufferVrRender = new VRTextureTarget("3D Render", eyeFBWidth, eyeFBHeight, true, false, -1, true, true, dataholder.vrSettings.vrUseStencil); + this.framebufferVrRender = new VRTextureTarget("3D Render", eyeFBWidth, eyeFBHeight, true, -1, true, true, dataholder.vrSettings.vrUseStencil && dataholder.vrSettings.useStencilBuffer); WorldRenderPass.stereoXR = new WorldRenderPass((VRTextureTarget) this.framebufferVrRender); dataholder.print(this.framebufferVrRender.toString()); this.checkGLError("3D framebuffer setup"); @@ -616,14 +629,14 @@ public void setupRenderConfiguration() throws Exception { // only do these, if the window is not minimized if (mirrorFBWidth > 0 && mirrorFBHeight > 0) { if (list.contains(RenderPass.THIRD) || ShadersHelper.isShaderActive()) { - this.framebufferMR = new VRTextureTarget("Mixed Reality Render", this.mirrorFBWidth, this.mirrorFBHeight, true, false, -1, true, false, false); + this.framebufferMR = new VRTextureTarget("Mixed Reality Render", this.mirrorFBWidth, this.mirrorFBHeight, true, -1, true, false, false); WorldRenderPass.mixedReality = new WorldRenderPass((VRTextureTarget) this.framebufferMR); dataholder.print(this.framebufferMR.toString()); this.checkGLError("Mixed reality framebuffer setup"); } if (list.contains(RenderPass.CENTER) || ShadersHelper.isShaderActive()) { - this.framebufferUndistorted = new VRTextureTarget("Undistorted View Render", this.mirrorFBWidth, this.mirrorFBHeight, true, false, -1, false, false, false); + this.framebufferUndistorted = new VRTextureTarget("Undistorted View Render", this.mirrorFBWidth, this.mirrorFBHeight, true, -1, false, false, false); WorldRenderPass.center = new WorldRenderPass((VRTextureTarget) this.framebufferUndistorted); dataholder.print(this.framebufferUndistorted.toString()); this.checkGLError("Undistorted view framebuffer setup"); @@ -631,30 +644,30 @@ public void setupRenderConfiguration() throws Exception { } GuiHandler.updateResolution(); - GuiHandler.guiFramebuffer = new VRTextureTarget("GUI", GuiHandler.guiWidth, GuiHandler.guiHeight, true, false, -1, false, true, false); + GuiHandler.guiFramebuffer = new VRTextureTarget("GUI", GuiHandler.guiWidth, GuiHandler.guiHeight, true, -1, false, true, false); dataholder.print(GuiHandler.guiFramebuffer.toString()); this.checkGLError("GUI framebuffer setup"); - KeyboardHandler.Framebuffer = new VRTextureTarget("Keyboard", GuiHandler.guiWidth, GuiHandler.guiHeight, true, false, -1, false, true, false); + KeyboardHandler.Framebuffer = new VRTextureTarget("Keyboard", GuiHandler.guiWidth, GuiHandler.guiHeight, true, -1, false, true, false); dataholder.print(KeyboardHandler.Framebuffer.toString()); this.checkGLError("Keyboard framebuffer setup"); - RadialHandler.Framebuffer = new VRTextureTarget("Radial Menu", GuiHandler.guiWidth, GuiHandler.guiHeight, true, false, -1, false, true, false); + RadialHandler.Framebuffer = new VRTextureTarget("Radial Menu", GuiHandler.guiWidth, GuiHandler.guiHeight, true, -1, false, true, false); dataholder.print(RadialHandler.Framebuffer.toString()); this.checkGLError("Radial framebuffer setup"); Tuple telescopeSize = getTelescopeTextureSize(eyeFBWidth, eyeFBHeight); - this.telescopeFramebufferR = new VRTextureTarget("TelescopeR", telescopeSize.getA(), telescopeSize.getB(), true, false, -1, true, false, false); + this.telescopeFramebufferR = new VRTextureTarget("TelescopeR", telescopeSize.getA(), telescopeSize.getB(), true, -1, true, false, false); WorldRenderPass.rightTelescope = new WorldRenderPass((VRTextureTarget) this.telescopeFramebufferR); dataholder.print(this.telescopeFramebufferR.toString()); this.telescopeFramebufferR.setClearColor(0.0f, 0.0f, 0.0f, 1.0f); - this.telescopeFramebufferR.clear(Minecraft.ON_OSX); + this.telescopeFramebufferR.clear(); this.checkGLError("TelescopeR framebuffer setup"); - this.telescopeFramebufferL = new VRTextureTarget("TelescopeL", telescopeSize.getA(), telescopeSize.getB(), true, false, -1, true, false, false); + this.telescopeFramebufferL = new VRTextureTarget("TelescopeL", telescopeSize.getA(), telescopeSize.getB(), true, -1, true, false, false); WorldRenderPass.leftTelescope = new WorldRenderPass((VRTextureTarget) this.telescopeFramebufferL); dataholder.print(this.telescopeFramebufferL.toString()); this.telescopeFramebufferL.setClearColor(0.0f, 0.0f, 0.0f, 1.0f); - this.telescopeFramebufferL.clear(Minecraft.ON_OSX); + this.telescopeFramebufferL.clear(); this.checkGLError("TelescopeL framebuffer setup"); @@ -667,11 +680,11 @@ public void setupRenderConfiguration() throws Exception { cameraRenderFBheight = eyeFBHeight; } - this.cameraFramebuffer = new VRTextureTarget("Handheld Camera", cameraSize.getA(), cameraSize.getB(), true, false, -1, true, false, false); + this.cameraFramebuffer = new VRTextureTarget("Handheld Camera", cameraSize.getA(), cameraSize.getB(), true, -1, true, false, false); dataholder.print(this.cameraFramebuffer.toString()); this.checkGLError("Camera framebuffer setup"); - this.cameraRenderFramebuffer = new VRTextureTarget("Handheld Camera Render", cameraRenderFBwidth, cameraRenderFBheight, true, false, -1, true, true, false); + this.cameraRenderFramebuffer = new VRTextureTarget("Handheld Camera Render", cameraRenderFBwidth, cameraRenderFBheight, true, -1, true, true, false); WorldRenderPass.camera = new WorldRenderPass((VRTextureTarget) this.cameraRenderFramebuffer); dataholder.print(this.cameraRenderFramebuffer.toString()); @@ -683,8 +696,8 @@ public void setupRenderConfiguration() throws Exception { if (dataholder.vrSettings.useFsaa) { try { this.checkGLError("pre FSAA FBO creation"); - this.fsaaFirstPassResultFBO = new VRTextureTarget("FSAA Pass1 FBO", eyew, eyeFBHeight, true, false, -1, false, false, false); - this.fsaaLastPassResultFBO = new VRTextureTarget("FSAA Pass2 FBO", eyew, eyeh, true, false, -1, false, false, false); + this.fsaaFirstPassResultFBO = new VRTextureTarget("FSAA Pass1 FBO", eyew, eyeFBHeight, true, -1, false, false, false); + this.fsaaLastPassResultFBO = new VRTextureTarget("FSAA Pass2 FBO", eyew, eyeh, true, -1, false, false, false); dataholder.print(this.fsaaFirstPassResultFBO.toString()); dataholder.print(this.fsaaLastPassResultFBO.toString()); this.checkGLError("FSAA FBO creation"); @@ -707,8 +720,6 @@ public void setupRenderConfiguration() throws Exception { ShaderHelper.checkGLError("init depth shader"); VRShaders.setupFOVReduction(); ShaderHelper.checkGLError("init FOV shader"); - VRShaders.setupPortalShaders(); - ShaderHelper.checkGLError("init portal shader"); minecraft.gameRenderer.checkEntityPostEffect(minecraft.getCameraEntity()); } catch (Exception exception1) { System.out.println(exception1.getMessage()); diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/nullvr/NullVR.java b/common/src/main/java/org/vivecraft/client_vr/provider/nullvr/NullVR.java index 09ff0186b..51bc0460e 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/nullvr/NullVR.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/nullvr/NullVR.java @@ -2,6 +2,7 @@ import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; +import net.minecraft.util.profiling.Profiler; import org.joml.Vector2f; import org.lwjgl.glfw.GLFW; import org.vivecraft.client.VivecraftVRMod; @@ -84,7 +85,7 @@ public boolean init() { public void poll(long frameIndex) { if (this.initialized) { - this.mc.getProfiler().push("updatePose"); + Profiler.get().push("updatePose"); // don't permanently change the sensitivity float xSens = this.dh.vrSettings.xSensitivity; @@ -130,10 +131,10 @@ public void poll(long frameIndex) { hmdRotation.M[2][1] = GuiHandler.guiRotation_room.M[2][1]; hmdRotation.M[2][2] = GuiHandler.guiRotation_room.M[2][2]; } - this.mc.getProfiler().popPush("hmdSampling"); + Profiler.get().popPush("hmdSampling"); this.hmdSampling(); - this.mc.getProfiler().pop(); + Profiler.get().pop(); } } diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/MCOpenVR.java b/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/MCOpenVR.java index 6c967a0fe..e824416ff 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/MCOpenVR.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/MCOpenVR.java @@ -12,6 +12,7 @@ import net.minecraft.client.resources.language.I18n; import net.minecraft.locale.Language; import net.minecraft.network.chat.Component; +import net.minecraft.util.profiling.Profiler; import net.minecraft.world.phys.Vec3; import org.joml.Vector2f; import org.lwjgl.openvr.*; @@ -337,12 +338,12 @@ public boolean init() { public void poll(long frameIndex) { if (this.initialized) { this.paused = VRSystem_ShouldApplicationPause(); - this.mc.getProfiler().push("events"); + Profiler.get().push("events"); this.pollVREvents(); if (!this.dh.vrSettings.seated) { - this.mc.getProfiler().popPush("controllers"); - this.mc.getProfiler().push("gui"); + Profiler.get().popPush("controllers"); + Profiler.get().push("gui"); if (this.mc.screen == null && this.dh.vrSettings.vrTouchHotbar) { VRSettings vrsettings = this.dh.vrSettings; @@ -352,18 +353,18 @@ public void poll(long frameIndex) { } } - this.mc.getProfiler().pop(); + Profiler.get().pop(); } - this.mc.getProfiler().popPush("processEvents"); + Profiler.get().popPush("processEvents"); this.processVREvents(); - this.mc.getProfiler().popPush("updatePose/Vsync"); + Profiler.get().popPush("updatePose/Vsync"); this.updatePose(); - this.mc.getProfiler().popPush("processInputs"); + Profiler.get().popPush("processInputs"); this.processInputs(); - this.mc.getProfiler().popPush("hmdSampling"); + Profiler.get().popPush("hmdSampling"); this.hmdSampling(); - this.mc.getProfiler().pop(); + Profiler.get().pop(); } } @@ -1219,7 +1220,7 @@ private void updatePose() { } if (this.inputInitialized) { - this.mc.getProfiler().push("updateActionState"); + Profiler.get().push("updateActionState"); if (this.updateActiveActionSets()) { int k = VRInput.VRInput_UpdateActionState(activeActionSetsBuffer, VRActiveActionSet.SIZEOF); @@ -1230,7 +1231,7 @@ private void updatePose() { } this.inputActions.values().forEach(this::readNewData); - this.mc.getProfiler().pop(); + Profiler.get().pop(); if (this.dh.vrSettings.reverseHands) { this.updateControllerPose(0, this.leftPoseHandle); diff --git a/common/src/main/java/org/vivecraft/client_vr/render/ShaderHelper.java b/common/src/main/java/org/vivecraft/client_vr/render/ShaderHelper.java index eb16439fa..efba96b8a 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/ShaderHelper.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/ShaderHelper.java @@ -17,7 +17,7 @@ private static int createShader(String shaderGLSL, int shaderType) throws Except if (i == 0) { return 0; } else { - GlStateManager.glShaderSource(i, List.of(shaderGLSL)); + GlStateManager.glShaderSource(i, shaderGLSL); GlStateManager.glCompileShader(i); String log = GL20C.glGetShaderInfoLog(i); diff --git a/common/src/main/java/org/vivecraft/client_vr/render/VRArmRenderer.java b/common/src/main/java/org/vivecraft/client_vr/render/VRArmRenderer.java index 06fcfdba5..fee457880 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/VRArmRenderer.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/VRArmRenderer.java @@ -5,46 +5,50 @@ import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.model.PlayerModel; import net.minecraft.client.model.geom.ModelPart; -import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.client.renderer.entity.player.PlayerRenderer; import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.ARGB; import net.minecraft.world.item.ItemStack; import org.vivecraft.client_vr.gameplay.trackers.SwingTracker; import org.vivecraft.client_vr.provider.ControllerType; public class VRArmRenderer extends PlayerRenderer { + + public float armAlpha = 1F; + public VRArmRenderer(EntityRendererProvider.Context p_117733_, boolean p_117734_) { super(p_117733_, p_117734_); } - public void renderRightHand(PoseStack pMatrixStack, MultiBufferSource pBuffer, int pCombinedLight, AbstractClientPlayer pPlayer) { - this.renderItem(ControllerType.RIGHT, pMatrixStack, pBuffer, pCombinedLight, pPlayer, (this.model).rightArm, (this.model).rightSleeve); + @Override + public void renderRightHand(PoseStack pMatrixStack, MultiBufferSource pBuffer, int pCombinedLight, ResourceLocation resourceLocation, boolean sleeve) { + this.renderItem(ControllerType.RIGHT, pMatrixStack, pBuffer, pCombinedLight, resourceLocation, (this.model).rightArm, sleeve); } - public void renderLeftHand(PoseStack pMatrixStack, MultiBufferSource pBuffer, int pCombinedLight, AbstractClientPlayer pPlayer) { - this.renderItem(ControllerType.LEFT, pMatrixStack, pBuffer, pCombinedLight, pPlayer, (this.model).leftArm, (this.model).leftSleeve); + @Override + public void renderLeftHand(PoseStack pMatrixStack, MultiBufferSource pBuffer, int pCombinedLight, ResourceLocation resourceLocation, boolean sleeve) { + this.renderItem(ControllerType.LEFT, pMatrixStack, pBuffer, pCombinedLight, resourceLocation, (this.model).leftArm, sleeve); } - private void renderItem(ControllerType side, PoseStack matrixStackIn, MultiBufferSource bufferIn, int combinedLightIn, AbstractClientPlayer playerIn, ModelPart rendererArmIn, ModelPart rendererArmwearIn) { - PlayerModel playermodel = this.getModel(); - this.setModelProperties(playerIn); + private void renderItem(ControllerType side, PoseStack matrixStackIn, MultiBufferSource bufferIn, int combinedLightIn, ResourceLocation resourceLocation, ModelPart arm, boolean sleeve) { + PlayerModel playermodel = this.getModel(); + arm.resetPose(); + arm.visible = true; + playermodel.leftSleeve.visible = sleeve; + playermodel.rightSleeve.visible = sleeve; + RenderSystem.enableBlend(); RenderSystem.enableCull(); RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); - playermodel.attackTime = 0.0F; - playermodel.crouching = false; - playermodel.swimAmount = 0.0F; - rendererArmIn.xRot = 0.0F; - playermodel.leftSleeve.copyFrom(playermodel.leftArm); - playermodel.rightSleeve.copyFrom(playermodel.rightArm); - float f = SwingTracker.getItemFade((LocalPlayer) playerIn, ItemStack.EMPTY); - rendererArmIn.render(matrixStackIn, bufferIn.getBuffer(RenderType.entityTranslucent(playerIn.getSkin().texture())), combinedLightIn, OverlayTexture.NO_OVERLAY); - rendererArmwearIn.xRot = 0.0F; - rendererArmwearIn.render(matrixStackIn, bufferIn.getBuffer(RenderType.entityTranslucent(playerIn.getSkin().texture())), combinedLightIn, OverlayTexture.NO_OVERLAY); + + arm.xRot = 0.0F; + arm.render(matrixStackIn, bufferIn.getBuffer(RenderType.entityTranslucent(resourceLocation)), combinedLightIn, OverlayTexture.NO_OVERLAY, ARGB.white(armAlpha)); + RenderSystem.disableBlend(); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); } diff --git a/common/src/main/java/org/vivecraft/client_vr/render/VRShaders.java b/common/src/main/java/org/vivecraft/client_vr/render/VRShaders.java index 850602ce3..93c6a6af9 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/VRShaders.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/VRShaders.java @@ -3,17 +3,25 @@ import com.mojang.blaze3d.shaders.AbstractUniform; import com.mojang.blaze3d.vertex.DefaultVertexFormat; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.ShaderInstance; +import net.minecraft.client.renderer.CompiledShaderProgram; +import net.minecraft.client.renderer.ShaderDefines; +import net.minecraft.client.renderer.ShaderProgram; +import net.minecraft.resources.ResourceLocation; public class VRShaders { - public static ShaderInstance lanczosShader; + public static final ShaderProgram lanczosShader = new ShaderProgram( + ResourceLocation.fromNamespaceAndPath("vivecraft", "core/lanczos"), + DefaultVertexFormat.POSITION_TEX, ShaderDefines.EMPTY); public static AbstractUniform _Lanczos_texelWidthOffsetUniform; public static AbstractUniform _Lanczos_texelHeightOffsetUniform; public static AbstractUniform _Lanczos_inputImageTextureUniform; public static AbstractUniform _Lanczos_inputDepthTextureUniform; public static AbstractUniform _Lanczos_projectionUniform; public static AbstractUniform _Lanczos_modelViewUniform; - public static ShaderInstance depthMaskShader; + + public static final ShaderProgram depthMaskShader = new ShaderProgram( + ResourceLocation.fromNamespaceAndPath("vivecraft", "core/mixedreality"), + DefaultVertexFormat.POSITION_TEX, ShaderDefines.EMPTY); public static AbstractUniform _DepthMask_hmdViewPosition; public static AbstractUniform _DepthMask_hmdPlaneNormal; public static AbstractUniform _DepthMask_projectionMatrix; @@ -21,11 +29,14 @@ public class VRShaders { public static AbstractUniform _DepthMask_firstPersonPassUniform; public static AbstractUniform _DepthMask_keyColorUniform; public static AbstractUniform _DepthMask_alphaModeUniform; + + public static final ShaderProgram fovReductionShader = new ShaderProgram( + ResourceLocation.fromNamespaceAndPath("vivecraft", "core/fovreduction"), + DefaultVertexFormat.POSITION_TEX, ShaderDefines.EMPTY); public static int _FOVReduction_Enabled; public static AbstractUniform _FOVReduction_RadiusUniform; public static AbstractUniform _FOVReduction_OffsetUniform; public static AbstractUniform _FOVReduction_BorderUniform; - public static ShaderInstance fovReductionShader; public static AbstractUniform _Overlay_HealthAlpha; public static AbstractUniform _Overlay_FreezeAlpha; public static AbstractUniform _Overlay_waterAmplitude; @@ -35,69 +46,60 @@ public class VRShaders { public static AbstractUniform _Overlay_BlackAlpha; public static AbstractUniform _Overlay_eye; - public static ShaderInstance blitAspectShader; + public static final ShaderProgram blitAspectShader = new ShaderProgram( + ResourceLocation.fromNamespaceAndPath("vivecraft", "core/blit_aspect"), + DefaultVertexFormat.POSITION_TEX, ShaderDefines.EMPTY); - public static ShaderInstance rendertypeEndPortalShaderVR; - public static ShaderInstance rendertypeEndGatewayShaderVR; - - public static ShaderInstance getRendertypeEndPortalShaderVR() { - return rendertypeEndPortalShaderVR; - } - - public static ShaderInstance getRendertypeEndGatewayShaderVR() { - return rendertypeEndGatewayShaderVR; - } + public static final ShaderProgram rendertypeEndPortalShaderVR = new ShaderProgram( + ResourceLocation.fromNamespaceAndPath("vivecraft", "core/rendertype_end_portal_vr"), + DefaultVertexFormat.POSITION, ShaderDefines.EMPTY); + public static final ShaderProgram rendertypeEndGatewayShaderVR = new ShaderProgram( + ResourceLocation.fromNamespaceAndPath("vivecraft", "core/rendertype_end_gateway_vr"), + DefaultVertexFormat.POSITION, ShaderDefines.EMPTY); private VRShaders() { } public static void setupDepthMask() throws Exception { - depthMaskShader = new ShaderInstance(Minecraft.getInstance().getResourceManager(), "mixedreality", DefaultVertexFormat.POSITION_TEX); - - _DepthMask_hmdViewPosition = depthMaskShader.safeGetUniform("hmdViewPosition"); - _DepthMask_hmdPlaneNormal = depthMaskShader.safeGetUniform("hmdPlaneNormal"); - _DepthMask_projectionMatrix = depthMaskShader.safeGetUniform("projectionMatrix"); - _DepthMask_viewMatrix = depthMaskShader.safeGetUniform("viewMatrix"); - _DepthMask_firstPersonPassUniform = depthMaskShader.safeGetUniform("firstPersonPass"); - _DepthMask_keyColorUniform = depthMaskShader.safeGetUniform("keyColor"); - _DepthMask_alphaModeUniform = depthMaskShader.safeGetUniform("alphaMode"); + CompiledShaderProgram program = Minecraft.getInstance().getShaderManager().getProgram(depthMaskShader); + + _DepthMask_hmdViewPosition = program.safeGetUniform("hmdViewPosition"); + _DepthMask_hmdPlaneNormal = program.safeGetUniform("hmdPlaneNormal"); + _DepthMask_projectionMatrix = program.safeGetUniform("projectionMatrix"); + _DepthMask_viewMatrix = program.safeGetUniform("viewMatrix"); + _DepthMask_firstPersonPassUniform = program.safeGetUniform("firstPersonPass"); + _DepthMask_keyColorUniform = program.safeGetUniform("keyColor"); + _DepthMask_alphaModeUniform = program.safeGetUniform("alphaMode"); } public static void setupFSAA() throws Exception { - lanczosShader = new ShaderInstance(Minecraft.getInstance().getResourceManager(), "lanczos", DefaultVertexFormat.POSITION_TEX); - - - _Lanczos_texelWidthOffsetUniform = lanczosShader.safeGetUniform("texelWidthOffset"); - _Lanczos_texelHeightOffsetUniform = lanczosShader.safeGetUniform("texelHeightOffset"); - _Lanczos_inputImageTextureUniform = lanczosShader.safeGetUniform("inputImageTexture"); - _Lanczos_inputDepthTextureUniform = lanczosShader.safeGetUniform("inputDepthTexture"); - _Lanczos_projectionUniform = lanczosShader.safeGetUniform("projection"); - _Lanczos_modelViewUniform = lanczosShader.safeGetUniform("modelView"); + CompiledShaderProgram program = Minecraft.getInstance().getShaderManager().getProgram(lanczosShader); + + _Lanczos_texelWidthOffsetUniform = program.safeGetUniform("texelWidthOffset"); + _Lanczos_texelHeightOffsetUniform = program.safeGetUniform("texelHeightOffset"); + _Lanczos_inputImageTextureUniform = program.safeGetUniform("inputImageTexture"); + _Lanczos_inputDepthTextureUniform = program.safeGetUniform("inputDepthTexture"); + _Lanczos_projectionUniform = program.safeGetUniform("projection"); + _Lanczos_modelViewUniform = program.safeGetUniform("modelView"); } public static void setupFOVReduction() throws Exception { - fovReductionShader = new ShaderInstance(Minecraft.getInstance().getResourceManager(), "fovreduction", DefaultVertexFormat.POSITION_TEX); - - - _FOVReduction_RadiusUniform = fovReductionShader.safeGetUniform("circle_radius"); - _FOVReduction_OffsetUniform = fovReductionShader.safeGetUniform("circle_offset"); - _FOVReduction_BorderUniform = fovReductionShader.safeGetUniform("border"); - _Overlay_HealthAlpha = fovReductionShader.safeGetUniform("redalpha"); - _Overlay_FreezeAlpha = fovReductionShader.safeGetUniform("bluealpha"); - _Overlay_waterAmplitude = fovReductionShader.safeGetUniform("water"); - _Overlay_portalAmplitutde = fovReductionShader.safeGetUniform("portal"); - _Overlay_pumpkinAmplitutde = fovReductionShader.safeGetUniform("pumpkin"); - _Overlay_eye = fovReductionShader.safeGetUniform("eye"); - _Overlay_time = fovReductionShader.safeGetUniform("portaltime"); - _Overlay_BlackAlpha = fovReductionShader.safeGetUniform("blackalpha"); + CompiledShaderProgram program = Minecraft.getInstance().getShaderManager().getProgram(fovReductionShader); + + _FOVReduction_RadiusUniform = program.safeGetUniform("circle_radius"); + _FOVReduction_OffsetUniform = program.safeGetUniform("circle_offset"); + _FOVReduction_BorderUniform = program.safeGetUniform("border"); + _Overlay_HealthAlpha = program.safeGetUniform("redalpha"); + _Overlay_FreezeAlpha = program.safeGetUniform("bluealpha"); + _Overlay_waterAmplitude = program.safeGetUniform("water"); + _Overlay_portalAmplitutde = program.safeGetUniform("portal"); + _Overlay_pumpkinAmplitutde = program.safeGetUniform("pumpkin"); + _Overlay_eye = program.safeGetUniform("eye"); + _Overlay_time = program.safeGetUniform("portaltime"); + _Overlay_BlackAlpha = program.safeGetUniform("blackalpha"); } public static void setupBlitAspect() throws Exception { - blitAspectShader = new ShaderInstance(Minecraft.getInstance().getResourceManager(), "blit_aspect", DefaultVertexFormat.POSITION_TEX); - } - - public static void setupPortalShaders() throws Exception { - rendertypeEndPortalShaderVR = new ShaderInstance(Minecraft.getInstance().getResourceManager(), "rendertype_end_portal_vr", DefaultVertexFormat.POSITION); - rendertypeEndGatewayShaderVR = new ShaderInstance(Minecraft.getInstance().getResourceManager(), "rendertype_end_gateway_vr", DefaultVertexFormat.POSITION); + Minecraft.getInstance().getShaderManager().getProgram(blitAspectShader); } } diff --git a/common/src/main/java/org/vivecraft/client_vr/render/VivecraftItemRendering.java b/common/src/main/java/org/vivecraft/client_vr/render/VivecraftItemRendering.java index bbddafd92..90c65d320 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/VivecraftItemRendering.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/VivecraftItemRendering.java @@ -28,7 +28,7 @@ public static VivecraftItemTransformType getTransformType(ItemStack pStack, Abst Item item = pStack.getItem(); Minecraft minecraft = Minecraft.getInstance(); - if (pStack.getUseAnimation() != UseAnim.EAT && pStack.getUseAnimation() != UseAnim.DRINK) { + if (pStack.getUseAnimation() != ItemUseAnimation.EAT && pStack.getUseAnimation() != ItemUseAnimation.DRINK) { if (item instanceof BlockItem) { Block block = ((BlockItem) item).getBlock(); @@ -45,7 +45,7 @@ public static VivecraftItemTransformType getTransformType(ItemStack pStack, Abst } } else if (item instanceof MapItem || pStack.is(ItemTags.VIVECRAFT_MAPS)) { rendertype = VivecraftItemTransformType.Map; - } else if (pStack.getUseAnimation() == UseAnim.BOW && !pStack.is(ItemTags.VIVECRAFT_BOW_EXCLUSION)) { + } else if (pStack.getUseAnimation() == ItemUseAnimation.BOW && !pStack.is(ItemTags.VIVECRAFT_BOW_EXCLUSION)) { rendertype = VivecraftItemTransformType.Bow_Seated; if (dh.bowTracker.isActive((LocalPlayer) pPlayer)) { @@ -55,7 +55,7 @@ public static VivecraftItemTransformType getTransformType(ItemStack pStack, Abst rendertype = VivecraftItemTransformType.Bow_Roomscale; } } - } else if (pStack.getUseAnimation() == UseAnim.TOOT_HORN) { + } else if (pStack.getUseAnimation() == ItemUseAnimation.TOOT_HORN) { rendertype = VivecraftItemTransformType.Horn; } else if (item instanceof MaceItem || pStack.is(ItemTags.VIVECRAFT_MACES)) { rendertype = VivecraftItemTransformType.Mace; diff --git a/common/src/main/java/org/vivecraft/client_vr/render/helpers/RenderHelper.java b/common/src/main/java/org/vivecraft/client_vr/render/helpers/RenderHelper.java index 28f0648b6..ed5528858 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/helpers/RenderHelper.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/helpers/RenderHelper.java @@ -1,5 +1,6 @@ package org.vivecraft.client_vr.render.helpers; +import com.mojang.blaze3d.ProjectionType; import com.mojang.blaze3d.pipeline.RenderTarget; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; @@ -9,9 +10,10 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.renderer.CoreShaders; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.LightTexture; -import net.minecraft.client.renderer.ShaderInstance; +import net.minecraft.client.renderer.ShaderProgram; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.core.Vec3i; import net.minecraft.resources.ResourceLocation; @@ -158,6 +160,7 @@ public static void setupRenderingAtController(int controller, Matrix4f matrix) { public static void renderDebugAxes(int r, int g, int b, float radius) { setupPolyRendering(true); RenderSystem.setShaderTexture(0, ResourceLocation.parse("vivecraft:textures/white.png")); + RenderSystem.bindTexture(RenderSystem.getShaderTexture(0)); renderCircle(new Vec3(0.0D, 0.0D, 0.0D), radius, 32, r, g, b, 255, 0); renderCircle(new Vec3(0.0D, 0.01D, 0.0D), radius * 0.75F, 32, r, g, b, 255, 0); renderCircle(new Vec3(0.0D, 0.02D, 0.0D), radius * 0.25F, 32, r, g, b, 255, 0); @@ -243,13 +246,12 @@ public static void drawScreen(DeltaTracker.Timer timer, Screen screen, GuiGraphi posestack.pushMatrix(); posestack.identity(); posestack.translate(0.0F, 0.0F, -11000.0F); - RenderSystem.applyModelViewMatrix(); Matrix4f guiProjection = (new Matrix4f()).setOrtho( 0.0F, (float) (mc.getWindow().getWidth() / mc.getWindow().getGuiScale()), (float) (mc.getWindow().getHeight() / mc.getWindow().getGuiScale()), 0.0F, 1000.0F, 21000.0F); - RenderSystem.setProjectionMatrix(guiProjection, VertexSorting.ORTHOGRAPHIC_Z); + RenderSystem.setProjectionMatrix(guiProjection, ProjectionType.ORTHOGRAPHIC); RenderSystem.blendFuncSeparate( GlStateManager.SourceFactor.SRC_ALPHA, @@ -266,7 +268,6 @@ public static void drawScreen(DeltaTracker.Timer timer, Screen screen, GuiGraphi GlStateManager.DestFactor.ONE); posestack.popMatrix(); - RenderSystem.applyModelViewMatrix(); RenderTarget main = mc.getMainRenderTarget(); main.bindRead(); @@ -305,7 +306,7 @@ public static void drawSizedQuad(float displayWidth, float displayHeight, float public static void drawSizedQuad(float displayWidth, float displayHeight, float size, float[] color, Matrix4f pMatrix) { float aspect = displayHeight / displayWidth; - RenderSystem.setShader(GameRenderer::getPositionTexShader); + RenderSystem.setShader(CoreShaders.POSITION_TEX); RenderSystem.setShaderColor(color[0], color[1], color[2], color[3]); BufferBuilder bufferbuilder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); bufferbuilder @@ -330,16 +331,16 @@ public static void drawSizedQuadWithLightmapCutout(float displayWidth, float dis public static void drawSizedQuadWithLightmapCutout(float displayWidth, float displayHeight, float size, int lighti, float[] color, Matrix4f pMatrix, boolean flipY) { - drawSizedQuadWithLightmap(displayWidth, displayHeight, size, lighti, color, pMatrix, GameRenderer::getRendertypeEntityCutoutNoCullShader, flipY); + drawSizedQuadWithLightmap(displayWidth, displayHeight, size, lighti, color, pMatrix, CoreShaders.RENDERTYPE_ENTITY_CUTOUT_NO_CULL, flipY); } public static void drawSizedQuadSolid(float displayWidth, float displayHeight, float size, float[] color, Matrix4f pMatrix) { - drawSizedQuadWithLightmap(displayWidth, displayHeight, size, LightTexture.pack(15, 15), color, pMatrix, GameRenderer::getRendertypeEntitySolidShader, false); + drawSizedQuadWithLightmap(displayWidth, displayHeight, size, LightTexture.pack(15, 15), color, pMatrix, CoreShaders.RENDERTYPE_ENTITY_SOLID, false); } public static void drawSizedQuadWithLightmap(float displayWidth, float displayHeight, float size, int lighti, - float[] color, Matrix4f pMatrix, Supplier shader, boolean flipY) { + float[] color, Matrix4f pMatrix, ShaderProgram shader, boolean flipY) { float aspect = displayHeight / displayWidth; RenderSystem.setShader(shader); mc.gameRenderer.lightTexture().turnOnLightLayer(); diff --git a/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRArmHelper.java b/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRArmHelper.java index c2ef06ddc..93f165d79 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRArmHelper.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRArmHelper.java @@ -4,12 +4,14 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.*; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.CoreShaders; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.core.BlockPos; import net.minecraft.core.Vec3i; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; +import net.minecraft.util.profiling.Profiler; import net.minecraft.world.InteractionHand; import net.minecraft.world.item.ItemStack; import net.minecraft.world.phys.Vec3; @@ -45,7 +47,7 @@ public static boolean shouldRenderHands() { public static void renderVRHands(float partialTicks, boolean renderRight, boolean renderLeft, boolean menuHandRight, boolean menuHandLeft) { - mc.getProfiler().push("hands"); + Profiler.get().push("hands"); // backup projection matrix, not doing that breaks sodium water on 1.19.3 RenderSystem.backupProjectionMatrix(); @@ -72,7 +74,7 @@ public static void renderVRHands(float partialTicks, boolean renderRight, boolea } RenderSystem.restoreProjectionMatrix(); - mc.getProfiler().pop(); + Profiler.get().pop(); } public static void renderMainMenuHand(int c, float partialTicks, boolean depthAlways) { @@ -86,8 +88,8 @@ public static void renderMainMenuHand(int c, float partialTicks, boolean depthAl RenderHelper.setupRenderingAtController(c, modelView); if (mc.getOverlay() == null) { - mc.getTextureManager().bindForSetup(ResourceLocation.parse("vivecraft:textures/white.png")); RenderSystem.setShaderTexture(0, ResourceLocation.parse("vivecraft:textures/white.png")); + RenderSystem.bindTexture(RenderSystem.getShaderTexture(0)); } if (depthAlways && c == 0) { @@ -114,11 +116,11 @@ public static void renderMainMenuHand(int c, float partialTicks, boolean depthAl light = (float) minLight; } - float lightPercent = light / (float) mc.level.getMaxLightLevel(); + float lightPercent = light / 15F; color = new Vec3i(Mth.floor(color.getX() * lightPercent), Mth.floor(color.getY() * lightPercent), Mth.floor(color.getZ() * lightPercent)); } - RenderSystem.setShader(GameRenderer::getPositionColorShader); + RenderSystem.setShader(CoreShaders.POSITION_COLOR); BufferBuilder bufferBuilder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_NORMAL); RenderHelper.renderBox(bufferBuilder, start, end, -0.02F, 0.02F, -0.0125F, 0.0125F, color, alpha, modelView); BufferUploader.drawWithShader(bufferBuilder.buildOrThrow()); @@ -267,9 +269,9 @@ public static void renderVRHand_Offhand(float partialTicks, boolean renderTelepo if (r < 0.0F) { r = 0.0F; } - RenderSystem.setShader(GameRenderer::getPositionColorShader); - mc.getTextureManager().bindForSetup(ResourceLocation.parse("vivecraft:textures/white.png")); + RenderSystem.setShader(CoreShaders.POSITION_COLOR); RenderSystem.setShaderTexture(0, ResourceLocation.parse("vivecraft:textures/white.png")); + RenderSystem.bindTexture(RenderSystem.getShaderTexture(0)); RenderHelper.renderFlatQuad(start.add(0.0D, 0.05001D, 0.0D), r, r, 0.0F, tpLimitedColor.getX(), tpLimitedColor.getY(), tpLimitedColor.getZ(), 128, poseStack.last().pose()); RenderHelper.renderFlatQuad(start.add(0.0D, 0.05D, 0.0D), max, max, 0.0F, tpLimitedColor.getX(), @@ -297,14 +299,14 @@ public static void renderTeleportArc(Matrix4f matrix) { if (dataHolder.teleportTracker.vrMovementStyle.showBeam && dataHolder.teleportTracker.isAiming() && dataHolder.teleportTracker.movementTeleportArcSteps > 1) { - mc.getProfiler().push("teleportArc"); + Profiler.get().push("teleportArc"); RenderSystem.enableCull(); - RenderSystem.setShader(GameRenderer::getPositionColorShader); + RenderSystem.setShader(CoreShaders.POSITION_COLOR); // to make shaders work - mc.getTextureManager().bindForSetup(ResourceLocation.parse("vivecraft:textures/white.png")); RenderSystem.setShaderTexture(0, ResourceLocation.parse("vivecraft:textures/white.png")); + RenderSystem.bindTexture(RenderSystem.getShaderTexture(0)); BufferBuilder bufferBuilder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_NORMAL); @@ -384,7 +386,7 @@ public static void renderTeleportArc(Matrix4f matrix) { RenderSystem.enableCull(); } - mc.getProfiler().pop(); + Profiler.get().pop(); } } } diff --git a/common/src/main/java/org/vivecraft/client_vr/render/helpers/VREffectsHelper.java b/common/src/main/java/org/vivecraft/client_vr/render/helpers/VREffectsHelper.java index b27dc7e62..6038dd288 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/helpers/VREffectsHelper.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/helpers/VREffectsHelper.java @@ -10,8 +10,7 @@ import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.ModelBakery; @@ -20,6 +19,7 @@ import net.minecraft.network.chat.HoverEvent; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; +import net.minecraft.util.profiling.Profiler; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.BlockHitResult; @@ -40,6 +40,7 @@ import org.vivecraft.client_vr.MethodHolder; import org.vivecraft.client_vr.extensions.GameRendererExtension; import org.vivecraft.client_vr.extensions.LevelRendererExtension; +import org.vivecraft.client_vr.extensions.LevelTargetBundleExtension; import org.vivecraft.client_vr.extensions.PlayerExtension; import org.vivecraft.client_vr.gameplay.VRPlayer; import org.vivecraft.client_vr.gameplay.screenhandlers.GuiHandler; @@ -67,7 +68,7 @@ public static boolean isInsideOpaqueBlock(Vec3 in) { return false; } else { BlockPos blockpos = BlockPos.containing(in); - return mc.level.getBlockState(blockpos).isSolidRender(mc.level, blockpos); + return mc.level.getBlockState(blockpos).isSolidRender(); } } @@ -77,7 +78,7 @@ public static Triple getNearOpaqueBlock(Vec3 in, do } else { AABB aabb = new AABB(in.subtract(dist, dist, dist), in.add(dist, dist, dist)); Stream stream = BlockPos.betweenClosedStream(aabb).filter((bp) -> - mc.level.getBlockState(bp).isSolidRender(mc.level, bp)); + mc.level.getBlockState(bp).isSolidRender()); Optional optional = stream.findFirst(); return optional.isPresent() ? Triple.of(1.0F, mc.level.getBlockState(optional.get()), optional.get()) @@ -121,7 +122,10 @@ public static void drawScopeFB(PoseStack matrixStackIn, int i) { private static boolean showedStencilMessage = false; public static void drawEyeStencil(boolean flag1) { - wasStencilOn = GL11C.glIsEnabled(GL11C.GL_STENCIL_TEST); + if (dataHolder.vrSettings.useStencilBuffer) { + wasStencilOn = GL11C.glIsEnabled(GL11C.GL_STENCIL_TEST); + } + if (wasStencilOn && !showedStencilMessage && dataHolder.vrSettings.vrUseStencil && dataHolder.vrSettings.showChatMessageStencil) { showedStencilMessage = true; @@ -171,7 +175,7 @@ public static void drawEyeStencil(boolean flag1) { public static void disableStencilTest() { // if we did enable the stencil test, disable it - if (!wasStencilOn) { + if (!wasStencilOn && dataHolder.vrSettings.useStencilBuffer) { GL11C.glDisable(GL11C.GL_STENCIL_TEST); } } @@ -186,8 +190,8 @@ public static void disableStencilTest() { private static final ResourceLocation grass = ResourceLocation.withDefaultNamespace("textures/block/grass_block_top.png"); public static void renderMenuPanorama(Matrix4fStack poseStack) { - RenderSystem.setShader(GameRenderer::getPositionTexColorShader); - RenderSystem.clear(GL11C.GL_COLOR_BUFFER_BIT | GL11C.GL_DEPTH_BUFFER_BIT, Minecraft.ON_OSX); + RenderSystem.setShader(CoreShaders.POSITION_TEX_COLOR); + RenderSystem.clear(GL11C.GL_COLOR_BUFFER_BIT | GL11C.GL_DEPTH_BUFFER_BIT); RenderSystem.depthMask(true); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); @@ -285,7 +289,7 @@ public static void renderMenuPanorama(Matrix4fStack poseStack) { float length = area.y + i * 2; poseStack.pushMatrix(); - RenderSystem.setShader(GameRenderer::getPositionTexColorShader); + RenderSystem.setShader(CoreShaders.POSITION_TEX_COLOR); int r, g, b; if (i == 0) { @@ -339,9 +343,9 @@ public static void renderJrbuddasAwesomeMainMenuRoomNew(Matrix4fStack pMatrixSta area = new Vector2f(2, 2); } - RenderSystem.setShader(GameRenderer::getPositionTexColorShader); + RenderSystem.setShader(CoreShaders.POSITION_TEX_COLOR); RenderSystem.depthFunc(GL11C.GL_ALWAYS); - RenderSystem.clear(GL11C.GL_COLOR_BUFFER_BIT | GL11C.GL_DEPTH_BUFFER_BIT, Minecraft.ON_OSX); + RenderSystem.clear(GL11C.GL_COLOR_BUFFER_BIT | GL11C.GL_DEPTH_BUFFER_BIT); RenderSystem.depthMask(false); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); @@ -429,15 +433,14 @@ public static void renderTechjarsAwesomeMainMenuRoom(Matrix4fStack poseStack) { // transfer the rotation RenderSystem.getModelViewStack().mul(poseStack, poseStack); RenderSystem.getModelViewStack().pushMatrix().identity(); - RenderSystem.applyModelViewMatrix(); int tzOffset = Calendar.getInstance().get(Calendar.ZONE_OFFSET); dataHolder.menuWorldRenderer.time = dataHolder.menuWorldRenderer.fastTime - ? (long) (dataHolder.menuWorldRenderer.ticks * 10L + 10 * mc.getTimer().getGameTimeDeltaPartialTick(false)) + ? (long) (dataHolder.menuWorldRenderer.ticks * 10L + 10 * mc.getDeltaTracker().getGameTimeDeltaPartialTick(false)) : (long) ((System.currentTimeMillis() + tzOffset - 21600000) / 86400000D * 24000D); dataHolder.menuWorldRenderer.fogRenderer.setupFogColor(); - RenderSystem.clear(GL11C.GL_COLOR_BUFFER_BIT | GL11C.GL_DEPTH_BUFFER_BIT, Minecraft.ON_OSX); + RenderSystem.clear(GL11C.GL_COLOR_BUFFER_BIT | GL11C.GL_DEPTH_BUFFER_BIT); dataHolder.menuWorldRenderer.updateLightmap(); dataHolder.menuWorldRenderer.render(poseStack); @@ -448,7 +451,7 @@ public static void renderTechjarsAwesomeMainMenuRoom(Matrix4fStack poseStack) { float width = area.x;//(float)Math.ceil(area.x); float length = area.y;//(float)Math.ceil(area.y); - RenderSystem.setShader(GameRenderer::getPositionTexColorShader); + RenderSystem.setShader(CoreShaders.POSITION_TEX_COLOR); RenderSystem.setShaderTexture(0, Screen.MENU_BACKGROUND); float sun = dataHolder.menuWorldRenderer.getSkyDarken(); RenderSystem.setShaderColor(sun, sun, sun, 0.3f); @@ -485,26 +488,26 @@ public static void renderTechjarsAwesomeMainMenuRoom(Matrix4fStack poseStack) { RenderSystem.defaultBlendFunc(); RenderSystem.getModelViewStack().popMatrix(); - RenderSystem.applyModelViewMatrix(); } - public static void renderVRFabulous(float partialTicks, LevelRenderer levelRenderer, boolean menuHandRight, boolean menuHandLeft) { + public static void renderVRFabulous(float partialTicks, LevelTargetBundle targets, boolean menuHandRight, boolean menuHandLeft) { if (ClientDataHolderVR.getInstance().currentPass == RenderPass.SCOPEL || ClientDataHolderVR.getInstance().currentPass == RenderPass.SCOPER) { return; } - mc.getProfiler().popPush("VR"); + Profiler.get().popPush("VR"); renderCrosshairAtDepth(!ClientDataHolderVR.getInstance().vrSettings.useCrosshairOcclusion); - mc.getMainRenderTarget().unbindWrite(); - ((LevelRendererExtension) levelRenderer).vivecraft$getAlphaSortVROccludedFramebuffer().clear(Minecraft.ON_OSX); - ((LevelRendererExtension) levelRenderer).vivecraft$getAlphaSortVROccludedFramebuffer().copyDepthFrom(mc.getMainRenderTarget()); - ((LevelRendererExtension) levelRenderer).vivecraft$getAlphaSortVROccludedFramebuffer().bindWrite(true); + + LevelTargetBundleExtension extTargets = (LevelTargetBundleExtension) targets; + extTargets.vivecraft$getOccluded().get().clear(); + extTargets.vivecraft$getOccluded().get().copyDepthFrom(mc.getMainRenderTarget()); + extTargets.vivecraft$getOccluded().get().bindWrite(false); if (shouldOccludeGui()) { renderGuiAndShadow(partialTicks, false, false); } - ((LevelRendererExtension) levelRenderer).vivecraft$getAlphaSortVRUnoccludedFramebuffer().clear(Minecraft.ON_OSX); - ((LevelRendererExtension) levelRenderer).vivecraft$getAlphaSortVRUnoccludedFramebuffer().bindWrite(true); + extTargets.vivecraft$getUnoccluded().get().clear(); + extTargets.vivecraft$getUnoccluded().get().bindWrite(false); if (!shouldOccludeGui()) { renderGuiAndShadow(partialTicks, false, false); @@ -517,15 +520,15 @@ public static void renderVRFabulous(float partialTicks, LevelRenderer levelRende VRArmHelper.renderVRHands(partialTicks, renderHands && menuHandRight, renderHands && menuHandLeft, true, true); - ((LevelRendererExtension) levelRenderer).vivecraft$getAlphaSortVRHandsFramebuffer().clear(Minecraft.ON_OSX); - ((LevelRendererExtension) levelRenderer).vivecraft$getAlphaSortVRHandsFramebuffer().copyDepthFrom(mc.getMainRenderTarget()); - ((LevelRendererExtension) levelRenderer).vivecraft$getAlphaSortVRHandsFramebuffer().bindWrite(true); + extTargets.vivecraft$getHands().get().clear(); + extTargets.vivecraft$getHands().get().copyDepthFrom(mc.getMainRenderTarget()); + extTargets.vivecraft$getHands().get().bindWrite(false); VRArmHelper.renderVRHands(partialTicks, renderHands && !menuHandRight, renderHands && !menuHandLeft, false, false); RenderSystem.defaultBlendFunc(); RenderSystem.setShaderColor(1, 1, 1, 1); - mc.getMainRenderTarget().bindWrite(true); + targets.main.get().bindWrite(false); } public static void renderVrFast(float partialTicks, boolean secondPass, boolean menuHandRight, boolean menuHandLeft) { @@ -533,7 +536,7 @@ public static void renderVrFast(float partialTicks, boolean secondPass, boolean || dataHolder.currentPass == RenderPass.SCOPER) { return; } - mc.getProfiler().popPush("VR"); + Profiler.get().popPush("VR"); mc.gameRenderer.lightTexture().turnOffLightLayer(); if (!secondPass) { @@ -599,7 +602,7 @@ public static void renderVrShadow(float partialTicks, boolean depthAlways) { if (mc.player.isAlive()) { if (!(((PlayerExtension) mc.player).vivecraft$getRoomYOffsetFromPose() < 0.0D)) { if (mc.player.getVehicle() == null) { - mc.getProfiler().push("vr shadow"); + Profiler.get().push("vr shadow"); AABB aabb = mc.player.getBoundingBox(); if (dataHolder.vrSettings.vrShowBlueCircleBuddy && aabb != null) { @@ -618,9 +621,9 @@ public static void renderVrShadow(float partialTicks, boolean depthAlways) { RenderSystem.depthFunc(GL11C.GL_LEQUAL); } - RenderSystem.setShader(GameRenderer::getPositionColorShader); - mc.getTextureManager().bindForSetup(ResourceLocation.parse("vivecraft:textures/white.png")); + RenderSystem.setShader(CoreShaders.POSITION_COLOR); RenderSystem.setShaderTexture(0, ResourceLocation.parse("vivecraft:textures/white.png")); + RenderSystem.bindTexture(RenderSystem.getShaderTexture(0)); RenderHelper.renderFlatQuad(pos, (float) (aabb.maxX - aabb.minX), (float) (aabb.maxZ - aabb.minZ), 0.0F, 0, 0, 0, 64, modelView); @@ -629,7 +632,7 @@ public static void renderVrShadow(float partialTicks, boolean depthAlways) { RenderHelper.setupPolyRendering(false); RenderSystem.enableCull(); } - mc.getProfiler().pop(); + Profiler.get().pop(); } } } @@ -665,7 +668,7 @@ public static void renderFireInFirstPerson() { // code adapted from net.minecraft.client.renderer.ScreenEffectRenderer.renderFire - RenderSystem.setShader(GameRenderer::getPositionTexColorShader); + RenderSystem.setShader(CoreShaders.POSITION_TEX_COLOR); RenderSystem.setShaderTexture(0, fireSprite.atlasLocation()); float uMin = fireSprite.getU0(); float uMax = fireSprite.getU1(); @@ -713,7 +716,7 @@ public static void renderPhysicalKeyboard(float partialTicks) { if (!dataHolder.bowTracker.isDrawing) { ((GameRendererExtension) mc.gameRenderer).vivecraft$resetProjectionMatrix(partialTicks); - mc.getProfiler().push("applyPhysicalKeyboardModelView"); + Profiler.get().push("applyPhysicalKeyboardModelView"); Vec3 eye = RenderHelper.getSmoothCameraPosition(dataHolder.currentPass, dataHolder.vrPlayer.vrdata_world_render); //convert previously calculated coords to world coords @@ -730,7 +733,7 @@ public static void renderPhysicalKeyboard(float partialTicks) { float scale = dataHolder.vrPlayer.vrdata_world_render.worldScale; modelView.scale(scale, scale, scale); - mc.getProfiler().pop(); + Profiler.get().pop(); KeyboardHandler.physicalKeyboard.render(modelView); } @@ -742,7 +745,7 @@ private static void renderScreen(Matrix4f poseStack, RenderTarget screenFramebuf RenderSystem.setShaderTexture(0, screenFramebuffer.getColorTextureId()); // cache fog distance - float fogStart = RenderSystem.getShaderFogStart(); + FogParameters oldFog = RenderSystem.getShaderFog(); float[] color = new float[]{1.0F, 1.0F, 1.0F, 1.0F}; if (!MethodHolder.isInMenuRoom()) { if (mc.screen == null) { @@ -750,7 +753,7 @@ private static void renderScreen(Matrix4f poseStack, RenderTarget screenFramebuf } if (noFog || mc.screen != null) { // disable fog for menus - RenderSystem.setShaderFogStart(Float.MAX_VALUE); + RenderSystem.setShaderFog(FogParameters.NO_FOG); } if (mc.player != null && mc.player.isShiftKeyDown()) { @@ -793,7 +796,7 @@ private static void renderScreen(Matrix4f poseStack, RenderTarget screenFramebuf } // reset fog - RenderSystem.setShaderFogStart(fogStart); + RenderSystem.setShaderFog(oldFog); RenderSystem.depthFunc(GL11C.GL_LEQUAL); RenderSystem.enableDepthTest(); RenderSystem.defaultBlendFunc(); @@ -804,7 +807,7 @@ public static void renderGuiLayer(float partialTicks, boolean depthAlways) { if (!dataHolder.bowTracker.isDrawing) { if (mc.screen != null || !mc.options.hideGui) { if (!RadialHandler.isShowing()) { - mc.getProfiler().push("GuiLayer"); + Profiler.get().push("GuiLayer"); Matrix4fStack modelView = new Matrix4fStack(8); // remove nausea effect from projection matrix @@ -847,7 +850,7 @@ public static void renderGuiLayer(float partialTicks, boolean depthAlways) { renderScreen(modelView, GuiHandler.guiFramebuffer, depthAlways, false, guiPos); - mc.getProfiler().pop(); + Profiler.get().pop(); } } } @@ -858,7 +861,7 @@ public static void render2D(float partialTicks, RenderTarget framebuffer, Vec3 p // remove nausea effect from projection matrix ((GameRendererExtension) mc.gameRenderer).vivecraft$resetProjectionMatrix(partialTicks); - mc.getProfiler().push("apply2DModelView"); + Profiler.get().push("apply2DModelView"); Vec3 eye = RenderHelper.getSmoothCameraPosition(dataHolder.currentPass, dataHolder.vrPlayer.vrdata_world_render); @@ -875,7 +878,7 @@ public static void render2D(float partialTicks, RenderTarget framebuffer, Vec3 p float scale = GuiHandler.guiScale * dataHolder.vrPlayer.vrdata_world_render.worldScale; modelView.scale(scale, scale, scale); - mc.getProfiler().pop(); + Profiler.get().pop(); renderScreen(modelView, framebuffer, depthAlways, true, guiPos); } @@ -887,19 +890,17 @@ public static void renderFaceOverlay(float partialTicks) { RenderSystem.getModelViewStack().pushMatrix().identity(); RenderHelper.applyVRModelView(dataHolder.currentPass, RenderSystem.getModelViewStack()); - RenderSystem.applyModelViewMatrix(); renderGuiAndShadow(partialTicks, true, true); VRArmHelper.renderVRHands(partialTicks, true, true, true, true); RenderSystem.getModelViewStack().popMatrix(); - RenderSystem.applyModelViewMatrix(); } } public static void renderFaceInBlock() { - RenderSystem.setShader(GameRenderer::getPositionShader); + RenderSystem.setShader(CoreShaders.POSITION); RenderSystem.setShaderColor(0.0F, 0.0F, 0.0F, 1.0f); // orthographic matrix, (-1, -1) to (1, 1), near = 0.0, far 2.0 @@ -967,7 +968,7 @@ private static boolean shouldRenderCrosshair() { public static void renderCrosshairAtDepth(boolean depthAlways) { if (shouldRenderCrosshair()) { - mc.getProfiler().push("crosshair"); + Profiler.get().push("crosshair"); // white crosshair, with blending RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); @@ -1045,7 +1046,7 @@ public static void renderCrosshairAtDepth(boolean depthAlways) { float uMax = 15.0F / 256.0F; float vMax = 15.0F / 256.0F; - RenderSystem.setShader(GameRenderer::getRendertypeEntityCutoutNoCullShader); + RenderSystem.setShader(CoreShaders.RENDERTYPE_ENTITY_CUTOUT_NO_CULL); BufferBuilder bufferbuilder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.NEW_ENTITY); bufferbuilder.addVertex(modelView, -1.0F, 1.0F, 0.0F).setColor(brightness, brightness, brightness, 1.0F) @@ -1062,7 +1063,7 @@ public static void renderCrosshairAtDepth(boolean depthAlways) { RenderSystem.defaultBlendFunc(); RenderSystem.disableBlend(); RenderSystem.depthFunc(GL11C.GL_LEQUAL); - mc.getProfiler().pop(); + Profiler.get().pop(); } } } diff --git a/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRPassHelper.java b/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRPassHelper.java index 4e0c527f7..9a7eb4ab9 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRPassHelper.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRPassHelper.java @@ -2,7 +2,6 @@ import com.mojang.blaze3d.pipeline.RenderTarget; import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.shaders.ProgramManager; import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.Util; import net.minecraft.client.DeltaTracker; @@ -10,6 +9,7 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.core.component.DataComponents; import net.minecraft.util.Mth; +import net.minecraft.util.profiling.Profiler; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.component.CustomModelData; import net.minecraft.world.level.block.Blocks; @@ -21,7 +21,6 @@ import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.extensions.GameRendererExtension; import org.vivecraft.client_vr.extensions.GuiExtension; -import org.vivecraft.client_vr.extensions.MinecraftExtension; import org.vivecraft.client_vr.gameplay.screenhandlers.KeyboardHandler; import org.vivecraft.client_vr.gameplay.screenhandlers.RadialHandler; import org.vivecraft.client_vr.render.RenderConfigException; @@ -44,28 +43,28 @@ public class VRPassHelper { public static void renderSingleView(RenderPass eye, DeltaTracker.Timer timer, boolean renderWorld) { RenderSystem.clearColor(0.0F, 0.0F, 0.0F, 1.0F); - RenderSystem.clear(16384, Minecraft.ON_OSX); + RenderSystem.clear(16384); RenderSystem.enableDepthTest(); mc.gameRenderer.render(timer, renderWorld); checkGLError("post game render " + eye.name()); if (dataHolder.currentPass == RenderPass.LEFT || dataHolder.currentPass == RenderPass.RIGHT) { - mc.getProfiler().push("postProcessEye"); + Profiler.get().push("postProcessEye"); RenderTarget rendertarget = mc.getMainRenderTarget(); if (dataHolder.vrSettings.useFsaa) { - RenderSystem.clearColor(RenderSystem.getShaderFogColor()[0], RenderSystem.getShaderFogColor()[1], RenderSystem.getShaderFogColor()[2], RenderSystem.getShaderFogColor()[3]); + RenderSystem.clearColor(RenderSystem.getShaderFog().red(), RenderSystem.getShaderFog().green(), RenderSystem.getShaderFog().blue(), RenderSystem.getShaderFog().alpha()); if (eye == RenderPass.LEFT) { dataHolder.vrRenderer.framebufferEye0.bindWrite(true); } else { dataHolder.vrRenderer.framebufferEye1.bindWrite(true); } - RenderSystem.clear(16384, Minecraft.ON_OSX); - mc.getProfiler().push("fsaa"); + RenderSystem.clear(16384); + Profiler.get().push("fsaa"); dataHolder.vrRenderer.doFSAA(false); rendertarget = dataHolder.vrRenderer.fsaaLastPassResultFBO; checkGLError("fsaa " + eye.name()); - mc.getProfiler().pop(); + Profiler.get().pop(); } if (eye == RenderPass.LEFT) { @@ -199,20 +198,19 @@ public static void renderSingleView(RenderPass eye, DeltaTracker.Timer timer, bo VRShaders._Overlay_eye.set(dataHolder.currentPass == RenderPass.LEFT ? 1 : -1); ((RenderTargetExtension) rendertarget).vivecraft$blitFovReduction(VRShaders.fovReductionShader, dataHolder.vrRenderer.framebufferEye0.viewWidth, dataHolder.vrRenderer.framebufferEye0.viewHeight); - ProgramManager.glUseProgram(0); checkGLError("post overlay" + eye); - mc.getProfiler().pop(); + Profiler.get().pop(); } if (dataHolder.currentPass == RenderPass.CAMERA) { - mc.getProfiler().push("cameraCopy"); + Profiler.get().push("cameraCopy"); dataHolder.vrRenderer.cameraFramebuffer.bindWrite(true); RenderSystem.clearColor(0.0F, 0.0F, 0.0F, 1.0F); - RenderSystem.clear(16640, Minecraft.ON_OSX); + RenderSystem.clear(16640); ((RenderTargetExtension) dataHolder.vrRenderer.cameraRenderFramebuffer).vivecraft$blitToScreen(0, dataHolder.vrRenderer.cameraFramebuffer.viewWidth, dataHolder.vrRenderer.cameraFramebuffer.viewHeight, 0, true, 0.0F, 0.0F, false); - mc.getProfiler().pop(); + Profiler.get().pop(); } if (dataHolder.currentPass == RenderPass.THIRD @@ -234,39 +232,32 @@ public static void renderSingleView(RenderPass eye, DeltaTracker.Timer timer, bo public static void renderAndSubmit(boolean renderLevel, DeltaTracker.Timer timer) { // still rendering - mc.getProfiler().push("gameRenderer"); + Profiler.get().push("gameRenderer"); - mc.getProfiler().push("VR guis"); + Profiler.get().push("VR guis"); // some mods mess with the depth mask? RenderSystem.depthMask(true); // some mods mess with the backface culling? RenderSystem.enableCull(); - mc.getProfiler().push("gui cursor"); + Profiler.get().push("gui cursor"); // draw cursor on Gui Layer if (mc.screen != null || !mc.mouseHandler.isMouseGrabbed()) { Matrix4fStack poseStack = RenderSystem.getModelViewStack(); poseStack.pushMatrix(); poseStack.identity(); poseStack.translate(0.0f, 0.0f, -11000.0f); - RenderSystem.applyModelViewMatrix(); int x = (int) (Minecraft.getInstance().mouseHandler.xpos() * (double) Minecraft.getInstance().getWindow().getGuiScaledWidth() / (double) Minecraft.getInstance().getWindow().getScreenWidth()); int y = (int) (Minecraft.getInstance().mouseHandler.ypos() * (double) Minecraft.getInstance().getWindow().getGuiScaledHeight() / (double) Minecraft.getInstance().getWindow().getScreenHeight()); ((GuiExtension) mc.gui).vivecraft$drawMouseMenuQuad(x, y); poseStack.popMatrix(); - RenderSystem.applyModelViewMatrix(); } - mc.getProfiler().popPush("fps pie"); - // draw debug pie - ((MinecraftExtension) mc).vivecraft$drawProfiler(); - // pop pose that we pushed before the gui RenderSystem.getModelViewStack().popMatrix(); - RenderSystem.applyModelViewMatrix(); // generate mipmaps // TODO: does this do anything? @@ -274,29 +265,29 @@ public static void renderAndSubmit(boolean renderLevel, DeltaTracker.Timer timer ((RenderTargetExtension) mc.mainRenderTarget).vivecraft$genMipMaps(); mc.mainRenderTarget.unbindRead(); - mc.getProfiler().popPush("2D Keyboard"); + Profiler.get().popPush("2D Keyboard"); GuiGraphics guiGraphics = new GuiGraphics(mc, mc.renderBuffers().bufferSource()); if (KeyboardHandler.Showing && !dataHolder.vrSettings.physicalKeyboard) { mc.mainRenderTarget = KeyboardHandler.Framebuffer; - mc.mainRenderTarget.clear(Minecraft.ON_OSX); + mc.mainRenderTarget.clear(); mc.mainRenderTarget.bindWrite(true); RenderHelper.drawScreen(timer, KeyboardHandler.UI, guiGraphics); guiGraphics.flush(); } - mc.getProfiler().popPush("Radial Menu"); + Profiler.get().popPush("Radial Menu"); if (RadialHandler.isShowing()) { mc.mainRenderTarget = RadialHandler.Framebuffer; - mc.mainRenderTarget.clear(Minecraft.ON_OSX); + mc.mainRenderTarget.clear(); mc.mainRenderTarget.bindWrite(true); RenderHelper.drawScreen(timer, RadialHandler.UI, guiGraphics); guiGraphics.flush(); } - mc.getProfiler().pop(); + Profiler.get().pop(); checkGLError("post 2d "); // done with guis - mc.getProfiler().pop(); + Profiler.get().pop(); // render the different vr passes List list = dataHolder.vrRenderer.getRenderPasses(); @@ -321,12 +312,12 @@ public static void renderAndSubmit(boolean renderLevel, DeltaTracker.Timer timer case CAMERA -> RenderPassManager.setWorldRenderPass(WorldRenderPass.camera); } - mc.getProfiler().push("Eye:" + dataHolder.currentPass); - mc.getProfiler().push("setup"); + Profiler.get().push("Eye:" + dataHolder.currentPass); + Profiler.get().push("setup"); mc.mainRenderTarget.bindWrite(true); - mc.getProfiler().pop(); + Profiler.get().pop(); VRPassHelper.renderSingleView(renderpass, timer, renderLevel); - mc.getProfiler().pop(); + Profiler.get().pop(); if (dataHolder.grabScreenShot) { boolean flag; @@ -350,7 +341,7 @@ public static void renderAndSubmit(boolean renderLevel, DeltaTracker.Timer timer mc.mainRenderTarget.unbindWrite(); Utils.takeScreenshot(rendertarget); - mc.getWindow().updateDisplay(); + mc.getWindow().updateDisplay(null); dataHolder.grabScreenShot = false; } } @@ -358,17 +349,17 @@ public static void renderAndSubmit(boolean renderLevel, DeltaTracker.Timer timer dataHolder.isFirstPass = false; } // now we are done with rendering - mc.getProfiler().pop(); + Profiler.get().pop(); dataHolder.vrPlayer.postRender(timer.getRealtimeDeltaTicks()); - mc.getProfiler().push("Display/Reproject"); + Profiler.get().push("Display/Reproject"); try { dataHolder.vrRenderer.endFrame(); } catch (RenderConfigException exception) { VRSettings.logger.error(exception.toString()); } - mc.getProfiler().pop(); + Profiler.get().pop(); checkGLError("post submit "); } diff --git a/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRWidgetHelper.java b/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRWidgetHelper.java index 49e0e2271..2d0f51c7b 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRWidgetHelper.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRWidgetHelper.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.vertex.*; import com.mojang.blaze3d.vertex.VertexFormat.Mode; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.CoreShaders; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.block.model.BakedQuad; @@ -82,6 +83,7 @@ public static void renderVRHandheldCameraWidget() { RenderSystem.setShaderTexture(0, dataholder.vrRenderer.cameraFramebuffer.getColorTextureId()); } else { RenderSystem.setShaderTexture(0, ResourceLocation.parse("vivecraft:textures/black.png")); + RenderSystem.bindTexture(RenderSystem.getShaderTexture(0)); } }, (face) -> { @@ -112,7 +114,6 @@ public static void renderVRCameraWidget(float offsetX, float offsetY, float offs } poseStack.translate(offsetX, offsetY, offsetZ); - RenderSystem.applyModelViewMatrix(); BlockPos blockpos = BlockPos.containing(dataholder.vrPlayer.vrdata_world_render.getEye(renderPass).getPosition()); int i = Utils.getCombinedLightWithMin(minecraft.level, blockpos, 0); @@ -121,9 +122,9 @@ public static void renderVRCameraWidget(float offsetX, float offsetY, float offs RenderSystem.defaultBlendFunc(); RenderSystem.setShaderTexture(0, InventoryMenu.BLOCK_ATLAS); if (minecraft.level != null) { - RenderSystem.setShader(GameRenderer::getRendertypeEntityCutoutNoCullShader); + RenderSystem.setShader(CoreShaders.RENDERTYPE_ENTITY_CUTOUT_NO_CULL); } else { - RenderSystem.setShader(GameRenderer::getPositionTexColorShader); + RenderSystem.setShader(CoreShaders.POSITION_TEX_COLOR); } minecraft.gameRenderer.lightTexture().turnOnLightLayer(); @@ -139,7 +140,7 @@ public static void renderVRCameraWidget(float offsetX, float offsetY, float offs RenderSystem.disableBlend(); displayBindFunc.run(); - RenderSystem.setShader(GameRenderer::getRendertypeEntitySolidShader); + RenderSystem.setShader(CoreShaders.RENDERTYPE_ENTITY_SOLID); bufferbuilder = Tesselator.getInstance().begin(Mode.QUADS, DefaultVertexFormat.NEW_ENTITY); @@ -194,7 +195,6 @@ public static void renderVRCameraWidget(float offsetX, float offsetY, float offs minecraft.gameRenderer.lightTexture().turnOffLightLayer(); RenderSystem.enableBlend(); poseStack.popMatrix(); - RenderSystem.applyModelViewMatrix(); } public enum DisplayFace { diff --git a/common/src/main/java/org/vivecraft/client_vr/settings/VRSettings.java b/common/src/main/java/org/vivecraft/client_vr/settings/VRSettings.java index 7ee793898..e78c3c485 100644 --- a/common/src/main/java/org/vivecraft/client_vr/settings/VRSettings.java +++ b/common/src/main/java/org/vivecraft/client_vr/settings/VRSettings.java @@ -320,6 +320,8 @@ public enum UpdateType implements OptionEnum { public float fovReductionMin = 0.25f; @SettingField(value = VrOptions.STENCIL_ON, config = "stencilOn") public boolean vrUseStencil = true; + // TODO 1.21.3 make stencil buffer work + public boolean useStencilBuffer = false; @SettingField public boolean insideBlockSolidColor = false; //unused @SettingField(VrOptions.RENDER_SCALEFACTOR) @@ -1170,8 +1172,8 @@ Object convertOption(String value) { @Override String getDisplayString(String prefix, Object value) { try { - SoundEvent se = BuiltInRegistries.SOUND_EVENT.get(ResourceLocation.parse((String) value)); - return I18n.get(se.getLocation().getPath()); + SoundEvent se = BuiltInRegistries.SOUND_EVENT.get(ResourceLocation.parse((String) value)).get().value(); + return I18n.get(se.location().getPath()); } catch (Exception e) { return "error"; } @@ -1179,12 +1181,12 @@ String getDisplayString(String prefix, Object value) { @Override Object setOptionValue(Object value) { - SoundEvent se = BuiltInRegistries.SOUND_EVENT.get(ResourceLocation.parse((String) value)); + SoundEvent se = BuiltInRegistries.SOUND_EVENT.get(ResourceLocation.parse((String) value)).get().value(); int i = BuiltInRegistries.SOUND_EVENT.getId(se); if (++i >= BuiltInRegistries.SOUND_EVENT.keySet().size()) { i = 0; } - return BuiltInRegistries.SOUND_EVENT.byId(i).getLocation().getPath(); + return BuiltInRegistries.SOUND_EVENT.byId(i).location().getPath(); } }, CROSSHAIR_SCALES_WITH_DISTANCE(false, true), // Crosshair Scaling diff --git a/common/src/main/java/org/vivecraft/client_xr/render_pass/RenderPassManager.java b/common/src/main/java/org/vivecraft/client_xr/render_pass/RenderPassManager.java index cda80a2e9..9c90ca6cb 100644 --- a/common/src/main/java/org/vivecraft/client_xr/render_pass/RenderPassManager.java +++ b/common/src/main/java/org/vivecraft/client_xr/render_pass/RenderPassManager.java @@ -1,8 +1,8 @@ package org.vivecraft.client_xr.render_pass; import com.mojang.blaze3d.pipeline.MainTarget; +import com.mojang.blaze3d.pipeline.RenderTarget; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.PostChain; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.gameplay.screenhandlers.GuiHandler; import org.vivecraft.client_vr.render.RenderPass; @@ -13,9 +13,7 @@ public class RenderPassManager { public static RenderPassManager INSTANCE; public final MainTarget vanillaRenderTarget; - public PostChain vanillaOutlineChain; - public PostChain vanillaPostEffect; - public PostChain vanillaTransparencyChain; + public RenderTarget vanillaOutlineTarget; public static RenderPassType renderPassType = RenderPassType.VANILLA; public static WorldRenderPass wrp; @@ -27,9 +25,6 @@ public static void setWorldRenderPass(WorldRenderPass wrp) { RenderPassManager.wrp = wrp; renderPassType = RenderPassType.WORLD_ONLY; mc.mainRenderTarget = wrp.target; - if (mc.gameRenderer != null) { - mc.gameRenderer.postEffect = wrp.postEffect; - } } public static void setGUIRenderPass() { @@ -44,8 +39,5 @@ public static void setVanillaRenderPass() { RenderPassManager.wrp = null; renderPassType = RenderPassType.VANILLA; mc.mainRenderTarget = INSTANCE.vanillaRenderTarget; - if (mc.gameRenderer != null) { - mc.gameRenderer.postEffect = INSTANCE.vanillaPostEffect; - } } } diff --git a/common/src/main/java/org/vivecraft/client_xr/render_pass/WorldRenderPass.java b/common/src/main/java/org/vivecraft/client_xr/render_pass/WorldRenderPass.java index 452afb117..e7fcb6921 100644 --- a/common/src/main/java/org/vivecraft/client_xr/render_pass/WorldRenderPass.java +++ b/common/src/main/java/org/vivecraft/client_xr/render_pass/WorldRenderPass.java @@ -1,17 +1,11 @@ package org.vivecraft.client_xr.render_pass; import com.mojang.blaze3d.pipeline.RenderTarget; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.PostChain; -import net.minecraft.resources.ResourceLocation; +import com.mojang.blaze3d.pipeline.TextureTarget; import org.vivecraft.client_vr.VRTextureTarget; -import java.io.IOException; - public class WorldRenderPass implements AutoCloseable { - private static final Minecraft mc = Minecraft.getInstance(); - public static WorldRenderPass stereoXR; public static WorldRenderPass center; public static WorldRenderPass mixedReality; @@ -21,43 +15,21 @@ public class WorldRenderPass implements AutoCloseable { public final VRTextureTarget target; - public final PostChain transparencyChain; - public final PostChain outlineChain; - public PostChain postEffect = null; + public final RenderTarget outlineTarget; - public WorldRenderPass(VRTextureTarget target) throws IOException { + public WorldRenderPass(VRTextureTarget target) { this.target = target; - if (Minecraft.useShaderTransparency()) { - this.transparencyChain = createPostChain(ResourceLocation.withDefaultNamespace("shaders/post/vrtransparency.json"), this.target); - } else { - this.transparencyChain = null; - } - this.outlineChain = createPostChain(ResourceLocation.withDefaultNamespace("shaders/post/entity_outline.json"), this.target); - } - - public static PostChain createPostChain(ResourceLocation resourceLocation, RenderTarget target) throws IOException { - PostChain postchain = new PostChain(mc.getTextureManager(), mc.getResourceManager(), target, resourceLocation); - postchain.resize(target.viewWidth, target.viewHeight); - return postchain; + this.outlineTarget = new TextureTarget(this.target.width, this.target.height, true); } public void resize(int width, int height) { - target.resize(width, height, Minecraft.ON_OSX); - outlineChain.resize(width, height); - if (transparencyChain != null) { - transparencyChain.resize(width, height); - } - if (postEffect != null) { - postEffect.resize(width, height); - } + target.resize(width, height); + outlineTarget.resize(width, height); } @Override public void close() { this.target.destroyBuffers(); - if (this.transparencyChain != null) { - this.transparencyChain.close(); - } - this.outlineChain.close(); + this.outlineTarget.destroyBuffers(); } } diff --git a/common/src/main/java/org/vivecraft/mixin/client/blaze3d/RenderTargetMixin.java b/common/src/main/java/org/vivecraft/mixin/client/blaze3d/RenderTargetMixin.java index c1dbd6a69..6e6877489 100644 --- a/common/src/main/java/org/vivecraft/mixin/client/blaze3d/RenderTargetMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client/blaze3d/RenderTargetMixin.java @@ -1,11 +1,13 @@ package org.vivecraft.mixin.client.blaze3d; +import com.mojang.blaze3d.ProjectionType; import com.mojang.blaze3d.pipeline.RenderTarget; import com.mojang.blaze3d.platform.TextureUtil; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.*; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.ShaderInstance; +import net.minecraft.client.renderer.CompiledShaderProgram; +import net.minecraft.client.renderer.ShaderProgram; import org.joml.Matrix4f; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL30; @@ -19,6 +21,8 @@ import org.vivecraft.client_xr.render_pass.RenderPassType; import org.vivecraft.client_vr.render.VRShaders; +import java.util.Objects; + @Mixin(RenderTarget.class) public abstract class RenderTargetMixin implements RenderTargetExtension { @@ -46,7 +50,7 @@ public abstract class RenderTargetMixin implements RenderTargetExtension { protected int colorTextureId; @Shadow - public abstract void clear(boolean onMacIn); + public abstract void clear(); @Override public void vivecraft$setUseStencil(boolean useStencil) { @@ -144,53 +148,51 @@ public String toString() { } @Override - public void vivecraft$blitFovReduction(ShaderInstance instance, int width, int height) { + public void vivecraft$blitFovReduction(ShaderProgram instance, int width, int height) { RenderSystem.assertOnRenderThread(); RenderSystem.colorMask(true, true, true, false); RenderSystem.disableDepthTest(); RenderSystem.depthMask(false); RenderSystem.viewport(0, 0, width, height); RenderSystem.disableBlend(); - Minecraft minecraft = Minecraft.getInstance(); + + CompiledShaderProgram program = Objects.requireNonNull( + RenderSystem.setShader(instance), "Vive blit shader not loaded"); RenderSystem.setShaderTexture(0, this.colorTextureId); - if (instance == null) { - instance = minecraft.gameRenderer.blitShader; - instance.setSampler("DiffuseSampler", this.colorTextureId); - } else { - for (int k = 0; k < RenderSystemAccessor.getShaderTextures().length; ++k) { - int l = RenderSystem.getShaderTexture(k); - instance.setSampler("Sampler" + k, l); - } + + for (int k = 0; k < RenderSystemAccessor.getShaderTextures().length; ++k) { + int l = RenderSystem.getShaderTexture(k); + program.bindSampler("Sampler" + k, l); } Matrix4f matrix4f = new Matrix4f().setOrtho(0, width, height, 0, 1000.0f, 3000.0f); - RenderSystem.setProjectionMatrix(matrix4f, VertexSorting.ORTHOGRAPHIC_Z); - if (instance.MODEL_VIEW_MATRIX != null) { - instance.MODEL_VIEW_MATRIX.set(new Matrix4f().translation(0.0f, 0.0f, -2000.0f)); + RenderSystem.setProjectionMatrix(matrix4f, ProjectionType.ORTHOGRAPHIC); + if (program.MODEL_VIEW_MATRIX != null) { + program.MODEL_VIEW_MATRIX.set(new Matrix4f().translation(0.0f, 0.0f, -2000.0f)); } - if (instance.PROJECTION_MATRIX != null) { - instance.PROJECTION_MATRIX.set(matrix4f); + if (program.PROJECTION_MATRIX != null) { + program.PROJECTION_MATRIX.set(matrix4f); } - instance.apply(); + program.apply(); float f = width; float g = height; float h = (float) this.viewWidth / (float) this.width; float k = (float) this.viewHeight / (float) this.height; - BufferBuilder bufferBuilder = RenderSystem.renderThreadTesselator().begin(VertexFormat.Mode.QUADS, instance.getVertexFormat()); - if (instance.getVertexFormat() == DefaultVertexFormat.POSITION_TEX) { + BufferBuilder bufferBuilder = RenderSystem.renderThreadTesselator().begin(VertexFormat.Mode.QUADS, instance.vertexFormat()); + if (instance.vertexFormat() == DefaultVertexFormat.POSITION_TEX) { bufferBuilder.addVertex(0.0F, g, 0.0F).setUv(0.0F, 0.0F); bufferBuilder.addVertex(f, g, 0.0F).setUv(h, 0.0F); bufferBuilder.addVertex(f, 0.0F, 0.0F).setUv(h, k); bufferBuilder.addVertex(0.0F, 0.0F, 0.0F).setUv(0.0F, k); - } else if (instance.getVertexFormat() == DefaultVertexFormat.POSITION_TEX_COLOR) { + } else if (instance.vertexFormat() == DefaultVertexFormat.POSITION_TEX_COLOR) { bufferBuilder.addVertex(0.0F, g, 0.0F).setUv(0.0F, 0.0F).setColor(255, 255, 255, 255); bufferBuilder.addVertex(f, g, 0.0F).setUv(h, 0.0F).setColor(255, 255, 255, 255); bufferBuilder.addVertex(f, 0.0F, 0.0F).setUv(h, k).setColor(255, 255, 255, 255); bufferBuilder.addVertex(0.0F, 0.0F, 0.0F).setUv(0.0F, k).setColor(255, 255, 255, 255); } else { - throw new IllegalStateException("Unexpected vertex format " + instance.getVertexFormat()); + throw new IllegalStateException("Unexpected vertex format " + instance.vertexFormat()); } BufferUploader.draw(bufferBuilder.buildOrThrow()); - instance.clear(); + program.clear(); RenderSystem.depthMask(true); RenderSystem.colorMask(true, true, true, true); } @@ -231,13 +233,13 @@ public String toString() { } } - - ShaderInstance instance = VRShaders.blitAspectShader; - instance.setSampler("DiffuseSampler", this.colorTextureId); + CompiledShaderProgram instance = Objects.requireNonNull( + RenderSystem.setShader(VRShaders.blitAspectShader), "Vive Blit shader not loaded"); + instance.bindSampler("DiffuseSampler", this.colorTextureId); instance.apply(); - BufferBuilder bufferbuilder = RenderSystem.renderThreadTesselator().begin(VertexFormat.Mode.QUADS, instance.getVertexFormat()); + BufferBuilder bufferbuilder = RenderSystem.renderThreadTesselator().begin(VertexFormat.Mode.QUADS, VRShaders.blitAspectShader.vertexFormat()); bufferbuilder.addVertex(0.0F, 0.0F, 0.0F).setUv(xMin, yMin); bufferbuilder.addVertex(1.0F, 0.0F, 0.0F).setUv(xMax, yMin); bufferbuilder.addVertex(1.0F, 1.0F, 0.0F).setUv(xMax, yMax); diff --git a/common/src/main/java/org/vivecraft/mixin/client/gui/screens/TitleScreenMixin.java b/common/src/main/java/org/vivecraft/mixin/client/gui/screens/TitleScreenMixin.java index d2f48c609..073efa722 100644 --- a/common/src/main/java/org/vivecraft/mixin/client/gui/screens/TitleScreenMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client/gui/screens/TitleScreenMixin.java @@ -12,6 +12,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.vivecraft.client.gui.screens.UpdateScreen; import org.vivecraft.client.utils.UpdateChecker; import org.vivecraft.client_vr.ClientDataHolderVR; @@ -30,12 +31,12 @@ protected TitleScreenMixin(Component component) { private Button vivecraft$updateButton; @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/TitleScreen;addRenderableWidget(Lnet/minecraft/client/gui/components/events/GuiEventListener;)Lnet/minecraft/client/gui/components/events/GuiEventListener;", shift = At.Shift.AFTER, ordinal = 1), method = "createNormalMenuOptions") - public void vivecraft$initFullGame(CallbackInfo ci) { + public void vivecraft$initFullGame(CallbackInfoReturnable cir) { vivecraft$addVRModeButton(); } @Inject(at = @At("TAIL"), method = "createDemoMenuOptions") - public void vivecraft$initDemo(CallbackInfo ci) { + public void vivecraft$initDemo(CallbackInfoReturnable cir) { vivecraft$addVRModeButton(); } diff --git a/common/src/main/java/org/vivecraft/mixin/client/renderer/culling/FrustumVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client/renderer/culling/FrustumVRMixin.java index 27b39fc33..9ceaff2a2 100644 --- a/common/src/main/java/org/vivecraft/mixin/client/renderer/culling/FrustumVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client/renderer/culling/FrustumVRMixin.java @@ -19,9 +19,6 @@ public abstract class FrustumVRMixin implements FrustumExtension { @Shadow private double camZ; - @Shadow - protected abstract boolean cubeInFrustum(double minX, double minY, double minZ, double maxX, double maxY, double maxZ); - @Override @Unique public void vivecraft$setCameraPosition(double var1, double var3, double var5) { @@ -29,10 +26,4 @@ public abstract class FrustumVRMixin implements FrustumExtension { this.camY = var3; this.camZ = var5; } - - @Override - @Unique - public boolean vivecraft$isBoundingBoxInFrustum(AABB var1) { - return this.cubeInFrustum(var1.minX, var1.minY, var1.minZ, var1.maxX, var1.maxY, var1.maxZ); - } } diff --git a/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/EntityRenderDispatcherMixin.java b/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/EntityRenderDispatcherMixin.java index 94387f9b3..f6aa7dd63 100644 --- a/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/EntityRenderDispatcherMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/EntityRenderDispatcherMixin.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.vertex.VertexConsumer; import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.client.renderer.ShapeRenderer; import net.minecraft.client.renderer.entity.EntityRenderDispatcher; import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRendererProvider; @@ -57,15 +58,15 @@ public abstract class EntityRenderDispatcherMixin implements ResourceManagerRelo AABB headBox; if ((headBox = Utils.getEntityHeadHitbox(entity, 0.0)) != null) { // raw head box - LevelRenderer.renderLineBox(poseStack, vertexConsumer, headBox.move(-entity.getX(), -entity.getY(), -entity.getZ()), 1.0f, 1.0f, 0.0f, 1.0f); + ShapeRenderer.renderLineBox(poseStack, vertexConsumer, headBox.move(-entity.getX(), -entity.getY(), -entity.getZ()), 1.0f, 1.0f, 0.0f, 1.0f); // inflated head box for arrows AABB headBoxArrow = Utils.getEntityHeadHitbox(entity, 0.3); - LevelRenderer.renderLineBox(poseStack, vertexConsumer, headBoxArrow.move(-entity.getX(), -entity.getY(), -entity.getZ()), 1.0f, 0.0f, 0.0f, 1.0f); + ShapeRenderer.renderLineBox(poseStack, vertexConsumer, headBoxArrow.move(-entity.getX(), -entity.getY(), -entity.getZ()), 1.0f, 0.0f, 0.0f, 1.0f); } } @Inject(at = @At("HEAD"), method = "getRenderer(Lnet/minecraft/world/entity/Entity;)Lnet/minecraft/client/renderer/entity/EntityRenderer;", cancellable = true) - public void vivecraft$renderer(Entity pEntity, CallbackInfoReturnable> info) { + public void vivecraft$renderer(Entity pEntity, CallbackInfoReturnable info) { if (pEntity instanceof AbstractClientPlayer) { String s = ((AbstractClientPlayer) pEntity).getSkin().model().id(); VRPlayersClient.RotInfo playermodelcontroller$rotinfo = VRPlayersClient.getInstance().getRotationsForPlayer(pEntity.getUUID()); diff --git a/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/EntityRendererMixin.java b/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/EntityRendererMixin.java new file mode 100644 index 000000000..30dafadd6 --- /dev/null +++ b/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/EntityRendererMixin.java @@ -0,0 +1,34 @@ +package org.vivecraft.mixin.client.renderer.entity; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.client.renderer.entity.state.EntityRenderState; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.Vec3; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.vivecraft.client.extensions.EntityRenderStateExtension; +import org.vivecraft.client_vr.render.helpers.RenderHelper; +import org.vivecraft.client_xr.render_pass.RenderPassType; + +@Mixin(EntityRenderer.class) +public class EntityRendererMixin { + @Inject(method = "extractRenderState", at = @At("TAIL")) + private void vivecraft$storeUUID(Entity entity, EntityRenderState entityRenderState, float partialTick, CallbackInfo ci) { + // set the UUID so we can identify what entity is rendered + ((EntityRenderStateExtension)entityRenderState).vivecraft$setEntityUUID(entity.getUUID()); + } + + @WrapOperation(method = "extractRenderState", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;getRopeHoldPosition(F)Lnet/minecraft/world/phys/Vec3;")) + private Vec3 vivecraft$getRopeHoldPosition(Entity instance, float f, Operation original) { + if (!RenderPassType.isVanilla() && instance == Minecraft.getInstance().player) { + return RenderHelper.getControllerRenderPos(0); + } else { + return original.call(instance, f); + } + } +} diff --git a/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/ItemRendererVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/ItemRendererVRMixin.java index 41a3e9d8d..166b4fa7c 100644 --- a/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/ItemRendererVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/ItemRendererVRMixin.java @@ -1,8 +1,8 @@ package org.vivecraft.mixin.client.renderer.entity; -import net.minecraft.client.renderer.ItemModelShaper; import net.minecraft.client.renderer.entity.ItemRenderer; import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.client.resources.model.ModelManager; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import org.spongepowered.asm.mixin.Final; @@ -14,21 +14,23 @@ import org.vivecraft.client_vr.VRState; import org.vivecraft.client_vr.gameplay.trackers.ClimbTracker; import org.vivecraft.client_vr.gameplay.trackers.TelescopeTracker; +import org.vivecraft.client_vr.render.RenderPass; @Mixin(ItemRenderer.class) public class ItemRendererVRMixin { @Shadow @Final - private ItemModelShaper itemModelShaper; + private ModelManager modelManager; @ModifyVariable(at = @At(value = "STORE"), method = "getModel") public BakedModel vivecraft$modelOverride(BakedModel bakedModel, ItemStack itemStack) { - if (VRState.vrRunning && itemStack.is(Items.SPYGLASS)) { - return itemModelShaper.getModelManager().getModel(TelescopeTracker.scopeModel); + // TODO 1.21.3 maybe use item properties? + if (VRState.vrRunning && ClientDataHolderVR.getInstance().currentPass != RenderPass.GUI && itemStack.is(Items.SPYGLASS)) { + return this.modelManager.getModel(TelescopeTracker.scopeModel); } if (ClientDataHolderVR.getInstance().climbTracker.isClaws(itemStack)) { - return itemModelShaper.getModelManager().getModel(ClimbTracker.clawsModel); + return this.modelManager.getModel(ClimbTracker.clawsModel); } return bakedModel; } diff --git a/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/LivingEntityRendererLayerCopyMixin.java b/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/LivingEntityRendererLayerCopyMixin.java new file mode 100644 index 000000000..cc2f958dd --- /dev/null +++ b/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/LivingEntityRendererLayerCopyMixin.java @@ -0,0 +1,151 @@ +package org.vivecraft.mixin.client.renderer.entity; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.model.EntityModel; +import net.minecraft.client.model.HumanoidModel; +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; +import net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer; +import net.minecraft.client.renderer.entity.layers.RenderLayer; +import net.minecraft.client.renderer.entity.player.PlayerRenderer; +import net.minecraft.client.renderer.entity.state.LivingEntityRenderState; +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; +import org.vivecraft.client_vr.settings.VRSettings; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +import static org.vivecraft.client.utils.RenderLayerTypes.LayerType.*; + +/** + * A hacky way of copying regular PlayerRenderer layers to the VRPlayerRenderers + * an alternative would be to add the VRPlayerRenderers to the skin model list, + * 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(LivingEntityRenderer.class) +public abstract class LivingEntityRendererLayerCopyMixin> extends EntityRenderer { + + @Shadow + protected M model; + + protected LivingEntityRendererLayerCopyMixin(EntityRendererProvider.Context context) { + super(context); + } + + @SuppressWarnings("unchecked") + @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 + EntityRenderDispatcherExtension renderExtension = (EntityRenderDispatcherExtension) entityRenderDispatcher; + if ((Object) this.getClass() == PlayerRenderer.class && !renderExtension.vivecraft$getSkinMapVRSeated().isEmpty()) { + + // try to find a suitable constructor, so we can create a new Object without issues + Constructor constructor = null; + RenderLayerTypes.LayerType type = OTHER; + for (Constructor c : renderLayer.getClass().getConstructors()) { + if (c.getParameterCount() == 1 + && RenderLayerParent.class.isAssignableFrom(c.getParameterTypes()[0])) { + constructor = c; + type = PARENT_ONLY; + break; + } else if (c.getParameterCount() == 2 + && RenderLayerParent.class.isAssignableFrom(c.getParameterTypes()[0]) + && EntityModelSet.class.isAssignableFrom(c.getParameterTypes()[1])) { + constructor = c; + type = PARENT_MODELSET; + } else if (c.getParameterCount() == 3 + && RenderLayerParent.class.isAssignableFrom(c.getParameterTypes()[0]) + && HumanoidModel.class.isAssignableFrom(c.getParameterTypes()[1]) + && HumanoidModel.class.isAssignableFrom(c.getParameterTypes()[2]) + && renderLayer instanceof HumanoidArmorLayer) { + constructor = c; + type = PARENT_MODEL_MODEL; + } + } + + // if no suitable constructor was found, use do a basic Object.clone call, and replace the parent of the copy + if (constructor == null) { + // do a hacky clone, and replace parent + if (((PlayerModel) model).slim && + !renderExtension.vivecraft$getSkinMapVRSeated().get("slim").hasLayerType(renderLayer)) { + vivecraft$addLayerClone(renderLayer, (LivingEntityRenderer) renderExtension.vivecraft$getSkinMapVRSeated().get("slim")); + vivecraft$addLayerClone(renderLayer, (LivingEntityRenderer) renderExtension.vivecraft$getSkinMapVR().get("slim")); + } else if (!renderExtension.vivecraft$getSkinMapVRSeated().get("default").hasLayerType(renderLayer)) { + vivecraft$addLayerClone(renderLayer, (LivingEntityRenderer) renderExtension.vivecraft$getSkinMapVRSeated().get("default")); + vivecraft$addLayerClone(renderLayer, (LivingEntityRenderer) renderExtension.vivecraft$getSkinMapVR().get("default")); + } + } else { + // make a new instance with the vr model as parent + if (((PlayerModel) model).slim && + !renderExtension.vivecraft$getSkinMapVRSeated().get("slim").hasLayerType(renderLayer)) { + vivecraft$addLayerConstructor(constructor, type, (LivingEntityRenderer) renderExtension.vivecraft$getSkinMapVRSeated().get("slim")); + vivecraft$addLayerConstructor(constructor, type, (LivingEntityRenderer) renderExtension.vivecraft$getSkinMapVR().get("slim")); + } else if (!renderExtension.vivecraft$getSkinMapVRSeated().get("default").hasLayerType(renderLayer)) { + vivecraft$addLayerConstructor(constructor, type, (LivingEntityRenderer) renderExtension.vivecraft$getSkinMapVRSeated().get("default")); + vivecraft$addLayerConstructor(constructor, type, (LivingEntityRenderer) renderExtension.vivecraft$getSkinMapVR().get("default")); + } + } + } + } + + /** + * does a basic Object.clone() copy + */ + @SuppressWarnings("unchecked") + @Unique + private void vivecraft$addLayerClone(RenderLayer renderLayer, LivingEntityRenderer target) { + try { + VRSettings.logger.warn("Copying layer: {} with Object.copy, this could cause issues", renderLayer.getClass()); + RenderLayer newLayer = (RenderLayer) ((RenderLayerExtension) renderLayer).clone(); + newLayer.renderer = target; + target.addLayer(newLayer); + } catch (CloneNotSupportedException e) { + throw new RuntimeException(e); + } + } + + /** + * uses the provided constructor, to create a new RenderLayer Instance + */ + @SuppressWarnings("unchecked") + @Unique + private void vivecraft$addLayerConstructor(Constructor constructor, RenderLayerTypes.LayerType type, LivingEntityRenderer target) { + try { + switch (type) { + case PARENT_ONLY -> target.addLayer((RenderLayer) constructor.newInstance(target)); + case PARENT_MODELSET -> + target.addLayer((RenderLayer) constructor.newInstance(target, Minecraft.getInstance().getEntityModels())); + case PARENT_MODEL_MODEL -> { + if (((PlayerModel) model).slim) { + target.addLayer((RenderLayer) constructor.newInstance(target, + new HumanoidModel<>(Minecraft.getInstance().getEntityModels().bakeLayer(ModelLayers.PLAYER_SLIM_INNER_ARMOR)), + new HumanoidModel<>(Minecraft.getInstance().getEntityModels().bakeLayer(ModelLayers.PLAYER_SLIM_OUTER_ARMOR)))); + } else { + target.addLayer((RenderLayer) constructor.newInstance(target, + new HumanoidModel<>(Minecraft.getInstance().getEntityModels().bakeLayer(ModelLayers.PLAYER_INNER_ARMOR)), + new HumanoidModel<>(Minecraft.getInstance().getEntityModels().bakeLayer(ModelLayers.PLAYER_OUTER_ARMOR)))); + } + } + } + } catch (InvocationTargetException | InstantiationException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } +} diff --git a/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/LivingEntityRendererMixin.java b/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/LivingEntityRendererMixin.java index e0d679d46..943c422e4 100644 --- a/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/LivingEntityRendererMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/LivingEntityRendererMixin.java @@ -1,150 +1,48 @@ package org.vivecraft.mixin.client.renderer.entity; -import net.minecraft.client.Minecraft; -import net.minecraft.client.model.EntityModel; -import net.minecraft.client.model.HumanoidModel; -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 com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; +import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.renderer.entity.LivingEntityRenderer; -import net.minecraft.client.renderer.entity.RenderLayerParent; -import net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer; -import net.minecraft.client.renderer.entity.layers.RenderLayer; -import net.minecraft.client.renderer.entity.player.PlayerRenderer; +import net.minecraft.client.renderer.entity.state.LivingEntityRenderState; +import net.minecraft.world.entity.HumanoidArm; import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; 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; -import org.vivecraft.client_vr.settings.VRSettings; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.vivecraft.client.VRPlayersClient; +import org.vivecraft.client.extensions.EntityRenderStateExtension; +import org.vivecraft.client.network.ClientNetworking; +import org.vivecraft.client_vr.ClientDataHolderVR; +import org.vivecraft.client_vr.gameplay.trackers.ClimbTracker; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; - -import static org.vivecraft.client.utils.RenderLayerTypes.LayerType.*; - -/** - * A hacky way of copying regular PlayerRenderer layers to the VRPlayerRenderers - * an alternative would be to add the VRPlayerRenderers to the skin model list, - * 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(LivingEntityRenderer.class) -public abstract class LivingEntityRendererMixin> extends EntityRenderer { - - @Shadow - protected M model; - - protected LivingEntityRendererMixin(EntityRendererProvider.Context context) { - super(context); - } - - @SuppressWarnings("unchecked") - @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 - EntityRenderDispatcherExtension renderExtension = (EntityRenderDispatcherExtension) entityRenderDispatcher; - if ((Object) this.getClass() == PlayerRenderer.class && !renderExtension.vivecraft$getSkinMapVRSeated().isEmpty()) { - - // try to find a suitable constructor, so we can create a new Object without issues - Constructor constructor = null; - RenderLayerTypes.LayerType type = OTHER; - for (Constructor c : renderLayer.getClass().getConstructors()) { - if (c.getParameterCount() == 1 - && RenderLayerParent.class.isAssignableFrom(c.getParameterTypes()[0])) { - constructor = c; - type = PARENT_ONLY; - break; - } else if (c.getParameterCount() == 2 - && RenderLayerParent.class.isAssignableFrom(c.getParameterTypes()[0]) - && EntityModelSet.class.isAssignableFrom(c.getParameterTypes()[1])) { - constructor = c; - type = PARENT_MODELSET; - } else if (c.getParameterCount() == 3 - && RenderLayerParent.class.isAssignableFrom(c.getParameterTypes()[0]) - && HumanoidModel.class.isAssignableFrom(c.getParameterTypes()[1]) - && HumanoidModel.class.isAssignableFrom(c.getParameterTypes()[2]) - && renderLayer instanceof HumanoidArmorLayer) { - constructor = c; - type = PARENT_MODEL_MODEL; - } - } - - // if no suitable constructor was found, use do a basic Object.clone call, and replace the parent of the copy - if (constructor == null) { - // do a hacky clone, and replace parent - if (((PlayerModel) model).slim && - !renderExtension.vivecraft$getSkinMapVRSeated().get("slim").hasLayerType(renderLayer)) { - vivecraft$addLayerClone(renderLayer, (LivingEntityRenderer) renderExtension.vivecraft$getSkinMapVRSeated().get("slim")); - vivecraft$addLayerClone(renderLayer, (LivingEntityRenderer) renderExtension.vivecraft$getSkinMapVR().get("slim")); - } else if (!renderExtension.vivecraft$getSkinMapVRSeated().get("default").hasLayerType(renderLayer)) { - vivecraft$addLayerClone(renderLayer, (LivingEntityRenderer) renderExtension.vivecraft$getSkinMapVRSeated().get("default")); - vivecraft$addLayerClone(renderLayer, (LivingEntityRenderer) renderExtension.vivecraft$getSkinMapVR().get("default")); - } - } else { - // make a new instance with the vr model as parent - if (((PlayerModel) model).slim && - !renderExtension.vivecraft$getSkinMapVRSeated().get("slim").hasLayerType(renderLayer)) { - vivecraft$addLayerConstructor(constructor, type, (LivingEntityRenderer) renderExtension.vivecraft$getSkinMapVRSeated().get("slim")); - vivecraft$addLayerConstructor(constructor, type, (LivingEntityRenderer) renderExtension.vivecraft$getSkinMapVR().get("slim")); - } else if (!renderExtension.vivecraft$getSkinMapVRSeated().get("default").hasLayerType(renderLayer)) { - vivecraft$addLayerConstructor(constructor, type, (LivingEntityRenderer) renderExtension.vivecraft$getSkinMapVRSeated().get("default")); - vivecraft$addLayerConstructor(constructor, type, (LivingEntityRenderer) renderExtension.vivecraft$getSkinMapVR().get("default")); - } +public class LivingEntityRendererMixin { + @WrapOperation(method = "extractRenderState(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/client/renderer/entity/state/LivingEntityRenderState;F)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;getItemHeldByArm(Lnet/minecraft/world/entity/HumanoidArm;)Lnet/minecraft/world/item/ItemStack;")) + private ItemStack vivecraft$clawOverride(LivingEntity instance, HumanoidArm humanoidArm, Operation original) { + ItemStack thisStack = original.call(instance, humanoidArm); + + ClimbTracker tracker = ClientDataHolderVR.getInstance().climbTracker; + if (ClientNetworking.serverAllowsClimbey && VRPlayersClient.getInstance().isTracked(instance.getUUID()) && !tracker.isClaws(thisStack)) { + ItemStack otherStack = original.call(instance, humanoidArm.getOpposite()); + if (tracker.isClaws(otherStack) && !VRPlayersClient.getInstance().getRotationsForPlayer(instance.getUUID()).seated) { + return otherStack; } } - } - /** - * does a basic Object.clone() copy - */ - @SuppressWarnings("unchecked") - @Unique - private void vivecraft$addLayerClone(RenderLayer renderLayer, LivingEntityRenderer target) { - try { - VRSettings.logger.warn("Copying layer: {} with Object.copy, this could cause issues", renderLayer.getClass()); - RenderLayer newLayer = (RenderLayer) ((RenderLayerExtension) renderLayer).clone(); - newLayer.renderer = target; - target.addLayer(newLayer); - } catch (CloneNotSupportedException e) { - throw new RuntimeException(e); - } + return thisStack; } - /** - * uses the provided constructor, to create a new RenderLayer Instance - */ - @SuppressWarnings("unchecked") - @Unique - private void vivecraft$addLayerConstructor(Constructor constructor, RenderLayerTypes.LayerType type, LivingEntityRenderer target) { - try { - switch (type) { - case PARENT_ONLY -> target.addLayer((RenderLayer) constructor.newInstance(target)); - case PARENT_MODELSET -> - target.addLayer((RenderLayer) constructor.newInstance(target, Minecraft.getInstance().getEntityModels())); - case PARENT_MODEL_MODEL -> { - if (((PlayerModel) model).slim) { - target.addLayer((RenderLayer) constructor.newInstance(target, - new HumanoidModel<>(Minecraft.getInstance().getEntityModels().bakeLayer(ModelLayers.PLAYER_SLIM_INNER_ARMOR)), - new HumanoidModel<>(Minecraft.getInstance().getEntityModels().bakeLayer(ModelLayers.PLAYER_SLIM_OUTER_ARMOR)))); - } else { - target.addLayer((RenderLayer) constructor.newInstance(target, - new HumanoidModel<>(Minecraft.getInstance().getEntityModels().bakeLayer(ModelLayers.PLAYER_INNER_ARMOR)), - new HumanoidModel<>(Minecraft.getInstance().getEntityModels().bakeLayer(ModelLayers.PLAYER_OUTER_ARMOR)))); - } - } - } - } catch (InvocationTargetException | InstantiationException | IllegalAccessException e) { - throw new RuntimeException(e); + @Inject(method = "render(Lnet/minecraft/client/renderer/entity/state/LivingEntityRenderState;Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;pushPose()V", shift = At.Shift.AFTER)) + private void vivecraft$vrPlayerHeightScale(CallbackInfo ci, @Local(argsOnly = true) LivingEntityRenderState state, @Local(argsOnly = true) PoseStack poseStack) { + // need to do this here, because doing it in the VRPlayerRenderer doesn't work, + // because forge/neoforge override the render method, and arch can't link that correctly + if (VRPlayersClient.getInstance().isTracked(((EntityRenderStateExtension)state).vivecraft$getEntityUUID())) { + VRPlayersClient.RotInfo rotInfo = VRPlayersClient.getInstance().getRotationsForPlayer(((EntityRenderStateExtension)state).vivecraft$getEntityUUID()); + poseStack.scale(rotInfo.heightScale, rotInfo.heightScale, rotInfo.heightScale); } } } diff --git a/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/layers/ItemInHandLayerMixin.java b/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/layers/ItemInHandLayerMixin.java deleted file mode 100644 index 8304f2f18..000000000 --- a/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/layers/ItemInHandLayerMixin.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.vivecraft.mixin.client.renderer.entity.layers; - -import net.minecraft.client.player.LocalPlayer; -import net.minecraft.client.player.RemotePlayer; -import net.minecraft.client.renderer.entity.layers.ItemInHandLayer; -import net.minecraft.world.entity.HumanoidArm; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemDisplayContext; -import net.minecraft.world.item.ItemStack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyVariable; -import org.vivecraft.client.VRPlayersClient; -import org.vivecraft.client.network.ClientNetworking; -import org.vivecraft.client_vr.ClientDataHolderVR; -import org.vivecraft.client_vr.VRState; -import org.vivecraft.client_vr.extensions.PlayerExtension; -import org.vivecraft.client_vr.gameplay.trackers.ClimbTracker; - -@Mixin(ItemInHandLayer.class) -public abstract class ItemInHandLayerMixin { - @ModifyVariable(at = @At("HEAD"), method = "renderArmWithItem", argsOnly = true) - private ItemStack vivecraft$climbClawsOverride(ItemStack itemStack, LivingEntity livingEntity, ItemStack itemStack2, ItemDisplayContext itemDisplayContext, HumanoidArm humanoidArm) { - ClimbTracker tracker = ClientDataHolderVR.getInstance().climbTracker; - if (ClientNetworking.serverAllowsClimbey && livingEntity instanceof Player && !tracker.isClaws(itemStack)) { - ItemStack otherStack = humanoidArm == livingEntity.getMainArm() ? livingEntity.getOffhandItem() : livingEntity.getMainHandItem(); - if (tracker.isClaws(otherStack)) { - if (livingEntity instanceof LocalPlayer player && VRState.vrRunning && tracker.isActive(player) && ((PlayerExtension) player).vivecraft$isClimbeyClimbEquipped()) { - return otherStack; - } else if (livingEntity instanceof RemotePlayer player && VRPlayersClient.getInstance().isVRPlayer(player) && !VRPlayersClient.getInstance().getRotationsForPlayer(player.getUUID()).seated) { - return otherStack; - } - } - } - - return itemStack; - } -} diff --git a/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/layers/RenderLayerMixin.java b/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/layers/RenderLayerMixin.java index 5ffda0873..80e4ccf02 100644 --- a/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/layers/RenderLayerMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/layers/RenderLayerMixin.java @@ -2,7 +2,7 @@ import net.minecraft.client.model.EntityModel; import net.minecraft.client.renderer.entity.layers.RenderLayer; -import net.minecraft.world.entity.Entity; +import net.minecraft.client.renderer.entity.state.EntityRenderState; import org.spongepowered.asm.mixin.Mixin; import org.vivecraft.client.extensions.RenderLayerExtension; @@ -11,7 +11,7 @@ */ @Mixin(RenderLayer.class) -public class RenderLayerMixin> implements Cloneable, RenderLayerExtension { +public class RenderLayerMixin> implements Cloneable, RenderLayerExtension { @Override public Object clone() throws CloneNotSupportedException { return super.clone(); diff --git a/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/state/EntityRenderStateMixin.java b/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/state/EntityRenderStateMixin.java new file mode 100644 index 000000000..087226f87 --- /dev/null +++ b/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/state/EntityRenderStateMixin.java @@ -0,0 +1,25 @@ +package org.vivecraft.mixin.client.renderer.entity.state; + +import net.minecraft.client.renderer.entity.state.EntityRenderState; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.vivecraft.client.extensions.EntityRenderStateExtension; + +import java.util.UUID; + +@Mixin(EntityRenderState.class) +public class EntityRenderStateMixin implements EntityRenderStateExtension { + + @Unique + private UUID vivecraft$uuid; + + @Override + public UUID vivecraft$getEntityUUID() { + return this.vivecraft$uuid; + } + + @Override + public void vivecraft$setEntityUUID(UUID uuid) { + this.vivecraft$uuid = uuid; + } +} diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/KeyboardInputVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/KeyboardInputVRMixin.java index 96d79eeff..ecd335062 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/KeyboardInputVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/KeyboardInputVRMixin.java @@ -2,8 +2,9 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.Options; -import net.minecraft.client.player.Input; +import net.minecraft.client.player.ClientInput; import net.minecraft.client.player.KeyboardInput; +import net.minecraft.world.entity.player.Input; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -22,7 +23,7 @@ import static org.vivecraft.client_vr.provider.openvr_lwjgl.control.VivecraftMovementInput.getMovementAxisValue; @Mixin(KeyboardInput.class) -public class KeyboardInputVRMixin extends Input { +public class KeyboardInputVRMixin extends ClientInput { @Final @Shadow @@ -55,32 +56,36 @@ public class KeyboardInputVRMixin extends Input { ClientDataHolderVR dataholder = ClientDataHolderVR.getInstance(); boolean climbing = dataholder.climbTracker.isClimbeyClimb() && !minecraft.player.isInWater() && dataholder.climbTracker.isGrabbingLadder(); + boolean up, down, left, right, jumping, shiftKeyDown; + boolean sprint = this.options.keySprint.isDown(); + + if (climbing || !this.options.keyUp.isDown() && !VivecraftVRMod.INSTANCE.keyTeleportFallback.isDown()) { - this.up = false; + up = false; } else { ++this.forwardImpulse; - this.up = true; + up = true; } if (!climbing && this.options.keyDown.isDown()) { --this.forwardImpulse; - this.down = true; + down = true; } else { - this.down = false; + down = false; } if (!climbing && this.options.keyLeft.isDown()) { ++this.leftImpulse; - this.left = true; + left = true; } else { - this.left = false; + left = false; } if (!climbing && this.options.keyRight.isDown()) { --this.leftImpulse; - this.right = true; + right = true; } else { - this.right = false; + right = false; } boolean flag1 = false; @@ -139,18 +144,21 @@ public class KeyboardInputVRMixin extends Input { if (flag1) { this.vivecraft$movementSetByAnalog = true; - this.up = this.forwardImpulse > 0.0F; - this.down = this.forwardImpulse < 0.0F; - this.left = this.leftImpulse > 0.0F; - this.right = this.leftImpulse < 0.0F; - VRInputAction.setKeyBindState(this.options.keyUp, this.up); - VRInputAction.setKeyBindState(this.options.keyDown, this.down); - VRInputAction.setKeyBindState(this.options.keyLeft, this.left); - VRInputAction.setKeyBindState(this.options.keyRight, this.right); + up = this.forwardImpulse > 0.0F; + down = this.forwardImpulse < 0.0F; + left = this.leftImpulse > 0.0F; + right = this.leftImpulse < 0.0F; + VRInputAction.setKeyBindState(this.options.keyUp, up); + VRInputAction.setKeyBindState(this.options.keyDown, down); + VRInputAction.setKeyBindState(this.options.keyLeft, left); + VRInputAction.setKeyBindState(this.options.keyRight, right); if (dataholder.vrSettings.autoSprint) { if (f >= dataholder.vrSettings.autoSprintThreshold) { minecraft.player.setSprinting(true); + if (!this.vivecraft$autoSprintActive) { + sprint = true; + } this.vivecraft$autoSprintActive = true; this.forwardImpulse = 1.0F; } else if (this.forwardImpulse > 0.0F && dataholder.vrSettings.analogMovement) { @@ -175,12 +183,14 @@ public class KeyboardInputVRMixin extends Input { } boolean flag2 = minecraft.screen == null && (dataholder.vrPlayer.getFreeMove() || dataholder.vrSettings.simulateFalling) && !climbing; - this.jumping = this.options.keyJump.isDown() && flag2; - this.shiftKeyDown = (dataholder.sneakTracker.sneakCounter > 0 || dataholder.sneakTracker.sneakOverride || this.options.keyShift.isDown()) && minecraft.screen == null; + jumping = this.options.keyJump.isDown() && flag2; + shiftKeyDown = (dataholder.sneakTracker.sneakCounter > 0 || dataholder.sneakTracker.sneakOverride || this.options.keyShift.isDown()) && minecraft.screen == null; if (isSneaking) { this.leftImpulse = (float) ((double) this.leftImpulse * sneakSpeed); this.forwardImpulse = (float) ((double) this.forwardImpulse * sneakSpeed); } + + this.keyPresses = new Input(up, down, left, right, jumping, shiftKeyDown, sprint); } } 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 40d8dadd6..aad11b75f 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 @@ -1,11 +1,11 @@ package org.vivecraft.mixin.client_vr; +import com.mojang.blaze3d.ProjectionType; import com.mojang.blaze3d.pipeline.MainTarget; import com.mojang.blaze3d.pipeline.RenderTarget; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.platform.Window; -import com.mojang.blaze3d.shaders.ProgramManager; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.*; import net.minecraft.ChatFormatting; @@ -18,9 +18,7 @@ import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.client.multiplayer.MultiPlayerGameMode; import net.minecraft.client.player.LocalPlayer; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.client.renderer.LevelRenderer; -import net.minecraft.client.renderer.RenderBuffers; +import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.entity.EntityRenderDispatcher; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.server.IntegratedServer; @@ -30,8 +28,7 @@ import net.minecraft.server.packs.PackResources; import net.minecraft.server.packs.resources.ReloadableResourceManager; import net.minecraft.server.packs.resources.ResourceManagerReloadListener; -import net.minecraft.util.profiling.ProfileResults; -import net.minecraft.util.profiling.ProfilerFiller; +import net.minecraft.util.profiling.Profiler; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.Entity; import net.minecraft.world.item.ItemStack; @@ -39,7 +36,6 @@ import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; import org.joml.Matrix4f; -import org.joml.Matrix4fStack; import org.lwjgl.glfw.GLFW; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Final; @@ -123,9 +119,6 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { @Shadow public Screen screen; - @Shadow - private ProfilerFiller profiler; - @Shadow @Final private Window window; @@ -154,9 +147,6 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { @Shadow public LocalPlayer player; - @Shadow - private ProfileResults fpsPieResults; - @Shadow private int rightClickDelay; @@ -190,9 +180,6 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { @Shadow public abstract Entity getCameraEntity(); - @Shadow - protected abstract void renderFpsMeter(GuiGraphics guiGraphics, ProfileResults profileResults); - @Shadow public abstract void tick(); @@ -214,7 +201,7 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { @Shadow @Final - private DeltaTracker.Timer timer; + private DeltaTracker.Timer deltaTracker; @ModifyArg(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;setOverlay(Lnet/minecraft/client/gui/screens/Overlay;)V"), method = "", index = 0) public Overlay vivecraft$initVivecraft(Overlay overlay) { @@ -302,12 +289,12 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { RenderPassManager.setGUIRenderPass(); // reset camera position, if there is one, since it only gets set at the start of rendering, and the last renderpass can be anywhere if (gameRenderer != null && gameRenderer.getMainCamera() != null && level != null && this.getCameraEntity() != null) { - this.gameRenderer.getMainCamera().setup(this.level, this.getCameraEntity(), false, false, timer.getGameTimeDeltaPartialTick(true)); + this.gameRenderer.getMainCamera().setup(this.level, this.getCameraEntity(), false, false, deltaTracker.getGameTimeDeltaPartialTick(true)); } - this.profiler.push("VR Poll/VSync"); + Profiler.get().push("VR Poll/VSync"); ClientDataHolderVR.getInstance().vr.poll(ClientDataHolderVR.getInstance().frameIndex); - this.profiler.pop(); + Profiler.get().pop(); ClientDataHolderVR.getInstance().vrPlayer.postPoll(); } } @@ -321,9 +308,9 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { if (ClientDataHolderVR.getInstance().menuWorldRenderer != null) { ClientDataHolderVR.getInstance().menuWorldRenderer.checkTask(); if (ClientDataHolderVR.getInstance().menuWorldRenderer.isBuilding()) { - this.profiler.push("Build Menu World"); + Profiler.get().push("Build Menu World"); ClientDataHolderVR.getInstance().menuWorldRenderer.buildNext(); - this.profiler.pop(); + Profiler.get().pop(); } } } @@ -339,10 +326,10 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { @Inject(at = @At(value = "CONSTANT", args = "stringValue=render"), method = "runTick") public void vivecraft$preRender(CallbackInfo ci) { if (VRState.vrRunning) { - this.profiler.push("preRender"); - ClientDataHolderVR.getInstance().vrPlayer.preRender(timer.getGameTimeDeltaPartialTick(true)); + Profiler.get().push("preRender"); + ClientDataHolderVR.getInstance().vrPlayer.preRender(deltaTracker.getGameTimeDeltaPartialTick(true)); VRHotkeys.updateMovingThirdPersonCam(); - this.profiler.pop(); + Profiler.get().pop(); } } @@ -350,7 +337,7 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { public boolean vivecraft$setupRenderGUI(boolean renderLevel) { if (VRState.vrRunning) { - this.profiler.push("setupRenderConfiguration"); + Profiler.get().push("setupRenderConfiguration"); try { this.vivecraft$checkGLError("pre render setup "); ClientDataHolderVR.getInstance().vrRenderer.setupRenderConfiguration(); @@ -359,18 +346,18 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { vivecraft$switchVRState(false); VRState.destroyVR(true); Minecraft.getInstance().setScreen(new ErrorScreen("VR Render Error", renderConfigException.error)); - this.profiler.pop(); + Profiler.get().pop(); return renderLevel; } catch (Exception exception2) { exception2.printStackTrace(); } - this.profiler.pop(); + Profiler.get().pop(); RenderPassManager.setGUIRenderPass(); RenderSystem.depthMask(true); RenderSystem.colorMask(true, true, true, true); RenderSystem.defaultBlendFunc(); - this.mainRenderTarget.clear(Minecraft.ON_OSX); + this.mainRenderTarget.clear(); this.mainRenderTarget.bindWrite(true); // draw screen/gui to buffer @@ -385,17 +372,12 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { } } - @Redirect(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;fpsPieResults:Lnet/minecraft/util/profiling/ProfileResults;"), method = "runTick") - public ProfileResults vivecraft$cancelRegularFpsPie(Minecraft instance) { - return VRState.vrRunning ? null : fpsPieResults; - } - @Redirect(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/pipeline/RenderTarget;blitToScreen(II)V"), method = "runTick") public void vivecraft$blitMirror(RenderTarget instance, int width, int height) { if (!VRState.vrRunning) { instance.blitToScreen(width, height); } else { - this.profiler.popPush("vrMirror"); + Profiler.get().popPush("vrMirror"); this.vivecraft$copyToMirror(); this.vivecraft$drawNotifyMirror(); this.vivecraft$checkGLError("post-mirror "); @@ -414,10 +396,6 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;getMainRenderTarget()Lcom/mojang/blaze3d/pipeline/RenderTarget;"), method = "resizeDisplay") void vivecraft$restoreVanillaState(CallbackInfo ci) { if (VRState.vrInitialized) { - // restore vanilla post chains before the resize, or it will resize the wrong ones - if (levelRenderer != null) { - ((LevelRendererExtension) levelRenderer).vivecraft$restoreVanillaPostChains(); - } if (VRState.vrRunning) { RenderPassManager.setGUIRenderPass(); } else { @@ -549,11 +527,11 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { ClientDataHolderVR.getInstance().menuWorldRenderer.tick(); } - this.profiler.push("vrProcessInputs"); + Profiler.get().push("vrProcessInputs"); ClientDataHolderVR.getInstance().vr.processInputs(); ClientDataHolderVR.getInstance().vr.processBindings(); - this.profiler.popPush("vrInputActionsTick"); + Profiler.get().popPush("vrInputActionsTick"); for (VRInputAction vrinputaction : ClientDataHolderVR.getInstance().vr.getInputActions()) { vrinputaction.tick(); @@ -567,17 +545,17 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { ClientDataHolderVR.getInstance().vrPlayer.updateFreeMove(); } - this.profiler.pop(); + Profiler.get().pop(); } - this.profiler.push("vrPlayers"); + Profiler.get().push("vrPlayers"); VRPlayersClient.getInstance().tick(); - this.profiler.popPush("Vivecraft Keybindings"); + Profiler.get().popPush("Vivecraft Keybindings"); vivecraft$processAlwaysAvailableKeybindings(); - this.profiler.pop(); + Profiler.get().pop(); } @Unique @@ -748,20 +726,19 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { RenderSystem.viewport(0, 0, screenX, screenY); Matrix4f matrix4f = new Matrix4f().setOrtho(0.0F, (float) screenX, screenY, 0.0F, 1000.0F, 3000.0F); - RenderSystem.setProjectionMatrix(matrix4f, VertexSorting.ORTHOGRAPHIC_Z); + RenderSystem.setProjectionMatrix(matrix4f, ProjectionType.ORTHOGRAPHIC); RenderSystem.getModelViewStack().pushMatrix(); RenderSystem.getModelViewStack().identity(); RenderSystem.getModelViewStack().translate(0, 0, -2000); - RenderSystem.applyModelViewMatrix(); - RenderSystem.setShaderFogStart(Float.MAX_VALUE); + RenderSystem.setShaderFog(FogParameters.NO_FOG); GuiGraphics guiGraphics = new GuiGraphics((Minecraft) (Object) this, renderBuffers.bufferSource()); guiGraphics.pose().scale(3, 3, 3); - RenderSystem.clear(256, ON_OSX); + RenderSystem.clear(256); if (this.vivecraft$mirrorNotifyClear) { RenderSystem.clearColor(0, 0, 0, 0); - RenderSystem.clear(16384, ON_OSX); + RenderSystem.clear(16384); } int i = this.window.getScreenWidth() / 22; @@ -826,18 +803,6 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { window.updateVsync(options.enableVsync().get()); } - @Unique - @Override - public void vivecraft$drawProfiler() { - if (this.fpsPieResults != null) { - this.profiler.push("fpsPie"); - GuiGraphics guiGraphics = new GuiGraphics((Minecraft) (Object) this, renderBuffers.bufferSource()); - this.renderFpsMeter(guiGraphics, this.fpsPieResults); - guiGraphics.flush(); - this.profiler.pop(); - } - } - @Unique private void vivecraft$checkGLError(String string) { // TODO optifine @@ -954,8 +919,10 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { RenderSystem.setShaderTexture(0, ClientDataHolderVR.getInstance().vrRenderer.framebufferMR.getColorTextureId()); RenderSystem.setShaderTexture(1, ClientDataHolderVR.getInstance().vrRenderer.framebufferMR.getDepthTextureId()); - VRShaders.depthMaskShader.setSampler("thirdPersonColor", RenderSystem.getShaderTexture(0)); - VRShaders.depthMaskShader.setSampler("thirdPersonDepth", RenderSystem.getShaderTexture(1)); + CompiledShaderProgram depthMaskShader = RenderSystem.setShader(VRShaders.depthMaskShader); + + depthMaskShader.bindSampler("thirdPersonColor", RenderSystem.getShaderTexture(0)); + depthMaskShader.bindSampler("thirdPersonDepth", RenderSystem.getShaderTexture(1)); if (ClientDataHolderVR.getInstance().vrSettings.mixedRealityUnityLike) { if (ClientDataHolderVR.getInstance().vrSettings.displayMirrorUseScreenshotCamera && ClientDataHolderVR.getInstance().cameraTracker.isVisible()) { @@ -973,19 +940,17 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { ClientDataHolderVR.getInstance().vrRenderer.framebufferEye1.getColorTextureId()); } } - VRShaders.depthMaskShader.setSampler("firstPersonColor", RenderSystem.getShaderTexture(2)); + depthMaskShader.bindSampler("firstPersonColor", RenderSystem.getShaderTexture(2)); } - VRShaders.depthMaskShader.apply(); + depthMaskShader.apply(); - BufferBuilder bufferbuilder = RenderSystem.renderThreadTesselator().begin(VertexFormat.Mode.QUADS, VRShaders.depthMaskShader.getVertexFormat()); + BufferBuilder bufferbuilder = RenderSystem.renderThreadTesselator().begin(VertexFormat.Mode.QUADS, VRShaders.depthMaskShader.vertexFormat()); bufferbuilder.addVertex(-1, -1, 0).setUv(0, 0); bufferbuilder.addVertex(1, -1, 0).setUv(2, 0); bufferbuilder.addVertex(1, 1, 0).setUv(2, 2); bufferbuilder.addVertex(-1, 1, 0).setUv(0, 2); BufferUploader.draw(bufferbuilder.buildOrThrow()); - VRShaders.depthMaskShader.clear(); - - ProgramManager.glUseProgram(0); + depthMaskShader.clear(); } } diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/gui/GuiComponentVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/gui/GuiComponentVRMixin.java deleted file mode 100644 index 8077d7d76..000000000 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/gui/GuiComponentVRMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.vivecraft.mixin.client_vr.gui; - -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.systems.RenderSystem; -import net.minecraft.client.gui.GuiGraphics; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.vivecraft.client_vr.VRState; - -@Mixin(GuiGraphics.class) -public class GuiComponentVRMixin { - - @Inject(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;setShader(Ljava/util/function/Supplier;)V", remap = false, shift = At.Shift.AFTER), method = "innerBlit(Lnet/minecraft/resources/ResourceLocation;IIIIIFFFFFFFF)V") - private void vivecraft$addBlend(CallbackInfo ci) { - if (VRState.vrRunning) { - RenderSystem.enableBlend(); - // only change the alpha blending - RenderSystem.blendFuncSeparate(GlStateManager.BLEND.srcRgb, GlStateManager.BLEND.dstRgb, GlStateManager.SourceFactor.ONE.value, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA.value); - } - } - - @Inject(at = @At("TAIL"), method = "innerBlit(Lnet/minecraft/resources/ResourceLocation;IIIIIFFFFFFFF)V") - private void vivecraft$stopBlend(CallbackInfo ci) { - if (VRState.vrRunning) { - RenderSystem.disableBlend(); - } - } -} diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/gui/GuiVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/gui/GuiVRMixin.java index 945193f28..2cbd08941 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/gui/GuiVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/gui/GuiVRMixin.java @@ -8,10 +8,13 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.renderer.CoreShaders; import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.Holder; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.ARGB; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.Entity; @@ -29,6 +32,7 @@ import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.VRState; import org.vivecraft.client_vr.extensions.GuiExtension; +import org.vivecraft.client_vr.render.RenderPass; import org.vivecraft.client_xr.render_pass.RenderPassType; @Mixin(Gui.class) @@ -94,17 +98,24 @@ public abstract class GuiVRMixin implements GuiExtension { } } + @Inject(at = @At("HEAD"), method = "renderConfusionOverlay", cancellable = true) + private void vivecraft$noConfusionOverlayOnGUI(CallbackInfo ci) { + if (RenderPassType.isGuiOnly()) { + ci.cancel(); + } + } + @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/KeyMapping;isDown()Z"), method = "renderTabList") public boolean vivecraft$toggleableTabList(KeyMapping instance) { return instance.isDown() || vivecraft$showPlayerList; } - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 1, shift = At.Shift.AFTER), method = "renderItemHotbar") + @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Ljava/util/function/Function;Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 1, shift = At.Shift.AFTER), method = "renderItemHotbar") public void vivecraft$hotbarContext(GuiGraphics guiGraphics, DeltaTracker deltaTracker, CallbackInfo ci) { if (VRState.vrRunning && ClientDataHolderVR.getInstance().interactTracker.hotbar >= 0 && ClientDataHolderVR.getInstance().interactTracker.hotbar < 9 && this.getCameraPlayer().getInventory().selected != ClientDataHolderVR.getInstance().interactTracker.hotbar && ClientDataHolderVR.getInstance().interactTracker.isActive(minecraft.player)) { int i = guiGraphics.guiWidth() / 2; RenderSystem.setShaderColor(0.0F, 1.0F, 0.0F, 1.0F); - guiGraphics.blitSprite(HOTBAR_SELECTION_SPRITE, i - 91 - 1 + ClientDataHolderVR.getInstance().interactTracker.hotbar * 20, guiGraphics.guiHeight() - 22 - 1, 24, 23); + guiGraphics.blitSprite(RenderType::guiTextured, HOTBAR_SELECTION_SPRITE, i - 91 - 1 + ClientDataHolderVR.getInstance().interactTracker.hotbar * 20, guiGraphics.guiHeight() - 22 - 1, 24, 23); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); } } @@ -121,35 +132,35 @@ public abstract class GuiVRMixin implements GuiExtension { } } - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 2, shift = At.Shift.BEFORE), method = "renderItemHotbar") + @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Ljava/util/function/Function;Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 2, shift = At.Shift.BEFORE), method = "renderItemHotbar") public void vivecraft$renderVRHotbarLeft(CallbackInfo ci) { if (VRState.vrRunning && ClientDataHolderVR.getInstance().interactTracker.hotbar == 9 && ClientDataHolderVR.getInstance().interactTracker.isActive(minecraft.player)) { RenderSystem.setShaderColor(0.0F, 0.0F, 1.0F, 1.0F); } } - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 2, shift = At.Shift.AFTER), method = "renderItemHotbar") + @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Ljava/util/function/Function;Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 2, shift = At.Shift.AFTER), method = "renderItemHotbar") public void vivecraft$renderVRHotbarLeftReset(CallbackInfo ci) { if (VRState.vrRunning && ClientDataHolderVR.getInstance().interactTracker.hotbar == 9) { RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); } } - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 3, shift = At.Shift.BEFORE), method = "renderItemHotbar") + @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Ljava/util/function/Function;Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 3, shift = At.Shift.BEFORE), method = "renderItemHotbar") public void vivecraft$renderVRHotbarRight(CallbackInfo ci) { if (VRState.vrRunning && ClientDataHolderVR.getInstance().interactTracker.hotbar == 9 && ClientDataHolderVR.getInstance().interactTracker.isActive(minecraft.player)) { RenderSystem.setShaderColor(0.0F, 0.0F, 1.0F, 1.0F); } } - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 3, shift = At.Shift.AFTER), method = "renderItemHotbar") + @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Ljava/util/function/Function;Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 3, shift = At.Shift.AFTER), method = "renderItemHotbar") public void vivecraft$renderVRHotbarRightReset(CallbackInfo ci) { if (VRState.vrRunning && ClientDataHolderVR.getInstance().interactTracker.hotbar == 9) { RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); } } - @Inject(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;disableBlend()V", remap = false), method = "renderItemHotbar") + @Inject(at = @At("TAIL"), method = "renderItemHotbar") public void vivecraft$renderVive(GuiGraphics guiGraphics, DeltaTracker deltaTracker, CallbackInfo ci) { if (VRState.vrRunning) { this.vivecraft$renderViveHudIcons(guiGraphics); @@ -199,7 +210,7 @@ public abstract class GuiVRMixin implements GuiExtension { if (mobeffect != null) { TextureAtlasSprite textureatlassprite = this.minecraft.getMobEffectTextures().get(mobeffect); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - guiGraphics.blit(x, y, 0, 18, 18, textureatlassprite); + guiGraphics.blitSprite(RenderType::guiTextured, textureatlassprite, x, y, 18, 18); } } } @@ -222,7 +233,7 @@ public abstract class GuiVRMixin implements GuiExtension { RenderSystem.enableBlend(); RenderSystem.disableDepthTest(); //uhhhh //RenderSystem.disableLighting(); - RenderSystem.setShader(GameRenderer::getPositionTexShader); + RenderSystem.setShader(CoreShaders.POSITION_TEX); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); TextureAtlasSprite crosshairSprite = minecraft.getGuiSprites().getSprite(CROSSHAIR_SPRITE); RenderSystem.setShaderTexture(0, crosshairSprite.atlasLocation()); diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/gui/TutorialToastVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/gui/TutorialToastVRMixin.java index 2dadcd811..bf3cf9386 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/gui/TutorialToastVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/gui/TutorialToastVRMixin.java @@ -1,8 +1,8 @@ package org.vivecraft.mixin.client_vr.gui; +import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.toasts.Toast; -import net.minecraft.client.gui.components.toasts.ToastComponent; import net.minecraft.client.gui.components.toasts.TutorialToast; import net.minecraft.network.chat.Component; import org.spongepowered.asm.mixin.Final; @@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(TutorialToast.class) public abstract class TutorialToastVRMixin implements Toast { @@ -29,19 +29,19 @@ public abstract class TutorialToastVRMixin implements Toast { private int vivecraft$offset; @Inject(at = @At("HEAD"), method = "render") - private void vivecraft$extendToast(GuiGraphics guiGraphics, ToastComponent toastComponent, long l, CallbackInfoReturnable cir) { - int width = Math.max(toastComponent.getMinecraft().font.width(this.title), message != null ? toastComponent.getMinecraft().font.width(this.message) : 0) + 34; + private void vivecraft$extendToast(GuiGraphics guiGraphics, Font font, long l, CallbackInfo ci) { + int width = Math.max(font.width(this.title), message != null ? font.width(this.message) : 0) + 34; vivecraft$offset = Math.min(this.width() - width, 0); } // change toast size // the texture gets stretched, but there seems to be no way to cut it in pieces, so that is probably the best option - @ModifyArg(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V"), method = "render", index = 1) + @ModifyArg(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Ljava/util/function/Function;Lnet/minecraft/resources/ResourceLocation;IIII)V"), method = "render", index = 2) private int vivecraft$offsetToast(int x) { return x + vivecraft$offset; } - @ModifyArg(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V"), method = "render", index = 3) + @ModifyArg(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Ljava/util/function/Function;Lnet/minecraft/resources/ResourceLocation;IIII)V"), method = "render", index = 4) private int vivecraft$changeToastWidth(int width) { return width - vivecraft$offset; } diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/gui/screens/inventory/CreativeModeInventoryScreenVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/gui/screens/inventory/CreativeModeInventoryScreenVRMixin.java index 8c27ad963..9d8ade020 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/gui/screens/inventory/CreativeModeInventoryScreenVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/gui/screens/inventory/CreativeModeInventoryScreenVRMixin.java @@ -1,8 +1,8 @@ package org.vivecraft.mixin.client_vr.gui.screens.inventory; import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen; -import net.minecraft.client.gui.screens.inventory.EffectRenderingInventoryScreen; import net.minecraft.core.NonNullList; import net.minecraft.core.component.DataComponents; import net.minecraft.core.registries.BuiltInRegistries; @@ -24,7 +24,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(CreativeModeInventoryScreen.class) -public abstract class CreativeModeInventoryScreenVRMixin extends EffectRenderingInventoryScreen { +public abstract class CreativeModeInventoryScreenVRMixin extends AbstractContainerScreen { @Shadow private EditBox searchBox; @@ -51,7 +51,7 @@ public CreativeModeInventoryScreenVRMixin(CreativeModeInventoryScreen.ItemPicker @Unique private void vivecraft$addCreativeItems(CreativeModeTab tab, NonNullList list) { - if (tab == BuiltInRegistries.CREATIVE_MODE_TAB.get(CreativeModeTabs.FOOD_AND_DRINKS) || tab == null) { + if (tab == BuiltInRegistries.CREATIVE_MODE_TAB.getValueOrThrow(CreativeModeTabs.FOOD_AND_DRINKS) || tab == null) { ItemStack pie = new ItemStack(Items.PUMPKIN_PIE); pie.set(DataComponents.CUSTOM_NAME, Component.literal("EAT ME")); @@ -62,7 +62,7 @@ public CreativeModeInventoryScreenVRMixin(CreativeModeInventoryScreen.ItemPicker list.add(drink); } - if (tab == BuiltInRegistries.CREATIVE_MODE_TAB.get(CreativeModeTabs.TOOLS_AND_UTILITIES) || tab == null) { + if (tab == BuiltInRegistries.CREATIVE_MODE_TAB.getValueOrThrow(CreativeModeTabs.TOOLS_AND_UTILITIES) || tab == null) { ItemStack boots = new ItemStack(Items.LEATHER_BOOTS); boots.set(DataComponents.CUSTOM_NAME, Component.translatableWithFallback("vivecraft.item.jumpboots", "Jump Boots")); boots.set(DataComponents.UNBREAKABLE, new Unbreakable(false)); diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/multiplayer/ClientPacketListenerVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/multiplayer/ClientPacketListenerVRMixin.java index 373314afa..5b2cc7c49 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/multiplayer/ClientPacketListenerVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/multiplayer/ClientPacketListenerVRMixin.java @@ -5,6 +5,7 @@ import net.minecraft.client.multiplayer.ClientCommonPacketListenerImpl; import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.client.multiplayer.CommonListenerCookie; +import net.minecraft.core.Holder; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.Connection; import net.minecraft.network.FriendlyByteBuf; @@ -12,6 +13,7 @@ import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.network.protocol.game.*; import net.minecraft.resources.ResourceLocation; +import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundSource; import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; @@ -28,6 +30,8 @@ import org.vivecraft.client_vr.settings.VRSettings; import org.vivecraft.common.network.packets.VivecraftDataPacket; +import java.util.Optional; + @Mixin(ClientPacketListener.class) public abstract class ClientPacketListenerVRMixin extends ClientCommonPacketListenerImpl { @@ -124,7 +128,8 @@ protected ClientPacketListenerVRMixin(Minecraft minecraft, Connection connection if (dataholder.vrSettings.chatNotifications == VRSettings.ChatNotifications.SOUND || dataholder.vrSettings.chatNotifications == VRSettings.ChatNotifications.BOTH) { Vec3 vec3 = dataholder.vrPlayer.vrdata_world_pre.getController(1).getPosition(); - minecraft.level.playLocalSound(vec3.x(), vec3.y(), vec3.z(), BuiltInRegistries.SOUND_EVENT.get(ResourceLocation.parse(dataholder.vrSettings.chatNotificationSound)), SoundSource.NEUTRAL, 0.3F, 0.1F, false); + BuiltInRegistries.SOUND_EVENT.get(ResourceLocation.parse(dataholder.vrSettings.chatNotificationSound)) + .ifPresent(soundEvent -> minecraft.level.playLocalSound(vec3.x(), vec3.y(), vec3.z(), soundEvent.value(), SoundSource.NEUTRAL, 0.3F, 0.1F, false)); } } } diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/player/LocalPlayerVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/player/LocalPlayerVRMixin.java index 6f5b0a1eb..248b8787b 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/player/LocalPlayerVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/player/LocalPlayerVRMixin.java @@ -118,7 +118,7 @@ public LocalPlayerVRMixin(ClientLevel clientLevel, GameProfile gameProfile) { } } - @ModifyVariable(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;isPassenger()Z"), ordinal = 2, method = "sendPosition") + @ModifyVariable(at = @At(value = "STORE"), ordinal = 1, method = "sendPosition") private boolean vivecraft$directTeleport(boolean updateRotation) { if (this.vivecraft$teleported) { updateRotation = true; @@ -135,7 +135,7 @@ public LocalPlayerVRMixin(ClientLevel clientLevel, GameProfile gameProfile) { } // needed, or the server will spam 'moved too quickly'/'moved wrongly' - @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/ClientPacketListener;send(Lnet/minecraft/network/protocol/Packet;)V"), method = "sendPosition", slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;isPassenger()Z"))) + @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/ClientPacketListener;send(Lnet/minecraft/network/protocol/Packet;)V"), method = "sendPosition") public void vivecraft$noMovePacketsOnTeleport(ClientPacketListener instance, Packet packet) { if (!this.vivecraft$teleported) { instance.send(packet); @@ -257,15 +257,6 @@ public LocalPlayerVRMixin(ClientLevel clientLevel, GameProfile gameProfile) { return VRState.vrRunning ? ClientDataHolderVR.getInstance().vrPlayer.vrdata_world_pre.getBodyYaw() * ((float) Math.PI / 180) : original; } - @Override - public ItemStack eat(Level level, ItemStack itemStack) { - if (VRState.vrRunning && itemStack.get(DataComponents.FOOD) != null && (Object) this == Minecraft.getInstance().player && itemStack.getHoverName().getString().equals("EAT ME")) { - ClientDataHolderVR.getInstance().vrPlayer.wfMode = 0.5D; - ClientDataHolderVR.getInstance().vrPlayer.wfCount = 400; - } - return super.eat(level, itemStack); - } - @Override public void moveTo(double pX, double p_20109_, double pY, float p_20111_, float pZ) { super.moveTo(pX, p_20109_, pY, p_20111_, pZ); diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/ShaderInstanceVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/CompiledShaderProgramVRMixin.java similarity index 77% rename from common/src/main/java/org/vivecraft/mixin/client_vr/renderer/ShaderInstanceVRMixin.java rename to common/src/main/java/org/vivecraft/mixin/client_vr/renderer/CompiledShaderProgramVRMixin.java index 00e07bdc5..03d2b347c 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/ShaderInstanceVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/CompiledShaderProgramVRMixin.java @@ -1,13 +1,13 @@ package org.vivecraft.mixin.client_vr.renderer; -import net.minecraft.client.renderer.ShaderInstance; +import net.minecraft.client.renderer.CompiledShaderProgram; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.Constant; import org.spongepowered.asm.mixin.injection.ModifyConstant; import org.vivecraft.mixin.client.blaze3d.RenderSystemAccessor; -@Mixin(ShaderInstance.class) -public class ShaderInstanceVRMixin { +@Mixin(CompiledShaderProgram.class) +public class CompiledShaderProgramVRMixin { @ModifyConstant(method = "setDefaultUniforms", constant = @Constant(intValue = 12)) public int vivecraft$moreTextures(int constant) { 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 3464bb4b5..8859903b9 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 @@ -3,6 +3,7 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.mojang.blaze3d.ProjectionType; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; @@ -15,10 +16,10 @@ import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.core.BlockPos; -import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.ResourceManagerReloadListener; import net.minecraft.tags.FluidTags; import net.minecraft.util.Mth; +import net.minecraft.util.profiling.Profiler; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.HitResult; @@ -50,12 +51,9 @@ import org.vivecraft.client_vr.render.helpers.VRArmHelper; import org.vivecraft.client_vr.render.helpers.VREffectsHelper; import org.vivecraft.client_vr.settings.VRSettings; -import org.vivecraft.client_xr.render_pass.RenderPassManager; import org.vivecraft.client_xr.render_pass.RenderPassType; -import org.vivecraft.client_xr.render_pass.WorldRenderPass; import org.vivecraft.mod_compat_vr.immersiveportals.ImmersivePortalsHelper; -import java.io.IOException; import java.nio.file.Path; @Mixin(GameRenderer.class) @@ -127,21 +125,18 @@ public abstract class GameRendererVRMixin @Shadow private float zoomY; @Shadow - private float fov; + private float fovModifier; @Shadow - private float oldFov; + private float oldFovModifier; @Shadow private boolean renderHand; @Shadow - public abstract Matrix4f getProjectionMatrix(double fov); + public abstract Matrix4f getProjectionMatrix(float fov); @Shadow - protected abstract double getFov(Camera mainCamera2, float partialTicks, boolean b); - - @Shadow - public abstract void resetProjectionMatrix(Matrix4f projectionMatrix); + protected abstract float getFov(Camera mainCamera2, float partialTicks, boolean b); @Shadow public abstract void renderItemActivationAnimation(GuiGraphics guiGraphics, float f); @@ -175,33 +170,6 @@ public abstract class GameRendererVRMixin return ClientDataHolderVR.getInstance().vrPlayer.vrdata_world_render == null ? null : instance.level; } - @Inject(at = @At("HEAD"), method = {"shutdownEffect", "checkEntityPostEffect", "loadEffect"}) - public void vivecraft$shutdownEffect(CallbackInfo ci) { - if (VRState.vrInitialized) { - RenderPassManager.setVanillaRenderPass(); - if (WorldRenderPass.stereoXR != null && WorldRenderPass.stereoXR.postEffect != null) { - WorldRenderPass.stereoXR.postEffect.close(); - WorldRenderPass.stereoXR.postEffect = null; - } - if (WorldRenderPass.center != null && WorldRenderPass.center.postEffect != null) { - WorldRenderPass.center.postEffect.close(); - WorldRenderPass.center.postEffect = null; - } - } - } - - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/PostChain;resize(II)V", shift = Shift.AFTER), method = "loadEffect") - public void vivecraft$loadEffect(ResourceLocation resourceLocation, CallbackInfo ci) throws IOException { - if (VRState.vrInitialized) { - if (WorldRenderPass.stereoXR != null) { - WorldRenderPass.stereoXR.postEffect = WorldRenderPass.createPostChain(resourceLocation, WorldRenderPass.stereoXR.target); - } - if (WorldRenderPass.center != null) { - WorldRenderPass.center.postEffect = WorldRenderPass.createPostChain(resourceLocation, WorldRenderPass.center.target); - } - } - } - @ModifyVariable(at = @At("STORE"), method = "pick(Lnet/minecraft/world/entity/Entity;DDF)Lnet/minecraft/world/phys/HitResult;", ordinal = 0) public Vec3 vivecraft$rayTrace(Vec3 original) { if (!VRState.vrRunning) { @@ -233,20 +201,20 @@ public abstract class GameRendererVRMixin @Inject(at = @At("HEAD"), method = "tickFov", cancellable = true) public void vivecraft$noFOVchangeInVR(CallbackInfo ci) { if (!RenderPassType.isVanilla()) { - this.oldFov = this.fov = 1.0f; + this.oldFovModifier = this.fovModifier = 1.0f; ci.cancel(); } } - @Inject(at = @At("HEAD"), method = "getFov(Lnet/minecraft/client/Camera;FZ)D", cancellable = true) - public void vivecraft$fov(Camera camera, float f, boolean bl, CallbackInfoReturnable info) { + @Inject(at = @At("HEAD"), method = "getFov(Lnet/minecraft/client/Camera;FZ)F", cancellable = true) + public void vivecraft$fov(Camera camera, float f, boolean bl, CallbackInfoReturnable info) { if (this.minecraft.level == null || MethodHolder.isInMenuRoom()) { // Vivecraft: using this on the main menu - info.setReturnValue(Double.valueOf(this.minecraft.options.fov().get())); + info.setReturnValue(Float.valueOf(this.minecraft.options.fov().get())); } } - @Inject(at = @At("HEAD"), method = "getProjectionMatrix(D)Lorg/joml/Matrix4f;", cancellable = true) - public void vivecraft$projection(double d, CallbackInfoReturnable info) { + @Inject(at = @At("HEAD"), method = "getProjectionMatrix(F)Lorg/joml/Matrix4f;", cancellable = true) + public void vivecraft$projection(float d, CallbackInfoReturnable info) { if (!VRState.vrRunning) { return; } @@ -310,13 +278,6 @@ public abstract class GameRendererVRMixin } } - @Inject(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;viewport(IIII)V", remap = false, shift = Shift.AFTER), method = "render(Lnet/minecraft/client/DeltaTracker;Z)V") - public void vivecraft$matrix(DeltaTracker deltaTracker, boolean bl, CallbackInfo ci) { - this.resetProjectionMatrix(this.getProjectionMatrix(minecraft.options.fov().get())); - RenderSystem.getModelViewStack().identity(); - RenderSystem.applyModelViewMatrix(); - } - @Inject(at = @At("HEAD"), method = "shouldRenderBlockOutline", cancellable = true) public void vivecraft$shouldDrawBlockOutline(CallbackInfoReturnable cir) { if (VRState.vrRunning) { @@ -379,7 +340,7 @@ public abstract class GameRendererVRMixin if (vivecraft$shouldDrawGui) { // when the gui is rendered it is expected that something got pushed to the profiler before // so do that now - this.minecraft.getProfiler().push("vanillaGuiSetup"); + Profiler.get().push("vanillaGuiSetup"); } return; } @@ -387,16 +348,15 @@ public abstract class GameRendererVRMixin float partialTicks = deltaTracker.getGameTimeDeltaPartialTick(false); if (!renderWorldIn || this.minecraft.level == null) { // no "level" got pushed so do a manual push - this.minecraft.getProfiler().push("MainMenu"); + Profiler.get().push("MainMenu"); } else { // do a popPush - this.minecraft.getProfiler().popPush("MainMenu"); + Profiler.get().popPush("MainMenu"); } GL11.glDisable(GL11.GL_STENCIL_TEST); RenderSystem.getModelViewStack().pushMatrix().identity(); RenderHelper.applyVRModelView(vivecraft$DATA_HOLDER.currentPass, RenderSystem.getModelViewStack()); - RenderSystem.applyModelViewMatrix(); VREffectsHelper.renderGuiLayer(partialTicks, true); @@ -415,10 +375,9 @@ public abstract class GameRendererVRMixin VRArmHelper.renderVRHands(partialTicks, true, true, true, true); } RenderSystem.getModelViewStack().popMatrix(); - RenderSystem.applyModelViewMatrix(); } // pop the "level" push, since that would happen after this - this.minecraft.getProfiler().pop(); + Profiler.get().pop(); info.cancel(); } @@ -444,13 +403,6 @@ public abstract class GameRendererVRMixin } } - @Inject(at = @At("HEAD"), method = "renderConfusionOverlay", cancellable = true) - private void vivecraft$noConfusionOverlayOnGUI(GuiGraphics guiGraphics, float f, CallbackInfo ci) { - if (vivecraft$DATA_HOLDER.currentPass == RenderPass.GUI) { - ci.cancel(); - } - } - @Redirect(method = "renderItemActivationAnimation", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;translate(FFF)V")) private void vivecraft$noTranslateItem(PoseStack poseStack, float x, float y, float z) { if (RenderPassType.isVanilla()) { @@ -757,6 +709,6 @@ public abstract class GameRendererVRMixin @Override @Unique public void vivecraft$resetProjectionMatrix(float partialTicks) { - this.resetProjectionMatrix(this.getProjectionMatrix(this.getFov(this.mainCamera, partialTicks, true))); + RenderSystem.setProjectionMatrix(this.getProjectionMatrix(this.getFov(this.mainCamera, partialTicks, true)), ProjectionType.PERSPECTIVE); } } diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/ItemInHandRendererVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/ItemInHandRendererVRMixin.java index 592dcef7a..94063a864 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/ItemInHandRendererVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/ItemInHandRendererVRMixin.java @@ -11,6 +11,7 @@ import net.minecraft.client.renderer.entity.EntityRenderDispatcher; import net.minecraft.client.renderer.entity.ItemRenderer; import net.minecraft.core.component.DataComponents; +import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.HumanoidArm; @@ -30,6 +31,7 @@ import org.vivecraft.client_vr.extensions.EntityRenderDispatcherVRExtension; import org.vivecraft.client_vr.extensions.ItemInHandRendererExtension; import org.vivecraft.client_vr.gameplay.trackers.BowTracker; +import org.vivecraft.client_vr.gameplay.trackers.SwingTracker; import org.vivecraft.client_vr.gameplay.trackers.TelescopeTracker; import org.vivecraft.client_vr.render.RenderPass; import org.vivecraft.client_vr.render.VRArmRenderer; @@ -197,7 +199,7 @@ public abstract class ItemInHandRendererVRMixin implements ItemInHandRendererExt private void vivecraft$vrPlayerArm(PoseStack poseStack, MultiBufferSource multiBufferSource, int i, float f, float g, HumanoidArm humanoidArm) { boolean flag = humanoidArm != HumanoidArm.LEFT; float h = flag ? 1.0F : -1.0F; - AbstractClientPlayer abstractclientplayer = this.minecraft.player; + LocalPlayer abstractclientplayer = this.minecraft.player; RenderSystem.setShaderTexture(0, abstractclientplayer.getSkin().texture()); VRArmRenderer vrarmrenderer = ((EntityRenderDispatcherVRExtension) entityRenderDispatcher).vivecraft$getArmSkinMap().get(abstractclientplayer.getSkin().model().id()); poseStack.pushPose(); @@ -227,10 +229,12 @@ public abstract class ItemInHandRendererVRMixin implements ItemInHandRendererExt poseStack.translate((slim ? -0.34375F : -0.375F) * h, 0.0F, slim ? 0.78125F : 0.75F); poseStack.mulPose(Axis.XP.rotationDegrees(-90)); poseStack.mulPose(Axis.YP.rotationDegrees(180)); + vrarmrenderer.armAlpha = SwingTracker.getItemFade(abstractclientplayer, ItemStack.EMPTY); + ResourceLocation skin = abstractclientplayer.getSkin().texture(); if (flag) { - vrarmrenderer.renderRightHand(poseStack, multiBufferSource, i, abstractclientplayer); + vrarmrenderer.renderRightHand(poseStack, multiBufferSource, i, skin, true); } else { - vrarmrenderer.renderLeftHand(poseStack, multiBufferSource, i, abstractclientplayer); + vrarmrenderer.renderLeftHand(poseStack, multiBufferSource, i, skin, true); } poseStack.popPose(); } diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/LevelEventHandlerVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/LevelEventHandlerVRMixin.java new file mode 100644 index 000000000..3bdec60e0 --- /dev/null +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/LevelEventHandlerVRMixin.java @@ -0,0 +1,50 @@ +package org.vivecraft.mixin.client_vr.renderer; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.LevelEventHandler; +import net.minecraft.core.BlockPos; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.vivecraft.client_vr.ClientDataHolderVR; +import org.vivecraft.client_vr.VRState; + +@Mixin(LevelEventHandler.class) +public class LevelEventHandlerVRMixin { + @Shadow + @Final + private Minecraft minecraft; + + @Inject(at = @At("HEAD"), method = "levelEvent") + public void vivecraft$shakeOnSound(int i, BlockPos blockPos, int j, CallbackInfo ci) { + boolean playerNearAndVR = VRState.vrRunning && this.minecraft.player != null && this.minecraft.player.isAlive() && this.minecraft.player.blockPosition().distSqr(blockPos) < 25.0D; + if (playerNearAndVR) { + switch (i) { + /* pre 1.19.4, they are now separate + case 1011, // IRON_DOOR_CLOSE + 1012, // WOODEN_DOOR_CLOSE + 1013, // WOODEN_TRAPDOOR_CLOSE + 1014, // FENCE_GATE_CLOSE + 1036 // IRON_TRAPDOOR_CLOSE + -> ClientDataHolderVR.getInstance().vr.triggerHapticPulse(0, 250); + */ + case 1019, // ZOMBIE_ATTACK_WOODEN_DOOR + 1020, // ZOMBIE_ATTACK_IRON_DOOR + 1021 // ZOMBIE_BREAK_WOODEN_DOOR + -> { + ClientDataHolderVR.getInstance().vr.triggerHapticPulse(0, 750); + ClientDataHolderVR.getInstance().vr.triggerHapticPulse(1, 750); + } + case 1030 -> // ANVIL_USE + ClientDataHolderVR.getInstance().vr.triggerHapticPulse(0, 500); + case 1031 -> { // ANVIL_LAND + ClientDataHolderVR.getInstance().vr.triggerHapticPulse(0, 1250); + ClientDataHolderVR.getInstance().vr.triggerHapticPulse(1, 1250); + } + } + } + } +} diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/LevelRendererVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/LevelRendererVRMixin.java index 3a2d66bb3..7e5788a57 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/LevelRendererVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/LevelRendererVRMixin.java @@ -1,25 +1,30 @@ package org.vivecraft.mixin.client_vr.renderer; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.sugar.Local; +import com.mojang.blaze3d.framegraph.FrameGraphBuilder; +import com.mojang.blaze3d.framegraph.FramePass; import com.mojang.blaze3d.pipeline.RenderTarget; +import com.mojang.blaze3d.resource.RenderTargetDescriptor; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import net.minecraft.client.Camera; -import net.minecraft.client.DeltaTracker; +import net.minecraft.client.CloudStatus; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.*; import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.server.packs.resources.ResourceManagerReloadListener; +import net.minecraft.util.profiling.Profiler; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.lighting.LevelLightEngine; +import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; -import net.minecraft.world.phys.shapes.VoxelShape; -import org.joml.Matrix4f; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -32,6 +37,7 @@ import org.vivecraft.client_vr.VRState; import org.vivecraft.client_vr.extensions.GameRendererExtension; import org.vivecraft.client_vr.extensions.LevelRendererExtension; +import org.vivecraft.client_vr.extensions.LevelTargetBundleExtension; import org.vivecraft.client_vr.gameplay.screenhandlers.KeyboardHandler; import org.vivecraft.client_vr.render.RenderPass; import org.vivecraft.client_vr.render.helpers.RenderHelper; @@ -42,27 +48,13 @@ import org.vivecraft.mod_compat_vr.ShadersHelper; import org.vivecraft.mod_compat_vr.optifine.OptifineHelper; -import javax.annotation.Nullable; +import java.util.Set; // priority 999 to inject before iris, for the vrFast rendering @Mixin(value = LevelRenderer.class, priority = 999) public abstract class LevelRendererVRMixin implements ResourceManagerReloadListener, AutoCloseable, LevelRendererExtension { - - @Unique - @Nullable - public RenderTarget vivecraft$alphaSortVROccludedFramebuffer; - @Unique - @Nullable - public RenderTarget vivecraft$alphaSortVRUnoccludedFramebuffer; - @Unique - @Nullable - public RenderTarget vivecraft$alphaSortVRHandsFramebuffer; - @Unique - public float vivecraft$selR; @Unique - public float vivecraft$selG; - @Unique - public float vivecraft$selB; + private static final ResourceLocation vivecraft$VR_TRANSPARENCY_POST_CHAIN_ID = ResourceLocation.fromNamespaceAndPath("vivecraft", "vrtransparency"); @Unique private Entity vivecraft$capturedEntity; @@ -75,31 +67,16 @@ public abstract class LevelRendererVRMixin implements ResourceManagerReloadListe @Shadow private ClientLevel level; @Shadow - private PostChain transparencyChain; - @Shadow - private RenderTarget translucentTarget; - @Shadow - private RenderTarget itemEntityTarget; - @Shadow - private RenderTarget particlesTarget; - @Shadow - private RenderTarget weatherTarget; + private RenderTarget entityOutlineTarget; @Shadow - private RenderTarget cloudsTarget; - @Shadow - private PostChain entityEffect; - @Shadow - private RenderTarget entityTarget; + @Final + private LevelTargetBundle targets; @Final @Shadow private RenderBuffers renderBuffers; @Shadow - protected abstract void renderHitOutline(PoseStack poseStack, VertexConsumer buffer, Entity entity, double d, double e, double g, BlockPos blockpos, BlockState blockstate); - - @Shadow - private static void renderShape(PoseStack poseStack, VertexConsumer vertexConsumer, VoxelShape voxelShape, double d, double e, double f, float g, float h, float i, float j) { - } + protected abstract void renderHitOutline(PoseStack poseStack, VertexConsumer vertexConsumer, Entity entity, double d, double e, double f, BlockPos blockPos, BlockState blockState, int i); @Override @Unique @@ -107,28 +84,13 @@ private static void renderShape(PoseStack poseStack, VertexConsumer vertexConsum return this.vivecraft$renderedEntity; } - @ModifyArg(at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Mth;floor(D)I", ordinal = 0), method = "renderSnowAndRain") - public double vivecraft$rainX(double x) { - if (!RenderPassType.isVanilla() && (ClientDataHolderVR.getInstance().currentPass == RenderPass.LEFT || ClientDataHolderVR.getInstance().currentPass == RenderPass.RIGHT)) { - return ClientDataHolderVR.getInstance().vrPlayer.vrdata_world_render.getEye(RenderPass.CENTER).getPosition().x; - } - return x; - } - - @ModifyArg(at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Mth;floor(D)I", ordinal = 1), method = "renderSnowAndRain") - public double vivecraft$rainY(double y) { - if (!RenderPassType.isVanilla() && (ClientDataHolderVR.getInstance().currentPass == RenderPass.LEFT || ClientDataHolderVR.getInstance().currentPass == RenderPass.RIGHT)) { - return ClientDataHolderVR.getInstance().vrPlayer.vrdata_world_render.getEye(RenderPass.CENTER).getPosition().y; - } - return y; - } - - @ModifyArg(at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Mth;floor(D)I", ordinal = 2), method = "renderSnowAndRain") - public double vivecraft$rainZ(double z) { + @ModifyVariable(at = @At("HEAD"), method = "addWeatherPass", argsOnly = true) + public Vec3 vivecraft$rainX(Vec3 cameraPos) { if (!RenderPassType.isVanilla() && (ClientDataHolderVR.getInstance().currentPass == RenderPass.LEFT || ClientDataHolderVR.getInstance().currentPass == RenderPass.RIGHT)) { - return ClientDataHolderVR.getInstance().vrPlayer.vrdata_world_render.getEye(RenderPass.CENTER).getPosition().z; + return ClientDataHolderVR.getInstance().vrPlayer.vrdata_world_render.getEye(RenderPass.CENTER).getPosition(); + } else { + return cameraPos; } - return z; } @Inject(at = @At("TAIL"), method = "onResourceManagerReload") @@ -139,9 +101,9 @@ private static void renderShape(PoseStack poseStack, VertexConsumer vertexConsum } @Inject(at = @At("HEAD"), method = "renderLevel") - public void vivecraft$setShaders(CallbackInfo ci) { + public void vivecraft$setOutlineTarget(CallbackInfo ci) { if (!RenderPassType.isVanilla()) { - this.vivecraft$setShaderGroup(); + this.entityOutlineTarget = RenderPassManager.wrp.outlineTarget; } } @@ -171,16 +133,22 @@ private static void renderShape(PoseStack poseStack, VertexConsumer vertexConsum * End `renderLevel` lighting poll */ - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GameRenderer;getRenderDistance()F", shift = Shift.BEFORE), + @Inject(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/framegraph/FramePass;executes(Ljava/lang/Runnable;)V", shift = Shift.AFTER), method = "renderLevel") - public void vivecraft$stencil(CallbackInfo ci) { + public void vivecraft$stencil(CallbackInfo ci, @Local FrameGraphBuilder frameGraphBuilder) { if (!RenderPassType.isVanilla()) { - this.minecraft.getProfiler().popPush("stencil"); - VREffectsHelper.drawEyeStencil(false); + if (ClientDataHolderVR.getInstance().vrSettings.vrUseStencil) { + FramePass framePass = frameGraphBuilder.addPass("vr_stencil"); + this.targets.main = framePass.readsAndWrites(this.targets.main); + framePass.executes(() -> { + Profiler.get().popPush("stencil"); + VREffectsHelper.drawEyeStencil(false); + }); + } } } - @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;isSleeping()Z"), method = "renderLevel") + @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;isSleeping()Z"), method = "collectVisibleEntities") public boolean vivecraft$noPlayerWhenSleeping(LivingEntity instance) { if (!RenderPassType.isVanilla()) { return false; @@ -207,38 +175,34 @@ private static void renderShape(PoseStack poseStack, VertexConsumer vertexConsum this.vivecraft$renderedEntity = null; } - @Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;hitResult:Lnet/minecraft/world/phys/HitResult;", ordinal = 1), method = "renderLevel") - public void vivecraft$interactOutline(DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci, @Local PoseStack poseStack) { + @Inject(at = @At("HEAD"), method = "renderBlockOutline") + public void vivecraft$interactOutline(CallbackInfo ci, @Local(argsOnly = true) Camera camera, @Local(argsOnly = true) MultiBufferSource.BufferSource bufferSource, @Local(argsOnly = true) PoseStack poseStack) { if (!RenderPassType.isVanilla()) { - this.level.getProfiler().popPush("interact outline"); - vivecraft$selR = vivecraft$selG = vivecraft$selB = 1f; + Profiler.get().popPush("interact outline"); Vec3 vec3 = camera.getPosition(); - double d = vec3.x(); - double e = vec3.y(); - double g = vec3.z(); if (OptifineHelper.isOptifineLoaded() && OptifineHelper.isShaderActive()) { OptifineHelper.beginOutlineShader(); } for (int c = 0; c < 2; c++) { if (ClientDataHolderVR.getInstance().interactTracker.isInteractActive(c) && (ClientDataHolderVR.getInstance().interactTracker.inBlockHit[c] != null || ClientDataHolderVR.getInstance().interactTracker.bukkit[c])) { BlockPos blockpos = ClientDataHolderVR.getInstance().interactTracker.inBlockHit[c] != null ? ClientDataHolderVR.getInstance().interactTracker.inBlockHit[c].getBlockPos() : BlockPos.containing(ClientDataHolderVR.getInstance().vrPlayer.vrdata_world_render.getController(c).getPosition()); + BlockState blockstate = this.level.getBlockState(blockpos); - this.renderHitOutline(poseStack, this.renderBuffers.bufferSource().getBuffer(RenderType.lines()), camera.getEntity(), d, e, g, blockpos, blockstate); + + this.renderHitOutline(poseStack, bufferSource.getBuffer(RenderType.lines()), camera.getEntity(), vec3.x, vec3.y, vec3.z, blockpos, blockstate, 0xFFFFFFFF); } } if (OptifineHelper.isOptifineLoaded() && OptifineHelper.isShaderActive()) { this.renderBuffers.bufferSource().endBatch(RenderType.lines()); OptifineHelper.endOutlineShader(); } - // reset outline color - vivecraft$selR = vivecraft$selG = vivecraft$selB = 0f; } } - @ModifyVariable(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;hitResult:Lnet/minecraft/world/phys/HitResult;", ordinal = 1), method = "renderLevel", ordinal = 0, argsOnly = true) - public boolean vivecraft$noBlockoutlineOnInteract(boolean renderBlockOutline) { + @ModifyExpressionValue(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;hitResult:Lnet/minecraft/world/phys/HitResult;"), method = "renderBlockOutline") + public HitResult vivecraft$noBlockoutlineOnInteract(HitResult hitPos) { // don't draw the block outline when the interaction outline is active - return renderBlockOutline && (RenderPassType.isVanilla() || !(ClientDataHolderVR.getInstance().interactTracker.isInteractActive(0) && (ClientDataHolderVR.getInstance().interactTracker.inBlockHit[0] != null || ClientDataHolderVR.getInstance().interactTracker.bukkit[0]))); + return (ClientDataHolderVR.getInstance().interactTracker.isInteractActive(0) && (ClientDataHolderVR.getInstance().interactTracker.inBlockHit[0] != null || ClientDataHolderVR.getInstance().interactTracker.bukkit[0])) ? null : hitPos; } @Unique @@ -253,205 +217,134 @@ private static void renderShape(PoseStack poseStack, VertexConsumer vertexConsum vivecraft$guiRendered = false; } - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch()V", ordinal = 0, shift = Shift.AFTER), method = "renderLevel") - public void vivecraft$renderVrStuffPart1(DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) { + @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/framegraph/FrameGraphBuilder;createInternal(Ljava/lang/String;Lcom/mojang/blaze3d/resource/ResourceDescriptor;)Lcom/mojang/blaze3d/resource/ResourceHandle;", ordinal = 0)) + public void vivecraft$addVRTargets(CallbackInfo ci, @Local FrameGraphBuilder frameGraphBuilder, @Local RenderTargetDescriptor renderTargetDescriptor) { + if (VRState.vrRunning) { + this.targets.replace(LevelTargetBundleExtension.OCCLUDED_TARGET_ID, frameGraphBuilder.createInternal("vroccluded", renderTargetDescriptor)); + this.targets.replace(LevelTargetBundleExtension.UNOCCLUDED_TARGET_ID, frameGraphBuilder.createInternal("vrunoccluded", renderTargetDescriptor)); + this.targets.replace(LevelTargetBundleExtension.HANDS_TARGET_ID, frameGraphBuilder.createInternal("vrhands", renderTargetDescriptor)); + } + } + + // no remap needed bnecause of optifine, to have the * + @Inject(method = {"method_62202", "addMainPass*"}, at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/framegraph/FramePass;readsAndWrites(Lcom/mojang/blaze3d/resource/ResourceHandle;)Lcom/mojang/blaze3d/resource/ResourceHandle;", ordinal = 0, remap = true), remap = false) + public void vivecraft$markVRTargetsForWrite(CallbackInfo ci, @Local FramePass framePass) { + if (VRState.vrRunning && this.targets instanceof LevelTargetBundleExtension ext) { + if (ext.vivecraft$getOccluded() != null) { + this.targets.replace(LevelTargetBundleExtension.OCCLUDED_TARGET_ID, framePass.readsAndWrites(ext.vivecraft$getOccluded())); + } + if (ext.vivecraft$getUnoccluded() != null) { + this.targets.replace(LevelTargetBundleExtension.UNOCCLUDED_TARGET_ID, framePass.readsAndWrites(ext.vivecraft$getUnoccluded())); + } + if (ext.vivecraft$getHands() != null) { + this.targets.replace(LevelTargetBundleExtension.HANDS_TARGET_ID, framePass.readsAndWrites(ext.vivecraft$getHands())); + } + // fix vanilla bug https://bugs.mojang.com/browse/MC-278096 + if (this.targets.clouds != null && this.minecraft.options.getCloudsType() == CloudStatus.OFF) { + this.targets.clouds = framePass.readsAndWrites(this.targets.clouds); + } + } + } + + @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch()V", ordinal = 0, shift = Shift.AFTER, remap = true), method = { + "method_62214", // fabric + "lambda$addMainPass$1(Lnet/minecraft/client/renderer/FogParameters;Lnet/minecraft/client/DeltaTracker;Lnet/minecraft/client/Camera;Lnet/minecraft/util/profiling/ProfilerFiller;Lorg/joml/Matrix4f;Lorg/joml/Matrix4f;Lcom/mojang/blaze3d/resource/ResourceHandle;Lcom/mojang/blaze3d/resource/ResourceHandle;Lcom/mojang/blaze3d/resource/ResourceHandle;Lcom/mojang/blaze3d/resource/ResourceHandle;Lnet/minecraft/client/renderer/culling/Frustum;ZLcom/mojang/blaze3d/resource/ResourceHandle;)V", // forge + "lambda$addMainPass$1(Lnet/minecraft/client/renderer/FogParameters;Lnet/minecraft/client/DeltaTracker;Lnet/minecraft/client/Camera;Lnet/minecraft/util/profiling/ProfilerFiller;Lorg/joml/Matrix4f;Lorg/joml/Matrix4f;Lcom/mojang/blaze3d/resource/ResourceHandle;Lcom/mojang/blaze3d/resource/ResourceHandle;Lcom/mojang/blaze3d/resource/ResourceHandle;Lcom/mojang/blaze3d/resource/ResourceHandle;Lnet/minecraft/client/renderer/culling/Frustum;ZLcom/mojang/blaze3d/resource/ResourceHandle;Lnet/minecraft/client/renderer/LightTexture;)V", // optifine + "lambda$addMainPass$2" // neoforge + }, remap = false) + public void vivecraft$renderVrStuffPart1(CallbackInfo ci, @Local float partialTick) { if (RenderPassType.isVanilla()) { return; } vivecraft$menuHandleft = MethodHolder.isInMenuRoom() || this.minecraft.screen != null || KeyboardHandler.Showing; vivecraft$menuhandright = vivecraft$menuHandleft || ClientDataHolderVR.getInstance().interactTracker.hotbar >= 0 && ClientDataHolderVR.getInstance().vrSettings.vrTouchHotbar; - if (transparencyChain != null) { - VREffectsHelper.renderVRFabulous(deltaTracker.getGameTimeDeltaPartialTick(false), (LevelRenderer) (Object) this, vivecraft$menuhandright, vivecraft$menuHandleft); + + if (this.targets.translucent != null) { + // fix vanilla bug https://bugs.mojang.com/browse/MC-278096 + if (this.targets.clouds != null && this.minecraft.options.getCloudsType() == CloudStatus.OFF) { + this.targets.clouds.get().clear(); + } + VREffectsHelper.renderVRFabulous(partialTick, this.targets, vivecraft$menuhandright, vivecraft$menuHandleft); } else { - VREffectsHelper.renderVrFast(deltaTracker.getGameTimeDeltaPartialTick(false), false, vivecraft$menuhandright, vivecraft$menuHandleft); + VREffectsHelper.renderVrFast(partialTick, false, vivecraft$menuhandright, vivecraft$menuHandleft); if (ShadersHelper.isShaderActive() && ClientDataHolderVR.getInstance().vrSettings.shaderGUIRender == VRSettings.ShaderGUIRender.BEFORE_TRANSLUCENT_SOLID) { // shaders active, and render gui before translucents - VREffectsHelper.renderVrFast(deltaTracker.getGameTimeDeltaPartialTick(false), true, vivecraft$menuhandright, vivecraft$menuHandleft); + VREffectsHelper.renderVrFast(partialTick, true, vivecraft$menuhandright, vivecraft$menuHandleft); vivecraft$guiRendered = true; } } } - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Options;getCloudsType()Lnet/minecraft/client/CloudStatus;", shift = Shift.BEFORE), - method = "renderLevel") - public void vivecraft$renderVrStuffPart2(DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) { + @Inject(at = @At(value = "TAIL"), method = { + "method_62213", // fabric + "lambda$addParticlesPass$2", // forge + "lambda$addParticlesPass$5"}, remap = false) // neoforge + public void vivecraft$renderVrStuffPart2(CallbackInfo ci, @Local(argsOnly = true) float partialTick) { if (RenderPassType.isVanilla()) { return; } - if (transparencyChain == null && (!ShadersHelper.isShaderActive() || ClientDataHolderVR.getInstance().vrSettings.shaderGUIRender == VRSettings.ShaderGUIRender.AFTER_TRANSLUCENT)) { + if (this.targets.translucent == null && (!ShadersHelper.isShaderActive() || ClientDataHolderVR.getInstance().vrSettings.shaderGUIRender == VRSettings.ShaderGUIRender.AFTER_TRANSLUCENT)) { // no shaders, or shaders, and gui after translucents - VREffectsHelper.renderVrFast(deltaTracker.getGameTimeDeltaPartialTick(false), true, vivecraft$menuhandright, vivecraft$menuHandleft); + VREffectsHelper.renderVrFast(partialTick, true, vivecraft$menuhandright, vivecraft$menuHandleft); vivecraft$guiRendered = true; } } - // if the gui didn't render yet, and something canceled the level renderer, render it now. + // if the gui didn't render yet, render it now. // or if shaders are on, and option AFTER_SHADER is selected - @Inject(at = @At("RETURN"), method = "renderLevel") - public void vivecraft$renderVrStuffFinal(DeltaTracker deltaTracker, boolean bl, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, Matrix4f matrix4f2, CallbackInfo ci) { + @Inject(at = @At(value = "RETURN"), method = "renderLevel") + public void vivecraft$renderVrStuffFinal(CallbackInfo ci, @Local(ordinal = 0) float partialTick) { if (RenderPassType.isVanilla()) { return; } - if (!vivecraft$guiRendered && transparencyChain == null) { + if (!vivecraft$guiRendered && !Minecraft.useShaderTransparency()) { + this.minecraft.getMainRenderTarget().bindWrite(true); RenderSystem.getModelViewStack().pushMatrix().identity(); RenderHelper.applyVRModelView(ClientDataHolderVR.getInstance().currentPass, RenderSystem.getModelViewStack()); - RenderSystem.applyModelViewMatrix(); - VREffectsHelper.renderVrFast(deltaTracker.getGameTimeDeltaPartialTick(false), true, vivecraft$menuhandright, vivecraft$menuHandleft); + VREffectsHelper.renderVrFast(partialTick, true, vivecraft$menuhandright, vivecraft$menuHandleft); RenderSystem.getModelViewStack().popMatrix(); - RenderSystem.applyModelViewMatrix(); vivecraft$guiRendered = true; } } - @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;renderShape(Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;Lnet/minecraft/world/phys/shapes/VoxelShape;DDDFFFF)V"), method = "renderHitOutline") - public void vivecraft$colorHitBox(PoseStack poseStack, VertexConsumer vertexConsumer, VoxelShape voxelShape, double d, double e, double f, float g, float h, float i, float j) { - renderShape(poseStack, vertexConsumer, voxelShape, d, e, f, this.vivecraft$selR, this.vivecraft$selG, this.vivecraft$selB, j); - } - - @Inject(at = @At("HEAD"), method = "levelEvent") - public void vivecraft$shakeOnSound(int i, BlockPos blockPos, int j, CallbackInfo ci) { - boolean playerNearAndVR = VRState.vrRunning && this.minecraft.player != null && this.minecraft.player.isAlive() && this.minecraft.player.blockPosition().distSqr(blockPos) < 25.0D; - if (playerNearAndVR) { - switch (i) { - /* pre 1.19.4, they are now separate - case 1011, // IRON_DOOR_CLOSE - 1012, // WOODEN_DOOR_CLOSE - 1013, // WOODEN_TRAPDOOR_CLOSE - 1014, // FENCE_GATE_CLOSE - 1036 // IRON_TRAPDOOR_CLOSE - -> ClientDataHolderVR.getInstance().vr.triggerHapticPulse(0, 250); - */ - case 1019, // ZOMBIE_ATTACK_WOODEN_DOOR - 1020, // ZOMBIE_ATTACK_IRON_DOOR - 1021 // ZOMBIE_BREAK_WOODEN_DOOR - -> { - ClientDataHolderVR.getInstance().vr.triggerHapticPulse(0, 750); - ClientDataHolderVR.getInstance().vr.triggerHapticPulse(1, 750); - } - case 1030 -> // ANVIL_USE - ClientDataHolderVR.getInstance().vr.triggerHapticPulse(0, 500); - case 1031 -> { // ANVIL_LAND - ClientDataHolderVR.getInstance().vr.triggerHapticPulse(0, 1250); - ClientDataHolderVR.getInstance().vr.triggerHapticPulse(1, 1250); - } - } - } - } - - @Inject(at = @At("HEAD"), method = {"initOutline", "initTransparency"}) - public void vivecraft$restorePostChain(CallbackInfo ci) { + @Inject(at = @At("HEAD"), method = {"initOutline", "resize"}) + public void vivecraft$restoreOutlineTarget(CallbackInfo ci) { if (VRState.vrInitialized) { - vivecraft$restoreVanillaPostChains(); - ClientDataHolderVR.getInstance().vrRenderer.reinitFrameBuffers("Outline/Transparency shaders Reloaded"); + this.entityOutlineTarget = RenderPassManager.INSTANCE.vanillaOutlineTarget; } } @Inject(at = @At("TAIL"), method = "initOutline") - public void vivecraft$captureOutlineChain(CallbackInfo ci) { - RenderPassManager.INSTANCE.vanillaOutlineChain = entityEffect; - } - - @Inject(at = @At("TAIL"), method = "initTransparency") - public void vivecraft$captureTransparencyChain(CallbackInfo ci) { - RenderPassManager.INSTANCE.vanillaTransparencyChain = transparencyChain; - } - - @Inject(at = @At("TAIL"), method = "deinitTransparency") - public void vivecraft$removeTransparencyChain(CallbackInfo ci) { - RenderPassManager.INSTANCE.vanillaTransparencyChain = null; + public void vivecraft$captureOutlineTarget(CallbackInfo ci) { + RenderPassManager.INSTANCE.vanillaOutlineTarget = this.entityOutlineTarget; } @Inject(at = @At("TAIL"), method = "close") - public void vivecraft$removePostChains(CallbackInfo ci) { - RenderPassManager.INSTANCE.vanillaOutlineChain = null; - RenderPassManager.INSTANCE.vanillaTransparencyChain = null; + public void vivecraft$clearOutlineTarget(CallbackInfo ci) { + RenderPassManager.INSTANCE.vanillaOutlineTarget = null; } - @Override - @Unique - public void vivecraft$restoreVanillaPostChains() { - transparencyChain = RenderPassManager.INSTANCE.vanillaTransparencyChain; - - if (transparencyChain != null) { - this.translucentTarget = transparencyChain.getTempTarget("translucent"); - this.itemEntityTarget = transparencyChain.getTempTarget("itemEntity"); - this.particlesTarget = transparencyChain.getTempTarget("particles"); - this.weatherTarget = transparencyChain.getTempTarget("weather"); - this.cloudsTarget = transparencyChain.getTempTarget("clouds"); + @ModifyArg(method = "getTransparencyChain", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/ShaderManager;getPostChain(Lnet/minecraft/resources/ResourceLocation;Ljava/util/Set;)Lnet/minecraft/client/renderer/PostChain;")) + private ResourceLocation vivecraft$VRTransparency(ResourceLocation postShader) { + if (VRState.vrRunning) { + return vivecraft$VR_TRANSPARENCY_POST_CHAIN_ID; } else { - this.translucentTarget = null; - this.itemEntityTarget = null; - this.particlesTarget = null; - this.weatherTarget = null; - this.cloudsTarget = null; - } - - entityEffect = RenderPassManager.INSTANCE.vanillaOutlineChain; - if (entityEffect != null) { - this.entityTarget = entityEffect.getTempTarget("final"); - } else { - this.entityTarget = null; + return postShader; } } - @Unique - private void vivecraft$setShaderGroup() { - PostChain transparencyChain = RenderPassManager.wrp.transparencyChain; - - if (transparencyChain != null) { - this.transparencyChain = transparencyChain; - this.translucentTarget = transparencyChain.getTempTarget("translucent"); - this.itemEntityTarget = transparencyChain.getTempTarget("itemEntity"); - this.particlesTarget = transparencyChain.getTempTarget("particles"); - this.weatherTarget = transparencyChain.getTempTarget("weather"); - this.cloudsTarget = transparencyChain.getTempTarget("clouds"); - this.vivecraft$alphaSortVRHandsFramebuffer = transparencyChain.getTempTarget("vrhands"); - this.vivecraft$alphaSortVROccludedFramebuffer = transparencyChain.getTempTarget("vroccluded"); - this.vivecraft$alphaSortVRUnoccludedFramebuffer = transparencyChain.getTempTarget("vrunoccluded"); + @ModifyArg(method = "getTransparencyChain", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/ShaderManager;getPostChain(Lnet/minecraft/resources/ResourceLocation;Ljava/util/Set;)Lnet/minecraft/client/renderer/PostChain;")) + private Set vivecraft$VRTargets(Set targets) { + if (VRState.vrRunning) { + return LevelTargetBundleExtension.VR_TARGETS; } else { - this.transparencyChain = null; - this.translucentTarget = null; - this.itemEntityTarget = null; - this.particlesTarget = null; - this.weatherTarget = null; - this.cloudsTarget = null; - this.vivecraft$alphaSortVRHandsFramebuffer = null; - this.vivecraft$alphaSortVROccludedFramebuffer = null; - this.vivecraft$alphaSortVRUnoccludedFramebuffer = null; + return targets; } - - PostChain outlineChain = RenderPassManager.wrp.outlineChain; - - if (outlineChain != null) { - this.entityEffect = outlineChain; - this.entityTarget = outlineChain.getTempTarget("final"); - } else { - this.entityEffect = null; - this.entityTarget = null; - } - } - - @Override - @Unique - public RenderTarget vivecraft$getAlphaSortVROccludedFramebuffer() { - return vivecraft$alphaSortVROccludedFramebuffer; - } - - @Override - @Unique - public RenderTarget vivecraft$getAlphaSortVRUnoccludedFramebuffer() { - return vivecraft$alphaSortVRUnoccludedFramebuffer; - } - - @Override - @Unique - public RenderTarget vivecraft$getAlphaSortVRHandsFramebuffer() { - return vivecraft$alphaSortVRHandsFramebuffer; } } diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/LevelTargetBundleVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/LevelTargetBundleVRMixin.java new file mode 100644 index 000000000..9dc20c500 --- /dev/null +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/LevelTargetBundleVRMixin.java @@ -0,0 +1,76 @@ +package org.vivecraft.mixin.client_vr.renderer; + +import com.mojang.blaze3d.pipeline.RenderTarget; +import com.mojang.blaze3d.resource.ResourceHandle; +import net.minecraft.client.renderer.LevelTargetBundle; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +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.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.vivecraft.client_vr.extensions.LevelTargetBundleExtension; + +@Mixin(LevelTargetBundle.class) +public class LevelTargetBundleVRMixin implements LevelTargetBundleExtension { + + @Unique + @Nullable + private ResourceHandle vivecraft$occluded; + @Unique + @Nullable + private ResourceHandle vivecraft$unoccluded; + @Unique + @Nullable + private ResourceHandle vivecraft$hands; + + @Inject(method = "replace", at = @At("HEAD"), cancellable = true) + private void vivecraft$replace(ResourceLocation resourceLocation, ResourceHandle resourceHandle, CallbackInfo ci) { + if (resourceLocation.equals(OCCLUDED_TARGET_ID)) { + this.vivecraft$occluded = resourceHandle; + ci.cancel(); + } else if (resourceLocation.equals(UNOCCLUDED_TARGET_ID)) { + this.vivecraft$unoccluded = resourceHandle; + ci.cancel(); + } else if (resourceLocation.equals(HANDS_TARGET_ID)) { + this.vivecraft$hands = resourceHandle; + ci.cancel(); + } + } + + @Inject(method = "get", at = @At("HEAD"), cancellable = true) + private void vivecraft$get(ResourceLocation resourceLocation, CallbackInfoReturnable> cir) { + if (resourceLocation.equals(OCCLUDED_TARGET_ID)) { + cir.setReturnValue(this.vivecraft$occluded); + } else if (resourceLocation.equals(UNOCCLUDED_TARGET_ID)) { + cir.setReturnValue(this.vivecraft$unoccluded); + } else if (resourceLocation.equals(HANDS_TARGET_ID)) { + cir.setReturnValue(this.vivecraft$hands); + } + } + + @Inject(method = "clear", at = @At("HEAD")) + private void vivecraft$clear(CallbackInfo ci) { + this.vivecraft$occluded = null; + this.vivecraft$unoccluded = null; + this.vivecraft$hands = null; + } + + + @Override + public ResourceHandle vivecraft$getOccluded() { + return this.vivecraft$occluded; + } + + @Override + public ResourceHandle vivecraft$getUnoccluded() { + return this.vivecraft$unoccluded; + } + + @Override + public ResourceHandle vivecraft$getHands() { + return this.vivecraft$hands; + } +} diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/PostChainVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/PostChainVRMixin.java index 37b173d6e..3ca0cebb5 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/PostChainVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/PostChainVRMixin.java @@ -12,7 +12,8 @@ @Mixin(PostChain.class) public class PostChainVRMixin { - + // TODO 1.21.3 stencil for post +/* @Shadow @Final private RenderTarget screenTarget; @@ -21,8 +22,8 @@ public class PostChainVRMixin { private RenderTarget vivecraft$vrTarget(RenderTarget old) { if (((RenderTargetExtension) screenTarget).vivecraft$getUseStencil()) { ((RenderTargetExtension) old).vivecraft$setUseStencil(true); - old.resize(old.width, old.height, Minecraft.ON_OSX); + old.resize(old.width, old.height); } return old; - } + }*/ } diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/blockentity/TheEndGatewayRendererVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/blockentity/TheEndGatewayRendererVRMixin.java index 7b6087ee7..628688a7b 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/blockentity/TheEndGatewayRendererVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/blockentity/TheEndGatewayRendererVRMixin.java @@ -27,7 +27,7 @@ public class TheEndGatewayRendererVRMixin { false, false, RenderType.CompositeState.builder() - .setShaderState(new RenderStateShard.ShaderStateShard(VRShaders::getRendertypeEndGatewayShaderVR)) + .setShaderState(new RenderStateShard.ShaderStateShard(VRShaders.rendertypeEndGatewayShaderVR)) .setTextureState( RenderStateShard .MultiTextureStateShard diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/blockentity/TheEndPortalRendererVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/blockentity/TheEndPortalRendererVRMixin.java index bd7d91aed..007b0049b 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/blockentity/TheEndPortalRendererVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/blockentity/TheEndPortalRendererVRMixin.java @@ -27,7 +27,7 @@ public class TheEndPortalRendererVRMixin { false, false, RenderType.CompositeState.builder() - .setShaderState(new RenderStateShard.ShaderStateShard(VRShaders::getRendertypeEndPortalShaderVR)) + .setShaderState(new RenderStateShard.ShaderStateShard(VRShaders.rendertypeEndPortalShaderVR)) .setTextureState( RenderStateShard .MultiTextureStateShard diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/entity/EntityRendererVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/entity/EntityRendererVRMixin.java index c99f33f00..f42e1d38c 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/entity/EntityRendererVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/entity/EntityRendererVRMixin.java @@ -1,10 +1,7 @@ package org.vivecraft.mixin.client_vr.renderer.entity; -import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.entity.EntityRenderDispatcher; import net.minecraft.client.renderer.entity.EntityRenderer; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.phys.Vec3; import org.joml.Quaternionf; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -12,8 +9,6 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; import org.vivecraft.client_vr.extensions.EntityRenderDispatcherVRExtension; -import org.vivecraft.client_vr.render.helpers.RenderHelper; -import org.vivecraft.client_xr.render_pass.RenderPassType; @Mixin(EntityRenderer.class) public class EntityRendererVRMixin { @@ -26,12 +21,4 @@ public class EntityRendererVRMixin { public Quaternionf vivecraft$cameraOffset(EntityRenderDispatcher instance) { return ((EntityRenderDispatcherVRExtension) this.entityRenderDispatcher).vivecraft$getCameraOrientation(1.0f, 0.5f); } - - @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;getRopeHoldPosition(F)Lnet/minecraft/world/phys/Vec3;"), method = "renderLeash") - public Vec3 vivecraft$leash(Entity instance, float f) { - if (!RenderPassType.isVanilla() && instance == Minecraft.getInstance().player) { - return RenderHelper.getControllerRenderPos(0); - } - return instance.getRopeHoldPosition(f); - } } diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/entity/FishingHookRendererVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/entity/FishingHookRendererVRMixin.java index df7f0bc70..38ae6d973 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/entity/FishingHookRendererVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/entity/FishingHookRendererVRMixin.java @@ -4,6 +4,7 @@ import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.client.renderer.entity.FishingHookRenderer; +import net.minecraft.client.renderer.entity.state.FishingHookRenderState; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.FishingHook; import net.minecraft.world.item.Items; @@ -18,7 +19,7 @@ import org.vivecraft.client_xr.render_pass.RenderPassType; @Mixin(FishingHookRenderer.class) -public abstract class FishingHookRendererVRMixin extends EntityRenderer { +public abstract class FishingHookRendererVRMixin extends EntityRenderer { // dummy constructor protected FishingHookRendererVRMixin(EntityRendererProvider.Context context) { diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/entity/GuardianRendererVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/entity/GuardianRendererVRMixin.java index 334de5fbb..cbf7d8575 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/entity/GuardianRendererVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/entity/GuardianRendererVRMixin.java @@ -1,13 +1,14 @@ package org.vivecraft.mixin.client_vr.renderer.entity; +import com.llamalad7.mixinextras.sugar.Local; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.entity.GuardianRenderer; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.render.RenderPass; import org.vivecraft.client_xr.render_pass.RenderPassType; @@ -15,14 +16,11 @@ @Mixin(GuardianRenderer.class) public abstract class GuardianRendererVRMixin { - @Shadow - protected abstract Vec3 getPosition(LivingEntity livingEntity, double d, float f); - - @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/GuardianRenderer;getPosition(Lnet/minecraft/world/entity/LivingEntity;DF)Lnet/minecraft/world/phys/Vec3;"), method = "render(Lnet/minecraft/world/entity/monster/Guardian;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V") - public Vec3 vivecraft$changeEye(GuardianRenderer instance, LivingEntity livingEntity, double d, float f) { + @Inject(method = "getPosition", at = @At(value = "HEAD"), cancellable = true) + public void vivecraft$changeEye(CallbackInfoReturnable cir, @Local(argsOnly = true) LivingEntity livingEntity) { if (!RenderPassType.isVanilla() && livingEntity == Minecraft.getInstance().getCameraEntity()) { - return ClientDataHolderVR.getInstance().vrPlayer.getVRDataWorld().getEye(RenderPass.CENTER).getPosition().subtract(0.0D, 0.3D * (double) ClientDataHolderVR.getInstance().vrPlayer.worldScale, 0.0D); + cir.setReturnValue( + ClientDataHolderVR.getInstance().vrPlayer.getVRDataWorld().getEye(RenderPass.CENTER).getPosition().subtract(0.0F, 0.3F * ClientDataHolderVR.getInstance().vrPlayer.worldScale, 0.0F)); } - return this.getPosition(livingEntity, d, f); } } diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/tutorial/MovementTutorialStepInstanceVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/tutorial/MovementTutorialStepInstanceVRMixin.java index c277d4664..a4bdc4e43 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/tutorial/MovementTutorialStepInstanceVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/tutorial/MovementTutorialStepInstanceVRMixin.java @@ -2,7 +2,7 @@ import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; -import net.minecraft.client.player.Input; +import net.minecraft.client.player.ClientInput; import net.minecraft.client.tutorial.MovementTutorialStepInstance; import net.minecraft.network.chat.Component; import org.spongepowered.asm.mixin.Mixin; @@ -124,7 +124,7 @@ public class MovementTutorialStepInstanceVRMixin { } @Inject(at = @At("TAIL"), method = "onInput") - private void vivecraft$addTeleport(Input input, CallbackInfo ci) { + private void vivecraft$addTeleport(ClientInput clientInput, CallbackInfo ci) { moved |= VivecraftVRMod.INSTANCE.keyTeleport.isDown(); } diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/world/BoatMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/world/AbstractBoatMixin.java similarity index 92% rename from common/src/main/java/org/vivecraft/mixin/client_vr/world/BoatMixin.java rename to common/src/main/java/org/vivecraft/mixin/client_vr/world/AbstractBoatMixin.java index 7829c16c1..8242ecd52 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/world/BoatMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/world/AbstractBoatMixin.java @@ -3,7 +3,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.vehicle.Boat; +import net.minecraft.world.entity.vehicle.AbstractBoat; import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -17,8 +17,8 @@ import org.vivecraft.client_vr.VRState; //TODO needed? -@Mixin(Boat.class) -public abstract class BoatMixin extends Entity { +@Mixin(AbstractBoat.class) +public abstract class AbstractBoatMixin extends Entity { @Shadow private float deltaRotation; @@ -32,7 +32,7 @@ public abstract class BoatMixin extends Entity { @Shadow public abstract void setPaddleState(boolean pLeft, boolean pRight); - public BoatMixin(EntityType entityType, Level level) { + public AbstractBoatMixin(EntityType entityType, Level level) { super(entityType, level); } @@ -50,7 +50,7 @@ public BoatMixin(EntityType entityType, Level level) { return -f1; } - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/vehicle/Boat;setDeltaMovement(Lnet/minecraft/world/phys/Vec3;)V", shift = At.Shift.BEFORE), method = "controlBoat", locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) + @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/vehicle/AbstractBoat;setDeltaMovement(Lnet/minecraft/world/phys/Vec3;)V", shift = At.Shift.BEFORE), method = "controlBoat", locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) public void vivecraft$roomscaleRowing(CallbackInfo ci, float f) { if (!VRState.vrRunning) { return; diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/world/ConsumableVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/world/ConsumableVRMixin.java new file mode 100644 index 000000000..6fb157605 --- /dev/null +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/world/ConsumableVRMixin.java @@ -0,0 +1,39 @@ +package org.vivecraft.mixin.client_vr.world; + +import net.minecraft.client.Minecraft; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.component.Consumable; +import net.minecraft.world.level.Level; +import org.spongepowered.asm.mixin.Mixin; +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_vr.ClientDataHolderVR; +import org.vivecraft.client_vr.VRState; + +@Mixin(Consumable.class) +public class ConsumableVRMixin { + + @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;canEat(Z)Z"), method = "canConsume", cancellable = true) + private void vivecraft$alwaysAllowEasterEggEating(LivingEntity livingEntity, ItemStack itemStack, CallbackInfoReturnable cir) { + if (itemStack.getHoverName().getString().equals("EAT ME")) { + cir.setReturnValue(true); + } + } + + @Inject(method = "onConsume", at = @At("HEAD")) + private void vivecraft$wonderFoodEasterEgg(Level level, LivingEntity livingEntity, ItemStack itemStack, CallbackInfoReturnable cir) { + if (VRState.vrInitialized && livingEntity == Minecraft.getInstance().player) { + if (itemStack.is(Items.POTION) && itemStack.getHoverName().getString().equals("DRINK ME")) { + ClientDataHolderVR.getInstance().vrPlayer.wfMode = -0.05; + ClientDataHolderVR.getInstance().vrPlayer.wfCount = 400; + } else if (itemStack.get(DataComponents.FOOD) != null && itemStack.getHoverName().getString().equals("EAT ME")) { + ClientDataHolderVR.getInstance().vrPlayer.wfMode = 0.5D; + ClientDataHolderVR.getInstance().vrPlayer.wfCount = 400; + } + } + } +} diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/world/ItemVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/world/ItemVRMixin.java deleted file mode 100644 index bcb642731..000000000 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/world/ItemVRMixin.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.vivecraft.mixin.client_vr.world; - -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResultHolder; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@Mixin(Item.class) -public class ItemVRMixin { - - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;canEat(Z)Z", shift = At.Shift.BEFORE), method = "use", locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) - private void vivecraft$alwaysAllowEasterEggEating(Level level, Player player, InteractionHand interactionHand, CallbackInfoReturnable> cir, ItemStack itemStack) { - if (itemStack.getHoverName().getString().equals("EAT ME")) { - player.startUsingItem(interactionHand); - cir.setReturnValue(InteractionResultHolder.consume(itemStack)); - } - } -} diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/world/PotionItemVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/world/PotionItemVRMixin.java deleted file mode 100644 index ef99d2f28..000000000 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/world/PotionItemVRMixin.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.vivecraft.mixin.client_vr.world; - -import net.minecraft.client.player.LocalPlayer; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.PotionItem; -import net.minecraft.world.level.Level; -import org.spongepowered.asm.mixin.Mixin; -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_vr.ClientDataHolderVR; -import org.vivecraft.client_vr.VRState; - -@Mixin(PotionItem.class) -public class PotionItemVRMixin { - @Inject(method = "finishUsingItem", at = @At("HEAD")) - private void vivecraft$drinkEasterEgg(ItemStack itemStack, Level level, LivingEntity livingEntity, CallbackInfoReturnable cir) { - if (VRState.vrInitialized && livingEntity instanceof LocalPlayer && itemStack.getHoverName().getString().equals("DRINK ME")) { - ClientDataHolderVR.getInstance().vrPlayer.wfMode = -0.05; - ClientDataHolderVR.getInstance().vrPlayer.wfCount = 400; - } - } -} diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/world/level/block/FenceGateBlockVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/world/level/block/FenceGateBlockVRMixin.java index 150886589..9f2d3d4d2 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/world/level/block/FenceGateBlockVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/world/level/block/FenceGateBlockVRMixin.java @@ -2,13 +2,13 @@ import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; -import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.FenceGateBlock; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.redstone.Orientation; import net.minecraft.world.phys.BlockHitResult; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -30,7 +30,7 @@ public class FenceGateBlockVRMixin { } @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;playSound(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/core/BlockPos;Lnet/minecraft/sounds/SoundEvent;Lnet/minecraft/sounds/SoundSource;FF)V"), method = "neighborChanged", locals = LocalCapture.CAPTURE_FAILHARD) - public void vivecraft$hapticFeedbackOnClose2(BlockState blockState, Level level, BlockPos blockPos, Block block, BlockPos blockPos2, boolean bl, CallbackInfo ci, boolean opening) { + public void vivecraft$hapticFeedbackOnClose2(BlockState blockState, Level level, BlockPos blockPos, Block block, Orientation orientation, boolean bl, CallbackInfo ci, boolean opening) { if (VRState.vrRunning && !opening && Minecraft.getInstance().player != null && Minecraft.getInstance().player.isAlive() && Minecraft.getInstance().player.blockPosition().distSqr(blockPos) < 25.0D) { ClientDataHolderVR.getInstance().vr.triggerHapticPulse(0, 250); } diff --git a/common/src/main/java/org/vivecraft/mixin/server/ServerPlayerMixin.java b/common/src/main/java/org/vivecraft/mixin/server/ServerPlayerMixin.java index b36ccf7bc..ad1ee517e 100644 --- a/common/src/main/java/org/vivecraft/mixin/server/ServerPlayerMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/server/ServerPlayerMixin.java @@ -18,7 +18,7 @@ import net.minecraft.world.entity.projectile.AbstractArrow; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.item.UseAnim; +import net.minecraft.world.item.ItemUseAnimation; import net.minecraft.world.item.alchemy.PotionContents; import net.minecraft.world.item.alchemy.Potions; import net.minecraft.world.level.Level; @@ -95,49 +95,6 @@ public void sweepAttack() { } } - // TODO: this is not needed - @Override - protected void triggerItemUseEffects(ItemStack pStack, int pCount) { - if (!pStack.isEmpty() && this.isUsingItem()) { - if (pStack.getUseAnimation() == UseAnim.DRINK) { - this.playSound(this.getDrinkingSound(pStack), 0.5F, this.level().random.nextFloat() * 0.1F + 0.9F); - } - - if (pStack.getUseAnimation() == UseAnim.EAT) { - this.vivecraft$addItemParticles(pStack, pCount); - this.playSound(this.getEatingSound(pStack), 0.5F + 0.5F * (float) this.random.nextInt(2), - (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F); - } - } - } - - // TODO: this should override "spawnItemParticles", or inject into LivingEntity - @Unique - private void vivecraft$addItemParticles(ItemStack stack, int count) { - ServerVivePlayer serverviveplayer = vivecraft$getVivePlayer(); - for (int i = 0; i < count; ++i) { - Vec3 vec3 = new Vec3(((double) this.random.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D); - vec3 = vec3.xRot(-this.getXRot() * ((float) Math.PI / 180F)); - vec3 = vec3.yRot(-this.getYRot() * ((float) Math.PI / 180F)); - double d0 = (double) (-this.random.nextFloat()) * 0.6D - 0.3D; - Vec3 vec31 = new Vec3(((double) this.random.nextFloat() - 0.5D) * 0.3D, d0, 0.6D); - vec31 = vec31.xRot(-this.getXRot() * ((float) Math.PI / 180F)); - vec31 = vec31.yRot(-this.getYRot() * ((float) Math.PI / 180F)); - vec31 = vec31.add(this.getX(), this.getEyeY(), this.getZ()); - if (serverviveplayer != null && serverviveplayer.isVR()) { - InteractionHand interactionhand = this.getUsedItemHand(); - - if (interactionhand == InteractionHand.MAIN_HAND) { - vec31 = serverviveplayer.getControllerPos(0, this); - } else { - vec31 = serverviveplayer.getControllerPos(1, this); - } - } - this.level().addParticle(new ItemParticleOption(ParticleTypes.ITEM, stack), vec31.x, vec31.y, vec31.z, vec3.x, - vec3.y + 0.05D, vec3.z); - } - } - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z", shift = Shift.BEFORE), method = "drop(Lnet/minecraft/world/item/ItemStack;ZZ)Lnet/minecraft/world/entity/item/ItemEntity;", locals = LocalCapture.CAPTURE_FAILHARD) public void vivecraft$dropvive(ItemStack p_9085_, boolean dropAround, boolean includeName, CallbackInfoReturnable info, @@ -153,8 +110,8 @@ protected void triggerItemUseEffects(ItemStack pStack, int pCount) { } } - @Inject(at = @At("HEAD"), method = "hurt", cancellable = true) - public void vivecraft$checkCanGetHurt(DamageSource damageSource, float f, CallbackInfoReturnable cir) { + @Inject(at = @At("HEAD"), method = "hurtServer", cancellable = true) + public void vivecraft$checkCanGetHurt(ServerLevel serverLevel, DamageSource damageSource, float f, CallbackInfoReturnable cir) { Entity entity = damageSource.getEntity(); ServerPlayer other = null; diff --git a/common/src/main/java/org/vivecraft/mixin/world/entity/LivingEntityMixin.java b/common/src/main/java/org/vivecraft/mixin/world/entity/LivingEntityMixin.java new file mode 100644 index 000000000..b6870bbcd --- /dev/null +++ b/common/src/main/java/org/vivecraft/mixin/world/entity/LivingEntityMixin.java @@ -0,0 +1,81 @@ +package org.vivecraft.mixin.world.entity; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.sugar.Share; +import com.llamalad7.mixinextras.sugar.ref.LocalRef; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.phys.Vec3; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.vivecraft.server.ServerVRPlayers; +import org.vivecraft.server.ServerVivePlayer; + +@Mixin(LivingEntity.class) +public class LivingEntityMixin { + + @WrapOperation(method = {"isLookingAtMe", + "Lnet/minecraft/world/entity/LivingEntity;isLookingAtMe(Lnet/minecraft/world/entity/LivingEntity;DZZLjava/util/function/BiPredicate;[Ljava/util/function/DoubleSupplier;)Z"}, // neoforge + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;getViewVector(F)Lnet/minecraft/world/phys/Vec3;")) + private Vec3 vivecraft$hmdDir(LivingEntity instance, float partialTick, Operation original) { + if (instance instanceof ServerPlayer serverPlayer && ServerVRPlayers.isVRPlayer(serverPlayer)) { + return ServerVRPlayers.getVivePlayer(serverPlayer).getHMDDir(); + } else { + return original.call(instance, partialTick); + } + } + + @WrapOperation(method = {"isLookingAtMe", + "Lnet/minecraft/world/entity/LivingEntity;isLookingAtMe(Lnet/minecraft/world/entity/LivingEntity;DZZLjava/util/function/BiPredicate;[Ljava/util/function/DoubleSupplier;)Z"}, // neoforge + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;getX()D", ordinal = 1)) + private double vivecraft$hmdPosX(LivingEntity instance, Operation original, @Share("hmdPos") LocalRef hmdPos) { + if (instance instanceof ServerPlayer serverPlayer && ServerVRPlayers.isVRPlayer(serverPlayer)) { + hmdPos.set(ServerVRPlayers.getVivePlayer(serverPlayer).getHMDPos(serverPlayer)); + return hmdPos.get().x; + } else { + return original.call(instance); + } + } + + @WrapOperation(method = {"isLookingAtMe", + "Lnet/minecraft/world/entity/LivingEntity;isLookingAtMe(Lnet/minecraft/world/entity/LivingEntity;DZZLjava/util/function/BiPredicate;[Ljava/util/function/DoubleSupplier;)Z"}, // neoforge + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;getEyeY()D")) + private double vivecraft$hmdPosY(LivingEntity instance, Operation original, @Share("hmdPos") LocalRef hmdPos) { + return hmdPos.get() != null ? hmdPos.get().y : original.call(instance); + } + + @WrapOperation(method = {"isLookingAtMe", + "Lnet/minecraft/world/entity/LivingEntity;isLookingAtMe(Lnet/minecraft/world/entity/LivingEntity;DZZLjava/util/function/BiPredicate;[Ljava/util/function/DoubleSupplier;)Z"}, // neoforge + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;getZ()D", ordinal = 1)) + private double vivecraft$hmdPosZ(LivingEntity instance, Operation original, @Share("hmdPos") LocalRef hmdPos) { + return hmdPos.get() != null ? hmdPos.get().z : original.call(instance); + } + + @WrapOperation(method = "hasLineOfSight(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/level/ClipContext$Block;Lnet/minecraft/world/level/ClipContext$Fluid;Ljava/util/function/DoubleSupplier;)Z", at = @At(value = "NEW", target = "net/minecraft/world/phys/Vec3", ordinal = 0)) + private Vec3 vivecraft$modifyOwnHeadPos(double x, double y, double z, Operation original) { + if ((Object) this instanceof ServerPlayer player) { + ServerVivePlayer serverVivePlayer = ServerVRPlayers.getVivePlayer(player); + if (serverVivePlayer != null && serverVivePlayer.isVR()) { + return serverVivePlayer.getHMDPos(player); + } + } + return original.call(x, y, z); + } + + @WrapOperation(method = "hasLineOfSight(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/level/ClipContext$Block;Lnet/minecraft/world/level/ClipContext$Fluid;Ljava/util/function/DoubleSupplier;)Z", at = @At(value = "NEW", target = "net/minecraft/world/phys/Vec3", ordinal = 1)) + private Vec3 vivecraft$modifyOtherHeadPos( + double x, double y, double z, Operation original, @Local(argsOnly = true) Entity other) { + if (other instanceof ServerPlayer player) { + ServerVivePlayer serverVivePlayer = ServerVRPlayers.getVivePlayer(player); + if (serverVivePlayer != null && serverVivePlayer.isVR()) { + Vec3 hmdPos = serverVivePlayer.getHMDPos(player); + // only use the hmd if it's meant to be the eye height + return original.call(hmdPos.x, y == other.getEyeY() ? hmdPos.y : y, hmdPos.z); + } + } + return original.call(x, y, z); + } +} diff --git a/common/src/main/java/org/vivecraft/mixin/world/entity/monster/EndermanMixin.java b/common/src/main/java/org/vivecraft/mixin/world/entity/monster/EndermanMixin.java index 792061d6e..9f9780819 100644 --- a/common/src/main/java/org/vivecraft/mixin/world/entity/monster/EndermanMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/world/entity/monster/EndermanMixin.java @@ -1,58 +1,21 @@ package org.vivecraft.mixin.world.entity.monster; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.sugar.Local; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.monster.EnderMan; -import net.minecraft.world.entity.monster.Monster; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -import net.minecraft.world.level.ClipContext; -import net.minecraft.world.level.Level; -import net.minecraft.world.phys.HitResult; -import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; -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.server.ServerVRPlayers; -import org.vivecraft.server.ServerVivePlayer; @Mixin(EnderMan.class) -public abstract class EndermanMixin extends Monster { +public abstract class EndermanMixin { - protected EndermanMixin(EntityType entityType, Level level) { - super(entityType, level); - } - - @Inject(at = @At("HEAD"), method = "Lnet/minecraft/world/entity/monster/EnderMan;isLookingAtMe(Lnet/minecraft/world/entity/player/Player;)Z", cancellable = true) - public void vivecraft$lookAtVR(Player player, CallbackInfoReturnable cir) { - if (ServerVRPlayers.isVRPlayer((ServerPlayer) player)) { - cir.setReturnValue(vivecraft$shouldEndermanAttackVRPlayer((EnderMan) (Object) this, (ServerPlayer) player)); - } - } - - @Unique - private static boolean vivecraft$shouldEndermanAttackVRPlayer(EnderMan enderman, ServerPlayer player) { - ItemStack itemstack = player.getInventory().armor.get(3); - if (!itemstack.is(Items.CARVED_PUMPKIN)) { //no enderitem - ServerVivePlayer data = ServerVRPlayers.getVivePlayer(player); - Vec3 vector3d = data.getHMDDir(); - Vec3 vector3d1 = new Vec3(enderman.getX() - data.getHMDPos(player).x, enderman.getEyeY() - data.getHMDPos(player).y, enderman.getZ() - data.getHMDPos(player).z); - double d0 = vector3d1.length(); - vector3d1 = vector3d1.normalize(); - double d1 = vector3d.dot(vector3d1); - return d1 > 1.0D - 0.025D / d0 && d0 < 128.0 && vivecraft$canEntityBeSeen(enderman, data.getHMDPos(player)); - } - - return false; - } - - @Unique - private static boolean vivecraft$canEntityBeSeen(Entity entity, Vec3 playerEyePos) { - Vec3 entityEyePos = new Vec3(entity.getX(), entity.getEyeY(), entity.getZ()); - return entity.level().clip(new ClipContext(playerEyePos, entityEyePos, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, entity)).getType() == HitResult.Type.MISS; + @ModifyExpressionValue(method = "isBeingStaredBy", at = @At(value = "CONSTANT", args = "doubleValue=0.025")) + private double vivecraft$biggerViewCone(double original, @Local(argsOnly = true) Player player) { + // increase the view cone check from 1.4° to 5.7°, makes it easier to stop enderman, + // since it's hard to know where the center of the view is + return player instanceof ServerPlayer serverPlayer && ServerVRPlayers.isVRPlayer(serverPlayer) ? 0.1 : original; } } diff --git a/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/FishingHookMixin.java b/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/FishingHookMixin.java index c008c6ff2..83f68dc6a 100644 --- a/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/FishingHookMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/FishingHookMixin.java @@ -31,7 +31,7 @@ protected FishingHookMixin(EntityType p_37248_, Level p_37 @Unique private Vec3 vivecraft$controllerPos = null; - @ModifyVariable(at = @At(value = "STORE"), method = "(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/Level;II)V", ordinal = 0) + @ModifyVariable(at = @At(value = "STORE"), method = "(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/Level;IILnet/minecraft/world/item/ItemStack;)V", ordinal = 0) private float vivecraft$modifyXrot(float xRot, Player player) { // some mods like Aquaculture create a FishingHook on the client with a LocalPlayer // this is nonsense, so just ignore it @@ -50,7 +50,7 @@ protected FishingHookMixin(EntityType p_37248_, Level p_37 } } - @ModifyVariable(at = @At(value = "STORE"), method = "(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/Level;II)V", ordinal = 1) + @ModifyVariable(at = @At(value = "STORE"), method = "(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/Level;IILnet/minecraft/world/item/ItemStack;)V", ordinal = 1) private float vivecraft$modifyYrot(float yRot) { if (vivecraft$serverviveplayer != null && vivecraft$serverviveplayer.isVR()) { return (float) Math.toDegrees(Math.atan2(-vivecraft$controllerDir.x, vivecraft$controllerDir.z)); @@ -59,7 +59,7 @@ protected FishingHookMixin(EntityType p_37248_, Level p_37 } } - @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/FishingHook;moveTo(DDDFF)V"), method = "(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/Level;II)V") + @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/FishingHook;moveTo(DDDFF)V"), method = "(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/Level;IILnet/minecraft/world/item/ItemStack;)V") private void vivecraft$modifyMoveTo(FishingHook instance, double x, double y, double z, float yRot, float xRot) { if (vivecraft$serverviveplayer != null && vivecraft$serverviveplayer.isVR()) { instance.moveTo(vivecraft$controllerPos.x + vivecraft$controllerDir.x * (double) 0.6F, vivecraft$controllerPos.y + vivecraft$controllerDir.y * (double) 0.6F, vivecraft$controllerPos.z + vivecraft$controllerDir.z * (double) 0.6F, yRot, xRot); diff --git a/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/ThrowableProjectileMixin.java b/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/ThrowableItemProjectileMixin.java similarity index 68% rename from common/src/main/java/org/vivecraft/mixin/world/entity/projectile/ThrowableProjectileMixin.java rename to common/src/main/java/org/vivecraft/mixin/world/entity/projectile/ThrowableItemProjectileMixin.java index 08c71d3d4..8832bdfa3 100644 --- a/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/ThrowableProjectileMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/ThrowableItemProjectileMixin.java @@ -4,9 +4,9 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.Projectile; -import net.minecraft.world.entity.projectile.ThrowableProjectile; +import net.minecraft.world.entity.projectile.ThrowableItemProjectile; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; @@ -16,20 +16,20 @@ import org.vivecraft.server.ServerVRPlayers; import org.vivecraft.server.ServerVivePlayer; -@Mixin(ThrowableProjectile.class) -public abstract class ThrowableProjectileMixin extends Entity { +@Mixin(ThrowableItemProjectile.class) +public abstract class ThrowableItemProjectileMixin extends Entity { - protected ThrowableProjectileMixin(EntityType p_37248_, Level p_37249_) { + protected ThrowableItemProjectileMixin(EntityType p_37248_, Level p_37249_) { super(p_37248_, p_37249_); // TODO Auto-generated constructor stub } - @Inject(at = @At("TAIL"), method = "(Lnet/minecraft/world/entity/EntityType;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/level/Level;)V") - public void vivecraft$init(EntityType p_37462_, LivingEntity p_37463_, Level p_37464_, CallbackInfo info) { - if (p_37463_ instanceof ServerPlayer player) { + @Inject(at = @At("TAIL"), method = "(Lnet/minecraft/world/entity/EntityType;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/item/ItemStack;)V") + public void vivecraft$init(EntityType entityType, LivingEntity livingEntity, Level level, ItemStack itemStack, CallbackInfo ci) { + if (livingEntity instanceof ServerPlayer player) { ServerVivePlayer serverviveplayer = ServerVRPlayers.getVivePlayer(player); if (serverviveplayer != null && serverviveplayer.isVR()) { - Vec3 vec3 = serverviveplayer.getControllerPos(serverviveplayer.activeHand, (Player) p_37463_); + Vec3 vec3 = serverviveplayer.getControllerPos(serverviveplayer.activeHand, player); Vec3 vec31 = serverviveplayer.getControllerDir(serverviveplayer.activeHand).scale(0.6F); this.setPos(vec3.x + vec31.x, vec3.y + vec31.y, vec3.z + vec31.z); } diff --git a/common/src/main/java/org/vivecraft/mod_compat_vr/optifine/OptifineHelper.java b/common/src/main/java/org/vivecraft/mod_compat_vr/optifine/OptifineHelper.java index 1b547fe39..b5458f151 100644 --- a/common/src/main/java/org/vivecraft/mod_compat_vr/optifine/OptifineHelper.java +++ b/common/src/main/java/org/vivecraft/mod_compat_vr/optifine/OptifineHelper.java @@ -11,6 +11,7 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.lang.reflect.RecordComponent; public class OptifineHelper { @@ -54,6 +55,10 @@ public class OptifineHelper { private static Field optionsOfCloudHeight; private static Field optionsOfAoLevel; private static Field vertexRenderPositions; + private static Method VertexRecord_renderPositions; + + private static Method Mutable_get; + private static Method Mutable_set; public static boolean isOptifineLoaded() { if (!checkedForOptifine) { @@ -288,6 +293,12 @@ public static void copyRenderPositions(ModelPart.Vertex source, ModelPart.Vertex } catch (IllegalAccessException e) { e.printStackTrace(); } + } else if (VertexRecord_renderPositions != null) { + try { + Mutable_set.invoke(VertexRecord_renderPositions.invoke(dest), Mutable_get.invoke(VertexRecord_renderPositions.invoke(source))); + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } } } @@ -346,6 +357,24 @@ private static void init() { } catch (NoSuchFieldException e) { // this version doesn't have the entity render improvements vertexRenderPositions = null; + // check if record type + if (ModelPart.Vertex.class.isRecord()) { + // check for mutable renderPositions + for (RecordComponent comp : ModelPart.Vertex.class.getRecordComponents()) { + if (comp.getName().equals("renderPositions")) { + VertexRecord_renderPositions = comp.getAccessor(); + } + } + } + try { + Class Mutable = Class.forName("net.optifine.util.Mutable"); + Mutable_get = Mutable.getMethod("get"); + Mutable_set = Mutable.getMethod("set", Object.class); + } catch (ClassNotFoundException | NoSuchMethodException eRecord) { + VertexRecord_renderPositions = null; + Mutable_get = null; + Mutable_set = null; + } } } catch (ClassNotFoundException e) { VRSettings.logger.error("Optifine detected, but couldn't load class: {}", e.getMessage()); diff --git a/common/src/main/resources/assets/minecraft/shaders/core/blit_aspect.json b/common/src/main/resources/assets/minecraft/shaders/core/blit_aspect.json deleted file mode 100644 index 82a1d90c6..000000000 --- a/common/src/main/resources/assets/minecraft/shaders/core/blit_aspect.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "vertex": "blit_aspect", - "fragment": "blit_aspect", - "attributes": ["Position", "UV0"], - "samplers": [ - { - "name": "DiffuseSampler" - } - ], - "uniforms": [] -} diff --git a/common/src/main/resources/assets/minecraft/shaders/post/vrtransparency.json b/common/src/main/resources/assets/minecraft/shaders/post/vrtransparency.json deleted file mode 100644 index bcd34d9b5..000000000 --- a/common/src/main/resources/assets/minecraft/shaders/post/vrtransparency.json +++ /dev/null @@ -1,96 +0,0 @@ -{ - "targets": [ - "water", - "translucent", - "itemEntity", - "particles", - "clouds", - "weather", - "vroccluded", - "vrunoccluded", - "vrhands", - "final" - ], - "passes": [ - { - "name": "vrtransparency", - "intarget": "minecraft:main", - "outtarget": "final", - "auxtargets": [ - { - "name": "DiffuseDepthSampler", - "id": "minecraft:main:depth" - }, - { - "name": "TranslucentSampler", - "id": "translucent" - }, - { - "name": "TranslucentDepthSampler", - "id": "translucent:depth" - }, - { - "name": "ItemEntitySampler", - "id": "itemEntity" - }, - { - "name": "ItemEntityDepthSampler", - "id": "itemEntity:depth" - }, - { - "name": "ParticlesSampler", - "id": "particles" - }, - { - "name": "ParticlesDepthSampler", - "id": "particles:depth" - }, - { - "name": "CloudsSampler", - "id": "clouds" - }, - { - "name": "CloudsDepthSampler", - "id": "clouds:depth" - }, - { - "name": "WeatherSampler", - "id": "weather" - }, - { - "name": "WeatherDepthSampler", - "id": "weather:depth" - }, - { - "name": "VrOccludedSampler", - "id": "vroccluded" - }, - { - "name": "VrOccludedDepthSampler", - "id": "vroccluded:depth" - }, - { - "name": "VrUnoccludedSampler", - "id": "vrunoccluded" - }, - { - "name": "VrUnoccludedDepthSampler", - "id": "vrunoccluded:depth" - }, - { - "name": "VrHandsSampler", - "id": "vrhands" - }, - { - "name": "VrHandsDepthSampler", - "id": "vrhands:depth" - } - ] - }, - { - "name": "blit", - "intarget": "final", - "outtarget": "minecraft:main" - } - ] -} diff --git a/common/src/main/resources/assets/vivecraft/models/camcorder.json b/common/src/main/resources/assets/vivecraft/models/item/camcorder.json similarity index 100% rename from common/src/main/resources/assets/vivecraft/models/camcorder.json rename to common/src/main/resources/assets/vivecraft/models/item/camcorder.json diff --git a/common/src/main/resources/assets/vivecraft/models/camcorder_display.json b/common/src/main/resources/assets/vivecraft/models/item/camcorder_display.json similarity index 100% rename from common/src/main/resources/assets/vivecraft/models/camcorder_display.json rename to common/src/main/resources/assets/vivecraft/models/item/camcorder_display.json diff --git a/common/src/main/resources/assets/vivecraft/models/camera.json b/common/src/main/resources/assets/vivecraft/models/item/camera.json similarity index 100% rename from common/src/main/resources/assets/vivecraft/models/camera.json rename to common/src/main/resources/assets/vivecraft/models/item/camera.json diff --git a/common/src/main/resources/assets/vivecraft/models/camera_display.json b/common/src/main/resources/assets/vivecraft/models/item/camera_display.json similarity index 100% rename from common/src/main/resources/assets/vivecraft/models/camera_display.json rename to common/src/main/resources/assets/vivecraft/models/item/camera_display.json diff --git a/common/src/main/resources/assets/vivecraft/models/item/spyglass_in_hand.json b/common/src/main/resources/assets/vivecraft/models/item/spyglass_in_hand.json index ce491e646..6de9ab7c2 100644 --- a/common/src/main/resources/assets/vivecraft/models/item/spyglass_in_hand.json +++ b/common/src/main/resources/assets/vivecraft/models/item/spyglass_in_hand.json @@ -68,10 +68,6 @@ "ground": { "rotation": [90, 0, 0] }, - "gui": { - "rotation": [-67.5, 0, 45], - "scale": [1.5, 1.5, 1.5] - }, "head": { "rotation": [90, 0, 0], "translation": [0, 0, -16], diff --git a/common/src/main/resources/assets/vivecraft/post_effect/vrtransparency.json b/common/src/main/resources/assets/vivecraft/post_effect/vrtransparency.json new file mode 100644 index 000000000..222dd4cc6 --- /dev/null +++ b/common/src/main/resources/assets/vivecraft/post_effect/vrtransparency.json @@ -0,0 +1,104 @@ +{ + "targets": { + "final": {} + }, + "passes": [ + { + "program": "vivecraft:post/vrtransparency", + "inputs": [ + { + "sampler_name": "Main", + "target": "minecraft:main" + }, + { + "sampler_name": "MainDepth", + "target": "minecraft:main", + "use_depth_buffer": true + }, + { + "sampler_name": "Translucent", + "target": "minecraft:translucent" + }, + { + "sampler_name": "TranslucentDepth", + "target": "minecraft:translucent", + "use_depth_buffer": true + }, + { + "sampler_name": "ItemEntity", + "target": "minecraft:item_entity" + }, + { + "sampler_name": "ItemEntityDepth", + "target": "minecraft:item_entity", + "use_depth_buffer": true + }, + { + "sampler_name": "Particles", + "target": "minecraft:particles" + }, + { + "sampler_name": "ParticlesDepth", + "target": "minecraft:particles", + "use_depth_buffer": true + }, + { + "sampler_name": "Clouds", + "target": "minecraft:clouds" + }, + { + "sampler_name": "CloudsDepth", + "target": "minecraft:clouds", + "use_depth_buffer": true + }, + { + "sampler_name": "Weather", + "target": "minecraft:weather" + }, + { + "sampler_name": "WeatherDepth", + "target": "minecraft:weather", + "use_depth_buffer": true + }, + { + "sampler_name": "VrOccluded", + "target": "vivecraft:vroccluded" + }, + { + "sampler_name": "VrOccludedDepth", + "target": "vivecraft:vroccluded", + "use_depth_buffer": true + }, + { + "sampler_name": "VrUnoccluded", + "target": "vivecraft:vrunoccluded" + }, + { + "sampler_name": "VrUnoccludedDepth", + "target": "vivecraft:vrunoccluded", + "use_depth_buffer": true + }, + { + "sampler_name": "VrHands", + "target": "vivecraft:vrhands" + }, + { + "sampler_name": "VrHandsDepth", + "target": "vivecraft:vrhands", + "use_depth_buffer": true + } + ], + "output": "final" + }, + { + "program": "minecraft:post/blit", + "inputs": [ + { + "sampler_name": "In", + "target": "final" + } + ], + "output": "minecraft:main" + } + ] +} diff --git a/common/src/main/resources/assets/minecraft/shaders/core/blit_aspect.fsh b/common/src/main/resources/assets/vivecraft/shaders/core/blit_aspect.fsh similarity index 100% rename from common/src/main/resources/assets/minecraft/shaders/core/blit_aspect.fsh rename to common/src/main/resources/assets/vivecraft/shaders/core/blit_aspect.fsh diff --git a/common/src/main/resources/assets/vivecraft/shaders/core/blit_aspect.json b/common/src/main/resources/assets/vivecraft/shaders/core/blit_aspect.json new file mode 100644 index 000000000..bd3845b50 --- /dev/null +++ b/common/src/main/resources/assets/vivecraft/shaders/core/blit_aspect.json @@ -0,0 +1,10 @@ +{ + "vertex": "vivecraft:core/blit_aspect", + "fragment": "vivecraft:core/blit_aspect", + "samplers": [ + { + "name": "DiffuseSampler" + } + ], + "uniforms": [] +} diff --git a/common/src/main/resources/assets/minecraft/shaders/core/blit_aspect.vsh b/common/src/main/resources/assets/vivecraft/shaders/core/blit_aspect.vsh similarity index 100% rename from common/src/main/resources/assets/minecraft/shaders/core/blit_aspect.vsh rename to common/src/main/resources/assets/vivecraft/shaders/core/blit_aspect.vsh diff --git a/common/src/main/resources/assets/minecraft/shaders/core/fovreduction.fsh b/common/src/main/resources/assets/vivecraft/shaders/core/fovreduction.fsh similarity index 100% rename from common/src/main/resources/assets/minecraft/shaders/core/fovreduction.fsh rename to common/src/main/resources/assets/vivecraft/shaders/core/fovreduction.fsh diff --git a/common/src/main/resources/assets/minecraft/shaders/core/fovreduction.json b/common/src/main/resources/assets/vivecraft/shaders/core/fovreduction.json similarity index 89% rename from common/src/main/resources/assets/minecraft/shaders/core/fovreduction.json rename to common/src/main/resources/assets/vivecraft/shaders/core/fovreduction.json index 43d8eb296..017484281 100644 --- a/common/src/main/resources/assets/minecraft/shaders/core/fovreduction.json +++ b/common/src/main/resources/assets/vivecraft/shaders/core/fovreduction.json @@ -1,12 +1,6 @@ { - "blend": { - "func": "add", - "srcrgb": "srcalpha", - "dstrgb": "1-srcalpha" - }, - "vertex": "fovreduction", - "fragment": "fovreduction", - "attributes": ["Position", "UV0"], + "vertex": "vivecraft:core/fovreduction", + "fragment": "vivecraft:core/fovreduction", "samplers": [ { "name": "Sampler0" diff --git a/common/src/main/resources/assets/minecraft/shaders/core/fovreduction.vsh b/common/src/main/resources/assets/vivecraft/shaders/core/fovreduction.vsh similarity index 100% rename from common/src/main/resources/assets/minecraft/shaders/core/fovreduction.vsh rename to common/src/main/resources/assets/vivecraft/shaders/core/fovreduction.vsh diff --git a/common/src/main/resources/assets/minecraft/shaders/core/lanczos.fsh b/common/src/main/resources/assets/vivecraft/shaders/core/lanczos.fsh similarity index 100% rename from common/src/main/resources/assets/minecraft/shaders/core/lanczos.fsh rename to common/src/main/resources/assets/vivecraft/shaders/core/lanczos.fsh diff --git a/common/src/main/resources/assets/minecraft/shaders/core/lanczos.json b/common/src/main/resources/assets/vivecraft/shaders/core/lanczos.json similarity index 66% rename from common/src/main/resources/assets/minecraft/shaders/core/lanczos.json rename to common/src/main/resources/assets/vivecraft/shaders/core/lanczos.json index 1475f40e8..a11d645be 100644 --- a/common/src/main/resources/assets/minecraft/shaders/core/lanczos.json +++ b/common/src/main/resources/assets/vivecraft/shaders/core/lanczos.json @@ -1,12 +1,6 @@ { - "blend": { - "func": "add", - "srcrgb": "srcalpha", - "dstrgb": "1-srcalpha" - }, - "vertex": "lanczos", - "fragment": "lanczos", - "attributes": ["Position", "UV0"], + "vertex": "vivecraft:core/lanczos", + "fragment": "vivecraft:core/lanczos", "samplers": [ { "name": "Sampler0" diff --git a/common/src/main/resources/assets/minecraft/shaders/core/lanczos.vsh b/common/src/main/resources/assets/vivecraft/shaders/core/lanczos.vsh similarity index 100% rename from common/src/main/resources/assets/minecraft/shaders/core/lanczos.vsh rename to common/src/main/resources/assets/vivecraft/shaders/core/lanczos.vsh diff --git a/common/src/main/resources/assets/minecraft/shaders/core/mixedreality.fsh b/common/src/main/resources/assets/vivecraft/shaders/core/mixedreality.fsh similarity index 100% rename from common/src/main/resources/assets/minecraft/shaders/core/mixedreality.fsh rename to common/src/main/resources/assets/vivecraft/shaders/core/mixedreality.fsh diff --git a/common/src/main/resources/assets/minecraft/shaders/core/mixedreality.json b/common/src/main/resources/assets/vivecraft/shaders/core/mixedreality.json similarity index 85% rename from common/src/main/resources/assets/minecraft/shaders/core/mixedreality.json rename to common/src/main/resources/assets/vivecraft/shaders/core/mixedreality.json index b167a1dba..120e65620 100644 --- a/common/src/main/resources/assets/minecraft/shaders/core/mixedreality.json +++ b/common/src/main/resources/assets/vivecraft/shaders/core/mixedreality.json @@ -1,12 +1,6 @@ { - "blend": { - "func": "add", - "srcrgb": "srcalpha", - "dstrgb": "1-srcalpha" - }, - "vertex": "passthrough", - "fragment": "mixedreality", - "attributes": ["Position", "UV0"], + "vertex": "vivecraft:core/passthrough", + "fragment": "vivecraft:core/mixedreality", "samplers": [ { "name": "thirdPersonColor" diff --git a/common/src/main/resources/assets/minecraft/shaders/core/passthrough.vsh b/common/src/main/resources/assets/vivecraft/shaders/core/passthrough.vsh similarity index 100% rename from common/src/main/resources/assets/minecraft/shaders/core/passthrough.vsh rename to common/src/main/resources/assets/vivecraft/shaders/core/passthrough.vsh diff --git a/common/src/main/resources/assets/minecraft/shaders/core/rendertype_end_gateway_vr.json b/common/src/main/resources/assets/vivecraft/shaders/core/rendertype_end_gateway_vr.json similarity index 81% rename from common/src/main/resources/assets/minecraft/shaders/core/rendertype_end_gateway_vr.json rename to common/src/main/resources/assets/vivecraft/shaders/core/rendertype_end_gateway_vr.json index 15b6541d6..50941cda7 100644 --- a/common/src/main/resources/assets/minecraft/shaders/core/rendertype_end_gateway_vr.json +++ b/common/src/main/resources/assets/vivecraft/shaders/core/rendertype_end_gateway_vr.json @@ -1,12 +1,6 @@ { - "blend": { - "func": "add", - "srcrgb": "srcalpha", - "dstrgb": "1-srcalpha" - }, - "vertex": "rendertype_end_portal_vr", - "fragment": "rendertype_end_portal_vr", - "attributes": [], + "vertex": "vivecraft:core/rendertype_end_portal_vr", + "fragment": "vivecraft:core/rendertype_end_portal_vr", "samplers": [ { "name": "Sampler0" diff --git a/common/src/main/resources/assets/minecraft/shaders/core/rendertype_end_portal_vr.fsh b/common/src/main/resources/assets/vivecraft/shaders/core/rendertype_end_portal_vr.fsh similarity index 100% rename from common/src/main/resources/assets/minecraft/shaders/core/rendertype_end_portal_vr.fsh rename to common/src/main/resources/assets/vivecraft/shaders/core/rendertype_end_portal_vr.fsh diff --git a/common/src/main/resources/assets/minecraft/shaders/core/rendertype_end_portal_vr.json b/common/src/main/resources/assets/vivecraft/shaders/core/rendertype_end_portal_vr.json similarity index 81% rename from common/src/main/resources/assets/minecraft/shaders/core/rendertype_end_portal_vr.json rename to common/src/main/resources/assets/vivecraft/shaders/core/rendertype_end_portal_vr.json index edec87990..78254068a 100644 --- a/common/src/main/resources/assets/minecraft/shaders/core/rendertype_end_portal_vr.json +++ b/common/src/main/resources/assets/vivecraft/shaders/core/rendertype_end_portal_vr.json @@ -1,12 +1,6 @@ { - "blend": { - "func": "add", - "srcrgb": "srcalpha", - "dstrgb": "1-srcalpha" - }, - "vertex": "rendertype_end_portal_vr", - "fragment": "rendertype_end_portal_vr", - "attributes": [], + "vertex": "vivecraft:core/rendertype_end_portal_vr", + "fragment": "vivecraft:core/rendertype_end_portal_vr", "samplers": [ { "name": "Sampler0" diff --git a/common/src/main/resources/assets/minecraft/shaders/core/rendertype_end_portal_vr.vsh b/common/src/main/resources/assets/vivecraft/shaders/core/rendertype_end_portal_vr.vsh similarity index 100% rename from common/src/main/resources/assets/minecraft/shaders/core/rendertype_end_portal_vr.vsh rename to common/src/main/resources/assets/vivecraft/shaders/core/rendertype_end_portal_vr.vsh diff --git a/common/src/main/resources/assets/vivecraft/shaders/fovreduction.fsh b/common/src/main/resources/assets/vivecraft/shaders/fovreduction.fsh deleted file mode 100644 index 1be21d6fc..000000000 --- a/common/src/main/resources/assets/vivecraft/shaders/fovreduction.fsh +++ /dev/null @@ -1,71 +0,0 @@ -#version 120 - -uniform sampler2D tex0; -uniform float circle_radius; -uniform float circle_offset = 0.1; -uniform float border; - -uniform float water; -uniform float portal; -uniform float pumpkin; - -uniform float portaltime; -uniform float redalpha; -uniform float bluealpha; -uniform float blackalpha; - -const vec4 black = vec4(0, 0, 0, 1.0); -const vec4 orange = vec4(.25, .125, 0, 1.0); -const float pi = 3.14159265; - -uniform int eye = 0; - -void main(){ - - vec4 bkg_color = texture2D(tex0, gl_TexCoord[0].st); - - if (portal > 0){ //swirly whirly - float ts = gl_TexCoord[0].s; - vec2 mod_texcoord = gl_TexCoord[0].st + vec2(portal*.005*cos(portaltime + 20*ts*pi), portal*.005*sin(portaltime + 30*ts*pi)); - bkg_color = texture2D(tex0, mod_texcoord); - } - - if (water > 0){ //goobly woobly - float ts = gl_TexCoord[0].s; - vec2 mod_texcoord = gl_TexCoord[0].st + vec2(0, water*.0010*sin(portaltime + 10*ts*pi)); - bkg_color = texture2D(tex0, mod_texcoord); - vec4 blue = vec4(0, 0, bkg_color.b, 1.0); - bkg_color = mix(bkg_color, blue, 0.1); - - } - - if (redalpha > 0){ //ouchy wouchy - vec4 red = vec4(bkg_color.r, 0, 0, 1.0); - bkg_color = mix(bkg_color, red, redalpha); - } - - if (bluealpha > 0){ //chilly willy - vec4 blue = vec4(0, bkg_color.g/2.0, bkg_color.b, 1.0); - bkg_color = mix(bkg_color, blue, bluealpha); - } - - if (blackalpha > 0){ //spooky wooky - bkg_color = mix(bkg_color, black, blackalpha); - } - - if (circle_radius < 0.8){ //arfy barfy - vec2 circle_center = vec2(0.5 + eye*circle_offset, 0.5); - vec2 uv = gl_TexCoord[0].xy; - uv -= circle_center; - float dist = sqrt(dot(uv, uv)); - float t = 1.0 + smoothstep(circle_radius, circle_radius+10, dist) - smoothstep(circle_radius-border, circle_radius, dist); - if (pumpkin>0){ - bkg_color = mix(orange, bkg_color, t); - } else { - bkg_color = mix(black, bkg_color, t); - } - } - - gl_FragColor = bkg_color; - -} diff --git a/common/src/main/resources/assets/vivecraft/shaders/lanczos.fsh b/common/src/main/resources/assets/vivecraft/shaders/lanczos.fsh deleted file mode 100644 index e8df8af76..000000000 --- a/common/src/main/resources/assets/vivecraft/shaders/lanczos.fsh +++ /dev/null @@ -1,52 +0,0 @@ -#version 150 core -uniform sampler2D inputImageTexture; -uniform sampler2D inputDepthTexture; - -in vec2 centerTextureCoordinate; -in vec2 oneStepLeftTextureCoordinate; -in vec2 twoStepsLeftTextureCoordinate; -in vec2 threeStepsLeftTextureCoordinate; -in vec2 fourStepsLeftTextureCoordinate; -in vec2 oneStepRightTextureCoordinate; -in vec2 twoStepsRightTextureCoordinate; -in vec2 threeStepsRightTextureCoordinate; -in vec2 fourStepsRightTextureCoordinate; -out vec4 fragColor; -// sinc(x) * sinc(x/a) = (a * sin(pi * x) * sin(pi * x / a)) / (pi^2 * x^2) -// Assuming a Lanczos constant of 2.0, and scaling values to max out at x = +/- 1.5 - -void main() -{ - vec4 fragmentColor = texture2D(inputImageTexture, centerTextureCoordinate) * 0.38026; - - fragmentColor += texture2D(inputImageTexture, oneStepLeftTextureCoordinate) * 0.27667; - fragmentColor += texture2D(inputImageTexture, oneStepRightTextureCoordinate) * 0.27667; - - fragmentColor += texture2D(inputImageTexture, twoStepsLeftTextureCoordinate) * 0.08074; - fragmentColor += texture2D(inputImageTexture, twoStepsRightTextureCoordinate) * 0.08074; - - fragmentColor += texture2D(inputImageTexture, threeStepsLeftTextureCoordinate) * -0.02612; - fragmentColor += texture2D(inputImageTexture, threeStepsRightTextureCoordinate) * -0.02612; - - fragmentColor += texture2D(inputImageTexture, fourStepsLeftTextureCoordinate) * -0.02143; - fragmentColor += texture2D(inputImageTexture, fourStepsRightTextureCoordinate) * -0.02143; - - fragColor = fragmentColor; - - float depth = texture2D(inputDepthTexture, centerTextureCoordinate).r * 0.38026; - - depth += texture2D(inputDepthTexture, oneStepLeftTextureCoordinate).r * 0.27667; - depth += texture2D(inputDepthTexture, oneStepRightTextureCoordinate).r * 0.27667; - - depth += texture2D(inputDepthTexture, twoStepsLeftTextureCoordinate).r * 0.08074; - depth += texture2D(inputDepthTexture, twoStepsRightTextureCoordinate).r * 0.08074; - - depth += texture2D(inputDepthTexture, threeStepsLeftTextureCoordinate).r * -0.02612; - depth += texture2D(inputDepthTexture, threeStepsRightTextureCoordinate).r * -0.02612; - - depth += texture2D(inputDepthTexture, fourStepsLeftTextureCoordinate).r * -0.02143; - depth += texture2D(inputDepthTexture, fourStepsRightTextureCoordinate).r * -0.02143; - - gl_FragDepth = depth; - -} diff --git a/common/src/main/resources/assets/vivecraft/shaders/lanczos.vsh b/common/src/main/resources/assets/vivecraft/shaders/lanczos.vsh deleted file mode 100644 index 487611c04..000000000 --- a/common/src/main/resources/assets/vivecraft/shaders/lanczos.vsh +++ /dev/null @@ -1,38 +0,0 @@ -#version 150 core - -uniform float texelWidthOffset; -uniform float texelHeightOffset; -uniform mat4 projection; -uniform mat4 modelView; -in vec3 in_Position; -in vec2 in_TextureCoord; -out vec2 centerTextureCoordinate; -out vec2 oneStepLeftTextureCoordinate; -out vec2 twoStepsLeftTextureCoordinate; -out vec2 threeStepsLeftTextureCoordinate; -out vec2 fourStepsLeftTextureCoordinate; -out vec2 oneStepRightTextureCoordinate; -out vec2 twoStepsRightTextureCoordinate; -out vec2 threeStepsRightTextureCoordinate; -out vec2 fourStepsRightTextureCoordinate; - -void main() -{ - gl_Position = projection * modelView * vec4(in_Position, 1.0); - - vec2 firstOffset = vec2(texelWidthOffset, texelHeightOffset); - vec2 secondOffset = vec2(2.0 * texelWidthOffset, 2.0 * texelHeightOffset); - vec2 thirdOffset = vec2(3.0 * texelWidthOffset, 3.0 * texelHeightOffset); - vec2 fourthOffset = vec2(4.0 * texelWidthOffset, 4.0 * texelHeightOffset); - - vec2 textCoord = in_TextureCoord; - centerTextureCoordinate = textCoord; - oneStepLeftTextureCoordinate = textCoord - firstOffset; - twoStepsLeftTextureCoordinate = textCoord - secondOffset; - threeStepsLeftTextureCoordinate = textCoord - thirdOffset; - fourStepsLeftTextureCoordinate = textCoord - fourthOffset; - oneStepRightTextureCoordinate = textCoord + firstOffset; - twoStepsRightTextureCoordinate = textCoord + secondOffset; - threeStepsRightTextureCoordinate = textCoord + thirdOffset; - fourStepsRightTextureCoordinate = textCoord + fourthOffset; -} diff --git a/common/src/main/resources/assets/vivecraft/shaders/mixedreality.fsh b/common/src/main/resources/assets/vivecraft/shaders/mixedreality.fsh deleted file mode 100644 index 8846c7490..000000000 --- a/common/src/main/resources/assets/vivecraft/shaders/mixedreality.fsh +++ /dev/null @@ -1,42 +0,0 @@ -#version 330 -uniform vec2 resolution; -uniform vec2 position; -uniform sampler2D colorTex; -uniform sampler2D depthTex; -uniform vec3 hmdViewPosition; -uniform vec3 hmdPlaneNormal; -uniform mat4 projectionMatrix; -uniform mat4 viewMatrix; -uniform int pass; -uniform vec3 keyColor; -uniform int alphaMode; -out vec4 out_Color; -vec3 getFragmentPosition(vec2 coord) { - vec4 posScreen = vec4(coord * 2.0 - 1.0, texture(depthTex, coord).x * 2.0 - 1.0, 1); - vec4 posView = inverse(projectionMatrix * viewMatrix) * posScreen; - return posView.xyz / posView.w; -} -void main(void) { - vec2 pos = (gl_FragCoord.xy - position) / resolution; - vec3 fragPos = getFragmentPosition(pos); - float fragHmdDot = dot(fragPos - hmdViewPosition, hmdPlaneNormal); - if (((pass == 0 || pass == 2) && fragHmdDot >= 0) || pass == 1) { - vec4 color = texture(colorTex, pos); - if (pass == 2) { - color = vec4(1, 1, 1, 1); - } else if (alphaMode == 0) { - vec3 diff = color.rgb - keyColor;// The following code prevents actual colors from matching the key color and looking weird - if (keyColor.r < 0.004 && keyColor.g < 0.004 && keyColor.b < 0.004 && color.r < 0.004 && color.g < 0.004 && color.b < 0.004) { - color = vec4(0.004, 0.004, 0.004, 1); - } else if (diff.r < 0.004 && diff.g < 0.004 && diff.b < 0.004) { - color = vec4(color.r - 0.004, color.g - 0.004, color.b - 0.004, color.a); - } - } - out_Color = color; - // out_Color = vec4(vec3((distance(fragPos.xz,hmdViewPosition.xz)) / 3), 1); // Draw distance to hmd - // out_Color = texture(depthTex, pos); // Draw depth buffer - } else { - discard;// Throw out the fragment to save some GPU processing - //out_Color = vec4(1, 0, 1, 1); - } -} diff --git a/common/src/main/resources/assets/vivecraft/shaders/passthru.vsh b/common/src/main/resources/assets/vivecraft/shaders/passthru.vsh deleted file mode 100644 index 974d83a4d..000000000 --- a/common/src/main/resources/assets/vivecraft/shaders/passthru.vsh +++ /dev/null @@ -1,5 +0,0 @@ -#version 110 -void main() { - gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; - gl_TexCoord[0] = gl_MultiTexCoord0; -} diff --git a/common/src/main/resources/assets/minecraft/shaders/program/vrtransparency.fsh b/common/src/main/resources/assets/vivecraft/shaders/post/vrtransparency.fsh similarity index 92% rename from common/src/main/resources/assets/minecraft/shaders/program/vrtransparency.fsh rename to common/src/main/resources/assets/vivecraft/shaders/post/vrtransparency.fsh index b3a8661d1..9b61388a8 100644 --- a/common/src/main/resources/assets/minecraft/shaders/program/vrtransparency.fsh +++ b/common/src/main/resources/assets/vivecraft/shaders/post/vrtransparency.fsh @@ -1,7 +1,7 @@ #version 150 -uniform sampler2D DiffuseSampler; -uniform sampler2D DiffuseDepthSampler; +uniform sampler2D MainSampler; +uniform sampler2D MainDepthSampler; uniform sampler2D TranslucentSampler; uniform sampler2D TranslucentDepthSampler; uniform sampler2D ItemEntitySampler; @@ -60,8 +60,8 @@ vec3 blend(vec3 dst, vec4 src) { } void main() { - color_layers[0] = vec4(texture(DiffuseSampler, texCoord).rgb, 1.0); - depth_layers[0] = texture(DiffuseDepthSampler, texCoord).r; + color_layers[0] = vec4(texture(MainSampler, texCoord).rgb, 1.0); + depth_layers[0] = texture(MainDepthSampler, texCoord).r; active_layers = 1; try_insert(texture(TranslucentSampler, texCoord), texture(TranslucentDepthSampler, texCoord).r); diff --git a/common/src/main/resources/assets/minecraft/shaders/program/vrtransparency.json b/common/src/main/resources/assets/vivecraft/shaders/post/vrtransparency.json similarity index 82% rename from common/src/main/resources/assets/minecraft/shaders/program/vrtransparency.json rename to common/src/main/resources/assets/vivecraft/shaders/post/vrtransparency.json index e210230d9..8610bc453 100644 --- a/common/src/main/resources/assets/minecraft/shaders/program/vrtransparency.json +++ b/common/src/main/resources/assets/vivecraft/shaders/post/vrtransparency.json @@ -1,18 +1,12 @@ { - "blend": { - "func": "add", - "srcrgb": "one", - "dstrgb": "zero" - }, - "vertex": "screenquad", - "fragment": "vrtransparency", - "attributes": ["Position"], + "vertex": "minecraft:post/screenquad", + "fragment": "vivecraft:post/vrtransparency", "samplers": [ { - "name": "DiffuseSampler" + "name": "MainSampler" }, { - "name": "DiffuseDepthSampler" + "name": "MainDepthSampler" }, { "name": "TranslucentSampler" diff --git a/common/src/main/resources/data/vivecraft/recipe/climbclaws.json b/common/src/main/resources/data/vivecraft/recipe/climbclaws.json index bf3b34020..792063c4f 100644 --- a/common/src/main/resources/data/vivecraft/recipe/climbclaws.json +++ b/common/src/main/resources/data/vivecraft/recipe/climbclaws.json @@ -5,12 +5,8 @@ "S S" ], "key": { - "E": { - "item": "minecraft:spider_eye" - }, - "S": { - "item": "minecraft:shears" - } + "E": "minecraft:spider_eye", + "S": "minecraft:shears" }, "result": { "id": "minecraft:shears", diff --git a/common/src/main/resources/data/vivecraft/recipe/jumpboots.json b/common/src/main/resources/data/vivecraft/recipe/jumpboots.json index 32e941b87..33ac60cd9 100644 --- a/common/src/main/resources/data/vivecraft/recipe/jumpboots.json +++ b/common/src/main/resources/data/vivecraft/recipe/jumpboots.json @@ -5,12 +5,8 @@ "S" ], "key": { - "B": { - "item": "minecraft:leather_boots" - }, - "S": { - "item": "minecraft:slime_block" - } + "B": "minecraft:leather_boots", + "S": "minecraft:slime_block" }, "result": { "id": "minecraft:leather_boots", diff --git a/common/src/main/resources/vivecraft.accesswidener b/common/src/main/resources/vivecraft.accesswidener index 7e3643373..1b77ea4ee 100644 --- a/common/src/main/resources/vivecraft.accesswidener +++ b/common/src/main/resources/vivecraft.accesswidener @@ -8,7 +8,6 @@ accessible field net/minecraft/client/model/geom/ModelPart$Cube polygons [Lnet/m # custom player modle rendering accessible field net/minecraft/client/model/PlayerModel slim Z -extendable method net/minecraft/client/renderer/entity/player/PlayerRenderer setModelProperties (Lnet/minecraft/client/player/AbstractClientPlayer;)V # modded layer supports accessible method net/minecraft/client/renderer/entity/LivingEntityRenderer addLayer (Lnet/minecraft/client/renderer/entity/layers/RenderLayer;)Z @@ -67,9 +66,6 @@ accessible method net/minecraft/client/renderer/RenderType create (Ljava/lang/St # to render item activation outside of gamerenderer accessible method net/minecraft/client/renderer/GameRenderer renderItemActivationAnimation (Lnet/minecraft/client/gui/GuiGraphics;F)V -# tohave differnt postEffects per pass -accessible field net/minecraft/client/renderer/GameRenderer postEffect Lnet/minecraft/client/renderer/PostChain; - # to disable destroy delay, on roomscale hitting accessible field net/minecraft/client/multiplayer/MultiPlayerGameMode destroyDelay I @@ -100,6 +96,3 @@ accessible method net/minecraft/world/item/BrushItem spawnDustParticles (Lnet/mi # do not kick climbing players accessible field net/minecraft/server/network/ServerGamePacketListenerImpl aboveGroundTickCount I - -# for roomscale eating -extendable method net/minecraft/world/entity/LivingEntity eat (Lnet/minecraft/world/level/Level;Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/item/ItemStack; diff --git a/common/src/main/resources/vivecraft.mixins.json b/common/src/main/resources/vivecraft.mixins.json index a2956b4ac..9558ec3bf 100644 --- a/common/src/main/resources/vivecraft.mixins.json +++ b/common/src/main/resources/vivecraft.mixins.json @@ -18,10 +18,12 @@ "client.renderer.RenderStateShardAccessor", "client.renderer.block.LiquidBlockRendererMixin", "client.renderer.entity.EntityRenderDispatcherMixin", + "client.renderer.entity.EntityRendererMixin", "client.renderer.entity.ItemRendererVRMixin", + "client.renderer.entity.LivingEntityRendererLayerCopyMixin", "client.renderer.entity.LivingEntityRendererMixin", - "client.renderer.entity.layers.ItemInHandLayerMixin", "client.renderer.entity.layers.RenderLayerMixin", + "client.renderer.entity.state.EntityRenderStateMixin", "client_vr.ClientBrandRetrieverVRMixin", "client_vr.KeyboardHandlerVRMixin", "client_vr.KeyboardInputVRMixin", @@ -34,7 +36,6 @@ "client_vr.blaze3d.platform.WindowVRMixin", "client_vr.blaze3d.systems.RenderSystemVRMixin", "client_vr.gui.EditBoxVRMixin", - "client_vr.gui.GuiComponentVRMixin", "client_vr.gui.GuiVRMixin", "client_vr.gui.TutorialToastVRMixin", "client_vr.gui.screens.OptionsScreenVRMixin", @@ -50,14 +51,16 @@ "client_vr.multiplayer.MultiPlayerGameModeVRMixin", "client_vr.particle.ItemPickupParticleVRMixin", "client_vr.player.LocalPlayerVRMixin", + "client_vr.renderer.CompiledShaderProgramVRMixin", "client_vr.renderer.GameRendererVRMixin", "client_vr.renderer.ItemInHandRendererVRMixin", "client_vr.renderer.ItemPropertiesVRMixin", + "client_vr.renderer.LevelEventHandlerVRMixin", "client_vr.renderer.LevelRendererVRMixin", + "client_vr.renderer.LevelTargetBundleVRMixin", "client_vr.renderer.NoSodiumLevelRendererVRMixin", "client_vr.renderer.PostChainVRMixin", "client_vr.renderer.SectionOcclusionGraphAccessor", - "client_vr.renderer.ShaderInstanceVRMixin", "client_vr.renderer.blockentity.TheEndGatewayRendererVRMixin", "client_vr.renderer.blockentity.TheEndPortalRendererVRMixin", "client_vr.renderer.entity.EntityRenderDispatcherVRMixin", @@ -67,10 +70,9 @@ "client_vr.tutorial.MovementTutorialStepInstanceVRMixin", "client_vr.tutorial.OpenInventoryTutorialStepVRMixin", "client_vr.tutorial.PunchTreeTutorialStepInstanceVRMixin", - "client_vr.world.BoatMixin", + "client_vr.world.AbstractBoatMixin", + "client_vr.world.ConsumableVRMixin", "client_vr.world.FishingHookVRMixin", - "client_vr.world.ItemVRMixin", - "client_vr.world.PotionItemVRMixin", "client_vr.world.entity.projectile.FireworkRocketEntityVRMixin", "client_vr.world.level.block.DoorBlockVRMixin", "client_vr.world.level.block.FenceGateBlockVRMixin", @@ -88,6 +90,7 @@ "server.ServerPlayerMixin", "server.TrackedEntityAccessor", "server.players.PlayerListMixin", + "world.entity.LivingEntityMixin", "world.entity.ai.goal.SwellGoalMixin", "world.entity.monster.EndermanFreezeWhenLookedAtMixin", "world.entity.monster.EndermanMixin", @@ -96,7 +99,7 @@ "world.entity.projectile.ProjectileDeflectionMixin", "world.entity.projectile.ProjectileMixin", "world.entity.projectile.ProjectileUtilMixin", - "world.entity.projectile.ThrowableProjectileMixin", + "world.entity.projectile.ThrowableItemProjectileMixin", "world.entity.projectile.ThrownTridentMixin", "world.item.CrossbowItemMixin" ] diff --git a/fabric/build.gradle b/fabric/build.gradle index 3f1d2653d..adcb34b83 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -29,15 +29,15 @@ dependencies { modCompileOnly("dev.architectury:architectury-fabric:${rootProject.architectury_version}") { exclude group: "net.fabricmc" exclude group: "net.fabricmc.fabric-api" } // for sodium compat - modRuntimeOnly "maven.modrinth:sodium:mc1.21-0.6.0-beta.2-fabric" + //modRuntimeOnly "maven.modrinth:sodium:mc1.21.3-0.6.1-fabric" // for iris compat - modRuntimeOnly "maven.modrinth:iris:1.8.0-beta.4+1.21-fabric" + //modRuntimeOnly "maven.modrinth:iris:1.8.1+1.21.3-fabric" modRuntimeOnly 'org.anarres:jcpp:1.4.14' //temp iris modRuntimeOnly 'io.github.douira:glsl-transformer:2.0.0-pre13' //temp iris // for REI compat - modCompileOnly("me.shedaniel:RoughlyEnoughItems-fabric:14.0.688") { exclude group: "net.fabricmc" exclude group: "net.fabricmc.fabric-api" exclude group: "dev.architectury" } + modCompileOnly("me.shedaniel:RoughlyEnoughItems-fabric:17.0.790") { exclude group: "net.fabricmc" exclude group: "net.fabricmc.fabric-api" exclude group: "dev.architectury" } // for Pehkui compat modCompileOnly("com.github.Virtuoel:Pehkui:3.7.12") { exclude group: "net.fabricmc" exclude group: "net.fabricmc.fabric-api" } @@ -48,7 +48,7 @@ dependencies { // modCompileOnly "maven.modrinth:indium:1.0.30+mc1.20.4" //mod menu - modApi("com.terraformersmc:modmenu:11.0.1") { exclude group: "net.fabricmc" exclude group: "net.fabricmc.fabric-api" } + modApi("com.terraformersmc:modmenu:12.0.0") { exclude group: "net.fabricmc" exclude group: "net.fabricmc.fabric-api" } // for immersive portals compat modCompileOnly('com.github.iPortalTeam:ImmersivePortalsMod:v5.1.7-mc1.20.4') { exclude group: "net.fabricmc" exclude group: "net.fabricmc.fabric-api" } diff --git a/fabric/src/main/java/org/vivecraft/fabric/mixin/FabricMinecraftVRMixin.java b/fabric/src/main/java/org/vivecraft/fabric/mixin/FabricMinecraftVRMixin.java index 4cdfc4587..e351ee041 100644 --- a/fabric/src/main/java/org/vivecraft/fabric/mixin/FabricMinecraftVRMixin.java +++ b/fabric/src/main/java/org/vivecraft/fabric/mixin/FabricMinecraftVRMixin.java @@ -8,7 +8,6 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import org.vivecraft.client_vr.VRState; import org.vivecraft.client_vr.render.helpers.VRPassHelper; @@ -17,12 +16,12 @@ public class FabricMinecraftVRMixin { @Shadow @Final - private DeltaTracker.Timer timer; + private DeltaTracker.Timer deltaTracker; - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiling/ProfilerFiller;pop()V", ordinal = 4, shift = At.Shift.AFTER), method = "runTick", locals = LocalCapture.CAPTURE_FAILHARD) + @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiling/ProfilerFiller;pop()V", ordinal = 3, shift = At.Shift.AFTER), method = "runTick") public void vivecraft$renderVRPassesFabric(boolean renderLevel, CallbackInfo ci) { if (VRState.vrRunning) { - VRPassHelper.renderAndSubmit(renderLevel, this.timer); + VRPassHelper.renderAndSubmit(renderLevel, this.deltaTracker); } } } diff --git a/fabric/src/main/java/org/vivecraft/fabric/mixin/client/resources/model/FabricModelBakeryMixin.java b/fabric/src/main/java/org/vivecraft/fabric/mixin/client/resources/model/FabricModelBakeryMixin.java deleted file mode 100644 index 5495038c8..000000000 --- a/fabric/src/main/java/org/vivecraft/fabric/mixin/client/resources/model/FabricModelBakeryMixin.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.vivecraft.fabric.mixin.client.resources.model; - -import net.minecraft.client.color.block.BlockColors; -import net.minecraft.client.renderer.block.model.BlockModel; -import net.minecraft.client.resources.model.ModelBakery; -import net.minecraft.client.resources.model.ModelResourceLocation; -import net.minecraft.client.resources.model.UnbakedModel; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.profiling.ProfilerFiller; -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.CallbackInfo; -import org.vivecraft.client_vr.ClientDataHolderVR; -import org.vivecraft.client_vr.gameplay.trackers.CameraTracker; -import org.vivecraft.client_vr.gameplay.trackers.ClimbTracker; -import org.vivecraft.client_vr.gameplay.trackers.TelescopeTracker; -import org.vivecraft.client_vr.settings.VRSettings; - -import java.io.IOException; -import java.util.Map; - -@Mixin(ModelBakery.class) -public abstract class FabricModelBakeryMixin { - @Shadow - protected abstract void registerModel(ModelResourceLocation modelResourceLocation, UnbakedModel unbakedModel); - - @Shadow - protected abstract BlockModel loadBlockModel(ResourceLocation resourceLocation) throws IOException; - - @Shadow - protected abstract void loadSpecialItemModelAndDependencies(ModelResourceLocation modelResourceLocation); - - @Inject(method = "", at = @At(value = "CONSTANT", args = "stringValue=special")) - private void loadModels(BlockColors blockColors, ProfilerFiller profilerFiller, Map map, Map map2, CallbackInfo ci) { - // item models - this.vivecraft$loadBlockModel(TelescopeTracker.scopeModel); - this.vivecraft$loadBlockModel(ClimbTracker.clawsModel); - - // blockmodels - this.vivecraft$loadBlockModel(ClientDataHolderVR.thirdPersonCameraModel); - this.vivecraft$loadBlockModel(ClientDataHolderVR.thirdPersonCameraDisplayModel); - this.vivecraft$loadBlockModel(CameraTracker.cameraModel); - this.vivecraft$loadBlockModel(CameraTracker.cameraDisplayModel); - } - - @Unique - private void vivecraft$loadBlockModel(ModelResourceLocation modelResourceLocation) { - try { - this.registerModel(modelResourceLocation, this.loadBlockModel(modelResourceLocation.id())); - } catch (IOException e) { - VRSettings.logger.error("Failed to load vivecraft model '{}': {}", modelResourceLocation, e.getMessage()); - } - } -} diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 08c031cc6..f9953253d 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -46,7 +46,7 @@ ], "depends": { "fabricloader": ">=0.15.6", - "minecraft": ["1.21","1.21.1"], + "minecraft": ["1.21.2","1.21.3"], "java": ">=21" }, "breaks": { diff --git a/fabric/src/main/resources/vivecraft.fabric.mixins.json b/fabric/src/main/resources/vivecraft.fabric.mixins.json index 760fb49bd..c099882a3 100644 --- a/fabric/src/main/resources/vivecraft.fabric.mixins.json +++ b/fabric/src/main/resources/vivecraft.fabric.mixins.json @@ -5,7 +5,6 @@ "compatibilityLevel": "JAVA_17", "client": [ "FabricMinecraftVRMixin", - "client.resources.model.FabricModelBakeryMixin", "screenhandler.client.FabricClientNetworkingVRMixin", "world.level.biome.BiomeAccessor" ], diff --git a/forge/src/main/java/org/vivecraft/forge/Vivecraft.java b/forge/src/main/java/org/vivecraft/forge/Vivecraft.java index 168a2de42..590c8f843 100644 --- a/forge/src/main/java/org/vivecraft/forge/Vivecraft.java +++ b/forge/src/main/java/org/vivecraft/forge/Vivecraft.java @@ -1,10 +1,15 @@ package org.vivecraft.forge; import net.minecraft.network.FriendlyByteBuf; +import net.minecraftforge.client.ConfigScreenHandler; +import net.minecraftforge.common.ForgeMod; import net.minecraftforge.event.network.CustomPayloadEvent; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.minecraftforge.fml.loading.FMLEnvironment; import net.minecraftforge.network.ChannelBuilder; import net.minecraftforge.network.EventNetworkChannel; +import org.vivecraft.client.gui.settings.VivecraftMainSettings; import org.vivecraft.client.network.ClientNetworking; import org.vivecraft.common.network.CommonNetworkHelper; import org.vivecraft.server.ServerNetworking; @@ -21,7 +26,7 @@ public class Vivecraft { .networkProtocolVersion(0) .eventNetworkChannel(); - public Vivecraft() { + public Vivecraft(FMLJavaModLoadingContext context) { // init server config ServerConfig.init(null); @@ -33,6 +38,10 @@ public Vivecraft() { } event.getSource().setPacketHandled(true); }); + + if (FMLEnvironment.dist.isClient()) { + context.registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () -> new ConfigScreenHandler.ConfigScreenFactory((mc, screen) -> new VivecraftMainSettings(screen))); + } } private static void handleClientVivePacket(FriendlyByteBuf buffer, CustomPayloadEvent.Context context) { diff --git a/forge/src/main/java/org/vivecraft/forge/event/ClientEvents.java b/forge/src/main/java/org/vivecraft/forge/event/ClientEvents.java deleted file mode 100644 index 765fdfcf5..000000000 --- a/forge/src/main/java/org/vivecraft/forge/event/ClientEvents.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.vivecraft.forge.event; - -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.client.ConfigScreenHandler; -import net.minecraftforge.client.event.ModelEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.FMLConstructModEvent; -import org.vivecraft.client.gui.settings.VivecraftMainSettings; -import org.vivecraft.client_vr.ClientDataHolderVR; -import org.vivecraft.client_vr.gameplay.trackers.CameraTracker; -import org.vivecraft.client_vr.gameplay.trackers.ClimbTracker; -import org.vivecraft.client_vr.gameplay.trackers.TelescopeTracker; -import org.vivecraft.forge.Vivecraft; - -@Mod.EventBusSubscriber(value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD, modid = Vivecraft.MODID) -public class ClientEvents { - @SubscribeEvent - public static void registerModels(ModelEvent.RegisterAdditional event) { - event.register(TelescopeTracker.scopeModel); - event.register(ClimbTracker.clawsModel); - event.register(ClientDataHolderVR.thirdPersonCameraModel); - event.register(ClientDataHolderVR.thirdPersonCameraDisplayModel); - event.register(CameraTracker.cameraModel); - event.register(CameraTracker.cameraDisplayModel); - } - - @SubscribeEvent - public static void registerConfigScreen(FMLConstructModEvent constructModEvent) { - ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () -> new ConfigScreenHandler.ConfigScreenFactory((mc, screen) -> new VivecraftMainSettings(screen))); - } -} diff --git a/forge/src/main/java/org/vivecraft/forge/mixin/ForgeMinecraftVRMixin.java b/forge/src/main/java/org/vivecraft/forge/mixin/ForgeMinecraftVRMixin.java index 89d4701da..3340cc443 100644 --- a/forge/src/main/java/org/vivecraft/forge/mixin/ForgeMinecraftVRMixin.java +++ b/forge/src/main/java/org/vivecraft/forge/mixin/ForgeMinecraftVRMixin.java @@ -17,12 +17,12 @@ public class ForgeMinecraftVRMixin { @Shadow @Final - private DeltaTracker.Timer timer; + private DeltaTracker.Timer deltaTracker; - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/event/ForgeEventFactoryClient;onRenderTickEnd(Lnet/minecraft/client/DeltaTracker;)V", shift = At.Shift.AFTER), method = "runTick", locals = LocalCapture.CAPTURE_FAILHARD) + @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/event/ForgeEventFactoryClient;onRenderTickEnd(Lnet/minecraft/client/DeltaTracker;)V", shift = At.Shift.AFTER), method = "runTick") public void vivecraft$renderVRPassesForge(boolean renderLevel, CallbackInfo ci) { if (VRState.vrRunning) { - VRPassHelper.renderAndSubmit(renderLevel, this.timer); + VRPassHelper.renderAndSubmit(renderLevel, this.deltaTracker); } } } diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index 2875bb190..8f31a2bf7 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader = "javafml" -loaderVersion = "[51,)" +loaderVersion = "[53,)" issueTrackerURL = "https://github.com/Vivecraft/VivecraftMod/issues" license = "LGPLv3" @@ -23,13 +23,13 @@ updateJSONURL = "https://raw.githubusercontent.com/Vivecraft/VivecraftMod/forge- [[dependencies.vivecraft]] modId = "forge" mandatory = true -versionRange = "[51.0.8,)" +versionRange = "[53.0.0,)" ordering = "NONE" side = "BOTH" [[dependencies.vivecraft]] modId = "minecraft" mandatory = true -versionRange = "[1.21,1.21.1]" +versionRange = "[1.21.2,1.21.3]" ordering = "NONE" side = "BOTH" diff --git a/gradle.properties b/gradle.properties index ce8ebca57..f4cbfea95 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,19 +1,19 @@ org.gradle.jvmargs=-Xmx4G -minecraft_version=1.21.1 +minecraft_version=1.21.3 enabled_platforms=fabric,forge,neoforge archives_base_name=vivecraft mod_version=1.1.14-b2 maven_group=org.vivecraft -architectury_version=13.0.6 +architectury_version=14.0.3 -fabric_loader_version=0.16.5 -fabric_api_version=0.106.0+1.21.1 +fabric_loader_version=0.16.8 +fabric_api_version=0.110.0+1.21.3 -forge_version=1.21.1-52.0.22 -neoforge_version=21.1.72 +forge_version=1.21.3-53.0.25 +neoforge_version=21.3.57 diff --git a/neoforge/src/main/java/org/vivecraft/client/neoforge/XplatImpl.java b/neoforge/src/main/java/org/vivecraft/client/neoforge/XplatImpl.java index 0d9330e98..23ef77a50 100644 --- a/neoforge/src/main/java/org/vivecraft/client/neoforge/XplatImpl.java +++ b/neoforge/src/main/java/org/vivecraft/client/neoforge/XplatImpl.java @@ -48,8 +48,10 @@ public static boolean isModLoadedSuccess() { } public static boolean enableRenderTargetStencil(RenderTarget renderTarget) { - renderTarget.enableStencil(); - return true; + // TODO 1.21.3 stencil not working + //renderTarget.enableStencil(); + //return true; + return false; } public static Path getJarPath() { diff --git a/neoforge/src/main/java/org/vivecraft/neoforge/event/ClientEvents.java b/neoforge/src/main/java/org/vivecraft/neoforge/event/ClientEvents.java index efd611d27..2ff4d1614 100644 --- a/neoforge/src/main/java/org/vivecraft/neoforge/event/ClientEvents.java +++ b/neoforge/src/main/java/org/vivecraft/neoforge/event/ClientEvents.java @@ -5,26 +5,12 @@ import net.neoforged.fml.ModLoadingContext; import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.fml.event.lifecycle.FMLConstructModEvent; -import net.neoforged.neoforge.client.event.ModelEvent; import net.neoforged.neoforge.client.gui.IConfigScreenFactory; import org.vivecraft.client.gui.settings.VivecraftMainSettings; -import org.vivecraft.client_vr.ClientDataHolderVR; -import org.vivecraft.client_vr.gameplay.trackers.CameraTracker; -import org.vivecraft.client_vr.gameplay.trackers.ClimbTracker; -import org.vivecraft.client_vr.gameplay.trackers.TelescopeTracker; import org.vivecraft.neoforge.Vivecraft; @EventBusSubscriber(value = Dist.CLIENT, bus = EventBusSubscriber.Bus.MOD, modid = Vivecraft.MODID) public class ClientEvents { - @SubscribeEvent - public static void registerModels(ModelEvent.RegisterAdditional event) { - event.register(TelescopeTracker.scopeModel); - event.register(ClimbTracker.clawsModel); - event.register(ClientDataHolderVR.thirdPersonCameraModel); - event.register(ClientDataHolderVR.thirdPersonCameraDisplayModel); - event.register(CameraTracker.cameraModel); - event.register(CameraTracker.cameraDisplayModel); - } @SubscribeEvent public static void registerConfigScreen(FMLConstructModEvent constructModEvent) { diff --git a/neoforge/src/main/java/org/vivecraft/neoforge/mixin/NeoForgeMinecraftVRMixin.java b/neoforge/src/main/java/org/vivecraft/neoforge/mixin/NeoForgeMinecraftVRMixin.java index 5b4e9042d..df11b81a4 100644 --- a/neoforge/src/main/java/org/vivecraft/neoforge/mixin/NeoForgeMinecraftVRMixin.java +++ b/neoforge/src/main/java/org/vivecraft/neoforge/mixin/NeoForgeMinecraftVRMixin.java @@ -17,12 +17,12 @@ public class NeoForgeMinecraftVRMixin { @Shadow @Final - private DeltaTracker.Timer timer; + private DeltaTracker.Timer deltaTracker; - @Inject(at = @At(value = "INVOKE", target = "Lnet/neoforged/neoforge/client/ClientHooks;fireRenderFramePost(Lnet/minecraft/client/DeltaTracker;)V", shift = At.Shift.AFTER), method = "runTick", locals = LocalCapture.CAPTURE_FAILHARD) + @Inject(at = @At(value = "INVOKE", target = "Lnet/neoforged/neoforge/client/ClientHooks;fireRenderFramePost(Lnet/minecraft/client/DeltaTracker;)V", shift = At.Shift.AFTER), method = "runTick") public void vivecraft$renderVRPassesNeoForge(boolean renderLevel, CallbackInfo ci) { if (VRState.vrRunning) { - VRPassHelper.renderAndSubmit(renderLevel, timer); + VRPassHelper.renderAndSubmit(renderLevel, this.deltaTracker); } } } diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml index 5160e09fb..1d86cefb6 100644 --- a/neoforge/src/main/resources/META-INF/neoforge.mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -23,14 +23,14 @@ updateJSONURL = "https://raw.githubusercontent.com/Vivecraft/VivecraftMod/forge- [[dependencies.vivecraft]] modId = "neoforge" type = "required" -versionRange = "[21.0.110-beta,)" +versionRange = "[21.2.0,)" ordering = "NONE" side = "BOTH" [[dependencies.vivecraft]] modId = "minecraft" type = "required" -versionRange = "[1.21,1.21.1]" +versionRange = "[1.21.2,1.21.3]" ordering = "NONE" side = "BOTH"