Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
fix stupid forge 48.0.32+ issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fayer3 committed Nov 1, 2023
1 parent 8c727aa commit 64f2e0e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.client.model.PlayerModel;
import net.minecraft.client.model.geom.EntityModelSet;
import net.minecraft.client.model.geom.ModelLayers;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.LivingEntityRenderer;
import net.minecraft.client.renderer.entity.RenderLayerParent;
Expand All @@ -14,7 +15,11 @@
import net.minecraft.client.renderer.entity.player.PlayerRenderer;
import net.minecraft.world.entity.LivingEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.vivecraft.client.extensions.EntityRenderDispatcherExtension;
import org.vivecraft.client.extensions.RenderLayerExtension;
import org.vivecraft.client.utils.RenderLayerTypes;
Expand All @@ -31,16 +36,18 @@
* so mods could add it manually, but some mods hardcode only the slim/default model,
* and that would mean the VRPlayerRenderers would be missing those layers completely
*/
@Mixin(PlayerRenderer.class)
public abstract class PlayerRendererMixin<T extends LivingEntity, M extends EntityModel<T>> extends LivingEntityRenderer<T, M> {
@Mixin(LivingEntityRenderer.class)
public abstract class LivingEntityRendererMixin<T extends LivingEntity, M extends EntityModel<T>> extends EntityRenderer<T> {

// dummy constructor
public PlayerRendererMixin(EntityRendererProvider.Context context, M entityModel, float f) {
super(context, entityModel, f);
@Shadow
protected M model;

protected LivingEntityRendererMixin(EntityRendererProvider.Context context) {
super(context);
}

@Override
public boolean addLayer(RenderLayer<T, M> renderLayer) {
@Inject(at = @At("HEAD"), method = "addLayer")
public void vivecraft$copyLayer(RenderLayer<T, M> renderLayer, CallbackInfoReturnable<Boolean> 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
Expand Down Expand Up @@ -91,7 +98,6 @@ public boolean addLayer(RenderLayer<T, M> renderLayer) {
}
}
}
return super.addLayer(renderLayer);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public abstract class MinecraftVRMixin implements MinecraftExtension {
private boolean vivecraft$lastClick;

@Unique
private ItemStack vivecraft$itemInHand; //Captured item
private int vivecraft$currentHand = 0;

@Unique
private long vivecraft$mirroNotifyStart;
Expand Down Expand Up @@ -570,22 +570,23 @@ public abstract class MinecraftVRMixin implements MinecraftExtension {
}
}

@ModifyVariable(at = @At(value = "STORE", ordinal = 0), method = "startUseItem")
public ItemStack vivecraft$handItemStore(ItemStack itemInHand) {
this.vivecraft$itemInHand = itemInHand;
return itemInHand;
}

@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;hitResult:Lnet/minecraft/world/phys/HitResult;", ordinal = 1), method = "startUseItem", locals = LocalCapture.CAPTURE_FAILHARD)
public void vivecraft$activeHandSend(CallbackInfo ci, InteractionHand[] var1, int var2, int var3, InteractionHand interactionHand) {
if (VRState.vrRunning && (ClientDataHolderVR.getInstance().vrSettings.seated || !TelescopeTracker.isTelescope(vivecraft$itemInHand))) {
ClientNetworking.sendActiveHand((byte) interactionHand.ordinal());
}
@Inject(at = @At("HEAD"), method = "startUseItem")
private void vivecraft$resetHand(CallbackInfo ci) {
vivecraft$currentHand = 0;
}

@Redirect(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;hitResult:Lnet/minecraft/world/phys/HitResult;", ordinal = 1), method = "startUseItem")
public HitResult vivecraft$activeHand2(Minecraft instance) {
if (!VRState.vrRunning || ClientDataHolderVR.getInstance().vrSettings.seated || !TelescopeTracker.isTelescope(vivecraft$itemInHand)) {
public HitResult vivecraft$activeHand(Minecraft instance) {
boolean isTelescope = false;
if (VRState.vrRunning) {
InteractionHand interactionHand = InteractionHand.values()[vivecraft$currentHand++];
ItemStack itemInHand = this.player.getItemInHand(interactionHand);
isTelescope = TelescopeTracker.isTelescope(itemInHand);
if (ClientDataHolderVR.getInstance().vrSettings.seated || !isTelescope) {
ClientNetworking.sendActiveHand((byte) interactionHand.ordinal());
}
}
if (!VRState.vrRunning || ClientDataHolderVR.getInstance().vrSettings.seated || !isTelescope) {
return instance.hitResult;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.spongepowered.asm.mixin.injection.At.Shift;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import org.vivecraft.client.Xevents;
import org.vivecraft.client.Xplat;
import org.vivecraft.client_vr.ClientDataHolderVR;
Expand Down Expand Up @@ -158,6 +157,9 @@ public abstract class GameRendererVRMixin
@Final
private Camera mainCamera;

@Shadow
private int itemActivationTicks;

@Redirect(method = "<init>", at = @At(value = "NEW", target = "net/minecraft/client/Camera"))
public Camera vivecraft$replaceCamera() {
return new XRCamera();
Expand Down Expand Up @@ -422,25 +424,27 @@ public abstract class GameRendererVRMixin
}

@Redirect(method = "renderItemActivationAnimation", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;scale(FFF)V"))
private void vivecraft$noScaleItem(PoseStack poseStack, float x, float y, float z) {
private void vivecraft$noScaleItem(PoseStack poseStack, float x, float y, float z, int width, int height, float partialTicks) {
if (RenderPassType.isVanilla()) {
poseStack.scale(x, y, z);
}
}

@Inject(method = "renderItemActivationAnimation", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;scale(FFF)V"), locals = LocalCapture.CAPTURE_FAILHARD)
private void vivecraft$transformItem(int i, int j, float f, CallbackInfo ci, int k, float g, float h, float l, float m, float n, float o, float p, PoseStack posestack) {
if (!RenderPassType.isVanilla()) {
} else {
// need to do stuff twice, because redirects have no access to locals
int i = 40 - this.itemActivationTicks;
float g = ((float) i + partialTicks) / 40.0f;
float h = g * g;
float l = g * h;
float m = 10.25f * l * h - 24.95f * h * h + 25.5f * l - 13.8f * h + 4.0f * g;
float n = m * (float) Math.PI;
float sinN = Mth.sin(n) * 0.5F;
posestack.translate(0, 0, sinN - 1.0);
poseStack.translate(0, 0, sinN - 1.0);
if (ClientDataHolderVR.getInstance().currentPass == RenderPass.THIRD) {
sinN *= ClientDataHolderVR.getInstance().vrSettings.mixedRealityFov / 70.0;
sinN *= (float) (ClientDataHolderVR.getInstance().vrSettings.mixedRealityFov / 70.0);
}
RenderHelper.applyVRModelView(ClientDataHolderVR.getInstance().currentPass, posestack);
RenderHelper.applyStereo(ClientDataHolderVR.getInstance().currentPass, posestack);
posestack.scale(sinN, sinN, sinN);
posestack.mulPose(Axis.YP.rotationDegrees(-ClientDataHolderVR.getInstance().vrPlayer.getVRDataWorld().getEye(ClientDataHolderVR.getInstance().currentPass).getYaw()));
posestack.mulPose(Axis.XP.rotationDegrees(-ClientDataHolderVR.getInstance().vrPlayer.getVRDataWorld().getEye(ClientDataHolderVR.getInstance().currentPass).getPitch()));
RenderHelper.applyVRModelView(ClientDataHolderVR.getInstance().currentPass, poseStack);
RenderHelper.applyStereo(ClientDataHolderVR.getInstance().currentPass, poseStack);
poseStack.scale(sinN, sinN, sinN);
poseStack.mulPose(Axis.YP.rotationDegrees(-ClientDataHolderVR.getInstance().vrPlayer.getVRDataWorld().getEye(ClientDataHolderVR.getInstance().currentPass).getYaw()));
poseStack.mulPose(Axis.XP.rotationDegrees(-ClientDataHolderVR.getInstance().vrPlayer.getVRDataWorld().getEye(ClientDataHolderVR.getInstance().currentPass).getPitch()));
}
}

Expand Down
1 change: 0 additions & 1 deletion common/src/main/resources/vivecraft.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ extendable method net/minecraft/client/renderer/entity/player/PlayerRenderer set

# modded layer supports
accessible method net/minecraft/client/renderer/entity/LivingEntityRenderer addLayer (Lnet/minecraft/client/renderer/entity/layers/RenderLayer;)Z
extendable method net/minecraft/client/renderer/entity/LivingEntityRenderer addLayer (Lnet/minecraft/client/renderer/entity/layers/RenderLayer;)Z
mutable field net/minecraft/client/renderer/entity/layers/RenderLayer renderer Lnet/minecraft/client/renderer/entity/RenderLayerParent;
accessible field net/minecraft/client/renderer/entity/layers/RenderLayer renderer Lnet/minecraft/client/renderer/entity/RenderLayerParent;

Expand Down
2 changes: 1 addition & 1 deletion common/src/main/resources/vivecraft.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"client.renderer.block.LiquidBlockRendererMixin",
"client.renderer.entity.EntityRenderDispatcherMixin",
"client.renderer.entity.ItemRendererVRMixin",
"client.renderer.entity.PlayerRendererMixin",
"client.renderer.entity.LivingEntityRendererMixin",
"client.renderer.entity.layers.RenderLayerMixin",
"client_vr.ClientBrandRetrieverVRMixin",
"client_vr.KeyboardHandlerVRMixin",
Expand Down

0 comments on commit 64f2e0e

Please sign in to comment.