diff --git a/common/build.gradle b/common/build.gradle index cc2ae9fc4..bf32d48be 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -15,10 +15,10 @@ dependencies { modApi("dev.architectury:architectury-fabric:${rootProject.architectury_version}") { exclude group: "net.fabricmc" exclude group: "net.fabricmc.fabric-api" } // for sodium compat - modCompileOnly "maven.modrinth:sodium:mc1.20.5-0.5.8" + modCompileOnly "maven.modrinth:sodium:mc1.20.6-0.5.8" // for iris compat - modCompileOnly "maven.modrinth:iris:1.7.0+1.20.5" + modCompileOnly "maven.modrinth:iris:1.7.0+1.20.6" // 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" } diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/InteractTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/InteractTracker.java index 3c41bf46e..9c6130b68 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/InteractTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/InteractTracker.java @@ -108,30 +108,26 @@ public void doProcess(LocalPlayer player) { Class oclass = object.getClass(); try { - if (oclass.getMethod(name, + oclass.getDeclaredMethod(name, BlockState.class, net.minecraft.world.level.Level.class, BlockPos.class, net.minecraft.world.entity.player.Player.class, - InteractionHand.class, - BlockHitResult.class).getDeclaringClass() == oclass) { - this.rightClickable.add(oclass); - } + BlockHitResult.class); + this.rightClickable.add(oclass); } catch (Throwable throwable1) { } oclass = oclass.getSuperclass(); try { - if (oclass.getMethod(name, + oclass.getDeclaredMethod(name, BlockState.class, net.minecraft.world.level.Level.class, BlockPos.class, net.minecraft.world.entity.player.Player.class, - InteractionHand.class, - BlockHitResult.class).getDeclaringClass() == oclass) { - this.rightClickable.add(oclass); - } + BlockHitResult.class); + this.rightClickable.add(oclass); } catch (Throwable throwable) { } } @@ -265,7 +261,8 @@ public void processBindings() { flag = this.mc.gameMode.interactAt(this.mc.player, this.inEntity[i], this.inEntityHit[i], interactionhand).consumesAction() || this.mc.gameMode.interact(this.mc.player, this.inEntity[i], interactionhand).consumesAction(); } else if (this.inBlockHit[i] != null) { - flag = this.mc.gameMode.useItemOn(this.mc.player, interactionhand, this.inBlockHit[i]).consumesAction(); + // force main hand, since 1.20.5 only checks no item interactions for the main hand + flag = this.mc.gameMode.useItemOn(this.mc.player, InteractionHand.MAIN_HAND, this.inBlockHit[i]).consumesAction(); } else if (this.bukkit[i]) { flag = this.mc.gameMode.useItem(this.mc.player, interactionhand).consumesAction(); } 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 efcd742f4..24ce3f4ca 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 @@ -24,6 +24,7 @@ import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL43; import org.lwjgl.system.MemoryUtil; +import org.vivecraft.client.Xplat; import org.vivecraft.client.extensions.RenderTargetExtension; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.VRTextureTarget; @@ -492,6 +493,9 @@ public void setupRenderConfiguration() throws Exception { // main render target ((RenderTargetExtension) WorldRenderPass.stereoXR.target).vivecraft$setUseStencil(dataholder.vrSettings.vrUseStencil); WorldRenderPass.stereoXR.resize(eyeFBWidth, eyeFBHeight); + if (dataholder.vrSettings.vrUseStencil) { + Xplat.enableRenderTargetStencil(WorldRenderPass.stereoXR.target); + } if (dataholder.vrSettings.useFsaa) { this.fsaaFirstPassResultFBO.resize(eyew, eyeFBHeight, Minecraft.ON_OSX); } diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/gui/screens/WinScreenVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/gui/screens/WinScreenVRMixin.java deleted file mode 100644 index 0c6942841..000000000 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/gui/screens/WinScreenVRMixin.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.vivecraft.mixin.client_vr.gui.screens; - -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.systems.RenderSystem; -import net.minecraft.client.gui.screens.WinScreen; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(WinScreen.class) -public class WinScreenVRMixin { - @Redirect(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;blendFunc(Lcom/mojang/blaze3d/platform/GlStateManager$SourceFactor;Lcom/mojang/blaze3d/platform/GlStateManager$DestFactor;)V"), method = "render") - private void vivecraft$dontDestroyAlpha(GlStateManager.SourceFactor sourceFactor, GlStateManager.DestFactor destFactor) { - RenderSystem.blendFuncSeparate(sourceFactor, destFactor, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); - } -} 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 7aaebbc85..f1e81be09 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 @@ -64,7 +64,7 @@ protected ClientPacketListenerVRMixin(Minecraft minecraft, Connection connection } } - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;setLevel(Lnet/minecraft/client/multiplayer/ClientLevel;)V", shift = At.Shift.AFTER), method = "handleRespawn") + @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;setLevel(Lnet/minecraft/client/multiplayer/ClientLevel;Lnet/minecraft/client/gui/screens/ReceivingLevelScreen$Reason;)V", shift = At.Shift.AFTER), method = "handleRespawn") public void vivecraft$resetOnDimensionChange(ClientboundRespawnPacket clientboundRespawnPacket, CallbackInfo ci) { // clear old data ClientNetworking.resetServerSettings(); 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 3f3b61ac5..df7f0bc70 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,13 +4,16 @@ import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.client.renderer.entity.FishingHookRenderer; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.FishingHook; -import net.minecraft.world.item.FishingRodItem; +import net.minecraft.world.item.Items; 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.ModifyVariable; +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.ItemTags; import org.vivecraft.client_vr.render.helpers.RenderHelper; import org.vivecraft.client_xr.render_pass.RenderPassType; @@ -22,52 +25,16 @@ protected FishingHookRendererVRMixin(EntityRendererProvider.Context context) { super(context); } - private Vec3 vivecraft$CachedHandPos; - - @ModifyVariable(at = @At(value = "LOAD"), - method = "render(Lnet/minecraft/world/entity/projectile/FishingHook;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", index = 25) - private double vivecraft$fishingLineStartX(double value, FishingHook fishingHook) { - if (!RenderPassType.isVanilla() && (this.entityRenderDispatcher.options == null || this.entityRenderDispatcher.options.getCameraType().isFirstPerson()) && fishingHook.getPlayerOwner() == Minecraft.getInstance().player) { - int j = 1; - if (fishingHook.getPlayerOwner().getMainHandItem().getItem() instanceof FishingRodItem) { - j = 0; + @Inject(at = @At("HEAD"), method = "getPlayerHandPos", cancellable = true) + private void vivecraft$getVRHandPos(Player player, float f, float g, CallbackInfoReturnable cir) { + if (!RenderPassType.isVanilla() && (this.entityRenderDispatcher.options.getCameraType().isFirstPerson()) && player == Minecraft.getInstance().player) { + int c = 1; + if (player.getMainHandItem().is(Items.FISHING_ROD) || player.getMainHandItem().is(ItemTags.VIVECRAFT_FISHING_RODS)) { + c = 0; } - Vec3 vec31 = RenderHelper.getControllerRenderPos(j); - Vec3 vec32 = ClientDataHolderVR.getInstance().vrPlayer.vrdata_world_render.getHand(j).getDirection(); - vivecraft$CachedHandPos = vec31.add(vec32.scale(0.47 * ClientDataHolderVR.getInstance().vrPlayer.vrdata_world_render.worldScale)); - return vivecraft$CachedHandPos.x; - } else { - return value; - } - } - - @ModifyVariable(at = @At(value = "LOAD"), - method = "render(Lnet/minecraft/world/entity/projectile/FishingHook;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", index = 27) - private double vivecraft$fishingLineStartY(double value, FishingHook fishingHook) { - if (!RenderPassType.isVanilla() && (this.entityRenderDispatcher.options == null || this.entityRenderDispatcher.options.getCameraType().isFirstPerson()) && fishingHook.getPlayerOwner() == Minecraft.getInstance().player) { - return vivecraft$CachedHandPos.y; - } else { - return value; - } - } - - @ModifyVariable(at = @At(value = "LOAD"), - method = "render(Lnet/minecraft/world/entity/projectile/FishingHook;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", index = 29) - private double vivecraft$fishingLineStartZ(double value, FishingHook fishingHook) { - if (!RenderPassType.isVanilla() && (this.entityRenderDispatcher.options == null || this.entityRenderDispatcher.options.getCameraType().isFirstPerson()) && fishingHook.getPlayerOwner() == Minecraft.getInstance().player) { - return vivecraft$CachedHandPos.z; - } else { - return value; - } - } - - @ModifyVariable(at = @At(value = "LOAD"), - method = "render(Lnet/minecraft/world/entity/projectile/FishingHook;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", index = 31) - private float vivecraft$fishingLineStartOffset(float value, FishingHook fishingHook) { - if (!RenderPassType.isVanilla() && (this.entityRenderDispatcher.options == null || this.entityRenderDispatcher.options.getCameraType().isFirstPerson()) && fishingHook.getPlayerOwner() == Minecraft.getInstance().player) { - return 0.0F; - } else { - return value; + Vec3 handPos = RenderHelper.getControllerRenderPos(c); + Vec3 rodOffset = ClientDataHolderVR.getInstance().vrPlayer.vrdata_world_render.getHand(c).getDirection(); + cir.setReturnValue(handPos.add(rodOffset.scale(0.47 * ClientDataHolderVR.getInstance().vrPlayer.vrdata_world_render.worldScale))); } } } diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/world/entity/player/PlayerVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/world/entity/player/PlayerVRMixin.java deleted file mode 100644 index 7c96f1d45..000000000 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/world/entity/player/PlayerVRMixin.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.vivecraft.mixin.client_vr.world.entity.player; - -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.phys.AABB; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(Player.class) -public class PlayerVRMixin { - - @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/phys/AABB;move(DDD)Lnet/minecraft/world/phys/AABB;"), method = "maybeBackOffFromEdge") - private AABB vivecraft$moveSidewaysExtendDown(AABB instance, double x, double y, double z) { - // this is to fix an issue with a maxStepUp size of 1 and trapdoors - return new AABB(instance.minX + x, instance.minY + y, instance.minZ + z, instance.maxX + x, instance.maxY, instance.maxZ + z); - } -} diff --git a/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/AbstractHurtingProjectileMixin.java b/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/ProjectileDeflectionMixin.java similarity index 74% rename from common/src/main/java/org/vivecraft/mixin/world/entity/projectile/AbstractHurtingProjectileMixin.java rename to common/src/main/java/org/vivecraft/mixin/world/entity/projectile/ProjectileDeflectionMixin.java index f939832de..137e045c1 100644 --- a/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/AbstractHurtingProjectileMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/ProjectileDeflectionMixin.java @@ -2,7 +2,7 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.projectile.AbstractHurtingProjectile; +import net.minecraft.world.entity.projectile.ProjectileDeflection; import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -10,11 +10,11 @@ import org.vivecraft.server.ServerVRPlayers; import org.vivecraft.server.ServerVivePlayer; -@Mixin(AbstractHurtingProjectile.class) -public abstract class AbstractHurtingProjectileMixin { +@Mixin(ProjectileDeflection.class) +public interface ProjectileDeflectionMixin { - @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;getLookAngle()Lnet/minecraft/world/phys/Vec3;"), method = "hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z") - public Vec3 vivecraft$hurtvive(Entity instance) { + @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;getLookAngle()Lnet/minecraft/world/phys/Vec3;"), method = "method_59862") + private static Vec3 vivecraft$deflectLook(Entity instance) { if (instance instanceof ServerPlayer player) { ServerVivePlayer serverviveplayer = ServerVRPlayers.getVivePlayer(player); if (serverviveplayer != null && serverviveplayer.isVR()) { diff --git a/common/src/main/resources/vivecraft.mixins.json b/common/src/main/resources/vivecraft.mixins.json index cb7ac3f52..57ed8508d 100644 --- a/common/src/main/resources/vivecraft.mixins.json +++ b/common/src/main/resources/vivecraft.mixins.json @@ -41,7 +41,6 @@ "client_vr.gui.screens.PauseScreenVRMixin", "client_vr.gui.screens.ScreenVRMixin", "client_vr.gui.screens.SoundOptionsScreenVRMixin", - "client_vr.gui.screens.WinScreenVRMixin", "client_vr.gui.screens.inventory.AbstractContainerScreenVRMixin", "client_vr.gui.screens.inventory.AbstractSignEditScreenVRMixin", "client_vr.gui.screens.inventory.BookEditScreenVRMixin", @@ -72,7 +71,6 @@ "client_vr.world.FishingHookVRMixin", "client_vr.world.ItemVRMixin", "client_vr.world.PotionItemVRMixin", - "client_vr.world.entity.player.PlayerVRMixin", "client_vr.world.entity.projectile.FireworkRocketEntityVRMixin", "client_vr.world.level.block.DoorBlockVRMixin", "client_vr.world.level.block.FenceGateBlockVRMixin", @@ -93,8 +91,8 @@ "world.entity.monster.EndermanFreezeWhenLookedAtMixin", "world.entity.monster.EndermanMixin", "world.entity.projectile.AbstractArrowMixin", - "world.entity.projectile.AbstractHurtingProjectileMixin", "world.entity.projectile.FishingHookMixin", + "world.entity.projectile.ProjectileDeflectionMixin", "world.entity.projectile.ProjectileMixin", "world.entity.projectile.ThrowableProjectileMixin", "world.entity.projectile.ThrownTridentMixin", diff --git a/fabric/build.gradle b/fabric/build.gradle index 52e91a5c9..0b0081d7a 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -29,10 +29,10 @@ dependencies { modApi("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.20.5-0.5.8" + modRuntimeOnly "maven.modrinth:sodium:mc1.20.6-0.5.8" // for iris compat - modRuntimeOnly "maven.modrinth:iris:1.7.0+1.20.5" + modRuntimeOnly "maven.modrinth:iris:1.7.0+1.20.6" modRuntimeOnly 'org.anarres:jcpp:1.4.14' //temp iris modRuntimeOnly 'io.github.douira:glsl-transformer:2.0.0-pre13' //temp iris diff --git a/fabric/src/main/java/org/vivecraft/client/fabric/XplatImpl.java b/fabric/src/main/java/org/vivecraft/client/fabric/XplatImpl.java index 17a4b0cad..4a51b6029 100644 --- a/fabric/src/main/java/org/vivecraft/client/fabric/XplatImpl.java +++ b/fabric/src/main/java/org/vivecraft/client/fabric/XplatImpl.java @@ -63,12 +63,11 @@ public static Path getJarPath() { public static String getUseMethodName() { return FabricLoader.getInstance().getMappingResolver().mapMethodName( "intermediary", - "net.minecraft.class_4970", "method_9534", + "net.minecraft.class_4970", "method_55766", "(Lnet/minecraft/class_2680;" + "Lnet/minecraft/class_1937;" + "Lnet/minecraft/class_2338;" + "Lnet/minecraft/class_1657;" + - "Lnet/minecraft/class_1268;" + "Lnet/minecraft/class_3965;)" + "Lnet/minecraft/class_1269;"); } diff --git a/forge/build.gradle b/forge/build.gradle index a8fe685f7..ddacb5df8 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -65,6 +65,9 @@ dependencies { bundle("org.lwjgl:lwjgl-openvr:3.3.3:natives-linux") { transitive = false } bundle("org.lwjgl:lwjgl-openvr:3.3.3:natives-macos") { transitive = false } bundle("org.lwjgl:lwjgl-openvr:3.3.3:natives-windows") { transitive = false } + + compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.3.5")) + implementation(include("io.github.llamalad7:mixinextras-forge:0.3.5")) } processResources { diff --git a/forge/src/main/java/org/vivecraft/client/forge/XplatImpl.java b/forge/src/main/java/org/vivecraft/client/forge/XplatImpl.java index 92c242fe9..b67f1d4b5 100644 --- a/forge/src/main/java/org/vivecraft/client/forge/XplatImpl.java +++ b/forge/src/main/java/org/vivecraft/client/forge/XplatImpl.java @@ -65,15 +65,7 @@ public static Path getJarPath() { } public static String getUseMethodName() { - return ObfuscationReflectionHelper.findMethod( - net.minecraft.world.level.block.state.BlockBehaviour.class, - "m_6227_", - net.minecraft.world.level.block.state.BlockState.class, - net.minecraft.world.level.Level.class, - net.minecraft.core.BlockPos.class, - net.minecraft.world.entity.player.Player.class, - net.minecraft.world.InteractionHand.class, - net.minecraft.world.phys.BlockHitResult.class).getName(); + return "useWithoutItem"; } public static TextureAtlasSprite[] getFluidTextures(BlockAndTintGetter level, BlockPos pos, FluidState fluidStateIn) { @@ -89,10 +81,11 @@ public static BiomeSpecialEffects getBiomeEffects(Biome biome) { } public static void addNetworkChannel(ClientPacketListener listener, ResourceLocation resourceLocation) { + /* // Forge I really don't know why you are insisting on this being a DiscardedPayload listener.send(new ServerboundCustomPayloadPacket(new DiscardedPayload( new ResourceLocation("minecraft:register"), new FriendlyByteBuf(Unpooled.buffer()) - .writeBytes(resourceLocation.toString().getBytes())))); + .writeBytes(resourceLocation.toString().getBytes()))));*/ } } diff --git a/forge/src/main/java/org/vivecraft/forge/Vivecraft.java b/forge/src/main/java/org/vivecraft/forge/Vivecraft.java index c53e4f82b..c2546b32b 100644 --- a/forge/src/main/java/org/vivecraft/forge/Vivecraft.java +++ b/forge/src/main/java/org/vivecraft/forge/Vivecraft.java @@ -1,6 +1,14 @@ package org.vivecraft.forge; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraftforge.event.network.CustomPayloadEvent; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.network.ChannelBuilder; +import net.minecraftforge.network.EventNetworkChannel; +import net.minecraftforge.network.NetworkDirection; +import org.vivecraft.client.network.ClientNetworking; +import org.vivecraft.common.network.CommonNetworkHelper; +import org.vivecraft.server.ServerNetworking; import org.vivecraft.server.config.ServerConfig; @Mod(Vivecraft.MODID) @@ -10,5 +18,31 @@ public class Vivecraft { public Vivecraft() { // init server config ServerConfig.init(null); + + EventNetworkChannel channel = ChannelBuilder.named(CommonNetworkHelper.CHANNEL) + .acceptedVersions((status, version) -> true) + .optional() + .networkProtocolVersion(0) + .eventNetworkChannel(); + channel.addListener(event -> { + if (event.getSource().getDirection() == NetworkDirection.PLAY_TO_SERVER) { + handleServerVivePacket(event.getPayload(), event.getSource()); + } else { + handleClientVivePacket(event.getPayload(), event.getSource()); + } + }); + } + + private static void handleClientVivePacket(FriendlyByteBuf buffer, CustomPayloadEvent.Context context) { + context.enqueueWork(() -> { + ClientNetworking.handlePacket(CommonNetworkHelper.PacketDiscriminators.values()[buffer.readByte()], buffer); + }); + } + + private static void handleServerVivePacket(FriendlyByteBuf buffer, CustomPayloadEvent.Context context) { + context.enqueueWork(() -> { + ServerNetworking.handlePacket(CommonNetworkHelper.PacketDiscriminators.values()[buffer.readByte()], buffer, context.getSender(), p -> context.getConnection().send(p)); + buffer.release(); + }); } } diff --git a/forge/src/main/java/org/vivecraft/forge/mixin/ForgeConnectionMixin.java b/forge/src/main/java/org/vivecraft/forge/mixin/ForgeConnectionMixin.java new file mode 100644 index 000000000..52a3753cb --- /dev/null +++ b/forge/src/main/java/org/vivecraft/forge/mixin/ForgeConnectionMixin.java @@ -0,0 +1,32 @@ +package org.vivecraft.forge.mixin; + +import io.netty.buffer.Unpooled; +import net.minecraft.network.Connection; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; +import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; +import net.minecraftforge.network.NetworkDirection; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; +import org.vivecraft.common.network.packets.VivecraftDataPacket; + +@Mixin(Connection.class) +public class ForgeConnectionMixin { + @ModifyVariable(at = @At("HEAD"), method = "send(Lnet/minecraft/network/protocol/Packet;)V", argsOnly = true) + private Packet vivecraft$convertPacket(Packet packet) { + // stupid forge doesn't register packets, so these wouldn't actually be sent correctly on the client + // need to convert them to forge packets + if (packet instanceof ClientboundCustomPayloadPacket clientPacket && clientPacket.payload() instanceof VivecraftDataPacket vivecraftDataPacket) { + FriendlyByteBuf buffer = new FriendlyByteBuf(Unpooled.buffer()); + vivecraftDataPacket.write(buffer); + packet = NetworkDirection.PLAY_TO_CLIENT.buildPacket(buffer, vivecraftDataPacket.type().id()).getThis(); + } else if (packet instanceof ServerboundCustomPayloadPacket serverPacket && serverPacket.payload() instanceof VivecraftDataPacket vivecraftDataPacket) { + FriendlyByteBuf buffer = new FriendlyByteBuf(Unpooled.buffer()); + vivecraftDataPacket.write(buffer); + packet = NetworkDirection.PLAY_TO_SERVER.buildPacket(buffer, vivecraftDataPacket.type().id()).getThis(); + } + return packet; + } +} diff --git a/forge/src/main/java/org/vivecraft/forge/mixin/ForgeGameRendererVRMixin.java b/forge/src/main/java/org/vivecraft/forge/mixin/ForgeGameRendererVRMixin.java index 8b2cf71e9..da611450a 100644 --- a/forge/src/main/java/org/vivecraft/forge/mixin/ForgeGameRendererVRMixin.java +++ b/forge/src/main/java/org/vivecraft/forge/mixin/ForgeGameRendererVRMixin.java @@ -1,11 +1,11 @@ package org.vivecraft.forge.mixin; -import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Camera; import net.minecraft.client.renderer.GameRenderer; -import org.joml.Quaternionf; +import org.joml.Matrix4f; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.Redirect; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.render.RenderPass; @@ -16,32 +16,32 @@ public class ForgeGameRendererVRMixin { @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setAnglesInternal(FF)V", remap = false), method = "renderLevel") - public void forgeInternal(Camera camera, float yaw, float pitch) { + public void vivecraft$forgeInternal(Camera camera, float yaw, float pitch) { if (RenderPassType.isVanilla() || ClientDataHolderVR.getInstance().currentPass != RenderPass.LEFT && ClientDataHolderVR.getInstance().currentPass != RenderPass.RIGHT) { camera.setAnglesInternal(yaw, pitch); } } - @Redirect(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;mulPose(Lorg/joml/Quaternionf;)V", ordinal = 2), method = "renderLevel") - public void forgeMulposZ(PoseStack poseStack, Quaternionf quaternion) { - if (RenderPassType.isVanilla() || ClientDataHolderVR.getInstance().currentPass != RenderPass.LEFT && ClientDataHolderVR.getInstance().currentPass != RenderPass.RIGHT) { - poseStack.mulPose(quaternion); - } + @ModifyArg(at = @At(value = "INVOKE", target = "Lorg/joml/Matrix4f;rotationXYZ(FFF)Lorg/joml/Matrix4f;", remap = false), method = "renderLevel", index = 0, remap = true) + public float vivecraft$nullifyXRotation(float xRot) { + return RenderPassType.isVanilla() ? xRot : 0F; } - @Redirect(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;mulPose(Lorg/joml/Quaternionf;)V ", ordinal = 3), method = "renderLevel(FJLcom/mojang/blaze3d/vertex/PoseStack;)V") - public void removeMulposeX(PoseStack s, Quaternionf quaternion) { - if (RenderPassType.isVanilla()) { - s.mulPose(quaternion); - } + @ModifyArg(at = @At(value = "INVOKE", target = "Lorg/joml/Matrix4f;rotationXYZ(FFF)Lorg/joml/Matrix4f;", remap = false), method = "renderLevel", index = 1, remap = true) + public float vivecraft$nullifyYRotation(float yRot) { + return RenderPassType.isVanilla() ? yRot : 0F; + } + + @ModifyArg(at = @At(value = "INVOKE", target = "Lorg/joml/Matrix4f;rotationXYZ(FFF)Lorg/joml/Matrix4f;", remap = false), method = "renderLevel", index = 2, remap = true) + public float vivecraft$nullifyZRotation(float zRot) { + return RenderPassType.isVanilla() ? zRot : 0F; } - @Redirect(at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;mulPose(Lorg/joml/Quaternionf;)V ", ordinal = 4), method = "renderLevel(FJLcom/mojang/blaze3d/vertex/PoseStack;)V") - public void removeMulposeY(PoseStack s, Quaternionf quaternion) { - if (RenderPassType.isVanilla()) { - s.mulPose(quaternion); - } else { - RenderHelper.applyVRModelView(ClientDataHolderVR.getInstance().currentPass, s); + @ModifyArg(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/LevelRenderer;prepareCullFrustum(Lnet/minecraft/world/phys/Vec3;Lorg/joml/Matrix4f;Lorg/joml/Matrix4f;)V"), method = "renderLevel", index = 1) + public Matrix4f vivecraft$applyModelView(Matrix4f matrix) { + if (!RenderPassType.isVanilla()) { + RenderHelper.applyVRModelView(ClientDataHolderVR.getInstance().currentPass, matrix); } + return matrix; } } diff --git a/forge/src/main/java/org/vivecraft/forge/mixin/ForgeIngameGuiVRMixin.java b/forge/src/main/java/org/vivecraft/forge/mixin/ForgeIngameGuiVRMixin.java deleted file mode 100644 index d5d6238dc..000000000 --- a/forge/src/main/java/org/vivecraft/forge/mixin/ForgeIngameGuiVRMixin.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.vivecraft.forge.mixin; - -import net.minecraft.client.KeyMapping; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraftforge.client.gui.overlay.ForgeGui; -import net.minecraftforge.client.gui.overlay.NamedGuiOverlay; -import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay; -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.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.vivecraft.client_vr.extensions.GuiExtension; -import org.vivecraft.client_xr.render_pass.RenderPassType; - -@Mixin(ForgeGui.class) -public abstract class ForgeIngameGuiVRMixin { - @Inject(method = "pre", at = @At("HEAD"), remap = false, cancellable = true) - private void noStuff(NamedGuiOverlay overlay, GuiGraphics guiGraphics, CallbackInfoReturnable info) { - if (RenderPassType.isGuiOnly() && (overlay == VanillaGuiOverlay.VIGNETTE.type() || overlay == VanillaGuiOverlay.SPYGLASS.type() || overlay == VanillaGuiOverlay.HELMET.type() || overlay == VanillaGuiOverlay.FROSTBITE.type() || overlay == VanillaGuiOverlay.PORTAL.type())) { - info.setReturnValue(true); - } - } - - @Redirect(method = "renderPlayerList", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/KeyMapping;isDown()Z")) - public boolean toggleableTabListForge(KeyMapping instance) { - return instance.isDown() || ((GuiExtension) this).vivecraft$getShowPlayerList(); - } -} diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index 57e1f85b0..04ee548d3 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 = "[49,)" +loaderVersion = "[50,)" 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 = "[49,)" +versionRange = "[50.0.7,)" ordering = "NONE" side = "BOTH" [[dependencies.vivecraft]] modId = "minecraft" mandatory = true -versionRange = "[1.20.3,1.20.4]" +versionRange = "[1.20.6]" ordering = "NONE" side = "BOTH" diff --git a/forge/src/main/resources/vivecraft.forge.mixins.json b/forge/src/main/resources/vivecraft.forge.mixins.json index 4f0872ea4..5c2a0784a 100644 --- a/forge/src/main/resources/vivecraft.forge.mixins.json +++ b/forge/src/main/resources/vivecraft.forge.mixins.json @@ -3,6 +3,7 @@ "package": "org.vivecraft.forge.mixin", "plugin": "org.vivecraft.MixinConfig", "compatibilityLevel": "JAVA_17", - "client": ["ForgeGameRendererVRMixin", "ForgeIngameGuiVRMixin", "network.ForgeOpenContainerVRMixin"], - "minVersion": "0.8.4" + "client": ["ForgeGameRendererVRMixin", "network.ForgeOpenContainerVRMixin"], + "minVersion": "0.8.4", + "mixins": ["ForgeConnectionMixin"] } diff --git a/gradle.properties b/gradle.properties index 02116dbb0..f46a3e7d6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,19 +1,19 @@ org.gradle.jvmargs=-Xmx4G -minecraft_version=1.20.5 -enabled_platforms=fabric,neoforge +minecraft_version=1.20.6 +enabled_platforms=fabric,forge,neoforge archives_base_name=vivecraft -mod_version=1.1.9-a3 +mod_version=1.1.9-b1 maven_group=org.vivecraft architectury_version=12.0.26 fabric_loader_version=0.15.7 -fabric_api_version=0.97.8+1.20.5 +fabric_api_version=0.97.8+1.20.6 -forge_version=1.20.4-49.0.30 -neoforge_version=20.5.5-beta +forge_version=1.20.6-50.0.5 +neoforge_version=20.6.1-beta diff --git a/neoforge/src/main/java/org/vivecraft/client/neoforge/XeventsImpl.java b/neoforge/src/main/java/org/vivecraft/client/neoforge/XeventsImpl.java index ca65dc392..d02a3a1a9 100644 --- a/neoforge/src/main/java/org/vivecraft/client/neoforge/XeventsImpl.java +++ b/neoforge/src/main/java/org/vivecraft/client/neoforge/XeventsImpl.java @@ -23,10 +23,10 @@ public static boolean renderFireOverlay(Player player, PoseStack mat) { } public static void onRenderTickStart(float f) { - EventHooks.onRenderTickStart(f); + ClientHooks.fireClientTickPre(); } public static void onRenderTickEnd(float f) { - EventHooks.onRenderTickEnd(f); + ClientHooks.fireRenderFramePost(f); } } 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 755914a5e..959f46b14 100644 --- a/neoforge/src/main/java/org/vivecraft/client/neoforge/XplatImpl.java +++ b/neoforge/src/main/java/org/vivecraft/client/neoforge/XplatImpl.java @@ -57,7 +57,7 @@ public static Path getJarPath() { } public static String getUseMethodName() { - return "use"; + return "useWithoutItem"; } public static TextureAtlasSprite[] getFluidTextures(BlockAndTintGetter level, BlockPos pos, FluidState fluidStateIn) { diff --git a/settings.gradle b/settings.gradle index 69c5a0351..d4ec7fbba 100644 --- a/settings.gradle +++ b/settings.gradle @@ -11,7 +11,7 @@ pluginManagement { include("common") include("stubs") include("fabric") -//include("forge") +include("forge") include("neoForge") rootProject.name = "vivecraft"