Skip to content

Commit

Permalink
fix telescope overlay being flipped
Browse files Browse the repository at this point in the history
fix telescope with optifine+shaders
make optifine mixins not required
  • Loading branch information
fayer3 committed Oct 4, 2023
1 parent ca044bf commit 138f0b9
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,22 +294,22 @@ public static void drawSizedQuad(float displayWidth, float displayHeight, float
RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
}

public static void drawSizedQuadWithLightmapCutout(float displayWidth, float displayHeight, float size, int lighti, Matrix4f pMatrix) {
drawSizedQuadWithLightmapCutout(displayWidth, displayHeight, size, lighti, new float[]{1, 1, 1, 1}, pMatrix);
public static void drawSizedQuadWithLightmapCutout(float displayWidth, float displayHeight, float size, int lighti, Matrix4f pMatrix, boolean flipY) {
drawSizedQuadWithLightmapCutout(displayWidth, displayHeight, size, lighti, new float[]{1, 1, 1, 1}, pMatrix, flipY);
}

public static void drawSizedQuadWithLightmapCutout(float displayWidth, float displayHeight, float size, int lighti,
float[] color, Matrix4f pMatrix) {
drawSizedQuadWithLightmap(displayWidth, displayHeight, size, lighti, color, pMatrix, GameRenderer::getRendertypeEntityCutoutNoCullShader);
float[] color, Matrix4f pMatrix, boolean flipY) {
drawSizedQuadWithLightmap(displayWidth, displayHeight, size, lighti, color, pMatrix, GameRenderer::getRendertypeEntityCutoutNoCullShader, 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);
drawSizedQuadWithLightmap(displayWidth, displayHeight, size, LightTexture.pack(15, 15), color, pMatrix, GameRenderer::getRendertypeEntitySolidShader, false);
}

public static void drawSizedQuadWithLightmap(float displayWidth, float displayHeight, float size, int lighti,
float[] color, Matrix4f pMatrix, Supplier<ShaderInstance> shader) {
float[] color, Matrix4f pMatrix, Supplier<ShaderInstance> shader, boolean flipY) {
float aspect = displayHeight / displayWidth;
RenderSystem.setShader(shader);
mc.gameRenderer.lightTexture().turnOnLightLayer();
Expand All @@ -327,25 +327,25 @@ public static void drawSizedQuadWithLightmap(float displayWidth, float displayHe

bufferbuilder.vertex(pMatrix, (-(size / 2.0F)), (-(size * aspect) / 2.0F), 0)
.color(color[0], color[1], color[2], color[3])
.uv(0.0F, 0.0F)
.uv(0.0F, flipY ? 1.0F : 0.0F)
.overlayCoords(OverlayTexture.NO_OVERLAY).uv2(lighti)
.normal(0, 0, 1)
.endVertex();
bufferbuilder.vertex(pMatrix, (size / 2.0F), (-(size * aspect) / 2.0F), 0)
.color(color[0], color[1], color[2], color[3])
.uv(1.0F, 0.0F)
.uv(1.0F, flipY ? 1.0F : 0.0F)
.overlayCoords(OverlayTexture.NO_OVERLAY).uv2(lighti)
.normal(0, 0, 1)
.endVertex();
bufferbuilder.vertex(pMatrix, (size / 2.0F), (size * aspect / 2.0F), 0)
.color(color[0], color[1], color[2], color[3])
.uv(1.0F, 1.0F)
.uv(1.0F, flipY ? 0.0F : 1.0F)
.overlayCoords(OverlayTexture.NO_OVERLAY).uv2(lighti)
.normal(0, 0, 1)
.endVertex();
bufferbuilder.vertex(pMatrix, (-(size / 2.0F)), (size * aspect / 2.0F), 0)
.color(color[0], color[1], color[2], color[3])
.uv(0.0F, 1.0F)
.uv(0.0F, flipY ? 0.0F : 1.0F)
.overlayCoords(OverlayTexture.NO_OVERLAY).uv2(lighti)
.normal(0, 0, 1)
.endVertex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static void drawScopeFB(PoseStack matrixStackIn, int i) {
RenderSystem.enableBlend();
matrixStackIn.translate(0.0D, 0.0D, 0.00001D);
int light = LevelRenderer.getLightColor(mc.level, BlockPos.containing(dataHolder.vrPlayer.vrdata_world_render.getController(i).getPosition()));
RenderHelper.drawSizedQuadWithLightmapCutout(720.0F, 720.0F, scale, light, matrixStackIn.last().pose());
RenderHelper.drawSizedQuadWithLightmapCutout(720.0F, 720.0F, scale, light, matrixStackIn.last().pose(), true);

matrixStackIn.popPose();
mc.gameRenderer.lightTexture().turnOnLightLayer();
Expand Down Expand Up @@ -660,7 +660,7 @@ private static void renderScreen(PoseStack poseStack, RenderTarget screenFramebu
int light = Utils.getCombinedLightWithMin(mc.level, BlockPos.containing(screenPos), minLight);
RenderHelper.drawSizedQuadWithLightmapCutout((float) mc.getWindow().getGuiScaledWidth(),
(float) mc.getWindow().getGuiScaledHeight(), 1.5F, light, color,
poseStack.last().pose());
poseStack.last().pose(), false);
} else {
RenderHelper.drawSizedQuad((float) mc.getWindow().getGuiScaledWidth(),
(float) mc.getWindow().getGuiScaledHeight(), 1.5F, color,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,60 +1,56 @@
package org.vivecraft.mixin.client.renderer.entity;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.Sheets;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.ItemModelShaper;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
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.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.vivecraft.client_vr.ClientDataHolderVR;
import org.vivecraft.client_vr.gameplay.trackers.SwingTracker;
import org.vivecraft.client_vr.gameplay.trackers.TelescopeTracker;

import java.util.List;

//TODO I don't think this does anything? Optifine
@Mixin(ItemRenderer.class)
public class ItemRendererVRMixin {

@Shadow
@Final
private ItemModelShaper itemModelShaper;

@ModifyVariable(at = @At(value = "STORE"), method = "getModel")
public BakedModel vivecraft$spyglassOverride(BakedModel bakedModel, ItemStack itemStack) {
return itemStack.is(Items.SPYGLASS) ? itemModelShaper.getModelManager().getModel(TelescopeTracker.scopeModel) : bakedModel;
}

// hand item fade
// needs custom item renderer, since the regular one doesn't accept a non 1.0 alpha
/*
@Unique
float vivecraft$fade = 1.0F;
@Unique
float vivecraft$manualFade = 1.0F;
@Inject(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;translate(FFF)V", shift = At.Shift.AFTER), method = "render")
public void fade(ItemStack itemStack, ItemDisplayContext itemDisplayContext, boolean bl, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, int j, BakedModel bakedModel, CallbackInfo ci) {
public void vivecraft$fade(ItemStack itemStack, ItemDisplayContext itemDisplayContext, boolean bl, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, int j, BakedModel bakedModel, CallbackInfo ci) {
LocalPlayer localplayer = Minecraft.getInstance().player;

if (localplayer != null && ClientDataHolderVR.isfphand) {
this.vivecraft$fade = SwingTracker.getItemFade(localplayer, itemStack);
} else {
this.vivecraft$fade = this.vivecraft$manualFade;
}
this.vivecraft$fade = localplayer != null && ClientDataHolderVR.isfphand
? SwingTracker.getItemFade(localplayer, itemStack)
: this.vivecraft$manualFade;
}
@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/ItemBlockRenderTypes;getRenderType(Lnet/minecraft/world/item/ItemStack;Z)Lnet/minecraft/client/renderer/RenderType;"), method = "render")
public RenderType vivecraft$rendertypeFade(ItemStack itemStack, boolean bl) {
@ModifyVariable(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/ItemBlockRenderTypes;getRenderType(Lnet/minecraft/world/item/ItemStack;Z)Lnet/minecraft/client/renderer/RenderType;"), ordinal = 0, method = "render")
public RenderType vivecraft$rendertypeFade(RenderType rendertype) {
if (ClientDataHolderVR.isfphand && this.vivecraft$fade < 1.0F) {
return Sheets.translucentCullBlockSheet();
}
return ItemBlockRenderTypes.getRenderType(itemStack, bl);
return rendertype;
}
*/

// Color vivecraft items, this clashes with old sodium
// Color vivecraft items, this clashes with old sodium
/*
@ModifyVariable(at = @At(value = "LOAD", ordinal = 0), ordinal = 2, method = "renderQuadList")
public int vivecraft$specialItems(int color, PoseStack poseStack, VertexConsumer vertexConsumer, List<BakedQuad> list, ItemStack itemStack) {
if (ClientDataHolderVR.getInstance().jumpTracker.isBoots(itemStack)) {
Expand All @@ -71,4 +67,5 @@ public void fade(ItemStack itemStack, ItemDisplayContext itemDisplayContext, boo
private int vivecraft$makeColor(int a, int r, int g, int b) {
return a << 24 | r << 16 | g << 8 | b;
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.ItemInHandRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.Sheets;
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.HumanoidArm;
Expand All @@ -36,6 +34,7 @@
import org.vivecraft.client_vr.render.VRFirstPersonArmSwing;
import org.vivecraft.client_vr.render.VivecraftItemRendering;
import org.vivecraft.client_vr.render.helpers.VREffectsHelper;
import org.vivecraft.mod_compat_vr.optifine.OptifineHelper;

@Mixin(value = ItemInHandRenderer.class, priority = 999)
public abstract class ItemInHandRendererVRMixin implements ItemInHandRendererExtension {
Expand Down Expand Up @@ -134,9 +133,8 @@ public abstract class ItemInHandRendererVRMixin implements ItemInHandRendererExt
if (dh.currentPass != RenderPass.SCOPEL && dh.currentPass != RenderPass.SCOPER) {
pMatrixStack.pushPose();
pMatrixStack.scale(0.625F, 0.625F, 0.625F);
pMatrixStack.translate(mainHand ? -0.53D : -0.47D, -0.5D, -0.6D);
//pMatrixStack.mulPose(Axis.XP.rotationDegrees(180.0F));
this.minecraft.getBlockRenderer().getModelRenderer().renderModel(pMatrixStack.last(), pBuffer.getBuffer(Sheets.solidBlockSheet()), null, this.minecraft.getModelManager().getModel(TelescopeTracker.scopeModel), 0.5F, 0.5F, 1.0F, pCombinedLight, OverlayTexture.NO_OVERLAY);
pMatrixStack.translate(mainHand ? -0.03D : 0.03D, 0.0D, -0.1D);
this.renderItem(pPlayer, pStack, itemDisplayContext, !mainHand && useLeftHandModelinLeftHand, pMatrixStack, pBuffer, pCombinedLight);
pMatrixStack.popPose();
}

Expand All @@ -145,8 +143,15 @@ public abstract class ItemInHandRendererVRMixin implements ItemInHandRendererExt
pMatrixStack.mulPose(Axis.XP.rotationDegrees(90.0F));
pMatrixStack.mulPose(Axis.YP.rotationDegrees(180.0F));
pMatrixStack.mulPose(Axis.ZP.rotationDegrees(180.0F));
if (OptifineHelper.isOptifineLoaded() && OptifineHelper.isShaderActive()) {
// this messes stuff up when rendering the quads
OptifineHelper.endEntities();
}
VREffectsHelper.drawScopeFB(pMatrixStack, pHand == InteractionHand.MAIN_HAND ? 0 : 1);
pMatrixStack.popPose();
if (OptifineHelper.isOptifineLoaded() && OptifineHelper.isShaderActive()) {
OptifineHelper.beginEntities();
}
} else {
this.renderItem(pPlayer, pStack, itemDisplayContext, !mainHand && useLeftHandModelinLeftHand, pMatrixStack, pBuffer, pCombinedLight);
}
Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/vivecraft.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"client.player.AbstractClientPlayerMixin",
"client.renderer.block.LiquidBlockRendererMixin",
"client.renderer.entity.EntityRenderDispatcherMixin",
"client.renderer.entity.ItemRendererVRMixin",
"client.renderer.entity.PlayerRendererMixin",
"client.renderer.entity.layers.RenderLayerMixin",
"client_vr.ClientBrandRetrieverVRMixin",
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/resources/vivecraft.optifine.mixins.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"required": true,
"required": false,
"package": "org.vivecraft.mod_compat_vr.optifine.mixin",
"plugin": "org.vivecraft.MixinConfig",
"compatibilityLevel": "JAVA_17",
Expand Down

0 comments on commit 138f0b9

Please sign in to comment.