From 90dbef1ea89f743d28e0f4e88d594a97bbdc142a Mon Sep 17 00:00:00 2001 From: fayer3 Date: Sat, 30 Sep 2023 14:54:04 +0200 Subject: [PATCH 1/9] update to 1.20.2 --- .../main/java/org/vivecraft/client/Xplat.java | 6 ++ .../gui/framework/GuiVROptionsBase.java | 9 +-- .../client/gui/screens/ErrorScreen.java | 2 +- .../client/gui/screens/UpdateScreen.java | 2 +- .../client/gui/settings/GuiListScreen.java | 8 ++- .../gui/settings/GuiQuickCommandsInGame.java | 2 +- .../gui/settings/GuiQuickCommandsList.java | 6 +- .../client/gui/widgets/TextScrollWidget.java | 8 +-- .../client/network/ClientNetworking.java | 22 +++---- .../org/vivecraft/client/render/HMDLayer.java | 1 - .../client/render/VRPlayerModel.java | 1 - .../client/render/VRPlayerModel_WithArms.java | 1 - .../org/vivecraft/client/utils/Utils.java | 1 - .../gameplay/screenhandlers/GuiHandler.java | 2 +- .../gameplay/trackers/BowTracker.java | 2 +- .../gameplay/trackers/ClimbTracker.java | 3 +- .../gameplay/trackers/CrawlTracker.java | 2 +- .../vivecraft/client_vr/gui/GuiKeyboard.java | 2 +- .../vivecraft/client_vr/gui/GuiRadial.java | 2 +- .../menuworlds/MenuWorldExporter.java | 2 +- .../vivecraft/client_vr/provider/MCVR.java | 1 - .../client_vr/render/VRArmRenderer.java | 4 +- .../render/helpers/VREffectsHelper.java | 14 +++-- .../render/helpers/VRWidgetHelper.java | 1 - .../client_vr/utils/LoaderUtils.java | 1 - .../vivecraft/common/CustomShapedRecipe.java | 46 ++++++++++++++ .../network/packets/VivecraftDataPacket.java | 18 ++++++ .../entity/EntityRenderDispatcherMixin.java | 2 +- .../mixin/client_vr/MinecraftVRMixin.java | 6 +- .../mixin/client_vr/MouseHandlerVRMixin.java | 6 +- .../mixin/client_vr/gui/GuiVRMixin.java | 40 +++++++------ .../client_vr/gui/TutorialToastVRMixin.java | 8 ++- .../gui/screens/PauseScreenVRMixin.java | 8 +-- .../client_vr/gui/screens/ScreenVRMixin.java | 11 ++-- ...ClientCommonPacketListenerImplVRMixin.java | 25 ++++++++ .../ClientPacketListenerVRMixin.java | 38 ++++-------- .../client_vr/player/LocalPlayerVRMixin.java | 2 +- .../renderer/ItemInHandRendererVRMixin.java | 7 +-- .../NoSodiumLevelRendererVRMixin.java | 15 ++--- .../ClientboundCustomPayloadPacketMixin.java | 24 ++++++++ .../ServerboundCustomPayloadPacketMixin.java | 24 ++++++++ .../ServerCommonPacketListenerImplMixin.java | 39 ++++++++++++ .../ServerGamePacketListenerImplMixin.java | 44 +++----------- .../PlayerListMixin.java} | 12 ++-- .../item/crafting/ShapedRecipeMixin.java | 60 +++---------------- .../vivecraft/server/ServerNetworking.java | 13 ++-- .../main/resources/vivecraft.accesswidener | 8 ++- .../src/main/resources/vivecraft.mixins.json | 6 +- .../resources/vivecraft.optifine.mixins.json | 2 +- fabric/build.gradle | 22 +++---- .../vivecraft/client/fabric/XplatImpl.java | 21 +++++++ fabric/src/main/resources/fabric.mod.json | 2 +- forge/build.gradle | 4 +- .../org/vivecraft/client/forge/XplatImpl.java | 7 +++ .../network/ForgeOpenContainerVRMixin.java | 10 ++-- forge/src/main/resources/META-INF/mods.toml | 6 +- gradle.properties | 6 +- 57 files changed, 390 insertions(+), 257 deletions(-) create mode 100644 common/src/main/java/org/vivecraft/common/CustomShapedRecipe.java create mode 100644 common/src/main/java/org/vivecraft/common/network/packets/VivecraftDataPacket.java create mode 100644 common/src/main/java/org/vivecraft/mixin/client_vr/multiplayer/ClientCommonPacketListenerImplVRMixin.java create mode 100644 common/src/main/java/org/vivecraft/mixin/network/ClientboundCustomPayloadPacketMixin.java create mode 100644 common/src/main/java/org/vivecraft/mixin/network/ServerboundCustomPayloadPacketMixin.java create mode 100644 common/src/main/java/org/vivecraft/mixin/server/ServerCommonPacketListenerImplMixin.java rename common/src/main/java/org/vivecraft/mixin/server/{ServerLoginPacketListenerImplMixin.java => players/PlayerListMixin.java} (54%) diff --git a/common/src/main/java/org/vivecraft/client/Xplat.java b/common/src/main/java/org/vivecraft/client/Xplat.java index 66be65a4f..e726f3f8a 100644 --- a/common/src/main/java/org/vivecraft/client/Xplat.java +++ b/common/src/main/java/org/vivecraft/client/Xplat.java @@ -2,8 +2,10 @@ import com.mojang.blaze3d.pipeline.RenderTarget; import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.BiomeSpecialEffects; @@ -84,4 +86,8 @@ static Biome.ClimateSettings getBiomeClimateSettings(Biome biome) { static BiomeSpecialEffects getBiomeEffects(Biome biome) { return null; } + + @ExpectPlatform + static void addNetworkChannel(ClientPacketListener listener, ResourceLocation resourceLocation) { + } } diff --git a/common/src/main/java/org/vivecraft/client/gui/framework/GuiVROptionsBase.java b/common/src/main/java/org/vivecraft/client/gui/framework/GuiVROptionsBase.java index 9b470e8c1..810aab225 100644 --- a/common/src/main/java/org/vivecraft/client/gui/framework/GuiVROptionsBase.java +++ b/common/src/main/java/org/vivecraft/client/gui/framework/GuiVROptionsBase.java @@ -184,7 +184,7 @@ public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPar this.init(); } - this.renderBackground(guiGraphics); + this.renderBackground(guiGraphics, pMouseX, pMouseY, pPartialTicks); if (this.visibleList != null) { this.visibleList.render(guiGraphics, pMouseX, pMouseY, pPartialTicks); @@ -235,12 +235,13 @@ public boolean mouseDragged(double pMouseX, double p_94741_, int pMouseY, double return this.visibleList != null ? this.visibleList.mouseDragged(pMouseX, p_94741_, pMouseY, p_94743_, pButton) : super.mouseDragged(pMouseX, p_94741_, pMouseY, p_94743_, pButton); } - public boolean mouseScrolled(double pMouseX, double p_94735_, double pMouseY) { + @Override + public boolean mouseScrolled(double x, double y, double scrollAmountX, double scrollAmountY) { if (this.visibleList != null) { - this.visibleList.mouseScrolled(pMouseX, p_94735_, pMouseY); + this.visibleList.mouseScrolled(x, y, scrollAmountX, scrollAmountY); } - return super.mouseScrolled(pMouseX, p_94735_, pMouseY); + return super.mouseScrolled(x, y, scrollAmountX, scrollAmountY); } public boolean keyPressed(int pKeyCode, int pScanCode, int pModifiers) { diff --git a/common/src/main/java/org/vivecraft/client/gui/screens/ErrorScreen.java b/common/src/main/java/org/vivecraft/client/gui/screens/ErrorScreen.java index af9e21a4f..556068a13 100644 --- a/common/src/main/java/org/vivecraft/client/gui/screens/ErrorScreen.java +++ b/common/src/main/java/org/vivecraft/client/gui/screens/ErrorScreen.java @@ -38,7 +38,7 @@ protected void init() { @Override public void render(@NotNull GuiGraphics guiGraphics, int i, int j, float f) { - this.renderBackground(guiGraphics); + this.renderBackground(guiGraphics, i, j, f); guiGraphics.drawCenteredString(this.font, this.title, this.width / 2, 15, 16777215); super.render(guiGraphics, i, j, f); diff --git a/common/src/main/java/org/vivecraft/client/gui/screens/UpdateScreen.java b/common/src/main/java/org/vivecraft/client/gui/screens/UpdateScreen.java index 3a5532a46..bbaa69b23 100644 --- a/common/src/main/java/org/vivecraft/client/gui/screens/UpdateScreen.java +++ b/common/src/main/java/org/vivecraft/client/gui/screens/UpdateScreen.java @@ -45,7 +45,7 @@ protected void init() { @Override public void render(@NotNull GuiGraphics guiGraphics, int i, int j, float f) { - this.renderBackground(guiGraphics); + this.renderBackground(guiGraphics, i, j, f); guiGraphics.drawCenteredString(this.font, this.title, this.width / 2, 15, 16777215); super.render(guiGraphics, i, j, f); } diff --git a/common/src/main/java/org/vivecraft/client/gui/settings/GuiListScreen.java b/common/src/main/java/org/vivecraft/client/gui/settings/GuiListScreen.java index b2a4503b2..0fd7c0e7b 100644 --- a/common/src/main/java/org/vivecraft/client/gui/settings/GuiListScreen.java +++ b/common/src/main/java/org/vivecraft/client/gui/settings/GuiListScreen.java @@ -40,15 +40,19 @@ public void onClose() { this.minecraft.setScreen(lastScreen); } + @Override + public void renderBackground(GuiGraphics guiGraphics, int i, int j, float f) { + this.renderDirtBackground(guiGraphics); + } + @Override public void render(GuiGraphics guiGraphics, int i, int j, float f) { if (reinit) { init(); reinit = false; } - this.renderBackground(guiGraphics); + super.render(guiGraphics, i, j, f); list.render(guiGraphics, i, j, f); guiGraphics.drawCenteredString(this.font, this.title, this.width / 2, 8, 0xFFFFFF); - super.render(guiGraphics, i, j, f); } } diff --git a/common/src/main/java/org/vivecraft/client/gui/settings/GuiQuickCommandsInGame.java b/common/src/main/java/org/vivecraft/client/gui/settings/GuiQuickCommandsInGame.java index 2aa97131c..11c926185 100644 --- a/common/src/main/java/org/vivecraft/client/gui/settings/GuiQuickCommandsInGame.java +++ b/common/src/main/java/org/vivecraft/client/gui/settings/GuiQuickCommandsInGame.java @@ -55,7 +55,7 @@ public void init() { } public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPartialTicks) { - this.renderBackground(guiGraphics); + this.renderBackground(guiGraphics, pMouseX, pMouseY, pPartialTicks); guiGraphics.drawCenteredString(this.font, "Quick Commands", this.width / 2, 16, 16777215); super.render(guiGraphics, pMouseX, pMouseY, pPartialTicks); } diff --git a/common/src/main/java/org/vivecraft/client/gui/settings/GuiQuickCommandsList.java b/common/src/main/java/org/vivecraft/client/gui/settings/GuiQuickCommandsList.java index 9c1a92295..e4507b9b2 100644 --- a/common/src/main/java/org/vivecraft/client/gui/settings/GuiQuickCommandsList.java +++ b/common/src/main/java/org/vivecraft/client/gui/settings/GuiQuickCommandsList.java @@ -77,11 +77,11 @@ public boolean mouseReleased(double pMouseX, double p_94754_, int pMouseY) { } } - public boolean mouseScrolled(double pMouseX, double p_94735_, double pMouseY) { - if (this.btnDelete.mouseScrolled(pMouseX, p_94735_, pMouseY)) { + public boolean mouseScrolled(double x, double y, double scrollAmountX, double scrollAmountY) { + if (this.btnDelete.mouseScrolled(x, y, scrollAmountX, scrollAmountY)) { return true; } else { - return this.txt.mouseScrolled(pMouseX, p_94735_, pMouseY) || super.mouseScrolled(pMouseX, p_94735_, pMouseY); + return this.txt.mouseScrolled(x, y, scrollAmountX, scrollAmountY) || super.mouseScrolled(x, y, scrollAmountX, scrollAmountY); } } diff --git a/common/src/main/java/org/vivecraft/client/gui/widgets/TextScrollWidget.java b/common/src/main/java/org/vivecraft/client/gui/widgets/TextScrollWidget.java index b50e03fa6..c8130ae28 100644 --- a/common/src/main/java/org/vivecraft/client/gui/widgets/TextScrollWidget.java +++ b/common/src/main/java/org/vivecraft/client/gui/widgets/TextScrollWidget.java @@ -133,10 +133,10 @@ private void setCurrentLineFromYPos(double y) { } @Override - public boolean mouseScrolled(double x, double y, double scrollAmount) { - if (scrollAmount < 0.0 && currentLine < scrollSteps) { + public boolean mouseScrolled(double x, double y, double scrollAmountX, double scrollAmountY) { + if (scrollAmountX < 0.0 && currentLine < scrollSteps) { currentLine++; - } else if (scrollAmount > 0.0 && currentLine > 0) { + } else if (scrollAmountX > 0.0 && currentLine > 0) { currentLine--; } else { // scroll bar on limit, didn't consume the input @@ -148,7 +148,7 @@ public boolean mouseScrolled(double x, double y, double scrollAmount) { @Override public boolean keyPressed(int key, int scancode, int mods) { if (key == GLFW.GLFW_KEY_UP || key == GLFW.GLFW_KEY_DOWN) { - if (mouseScrolled(0, 0, key == GLFW.GLFW_KEY_UP ? 1 : -1)) { + if (mouseScrolled(0, 0, key == GLFW.GLFW_KEY_UP ? 1 : -1, 0)) { return true; } } 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 a26ffb6a3..459fc1273 100644 --- a/common/src/main/java/org/vivecraft/client/network/ClientNetworking.java +++ b/common/src/main/java/org/vivecraft/client/network/ClientNetworking.java @@ -9,7 +9,7 @@ import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; -import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket; +import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Pose; @@ -18,6 +18,7 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.phys.Vec3; import org.vivecraft.client.VRPlayersClient; +import org.vivecraft.client.Xplat; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.VRState; import org.vivecraft.client_vr.gameplay.VRPlayer; @@ -27,6 +28,7 @@ import org.vivecraft.common.VRServerPerms; import org.vivecraft.common.network.CommonNetworkHelper; import org.vivecraft.common.network.VrPlayerState; +import org.vivecraft.common.network.packets.VivecraftDataPacket; import java.util.UUID; @@ -54,14 +56,14 @@ public static ServerboundCustomPayloadPacket getVivecraftClientPacket(CommonNetw FriendlyByteBuf friendlybytebuf = new FriendlyByteBuf(Unpooled.buffer()); friendlybytebuf.writeByte(command.ordinal()); friendlybytebuf.writeBytes(payload); - return new ServerboundCustomPayloadPacket(CommonNetworkHelper.CHANNEL, friendlybytebuf); + return new ServerboundCustomPayloadPacket(new VivecraftDataPacket(friendlybytebuf)); } public static ServerboundCustomPayloadPacket createVRActivePacket(boolean vrActive) { var buffer = new FriendlyByteBuf(Unpooled.buffer()); buffer.writeByte(CommonNetworkHelper.PacketDiscriminators.IS_VR_ACTIVE.ordinal()); buffer.writeBoolean(vrActive); - return new ServerboundCustomPayloadPacket(CommonNetworkHelper.CHANNEL, buffer); + return new ServerboundCustomPayloadPacket(new VivecraftDataPacket(buffer)); } public static void resetServerSettings() { @@ -77,10 +79,8 @@ public static void resetServerSettings() { } public static void sendVersionInfo() { - String s = CommonNetworkHelper.CHANNEL.toString(); - FriendlyByteBuf friendlybytebuf = new FriendlyByteBuf(Unpooled.buffer()); - friendlybytebuf.writeBytes(s.getBytes()); - Minecraft.getInstance().getConnection().send(new ServerboundCustomPayloadPacket(new ResourceLocation("minecraft:register"), friendlybytebuf)); + //Minecraft.getInstance().getConnection().send(new ServerboundCustomPayloadPacket(new ChannelRegisterPacket(CommonNetworkHelper.CHANNEL.toString()))); + Xplat.addNetworkChannel(Minecraft.getInstance().getConnection(), CommonNetworkHelper.CHANNEL); // send version string, with currently running Minecraft.getInstance().getConnection().send(getVivecraftClientPacket(CommonNetworkHelper.PacketDiscriminators.VERSION, (CommonDataHolder.getInstance().versionIdentifier + (VRState.vrRunning ? " VR" : " NONVR") @@ -133,7 +133,7 @@ public static ServerboundCustomPayloadPacket createVrPlayerStatePacket(VrPlayerS var buffer = new FriendlyByteBuf(Unpooled.buffer()); buffer.writeByte(CommonNetworkHelper.PacketDiscriminators.VR_PLAYER_STATE.ordinal()); vrPlayerState.serialize(buffer); - return new ServerboundCustomPayloadPacket(CommonNetworkHelper.CHANNEL, buffer); + return new ServerboundCustomPayloadPacket(new VivecraftDataPacket(buffer)); } public static void sendLegacyPackets(ClientPacketListener connection, VrPlayerState vrPlayerState) { @@ -142,21 +142,21 @@ public static void sendLegacyPackets(ClientPacketListener connection, VrPlayerSt controller0Buffer.writeByte(CommonNetworkHelper.PacketDiscriminators.CONTROLLER0DATA.ordinal()); controller0Buffer.writeBoolean(ClientDataHolderVR.getInstance().vrSettings.reverseHands); vrPlayerState.controller0().serialize(controller0Buffer); - connection.send(new ServerboundCustomPayloadPacket(CommonNetworkHelper.CHANNEL, controller0Buffer)); + connection.send(new ServerboundCustomPayloadPacket(new VivecraftDataPacket(controller0Buffer))); // right controller packet FriendlyByteBuf controller1Buffer = new FriendlyByteBuf(Unpooled.buffer()); controller1Buffer.writeByte(CommonNetworkHelper.PacketDiscriminators.CONTROLLER1DATA.ordinal()); controller1Buffer.writeBoolean(ClientDataHolderVR.getInstance().vrSettings.reverseHands); vrPlayerState.controller1().serialize(controller1Buffer); - connection.send(new ServerboundCustomPayloadPacket(CommonNetworkHelper.CHANNEL, controller1Buffer)); + connection.send(new ServerboundCustomPayloadPacket(new VivecraftDataPacket(controller1Buffer))); // hmd packet FriendlyByteBuf headBuffer = new FriendlyByteBuf(Unpooled.buffer()); headBuffer.writeByte(CommonNetworkHelper.PacketDiscriminators.HEADDATA.ordinal()); headBuffer.writeBoolean(ClientDataHolderVR.getInstance().vrSettings.seated); vrPlayerState.hmd().serialize(headBuffer); - connection.send(new ServerboundCustomPayloadPacket(CommonNetworkHelper.CHANNEL, headBuffer)); + connection.send(new ServerboundCustomPayloadPacket(new VivecraftDataPacket(headBuffer))); } public static boolean isLimitedSurvivalTeleport() { 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 74365011e..a6561b759 100644 --- a/common/src/main/java/org/vivecraft/client/render/HMDLayer.java +++ b/common/src/main/java/org/vivecraft/client/render/HMDLayer.java @@ -10,7 +10,6 @@ import net.minecraft.client.renderer.entity.layers.RenderLayer; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.player.Player; import org.vivecraft.client.VRPlayersClient; public class HMDLayer extends RenderLayer> { 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 92bac0994..931136b16 100644 --- a/common/src/main/java/org/vivecraft/client/render/VRPlayerModel.java +++ b/common/src/main/java/org/vivecraft/client/render/VRPlayerModel.java @@ -10,7 +10,6 @@ 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.world.entity.player.Player; import org.vivecraft.client.VRPlayersClient; public class VRPlayerModel extends PlayerModel { 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 3d3645529..0e917b993 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 @@ -15,7 +15,6 @@ import net.minecraft.util.Mth; import net.minecraft.world.entity.HumanoidArm; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.phys.Vec3; import org.vivecraft.client.VRPlayersClient; import org.vivecraft.client.Xplat; diff --git a/common/src/main/java/org/vivecraft/client/utils/Utils.java b/common/src/main/java/org/vivecraft/client/utils/Utils.java index 78977313c..d8baba3f4 100644 --- a/common/src/main/java/org/vivecraft/client/utils/Utils.java +++ b/common/src/main/java/org/vivecraft/client/utils/Utils.java @@ -32,7 +32,6 @@ import javax.annotation.Nullable; import java.io.*; import java.net.HttpURLConnection; -import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Path; 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 12488f916..c91eb3fbe 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 @@ -429,7 +429,7 @@ public static Vec3 applyGUIModelView(RenderPass currentPass, PoseStack pMatrixSt guirot = Matrix4f.multiply(guirot, Matrix4f.rotationY(0.9424779F * (float) i)); guipos = RenderHelper.getControllerRenderPos(1); dh.vr.hudPopup = true; - boolean flag = mc.player.getModelName().equals("slim"); + boolean flag = mc.player.getSkin().model().id().equals("slim"); scale = 0.4F; guilocal = new Vec3((float) i * -0.136F * dh.vrPlayer.vrdata_world_render.worldScale, (flag ? 0.13D : 0.12D) * (double) dh.vrPlayer.vrdata_world_render.worldScale, 0.06D * (double) dh.vrPlayer.vrdata_world_render.worldScale); guirot = Matrix4f.multiply(guirot, Matrix4f.rotationY(((float) Math.PI / 5F) * (float) i)); 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 0a87abeb6..32f118731 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 @@ -3,7 +3,7 @@ import net.minecraft.Util; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; -import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket; +import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; import net.minecraft.tags.ItemTags; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.LivingEntity; 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 658d58de3..6d47084db 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 @@ -3,9 +3,8 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; import net.minecraft.network.chat.contents.TranslatableContents; -import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket; +import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.effect.MobEffects; import net.minecraft.world.item.ItemStack; 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 c7480ed9d..771782a3f 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 @@ -2,7 +2,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; -import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket; +import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; import net.minecraft.world.entity.Pose; import org.vivecraft.client.Xplat; import org.vivecraft.client.network.ClientNetworking; diff --git a/common/src/main/java/org/vivecraft/client_vr/gui/GuiKeyboard.java b/common/src/main/java/org/vivecraft/client_vr/gui/GuiKeyboard.java index 197a2a2a4..95421f085 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gui/GuiKeyboard.java +++ b/common/src/main/java/org/vivecraft/client_vr/gui/GuiKeyboard.java @@ -171,7 +171,7 @@ public void setShift(boolean shift) { } public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPartialTicks) { - this.renderBackground(guiGraphics); + this.renderBackground(guiGraphics, pMouseX, pMouseY, pPartialTicks); guiGraphics.drawCenteredString(this.font, "Keyboard", this.width / 2, 2, 16777215); super.render(guiGraphics, 0, 0, pPartialTicks); } diff --git a/common/src/main/java/org/vivecraft/client_vr/gui/GuiRadial.java b/common/src/main/java/org/vivecraft/client_vr/gui/GuiRadial.java index 91a8fd22b..74fe825fc 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gui/GuiRadial.java +++ b/common/src/main/java/org/vivecraft/client_vr/gui/GuiRadial.java @@ -104,7 +104,7 @@ public void setShift(boolean shift) { } public void render(GuiGraphics guiGraphics, int pMouseX, int pMouseY, float pPartialTicks) { - this.renderBackground(guiGraphics); + this.renderBackground(guiGraphics, pMouseX, pMouseY, pPartialTicks); super.render(guiGraphics, 0, 0, pPartialTicks); } } 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 367c9b732..169ae881e 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 @@ -388,7 +388,7 @@ void readPalette(DataInputStream dis, int dataVersion) throws IOException { int size = dis.readInt(); for (int i = 0; i < size; i++) { - CompoundTag tag = CompoundTag.TYPE.load(dis, 0, NbtAccounter.UNLIMITED); + 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)); } 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 ae986b0e0..5a6de9e07 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 @@ -3,7 +3,6 @@ import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.ChatScreen; -import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.WinScreen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.network.chat.Component; 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 842a936f5..c24950941 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 @@ -42,9 +42,9 @@ private void renderItem(ControllerType side, PoseStack matrixStackIn, MultiBuffe 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.getSkinTextureLocation())), combinedLightIn, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, f); + rendererArmIn.render(matrixStackIn, bufferIn.getBuffer(RenderType.entityTranslucent(playerIn.getSkin().texture())), combinedLightIn, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, f); rendererArmwearIn.xRot = 0.0F; - rendererArmwearIn.render(matrixStackIn, bufferIn.getBuffer(RenderType.entityTranslucent(playerIn.getSkinTextureLocation())), combinedLightIn, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, f); + rendererArmwearIn.render(matrixStackIn, bufferIn.getBuffer(RenderType.entityTranslucent(playerIn.getSkin().texture())), combinedLightIn, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, f); RenderSystem.disableBlend(); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); } 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 6facd1fc4..d994bfe99 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 @@ -820,8 +820,9 @@ private static boolean shouldRenderCrosshair() { return false; } else if (dataHolder.climbTracker.isGrabbingLadder(0)) { return false; - } else + } else { return !(dataHolder.vrPlayer.worldScale > 15.0F); + } } public static void renderCrosshairAtDepth(boolean depthAlways, PoseStack poseStack) { @@ -902,7 +903,8 @@ public static void renderCrosshairAtDepth(boolean depthAlways, PoseStack poseSta brightness = 0.5F; } - RenderSystem.setShaderTexture(0, Gui.GUI_ICONS_LOCATION); + TextureAtlasSprite crosshairSprite = Minecraft.getInstance().getGuiSprites().getSprite(Gui.CROSSHAIR_SPRITE); + RenderSystem.setShaderTexture(0, crosshairSprite.atlasLocation()); float uMax = 15.0F / 256.0F; float vMax = 15.0F / 256.0F; @@ -912,13 +914,13 @@ public static void renderCrosshairAtDepth(boolean depthAlways, PoseStack poseSta bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.NEW_ENTITY); bufferbuilder.vertex(poseStack.last().pose(), -1.0F, 1.0F, 0.0F).color(brightness, brightness, brightness, 1.0F) - .uv(0.0F, vMax).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(0.0F, 0.0F, 1.0F).endVertex(); + .uv(crosshairSprite.getU0(), crosshairSprite.getV1()).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(0.0F, 0.0F, 1.0F).endVertex(); bufferbuilder.vertex(poseStack.last().pose(), 1.0F, 1.0F, 0.0F).color(brightness, brightness, brightness, 1.0F) - .uv(uMax, vMax).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(0.0F, 0.0F, 1.0F).endVertex(); + .uv(crosshairSprite.getU1(), crosshairSprite.getV1()).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(0.0F, 0.0F, 1.0F).endVertex(); bufferbuilder.vertex(poseStack.last().pose(), 1.0F, -1.0F, 0.0F).color(brightness, brightness, brightness, 1.0F) - .uv(uMax, 0.0F).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(0.0F, 0.0F, 1.0F).endVertex(); + .uv(crosshairSprite.getU1(), crosshairSprite.getV0()).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(0.0F, 0.0F, 1.0F).endVertex(); bufferbuilder.vertex(poseStack.last().pose(), -1.0F, -1.0F, 0.0F).color(brightness, brightness, brightness, 1.0F) - .uv(0.0F, 0.0F).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(0.0F, 0.0F, 1.0F).endVertex(); + .uv(crosshairSprite.getU0(), crosshairSprite.getV0()).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(0.0F, 0.0F, 1.0F).endVertex(); BufferUploader.drawWithShader(bufferbuilder.end()); 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 449ba9d84..9320ea405 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 @@ -17,7 +17,6 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.util.RandomSource; import net.minecraft.world.inventory.InventoryMenu; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec3; import org.vivecraft.client.utils.Utils; import org.vivecraft.client_vr.ClientDataHolderVR; diff --git a/common/src/main/java/org/vivecraft/client_vr/utils/LoaderUtils.java b/common/src/main/java/org/vivecraft/client_vr/utils/LoaderUtils.java index b94702c28..62d996189 100644 --- a/common/src/main/java/org/vivecraft/client_vr/utils/LoaderUtils.java +++ b/common/src/main/java/org/vivecraft/client_vr/utils/LoaderUtils.java @@ -8,7 +8,6 @@ import java.nio.file.FileSystems; import java.util.HashMap; import java.util.Map; -import java.util.zip.ZipException; public class LoaderUtils { public static URL ZipFileUrl; diff --git a/common/src/main/java/org/vivecraft/common/CustomShapedRecipe.java b/common/src/main/java/org/vivecraft/common/CustomShapedRecipe.java new file mode 100644 index 000000000..076aada7d --- /dev/null +++ b/common/src/main/java/org/vivecraft/common/CustomShapedRecipe.java @@ -0,0 +1,46 @@ +package org.vivecraft.common; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.network.chat.Component; +import net.minecraft.util.ExtraCodecs; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; + +public class CustomShapedRecipe { + public static final Codec VIVECRAFT_ITEMSTACK_OBJECT_CODEC = RecordCodecBuilder.create((instance) -> + instance.group( + BuiltInRegistries.ITEM.byNameCodec() + .fieldOf("item") + .forGetter(ItemStack::getItem), + ExtraCodecs + .strictOptionalField(BuiltInRegistries.ITEM.byNameCodec(), "vanillaitem", Items.AIR) + .forGetter(ItemStack::getItem), + ExtraCodecs + .strictOptionalField(ExtraCodecs.POSITIVE_INT, "count", 1) + .forGetter(ItemStack::getCount), + ExtraCodecs + .strictOptionalField(ExtraCodecs.COMPONENT, "name", Component.empty()) + .forGetter(ItemStack::getHoverName), + ExtraCodecs + .strictOptionalField(Codec.BOOL, "unbreakable", false) + .forGetter(itemStack -> itemStack.getOrCreateTag().getBoolean("Unbreakable")), + ExtraCodecs + .strictOptionalField(ExtraCodecs.POSITIVE_INT, "hideflags", 0) + .forGetter(itemStack -> itemStack.getOrCreateTag().getInt("HideFlags")) + ).apply(instance, (item, vanillaitem, count, name, unbreakable, hideflags) -> { + if (vanillaitem != Items.AIR) { + ItemStack itemStack = new ItemStack(vanillaitem, count); + if (!name.getString().isEmpty()) { + itemStack.setHoverName(Component.translatable(name.getString())); + } + itemStack.getOrCreateTag().putInt("HideFlags", hideflags); + itemStack.getOrCreateTag().putBoolean("Unbreakable", unbreakable); + return itemStack; + } else { + return new ItemStack(item, count); + } + }) + ); +} diff --git a/common/src/main/java/org/vivecraft/common/network/packets/VivecraftDataPacket.java b/common/src/main/java/org/vivecraft/common/network/packets/VivecraftDataPacket.java new file mode 100644 index 000000000..5e30616d1 --- /dev/null +++ b/common/src/main/java/org/vivecraft/common/network/packets/VivecraftDataPacket.java @@ -0,0 +1,18 @@ +package org.vivecraft.common.network.packets; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import org.vivecraft.common.network.CommonNetworkHelper; + +public record VivecraftDataPacket(FriendlyByteBuf buffer) implements CustomPacketPayload { + @Override + public void write(FriendlyByteBuf friendlyByteBuf) { + friendlyByteBuf.writeBytes(buffer); + } + + @Override + public ResourceLocation id() { + return CommonNetworkHelper.CHANNEL; + } +} 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 4dbbdde63..2b1b8d9ef 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 @@ -67,7 +67,7 @@ public abstract class EntityRenderDispatcherMixin implements ResourceManagerRelo @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) { if (pEntity instanceof AbstractClientPlayer) { - String s = ((AbstractClientPlayer) pEntity).getModelName(); + String s = ((AbstractClientPlayer) pEntity).getSkin().model().id(); VRPlayersClient.RotInfo playermodelcontroller$rotinfo = VRPlayersClient.getInstance().getRotationsForPlayer(pEntity.getUUID()); if (playermodelcontroller$rotinfo != null) { VRPlayerRenderer vrplayerrenderer; 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 c0ef5dd56..32b2a9cd2 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 @@ -249,8 +249,8 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { // on first resource load finished @Inject(at = @At("HEAD"), method = { - "method_24040", // fabric - "lambda$new$4"} // forge + "method_53522", // fabric + "lambda$new$6"} // forge , remap = false) public void vivecraft$initVROnLaunch(CallbackInfo ci) { // init vr after resource loading @@ -269,7 +269,7 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { if (OptifineHelper.isOptifineLoaded() && ClientDataHolderVR.getInstance().menuWorldRenderer != null && ClientDataHolderVR.getInstance().menuWorldRenderer.isReady()) { // with optifine this texture somehow fails to load, so manually reload it try { - textureManager.getTexture(Gui.GUI_ICONS_LOCATION).load(resourceManager); + textureManager.getTexture(Gui.CROSSHAIR_SPRITE).load(resourceManager); } catch (IOException e) { // if there was an error, just reload everything reloadResourcePacks(); diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/MouseHandlerVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/MouseHandlerVRMixin.java index a18d108af..6707c3b8c 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/MouseHandlerVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/MouseHandlerVRMixin.java @@ -24,11 +24,11 @@ public class MouseHandlerVRMixin { private Minecraft minecraft; // TODO, this seems unnecessary, and wrong - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;mouseScrolled(DDD)Z", shift = At.Shift.BEFORE), method = "onScroll", cancellable = true) + @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;mouseScrolled(DDDD)Z", shift = At.Shift.BEFORE), method = "onScroll", cancellable = true) public void vivecraft$cancelScroll(long g, double h, double f, CallbackInfo ci) { - if (this.minecraft.screen.mouseScrolled(g, h, f)) { + /*if (this.minecraft.screen.mouseScrolled(x, y, scrollAmountX, scrollAmountY)) { ci.cancel(); - } + }*/ } @Redirect(method = "onPress", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;isSpectator()Z")) 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 caf20a4f3..d82839719 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 @@ -45,10 +45,11 @@ public abstract class GuiVRMixin implements GuiExtension { @Final @Shadow - private static ResourceLocation WIDGETS_LOCATION; - @Final + public static ResourceLocation CROSSHAIR_SPRITE; + @Shadow - private static ResourceLocation GUI_ICONS_LOCATION; + @Final + private static ResourceLocation HOTBAR_SELECTION_SPRITE; @Shadow protected abstract Player getCameraPlayer(); @@ -99,12 +100,12 @@ public abstract class GuiVRMixin implements GuiExtension { return instance.isDown() || vivecraft$showPlayerList; } - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blit(Lnet/minecraft/resources/ResourceLocation;IIIIII)V", ordinal = 1, shift = At.Shift.AFTER), method = "renderHotbar") + @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 = "renderHotbar") public void vivecraft$hotbarContext(float f, GuiGraphics guiGraphics, 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 = this.screenWidth / 2; RenderSystem.setShaderColor(0.0F, 1.0F, 0.0F, 1.0F); - guiGraphics.blit(WIDGETS_LOCATION, i - 91 - 1 + ClientDataHolderVR.getInstance().interactTracker.hotbar * 20, this.screenHeight - 22 - 1, 0, 22, 24, 22); + guiGraphics.blitSprite(HOTBAR_SELECTION_SPRITE, i - 91 - 1 + ClientDataHolderVR.getInstance().interactTracker.hotbar * 20, this.screenHeight - 22 - 1, 24, 23); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); } } @@ -121,28 +122,28 @@ public abstract class GuiVRMixin implements GuiExtension { } } - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blit(Lnet/minecraft/resources/ResourceLocation;IIIIII)V", ordinal = 2, shift = At.Shift.BEFORE), method = "renderHotbar") + @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 = "renderHotbar") public void vivecraft$renderVRHotbarLeft(float f, GuiGraphics guiGraphics, 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;blit(Lnet/minecraft/resources/ResourceLocation;IIIIII)V", ordinal = 2, shift = At.Shift.AFTER), method = "renderHotbar") + @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 = "renderHotbar") public void vivecraft$renderVRHotbarLeftReset(float f, GuiGraphics guiGraphics, 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;blit(Lnet/minecraft/resources/ResourceLocation;IIIIII)V", ordinal = 3, shift = At.Shift.BEFORE), method = "renderHotbar") + @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 = "renderHotbar") public void vivecraft$renderVRHotbarRight(float f, GuiGraphics guiGraphics, 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;blit(Lnet/minecraft/resources/ResourceLocation;IIIIII)V", ordinal = 3, shift = At.Shift.AFTER), method = "renderHotbar") + @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 = "renderHotbar") public void vivecraft$renderVRHotbarRightReset(float f, GuiGraphics guiGraphics, CallbackInfo ci) { if (VRState.vrRunning && ClientDataHolderVR.getInstance().interactTracker.hotbar == 9) { RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); @@ -225,24 +226,27 @@ public abstract class GuiVRMixin implements GuiExtension { //uhhhh //RenderSystem.disableLighting(); RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - RenderSystem.setShaderTexture(0, GUI_ICONS_LOCATION); + TextureAtlasSprite crosshairSprite = minecraft.getGuiSprites().getSprite(CROSSHAIR_SPRITE); + RenderSystem.setShaderTexture(0, crosshairSprite.atlasLocation()); float f = 16.0F * ClientDataHolderVR.getInstance().vrSettings.menuCrosshairScale; RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.ONE_MINUS_DST_COLOR, GlStateManager.DestFactor.ZERO, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE); - this.vivecraft$drawCentredTexturedModalRect(mouseX, mouseY, f, f, 0, 0, 15, 15); + this.vivecraft$drawCentredTexturedModalRect(mouseX, mouseY, f, f, crosshairSprite.getU0(), crosshairSprite.getV0(), crosshairSprite.getU1(), crosshairSprite.getV1()); RenderSystem.disableBlend(); RenderSystem.defaultBlendFunc(); } @Unique - public void vivecraft$drawCentredTexturedModalRect(int centreX, int centreY, float width, float height, int u, int v, int texWidth, int texHeight) { - float f = 0.00390625F; - float f1 = 0.00390625F; + public void vivecraft$drawCentredTexturedModalRect(int centreX, int centreY, float width, float height, float uMin, float vMin, float uMax, float vMax) { BufferBuilder bufferbuilder = Tesselator.getInstance().getBuilder(); bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); - bufferbuilder.vertex((float) centreX - width / 2.0F, (float) centreY + height / 2.0F, 0).uv((float) (u) * f, (float) (v + texHeight) * f1).endVertex(); - bufferbuilder.vertex((float) centreX + width / 2.0F, (float) centreY + height / 2.0F, 0).uv((float) (u + texWidth) * f, (float) (v + texHeight) * f1).endVertex(); - bufferbuilder.vertex((float) centreX + width / 2.0F, (float) centreY - height / 2.0F, 0).uv((float) (u + texWidth) * f, (float) (v) * f1).endVertex(); - bufferbuilder.vertex((float) centreX - width / 2.0F, (float) centreY - height / 2.0F, 0).uv((float) (u) * f, (float) (v) * f1).endVertex(); + bufferbuilder.vertex((float) centreX - width / 2.0F, (float) centreY + height / 2.0F, 0) + .uv(uMin, vMin).endVertex(); + bufferbuilder.vertex((float) centreX + width / 2.0F, (float) centreY + height / 2.0F, 0) + .uv(uMin, vMax).endVertex(); + bufferbuilder.vertex((float) centreX + width / 2.0F, (float) centreY - height / 2.0F, 0) + .uv(uMax, vMax).endVertex(); + bufferbuilder.vertex((float) centreX - width / 2.0F, (float) centreY - height / 2.0F, 0) + .uv(uMax, vMin).endVertex(); BufferUploader.drawWithShader(bufferbuilder.end()); } } 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 72cd12d0e..69576d0e8 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 @@ -5,6 +5,7 @@ import net.minecraft.client.gui.components.toasts.ToastComponent; import net.minecraft.client.gui.components.toasts.TutorialToast; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -25,17 +26,20 @@ public abstract class TutorialToastVRMixin implements Toast { @Final private Component message; + @Shadow + @Final + private static ResourceLocation BACKGROUND_SPRITE; @Unique private int vivecraft$offset; - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blit(Lnet/minecraft/resources/ResourceLocation;IIIIII)V", shift = At.Shift.AFTER), method = "render") + @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", shift = At.Shift.AFTER), 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; vivecraft$offset = Math.min(this.width() - width, 0); if (vivecraft$offset < 0) { // draw a bigger toast from right to left, to override the left border for (int i = vivecraft$offset - (this.width() - 8) * (vivecraft$offset / (this.width() - 8)); i >= vivecraft$offset; i -= this.width() - 8) { - guiGraphics.blit(TEXTURE, i, 0, 0, 96, this.width() - 4, this.height()); + guiGraphics.blit(BACKGROUND_SPRITE, i, 0, 0, 96, this.width() - 4, this.height()); } } } diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/gui/screens/PauseScreenVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/gui/screens/PauseScreenVRMixin.java index 3faf34e16..1cb13501a 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/gui/screens/PauseScreenVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/gui/screens/PauseScreenVRMixin.java @@ -80,17 +80,13 @@ protected PauseScreenVRMixin(Component component) { GridLayout.RowHelper rowHelperOverlay_Profiler = gridWidgetOverlay_Profiler.createRowHelper(2); rowHelperOverlay_Profiler.addChild(new Button.Builder(Component.translatable("vivecraft.gui.overlay"), (p) -> { - this.minecraft.options.renderDebug = !this.minecraft.options.renderDebug; + this.minecraft.gui.getDebugOverlay().toggleOverlay(); this.minecraft.setScreen(null); }).width(48).build()); rowHelperOverlay_Profiler.addChild(new Button.Builder(Component.translatable("vivecraft.gui.profiler"), (p) -> { - if (!this.minecraft.options.renderDebug) { - this.minecraft.options.renderDebugCharts = false; - } - this.minecraft.options.renderDebugCharts = !this.minecraft.options.renderDebugCharts; - this.minecraft.options.renderDebug = this.minecraft.options.renderDebugCharts; + this.minecraft.gui.getDebugOverlay().toggleProfilerChart(); this.minecraft.setScreen(null); }).width(48).pos(50, 0).build()); diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/gui/screens/ScreenVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/gui/screens/ScreenVRMixin.java index 2c1321ac8..e1c33c6ca 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/gui/screens/ScreenVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/gui/screens/ScreenVRMixin.java @@ -6,19 +6,18 @@ import net.minecraft.client.gui.screens.Screen; import org.spongepowered.asm.mixin.Mixin; 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.CallbackInfo; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.VRState; @Mixin(Screen.class) public abstract class ScreenVRMixin extends AbstractContainerEventHandler implements Renderable { - @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;fillGradient(IIIIII)V"), method = "renderBackground") - public void vivecraft$vrBackground(GuiGraphics guiGraphics, int i, int j, int k, int l, int m, int n) { + @Inject(at = @At("HEAD"), method = "renderTransparentBackground", cancellable = true) + public void vivecraft$vrBackground(GuiGraphics guiGraphics, CallbackInfo ci) { if (VRState.vrRunning && ClientDataHolderVR.getInstance().vrSettings != null && !ClientDataHolderVR.getInstance().vrSettings.menuBackground) { - guiGraphics.fillGradient(i, j, k, l, 0, 0); - } else { - guiGraphics.fillGradient(i, j, k, l, m, n); + ci.cancel(); } } } diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/multiplayer/ClientCommonPacketListenerImplVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/multiplayer/ClientCommonPacketListenerImplVRMixin.java new file mode 100644 index 000000000..6d886ac08 --- /dev/null +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/multiplayer/ClientCommonPacketListenerImplVRMixin.java @@ -0,0 +1,25 @@ +package org.vivecraft.mixin.client_vr.multiplayer; + +import net.minecraft.client.multiplayer.ClientCommonPacketListenerImpl; +import net.minecraft.network.chat.Component; +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.ClientDataHolderVR; +import org.vivecraft.client_vr.VRState; +import org.vivecraft.common.VRServerPerms; + +@Mixin(ClientCommonPacketListenerImpl.class) +public class ClientCommonPacketListenerImplVRMixin { + + + @Inject(at = @At("TAIL"), method = "onDisconnect") + public void vivecraft$disconnect(Component component, CallbackInfo ci) { + VRServerPerms.INSTANCE.setTeleportSupported(false); + if (VRState.vrInitialized) { + ClientDataHolderVR.getInstance().vrPlayer.setTeleportOverride(false); + } + ClientDataHolderVR.getInstance().vrSettings.overrides.resetAll(); + } +} 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 32f2ba356..67fae2536 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 @@ -1,22 +1,18 @@ package org.vivecraft.mixin.client_vr.multiplayer; -import com.mojang.authlib.GameProfile; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.multiplayer.ClientCommonPacketListenerImpl; import net.minecraft.client.multiplayer.ClientPacketListener; -import net.minecraft.client.multiplayer.ServerData; -import net.minecraft.client.telemetry.WorldSessionTelemetryManager; +import net.minecraft.client.multiplayer.CommonListenerCookie; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.Connection; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.network.protocol.game.*; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundSource; import net.minecraft.world.phys.Vec3; -import org.spongepowered.asm.mixin.Final; 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; @@ -29,17 +25,17 @@ import org.vivecraft.client_vr.gameplay.screenhandlers.GuiHandler; import org.vivecraft.client_vr.provider.ControllerType; import org.vivecraft.client_vr.settings.VRSettings; -import org.vivecraft.common.VRServerPerms; import org.vivecraft.common.network.CommonNetworkHelper; +import org.vivecraft.common.network.packets.VivecraftDataPacket; @Mixin(ClientPacketListener.class) -public class ClientPacketListenerVRMixin { - @Final - @Shadow - private Minecraft minecraft; +public abstract class ClientPacketListenerVRMixin extends ClientCommonPacketListenerImpl { + protected ClientPacketListenerVRMixin(Minecraft minecraft, Connection connection, CommonListenerCookie commonListenerCookie) { + super(minecraft, connection, commonListenerCookie); + } @Inject(at = @At("TAIL"), method = "") - public void vivecraft$init(Minecraft minecraft, Screen screen, Connection connection, ServerData serverData, GameProfile gameProfile, WorldSessionTelemetryManager worldSessionTelemetryManager, CallbackInfo ci) { + public void vivecraft$init(Minecraft minecraft, Connection connection, CommonListenerCookie commonListenerCookie, CallbackInfo ci) { if (ClientNetworking.needsReset) { ClientDataHolderVR.getInstance().vrSettings.overrides.resetAll(); ClientNetworking.resetServerSettings(); @@ -62,15 +58,6 @@ public class ClientPacketListenerVRMixin { } } - @Inject(at = @At("TAIL"), method = "onDisconnect") - public void vivecraft$disconnect(Component component, CallbackInfo ci) { - VRServerPerms.INSTANCE.setTeleportSupported(false); - if (VRState.vrInitialized) { - ClientDataHolderVR.getInstance().vrPlayer.setTeleportOverride(false); - } - ClientDataHolderVR.getInstance().vrSettings.overrides.resetAll(); - } - @Inject(at = @At("TAIL"), method = "close") public void vivecraft$cleanup(CallbackInfo ci) { ClientNetworking.needsReset = true; @@ -137,9 +124,10 @@ public class ClientPacketListenerVRMixin { ClientDataHolderVR.getInstance().vrSettings.overrides.resetAll(); } - @Inject(at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/network/protocol/game/ClientboundCustomPayloadPacket;getData()Lnet/minecraft/network/FriendlyByteBuf;"), method = "handleCustomPayload(Lnet/minecraft/network/protocol/game/ClientboundCustomPayloadPacket;)V", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD) - public void vivecraft$handlepacket(ClientboundCustomPayloadPacket p_105004_, CallbackInfo info, ResourceLocation channelID, FriendlyByteBuf buffer) { - if (channelID.equals(CommonNetworkHelper.CHANNEL)) { + @Inject(at = @At("HEAD"), method = "handleCustomPayload", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD) + public void vivecraft$handlepacket(CustomPacketPayload customPacketPayload, CallbackInfo info) { + if (customPacketPayload instanceof VivecraftDataPacket dataPacket) { + FriendlyByteBuf buffer = dataPacket.buffer(); var packetID = CommonNetworkHelper.PacketDiscriminators.values()[buffer.readByte()]; ClientNetworking.handlePacket(packetID, buffer); buffer.release(); 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 c82048ff7..f3b2eede8 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 @@ -11,7 +11,7 @@ import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.BlockPos; import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket; +import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; import net.minecraft.sounds.SoundEvent; import net.minecraft.util.Mth; import net.minecraft.world.InteractionHand; 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 eff1a2cef..77b003992 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 @@ -18,7 +18,6 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.state.BlockState; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -178,8 +177,8 @@ public abstract class ItemInHandRendererVRMixin implements ItemInHandRendererExt boolean flag = humanoidArm != HumanoidArm.LEFT; float h = flag ? 1.0F : -1.0F; AbstractClientPlayer abstractclientplayer = this.minecraft.player; - RenderSystem.setShaderTexture(0, abstractclientplayer.getSkinTextureLocation()); - VRArmRenderer vrarmrenderer = ((EntityRenderDispatcherVRExtension) entityRenderDispatcher).vivecraft$getArmSkinMap().get(abstractclientplayer.getModelName()); + RenderSystem.setShaderTexture(0, abstractclientplayer.getSkin().texture()); + VRArmRenderer vrarmrenderer = ((EntityRenderDispatcherVRExtension) entityRenderDispatcher).vivecraft$getArmSkinMap().get(abstractclientplayer.getSkin().model().id()); poseStack.pushPose(); if (abstractclientplayer.swingingArm == InteractionHand.MAIN_HAND && flag) { @@ -191,7 +190,7 @@ public abstract class ItemInHandRendererVRMixin implements ItemInHandRendererExt } poseStack.scale(0.4f, 0.4F, 0.4F); - boolean slim = abstractclientplayer.getModelName().equals("slim"); + boolean slim = abstractclientplayer.getSkin().model().id().equals("slim"); /* x offset: (arm x origin + arm x offset + arm x dimension * 0.5) / 16 diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/NoSodiumLevelRendererVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/NoSodiumLevelRendererVRMixin.java index 30bc23587..25d5b456a 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/NoSodiumLevelRendererVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/NoSodiumLevelRendererVRMixin.java @@ -2,6 +2,7 @@ import net.minecraft.client.Camera; import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.client.renderer.SectionOcclusionGraph; import net.minecraft.client.renderer.culling.Frustum; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -14,28 +15,22 @@ import org.vivecraft.client_vr.VRState; import org.vivecraft.mixin.client.blaze3d.RenderSystemAccessor; -import java.util.concurrent.atomic.AtomicBoolean; - @Mixin(LevelRenderer.class) public class NoSodiumLevelRendererVRMixin { - @Shadow - private boolean needsFullRenderChunkUpdate; - @Shadow @Final - private AtomicBoolean needsFrustumUpdate; + private SectionOcclusionGraph sectionOcclusionGraph; - @Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/LevelRenderer;needsFullRenderChunkUpdate:Z", ordinal = 1, shift = At.Shift.AFTER), method = "setupRender(Lnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/culling/Frustum;ZZ)V") + @Inject(at = @At("HEAD"), method = "setupRender(Lnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/culling/Frustum;ZZ)V") public void vivecraft$alwaysUpdateCull(Camera camera, Frustum frustum, boolean bl, boolean bl2, CallbackInfo info) { if (VRState.vrRunning) { - this.needsFullRenderChunkUpdate = true; // if VR is on, always update the frustum, to fix flickering chunks between eyes - needsFrustumUpdate.set(true); + sectionOcclusionGraph.invalidate(); } } - @ModifyConstant(method = "renderChunkLayer", constant = @Constant(intValue = 12)) + @ModifyConstant(method = "renderSectionLayer", constant = @Constant(intValue = 12)) public int vivecraft$moreTextures(int constant) { return RenderSystemAccessor.getShaderTextures().length; } diff --git a/common/src/main/java/org/vivecraft/mixin/network/ClientboundCustomPayloadPacketMixin.java b/common/src/main/java/org/vivecraft/mixin/network/ClientboundCustomPayloadPacketMixin.java new file mode 100644 index 000000000..ad45d297c --- /dev/null +++ b/common/src/main/java/org/vivecraft/mixin/network/ClientboundCustomPayloadPacketMixin.java @@ -0,0 +1,24 @@ +package org.vivecraft.mixin.network; + +import io.netty.buffer.Unpooled; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +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.common.network.CommonNetworkHelper; +import org.vivecraft.common.network.packets.VivecraftDataPacket; + +@Mixin(value = {ClientboundCustomPayloadPacket.class}) +public class ClientboundCustomPayloadPacketMixin { + + @Inject(at = @At("HEAD"), method = "readPayload", cancellable = true) + private static void vivecraft$catchVivecraftPackets(ResourceLocation resourceLocation, FriendlyByteBuf friendlyByteBuf, CallbackInfoReturnable cir) { + if (CommonNetworkHelper.CHANNEL.equals(resourceLocation)) { + cir.setReturnValue(new VivecraftDataPacket(new FriendlyByteBuf(Unpooled.buffer()).writeBytes(friendlyByteBuf))); + } + } +} diff --git a/common/src/main/java/org/vivecraft/mixin/network/ServerboundCustomPayloadPacketMixin.java b/common/src/main/java/org/vivecraft/mixin/network/ServerboundCustomPayloadPacketMixin.java new file mode 100644 index 000000000..d9b2f4be3 --- /dev/null +++ b/common/src/main/java/org/vivecraft/mixin/network/ServerboundCustomPayloadPacketMixin.java @@ -0,0 +1,24 @@ +package org.vivecraft.mixin.network; + +import io.netty.buffer.Unpooled; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +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.common.network.CommonNetworkHelper; +import org.vivecraft.common.network.packets.VivecraftDataPacket; + +@Mixin(value = {ServerboundCustomPayloadPacket.class}) +public class ServerboundCustomPayloadPacketMixin { + + @Inject(at = @At("HEAD"), method = "readPayload", cancellable = true) + private static void vivecraft$catchVivecraftPackets(ResourceLocation resourceLocation, FriendlyByteBuf friendlyByteBuf, CallbackInfoReturnable cir) { + if (CommonNetworkHelper.CHANNEL.equals(resourceLocation)) { + cir.setReturnValue(new VivecraftDataPacket(new FriendlyByteBuf(Unpooled.buffer()).writeBytes(friendlyByteBuf))); + } + } +} diff --git a/common/src/main/java/org/vivecraft/mixin/server/ServerCommonPacketListenerImplMixin.java b/common/src/main/java/org/vivecraft/mixin/server/ServerCommonPacketListenerImplMixin.java new file mode 100644 index 000000000..721239571 --- /dev/null +++ b/common/src/main/java/org/vivecraft/mixin/server/ServerCommonPacketListenerImplMixin.java @@ -0,0 +1,39 @@ +package org.vivecraft.mixin.server; + +import net.minecraft.network.protocol.PacketUtils; +import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.network.ServerCommonPacketListenerImpl; +import net.minecraft.server.network.ServerGamePacketListenerImpl; +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.common.network.CommonNetworkHelper; +import org.vivecraft.common.network.packets.VivecraftDataPacket; +import org.vivecraft.server.ServerNetworking; + +@Mixin(ServerCommonPacketListenerImpl.class) +public abstract class ServerCommonPacketListenerImplMixin { + + @Shadow + @Final + protected MinecraftServer server; + + @Inject(at = @At("TAIL"), method = "handleCustomPayload") + public void vivecraft$handleVivecraftPackets(ServerboundCustomPayloadPacket payloadPacket, CallbackInfo ci) { + if (payloadPacket.payload() instanceof VivecraftDataPacket dataPacket) { + var buffer = dataPacket.buffer(); + PacketUtils.ensureRunningOnSameThread(payloadPacket, (ServerCommonPacketListenerImpl) (Object) this, server); + CommonNetworkHelper.PacketDiscriminators packetDiscriminator = CommonNetworkHelper.PacketDiscriminators.values()[buffer.readByte()]; + ServerNetworking.handlePacket(packetDiscriminator, buffer, (ServerGamePacketListenerImpl) (Object) this); + + if ((Object) this instanceof ServerGamePacketListenerImpl gamePacketListener + && packetDiscriminator == CommonNetworkHelper.PacketDiscriminators.CLIMBING) { + gamePacketListener.aboveGroundTickCount = 0; + } + } + } +} diff --git a/common/src/main/java/org/vivecraft/mixin/server/ServerGamePacketListenerImplMixin.java b/common/src/main/java/org/vivecraft/mixin/server/ServerGamePacketListenerImplMixin.java index 5d301d599..ba3c7f99b 100644 --- a/common/src/main/java/org/vivecraft/mixin/server/ServerGamePacketListenerImplMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/server/ServerGamePacketListenerImplMixin.java @@ -2,46 +2,33 @@ import net.minecraft.network.Connection; import net.minecraft.network.chat.Component; -import net.minecraft.network.protocol.PacketUtils; -import net.minecraft.network.protocol.game.ServerGamePacketListener; -import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.CommonListenerCookie; +import net.minecraft.server.network.ServerCommonPacketListenerImpl; import net.minecraft.server.network.ServerGamePacketListenerImpl; -import net.minecraft.server.network.ServerPlayerConnection; -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.common.network.CommonNetworkHelper; import org.vivecraft.server.AimFixHandler; import org.vivecraft.server.ServerNetworking; import org.vivecraft.server.ServerVRPlayers; import org.vivecraft.server.config.ServerConfig; -import static org.vivecraft.common.network.CommonNetworkHelper.PacketDiscriminators.CLIMBING; - @Mixin(ServerGamePacketListenerImpl.class) -public abstract class ServerGamePacketListenerImplMixin implements ServerPlayerConnection, ServerGamePacketListener { - - @Shadow - @Final - private Connection connection; - - @Shadow - @Final - private MinecraftServer server; +public abstract class ServerGamePacketListenerImplMixin extends ServerCommonPacketListenerImpl { @Shadow public ServerPlayer player; - @Shadow - private int aboveGroundTickCount; + public ServerGamePacketListenerImplMixin(MinecraftServer minecraftServer, Connection connection, CommonListenerCookie commonListenerCookie) { + super(minecraftServer, connection, commonListenerCookie); + } - @Inject(at = @At("TAIL"), method = "(Lnet/minecraft/server/MinecraftServer;Lnet/minecraft/network/Connection;Lnet/minecraft/server/level/ServerPlayer;)V") - public void vivecraft$init(MinecraftServer p_9770_, Connection p_9771_, ServerPlayer p_9772_, CallbackInfo info) { + @Inject(at = @At("TAIL"), method = "") + public void vivecraft$init(MinecraftServer minecraftServer, Connection connection, ServerPlayer serverPlayer, CommonListenerCookie commonListenerCookie, CallbackInfo ci) { // Vivecraft if (this.connection.channel != null && this.connection.channel.pipeline().get("packet_handler") != null) { //fake player fix this.connection.channel.pipeline().addBefore("packet_handler", "vr_aim_fix", @@ -54,21 +41,6 @@ public abstract class ServerGamePacketListenerImplMixin implements ServerPlayerC ServerNetworking.sendVrPlayerStateToClients(this.player); } - @Inject(at = @At("TAIL"), method = "handleCustomPayload(Lnet/minecraft/network/protocol/game/ServerboundCustomPayloadPacket;)V") - public void vivecraft$handleVivecraftPackets(ServerboundCustomPayloadPacket pPacket, CallbackInfo info) { - var buffer = pPacket.getData(); - var channelID = pPacket.getIdentifier(); - - if (channelID.equals(CommonNetworkHelper.CHANNEL)) { - PacketUtils.ensureRunningOnSameThread(pPacket, this, this.player.serverLevel()); - CommonNetworkHelper.PacketDiscriminators packetDiscriminator = CommonNetworkHelper.PacketDiscriminators.values()[buffer.readByte()]; - ServerNetworking.handlePacket(packetDiscriminator, buffer, (ServerGamePacketListenerImpl) (Object) this); - if (packetDiscriminator == CLIMBING) { - this.aboveGroundTickCount = 0; - } - } - } - @Inject(at = @At("TAIL"), method = "onDisconnect") public void vivecraft$doLeaveMessage(Component component, CallbackInfo ci) { if (ServerConfig.messagesEnabled.get()) { diff --git a/common/src/main/java/org/vivecraft/mixin/server/ServerLoginPacketListenerImplMixin.java b/common/src/main/java/org/vivecraft/mixin/server/players/PlayerListMixin.java similarity index 54% rename from common/src/main/java/org/vivecraft/mixin/server/ServerLoginPacketListenerImplMixin.java rename to common/src/main/java/org/vivecraft/mixin/server/players/PlayerListMixin.java index 3f5553415..0934830c3 100644 --- a/common/src/main/java/org/vivecraft/mixin/server/ServerLoginPacketListenerImplMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/server/players/PlayerListMixin.java @@ -1,18 +1,20 @@ -package org.vivecraft.mixin.server; +package org.vivecraft.mixin.server.players; +import net.minecraft.network.Connection; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.ServerLoginPacketListenerImpl; +import net.minecraft.server.network.CommonListenerCookie; +import net.minecraft.server.players.PlayerList; 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.server.ServerUtil; -@Mixin(ServerLoginPacketListenerImpl.class) -public class ServerLoginPacketListenerImplMixin { +@Mixin(PlayerList.class) +public class PlayerListMixin { @Inject(at = @At("HEAD"), method = "placeNewPlayer") - private void vivecraft$scheduleLoginMessages(ServerPlayer serverPlayer, CallbackInfo ci) { + private void vivecraft$scheduleLoginMessages(Connection connection, ServerPlayer serverPlayer, CommonListenerCookie commonListenerCookie, CallbackInfo ci) { ServerUtil.scheduleWelcomeMessageOrKick(serverPlayer); ServerUtil.sendUpdateNotificationIfOP(serverPlayer); } diff --git a/common/src/main/java/org/vivecraft/mixin/world/item/crafting/ShapedRecipeMixin.java b/common/src/main/java/org/vivecraft/mixin/world/item/crafting/ShapedRecipeMixin.java index 2f66d672a..d5a7dd44f 100644 --- a/common/src/main/java/org/vivecraft/mixin/world/item/crafting/ShapedRecipeMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/world/item/crafting/ShapedRecipeMixin.java @@ -1,60 +1,16 @@ package org.vivecraft.mixin.world.item.crafting; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSyntaxException; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.GsonHelper; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.ShapedRecipe; +import com.mojang.serialization.Codec; 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.spongepowered.asm.mixin.injection.callback.LocalCapture; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.vivecraft.common.CustomShapedRecipe; -@Mixin(ShapedRecipe.class) +@Mixin(targets = "net.minecraft.world.item.crafting.ShapedRecipe$Serializer$RawShapedRecipe") public class ShapedRecipeMixin { - @Inject(method = "itemFromJson", at = @At(value = "INVOKE", target = "Lnet/minecraft/core/DefaultedRegistry;getOptional(Lnet/minecraft/resources/ResourceLocation;)Ljava/util/Optional;", shift = At.Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) - private static void vivecraft$getVivecraftVanillaItemInject(JsonObject jsonObject, CallbackInfoReturnable cir, String resourceLocation) { - if (resourceLocation.startsWith("vivecraft")) { - cir.setReturnValue(vivecraft$getVivecraftVanillaItem(jsonObject, resourceLocation)); - } - } - - @Unique - private static Item vivecraft$getVivecraftVanillaItem(JsonObject jsonObject, String resourceLocation) { - String vanillaItem = GsonHelper.getAsString(jsonObject, "vanillaitem"); - return BuiltInRegistries.ITEM.getOptional(new ResourceLocation(vanillaItem)).orElseThrow(() -> new JsonSyntaxException("Unknown item '" + vanillaItem + "'")); - } - - @Inject(method = "itemStackFromJson", at = @At("HEAD"), cancellable = true) - private static void vivecraft$customizeVanillaItemStackFabric(JsonObject jsonObject, CallbackInfoReturnable cir) { - if (GsonHelper.getAsString(jsonObject, "item").startsWith("vivecraft")) { - Item vanillaItem = vivecraft$getVivecraftVanillaItem(jsonObject, GsonHelper.getAsString(jsonObject, "item")); - cir.setReturnValue(vivecraft$customizeVanillaItemStack(jsonObject, vanillaItem)); - } - } - - @Unique - private static ItemStack vivecraft$customizeVanillaItemStack(JsonObject jsonObject, Item vanillaItem) { - if (jsonObject.has("data")) { - throw new JsonParseException("Disallowed data tag found"); - } else { - int i = GsonHelper.getAsInt(jsonObject, "count", 1); - if (i < 1) { - throw new JsonSyntaxException("Invalid output count: " + i); - } else { - ItemStack itemStack = new ItemStack(vanillaItem, i); - itemStack.setHoverName(Component.translatable(jsonObject.get("name").getAsString())); - itemStack.getOrCreateTag().putBoolean("Unbreakable", GsonHelper.getAsBoolean(jsonObject, "unbreakable", false)); - itemStack.getOrCreateTag().putInt("HideFlags", GsonHelper.getAsInt(jsonObject, "hideflags", 0)); - return itemStack; - } - } + @Redirect(at = @At(value = "FIELD", target = "Lnet/minecraft/world/item/crafting/CraftingRecipeCodecs;ITEMSTACK_OBJECT_CODEC:Lcom/mojang/serialization/Codec;"), method = "method_53750") + private static Codec vivecraft$handleVivecraftRecipe() { + // CODEC needs to be external, or it isn't initialized, when the other static codec want's to access it + return CustomShapedRecipe.VIVECRAFT_ITEMSTACK_OBJECT_CODEC; } } diff --git a/common/src/main/java/org/vivecraft/server/ServerNetworking.java b/common/src/main/java/org/vivecraft/server/ServerNetworking.java index 31c894455..94273ac7d 100644 --- a/common/src/main/java/org/vivecraft/server/ServerNetworking.java +++ b/common/src/main/java/org/vivecraft/server/ServerNetworking.java @@ -4,7 +4,7 @@ import io.netty.buffer.Unpooled; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; -import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket; +import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; import net.minecraft.server.level.ServerChunkCache; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerGamePacketListenerImpl; @@ -16,6 +16,7 @@ import org.vivecraft.common.CommonDataHolder; import org.vivecraft.common.network.CommonNetworkHelper; import org.vivecraft.common.network.VrPlayerState; +import org.vivecraft.common.network.packets.VivecraftDataPacket; import org.vivecraft.mixin.server.ChunkMapAccessor; import org.vivecraft.server.config.ServerConfig; @@ -246,7 +247,7 @@ public static ClientboundCustomPayloadPacket createVRActivePlayerPacket(boolean buffer.writeByte(CommonNetworkHelper.PacketDiscriminators.IS_VR_ACTIVE.ordinal()); buffer.writeBoolean(vrActive); buffer.writeUUID(playerID); - return new ClientboundCustomPayloadPacket(CommonNetworkHelper.CHANNEL, buffer); + return new ClientboundCustomPayloadPacket(new VivecraftDataPacket(buffer)); } public static ClientboundCustomPayloadPacket createUberPacket(Player player, VrPlayerState vrPlayerState, float worldScale, float heightScale) { @@ -256,14 +257,14 @@ public static ClientboundCustomPayloadPacket createUberPacket(Player player, VrP vrPlayerState.serialize(buffer); buffer.writeFloat(worldScale); buffer.writeFloat(heightScale); - return new ClientboundCustomPayloadPacket(CommonNetworkHelper.CHANNEL, buffer); + return new ClientboundCustomPayloadPacket(new VivecraftDataPacket(buffer)); } public static ClientboundCustomPayloadPacket getVivecraftServerPacket(CommonNetworkHelper.PacketDiscriminators command, byte[] payload) { FriendlyByteBuf friendlybytebuf = new FriendlyByteBuf(Unpooled.buffer()); friendlybytebuf.writeByte(command.ordinal()); friendlybytebuf.writeBytes(payload); - return new ClientboundCustomPayloadPacket(CommonNetworkHelper.CHANNEL, friendlybytebuf); + return new ClientboundCustomPayloadPacket(new VivecraftDataPacket(friendlybytebuf)); } public static ClientboundCustomPayloadPacket getClimbeyServerPacket() { @@ -283,14 +284,14 @@ public static ClientboundCustomPayloadPacket getClimbeyServerPacket() { // no block list friendlybytebuf.writeByte(0); } - return new ClientboundCustomPayloadPacket(CommonNetworkHelper.CHANNEL, friendlybytebuf); + return new ClientboundCustomPayloadPacket(new VivecraftDataPacket(friendlybytebuf)); } public static ClientboundCustomPayloadPacket getVivecraftServerPacket(CommonNetworkHelper.PacketDiscriminators command, String payload) { FriendlyByteBuf friendlybytebuf = new FriendlyByteBuf(Unpooled.buffer()); friendlybytebuf.writeByte(command.ordinal()); friendlybytebuf.writeUtf(payload); - return new ClientboundCustomPayloadPacket(CommonNetworkHelper.CHANNEL, friendlybytebuf); + return new ClientboundCustomPayloadPacket(new VivecraftDataPacket(friendlybytebuf)); } public static void sendVrPlayerStateToClients(ServerPlayer vrPlayerEntity) { diff --git a/common/src/main/resources/vivecraft.accesswidener b/common/src/main/resources/vivecraft.accesswidener index 1d61305e9..866b61e0e 100644 --- a/common/src/main/resources/vivecraft.accesswidener +++ b/common/src/main/resources/vivecraft.accesswidener @@ -82,7 +82,7 @@ accessible field net/minecraft/world/item/CreativeModeTabs TOOLS_AND_UTILITIES L accessible field net/minecraft/world/item/CreativeModeTabs FOOD_AND_DRINKS Lnet/minecraft/resources/ResourceKey; # to render crosshair -accessible field net/minecraft/client/gui/Gui GUI_ICONS_LOCATION Lnet/minecraft/resources/ResourceLocation; +accessible field net/minecraft/client/gui/Gui CROSSHAIR_SPRITE Lnet/minecraft/resources/ResourceLocation; # for menuworlds accessible field net/minecraft/client/multiplayer/ClientLevel$ClientLevelData isFlat Z @@ -91,3 +91,9 @@ accessible class net/minecraft/world/level/biome/Biome$ClimateSettings accessible field net/minecraft/world/level/biome/AmbientParticleSettings probability F extendable class net/minecraft/world/level/material/FluidState accessible field net/minecraft/world/level/block/state/StateHolder propertiesCodec Lcom/mojang/serialization/MapCodec; + +# to spawn brush particles +accessible method net/minecraft/world/item/BrushItem spawnDustParticles (Lnet/minecraft/world/level/Level;Lnet/minecraft/world/phys/BlockHitResult;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/entity/HumanoidArm;)V + +# do not kick climbing players +accessible field net/minecraft/server/network/ServerGamePacketListenerImpl aboveGroundTickCount I diff --git a/common/src/main/resources/vivecraft.mixins.json b/common/src/main/resources/vivecraft.mixins.json index fdf23d1d5..6a91a5cb1 100644 --- a/common/src/main/resources/vivecraft.mixins.json +++ b/common/src/main/resources/vivecraft.mixins.json @@ -38,6 +38,7 @@ "client_vr.gui.screens.inventory.AbstractSignEditScreenVRMixin", "client_vr.gui.screens.inventory.BookEditScreenVRMixin", "client_vr.gui.screens.inventory.CreativeModeInventoryScreenVRMixin", + "client_vr.multiplayer.ClientCommonPacketListenerImplVRMixin", "client_vr.multiplayer.ClientPacketListenerVRMixin", "client_vr.multiplayer.MultiPlayerGameModeVRMixin", "client_vr.particle.ItemPickupParticleVRMixin", @@ -70,12 +71,15 @@ ], "minVersion": "0.8.4", "mixins": [ + "network.ClientboundCustomPayloadPacketMixin", + "network.ServerboundCustomPayloadPacketMixin", "server.ChunkMapAccessor", "server.MinecraftServerMixin", + "server.ServerCommonPacketListenerImplMixin", "server.ServerGamePacketListenerImplMixin", - "server.ServerLoginPacketListenerImplMixin", "server.ServerPlayerMixin", "server.TrackedEntityAccessor", + "server.players.PlayerListMixin", "world.entity.ai.goal.SwellGoalMixin", "world.entity.monster.EndermanFreezeWhenLookedAtMixin", "world.entity.monster.EndermanMixin", diff --git a/common/src/main/resources/vivecraft.optifine.mixins.json b/common/src/main/resources/vivecraft.optifine.mixins.json index d9290efd5..528162e66 100644 --- a/common/src/main/resources/vivecraft.optifine.mixins.json +++ b/common/src/main/resources/vivecraft.optifine.mixins.json @@ -1,5 +1,5 @@ { - "required": true, + "required": false, "package": "org.vivecraft.mod_compat_vr.optifine.mixin", "plugin": "org.vivecraft.MixinConfig", "compatibilityLevel": "JAVA_17", diff --git a/fabric/build.gradle b/fabric/build.gradle index cee714949..7a93abe57 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -29,41 +29,41 @@ dependencies { modApi("dev.architectury:architectury-fabric:${rootProject.architectury_version}") // for sodium compat - modRuntimeOnly "maven.modrinth:sodium:mc1.20.1-0.5.2" + modRuntimeOnly "maven.modrinth:sodium:mc1.20.2-0.5.3" // for iris compat - modRuntimeOnly "maven.modrinth:iris:1.6.8+1.20.1" + modRuntimeOnly "maven.modrinth:iris:1.6.9+1.20.2" modRuntimeOnly 'org.anarres:jcpp:1.4.14' //temp iris modRuntimeOnly 'io.github.douira:glsl-transformer:2.0.0-pre13' //temp iris // for REI compat - modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-fabric:12.0.634" + modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-fabric:13.0.661" // for Pehkui compat - modRuntimeOnly("com.github.Virtuoel:Pehkui:3.7.7", { exclude group: "net.fabricmc.fabric-api" }) + modCompileOnly("com.github.Virtuoel:Pehkui:3.7.7", { exclude group: "net.fabricmc.fabric-api" }) // other mods // modRuntimeOnly("com.simibubi.create:create-fabric-1.19.2:0.5.0.i-969+1.19.2") - modCompileOnly "maven.modrinth:lithium:mc1.20.1-0.11.2" - modCompileOnly "maven.modrinth:indium:1.0.21+mc1.20.1" + modCompileOnly "maven.modrinth:lithium:mc1.20.2-0.12.0" + modCompileOnly "maven.modrinth:indium:1.0.27+mc1.20.1" //mod menu - modApi("com.terraformersmc:modmenu:7.2.2") + modApi("com.terraformersmc:modmenu:8.0.0") // for immersive portals compat - modRuntimeOnly('com.github.iPortalTeam.ImmersivePortalsMod:imm_ptl_core:v3.3.1-mc1.20.1') { + modCompileOnly('com.github.iPortalTeam.ImmersivePortalsMod:imm_ptl_core:v3.3.1-mc1.20.1') { exclude(group: "net.fabricmc.fabric-api") transitive(false) } - modRuntimeOnly('com.github.iPortalTeam.ImmersivePortalsMod:q_misc_util:v3.3.1-mc1.20.1') { + modCompileOnly('com.github.iPortalTeam.ImmersivePortalsMod:q_misc_util:v3.3.1-mc1.20.1') { exclude(group: "net.fabricmc.fabric-api") transitive(false) } - modRuntimeOnly('com.github.iPortalTeam.ImmersivePortalsMod:build:v3.3.1-mc1.20.1') { + modCompileOnly('com.github.iPortalTeam.ImmersivePortalsMod:build:v3.3.1-mc1.20.1') { exclude(group: "net.fabricmc.fabric-api") transitive(false) } - modRuntimeOnly("com.github.llamalad7.mixinextras:mixinextras-fabric:0.2.0-beta.9") + modCompileOnly("com.github.llamalad7.mixinextras:mixinextras-fabric:0.2.0-beta.9") // needed for resource loading include(modImplementation(fabricApi.module("fabric-resource-loader-v0", rootProject.fabric_api_version))) 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 e8e173d52..01a636122 100644 --- a/fabric/src/main/java/org/vivecraft/client/fabric/XplatImpl.java +++ b/fabric/src/main/java/org/vivecraft/client/fabric/XplatImpl.java @@ -5,9 +5,14 @@ import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.ModelBakery; import net.minecraft.core.BlockPos; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.FluidTags; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.biome.Biome; @@ -94,4 +99,20 @@ public static Biome.ClimateSettings getBiomeClimateSettings(Biome biome) { public static BiomeSpecialEffects getBiomeEffects(Biome biome) { return biome.getSpecialEffects(); } + + public static void addNetworkChannel(ClientPacketListener listener, ResourceLocation resourceLocation) { + listener.send(new ServerboundCustomPayloadPacket(new CustomPacketPayload() { + public static final ResourceLocation ID = new ResourceLocation("minecraft:register"); + + @Override + public void write(FriendlyByteBuf friendlyByteBuf) { + friendlyByteBuf.writeBytes(resourceLocation.toString().getBytes()); + } + + @Override + public ResourceLocation id() { + return ID; + } + })); + } } diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 5de6b87d8..657f4be0d 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -40,7 +40,7 @@ ], "depends": { "fabricloader": ">=0.14.14", - "minecraft": ["1.20", "1.20.1"], + "minecraft": ["1.20.2"], "java": ">=17" }, "suggests": { diff --git a/forge/build.gradle b/forge/build.gradle index f35f564e1..9254284ca 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -47,8 +47,8 @@ dependencies { common(project(path: ":common", configuration: "namedElements")) { transitive false } shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false } - modRuntimeOnly("maven.modrinth:rubidium:0.6.5") - modRuntimeOnly("maven.modrinth:oculus:1.20-1.6.4") + modCompileOnly("maven.modrinth:rubidium:0.6.5") + modCompileOnly("maven.modrinth:oculus:1.20-1.6.4") forgeRuntimeLibrary("org.lwjgl:lwjgl-openvr:3.3.1") forgeRuntimeLibrary("org.lwjgl:lwjgl-openvr:3.3.1:natives-linux") 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 f50c8b5ca..c7881b6ac 100644 --- a/forge/src/main/java/org/vivecraft/client/forge/XplatImpl.java +++ b/forge/src/main/java/org/vivecraft/client/forge/XplatImpl.java @@ -1,8 +1,10 @@ package org.vivecraft.client.forge; import com.mojang.blaze3d.pipeline.RenderTarget; +import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.BiomeSpecialEffects; @@ -13,6 +15,7 @@ import net.minecraftforge.fml.loading.FMLLoader; import net.minecraftforge.fml.loading.FMLPaths; import net.minecraftforge.fml.util.ObfuscationReflectionHelper; +import net.minecraftforge.network.ChannelListManager; import java.nio.file.Path; @@ -77,4 +80,8 @@ public static Biome.ClimateSettings getBiomeClimateSettings(Biome biome) { public static BiomeSpecialEffects getBiomeEffects(Biome biome) { return biome.getModifiedSpecialEffects(); } + + public static void addNetworkChannel(ClientPacketListener listener, ResourceLocation resourceLocation) { + ChannelListManager.addChannels(listener.getConnection(), resourceLocation); + } } diff --git a/forge/src/main/java/org/vivecraft/forge/mixin/network/ForgeOpenContainerVRMixin.java b/forge/src/main/java/org/vivecraft/forge/mixin/network/ForgeOpenContainerVRMixin.java index e3133bcab..eddd0fe1d 100644 --- a/forge/src/main/java/org/vivecraft/forge/mixin/network/ForgeOpenContainerVRMixin.java +++ b/forge/src/main/java/org/vivecraft/forge/mixin/network/ForgeOpenContainerVRMixin.java @@ -1,19 +1,17 @@ package org.vivecraft.forge.mixin.network; -import net.minecraftforge.network.NetworkEvent; -import net.minecraftforge.network.PlayMessages; +import net.minecraftforge.event.network.CustomPayloadEvent; +import net.minecraftforge.network.packets.OpenContainer; 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.gameplay.screenhandlers.GuiHandler; -import java.util.function.Supplier; - -@Mixin(PlayMessages.OpenContainer.class) +@Mixin(OpenContainer.class) public class ForgeOpenContainerVRMixin { @Inject(at = @At("HEAD"), method = "handle", remap = false) - private static void markScreenActiveForge(PlayMessages.OpenContainer msg, Supplier ctx, CallbackInfo ci) { + private static void markScreenActiveForge(OpenContainer msg, CustomPayloadEvent.Context ctx, CallbackInfo ci) { GuiHandler.guiAppearOverBlockActive = true; } } diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index 8033a89f5..a5c56ec21 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 = "[46,48)" +loaderVersion = "[48,)" 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 = "[46,48)" +versionRange = "[48,)" ordering = "NONE" side = "BOTH" [[dependencies.vivecraft]] modId = "minecraft" mandatory = true -versionRange = "[1.20,1.20.1]" +versionRange = "[1.20.2]" ordering = "NONE" side = "BOTH" diff --git a/gradle.properties b/gradle.properties index 8f6a9b229..ab37a000e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ org.gradle.jvmargs=-Xmx4G -minecraft_version=1.20.1 +minecraft_version=1.20.2 enabled_platforms=fabric,forge archives_base_name=vivecraft @@ -10,9 +10,9 @@ maven_group=org.vivecraft architectury_version=9.0.5 fabric_loader_version=0.14.21 -fabric_api_version=0.87.0+1.20.1 +fabric_api_version=0.89.2+1.20.2 -forge_version=1.20.1-47.1.43 +forge_version=1.20.2-48.0.10 From 528a25b381f203c0037a47292f00e9bf13f67237 Mon Sep 17 00:00:00 2001 From: fayer3 Date: Sat, 30 Sep 2023 15:01:27 +0200 Subject: [PATCH 2/9] fix potential class cast exception --- .../mixin/server/ServerCommonPacketListenerImplMixin.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/org/vivecraft/mixin/server/ServerCommonPacketListenerImplMixin.java b/common/src/main/java/org/vivecraft/mixin/server/ServerCommonPacketListenerImplMixin.java index 721239571..2170e50ae 100644 --- a/common/src/main/java/org/vivecraft/mixin/server/ServerCommonPacketListenerImplMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/server/ServerCommonPacketListenerImplMixin.java @@ -24,14 +24,14 @@ public abstract class ServerCommonPacketListenerImplMixin { @Inject(at = @At("TAIL"), method = "handleCustomPayload") public void vivecraft$handleVivecraftPackets(ServerboundCustomPayloadPacket payloadPacket, CallbackInfo ci) { - if (payloadPacket.payload() instanceof VivecraftDataPacket dataPacket) { + if (payloadPacket.payload() instanceof VivecraftDataPacket dataPacket + && (Object) this instanceof ServerGamePacketListenerImpl gamePacketListener) { var buffer = dataPacket.buffer(); PacketUtils.ensureRunningOnSameThread(payloadPacket, (ServerCommonPacketListenerImpl) (Object) this, server); CommonNetworkHelper.PacketDiscriminators packetDiscriminator = CommonNetworkHelper.PacketDiscriminators.values()[buffer.readByte()]; - ServerNetworking.handlePacket(packetDiscriminator, buffer, (ServerGamePacketListenerImpl) (Object) this); + ServerNetworking.handlePacket(packetDiscriminator, buffer, gamePacketListener); - if ((Object) this instanceof ServerGamePacketListenerImpl gamePacketListener - && packetDiscriminator == CommonNetworkHelper.PacketDiscriminators.CLIMBING) { + if (packetDiscriminator == CommonNetworkHelper.PacketDiscriminators.CLIMBING) { gamePacketListener.aboveGroundTickCount = 0; } } From 62ad7f08c21b2a67720d12787d09a9d0eba0be79 Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Sun, 1 Oct 2023 00:31:17 +0200 Subject: [PATCH 3/9] New codec based on either codec --- .../vivecraft/common/CustomShapedRecipe.java | 31 ++++++++++--------- .../item/crafting/ShapedRecipeMixin.java | 19 ++++++++++-- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/common/src/main/java/org/vivecraft/common/CustomShapedRecipe.java b/common/src/main/java/org/vivecraft/common/CustomShapedRecipe.java index 076aada7d..fc5055c9e 100644 --- a/common/src/main/java/org/vivecraft/common/CustomShapedRecipe.java +++ b/common/src/main/java/org/vivecraft/common/CustomShapedRecipe.java @@ -1,5 +1,6 @@ package org.vivecraft.common; +import com.mojang.datafixers.util.Either; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.core.registries.BuiltInRegistries; @@ -7,15 +8,15 @@ import net.minecraft.util.ExtraCodecs; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; +import net.minecraft.world.item.crafting.CraftingRecipeCodecs; +import net.minecraft.world.item.crafting.ShapedRecipe; public class CustomShapedRecipe { + public static final Codec VIVECRAFT_ITEMSTACK_OBJECT_CODEC = RecordCodecBuilder.create((instance) -> instance.group( BuiltInRegistries.ITEM.byNameCodec() - .fieldOf("item") - .forGetter(ItemStack::getItem), - ExtraCodecs - .strictOptionalField(BuiltInRegistries.ITEM.byNameCodec(), "vanillaitem", Items.AIR) + .fieldOf("vanillaitem") .forGetter(ItemStack::getItem), ExtraCodecs .strictOptionalField(ExtraCodecs.POSITIVE_INT, "count", 1) @@ -29,18 +30,18 @@ public class CustomShapedRecipe { ExtraCodecs .strictOptionalField(ExtraCodecs.POSITIVE_INT, "hideflags", 0) .forGetter(itemStack -> itemStack.getOrCreateTag().getInt("HideFlags")) - ).apply(instance, (item, vanillaitem, count, name, unbreakable, hideflags) -> { - if (vanillaitem != Items.AIR) { - ItemStack itemStack = new ItemStack(vanillaitem, count); - if (!name.getString().isEmpty()) { - itemStack.setHoverName(Component.translatable(name.getString())); - } - itemStack.getOrCreateTag().putInt("HideFlags", hideflags); - itemStack.getOrCreateTag().putBoolean("Unbreakable", unbreakable); - return itemStack; - } else { - return new ItemStack(item, count); + ).apply(instance, (vanillaitem, count, name, unbreakable, hideflags) -> { + ItemStack itemStack = new ItemStack(vanillaitem, count); + if (!name.getString().isEmpty()) { + itemStack.setHoverName(Component.translatable(name.getString())); } + itemStack.getOrCreateTag().putInt("HideFlags", hideflags); + itemStack.getOrCreateTag().putBoolean("Unbreakable", unbreakable); + return itemStack; }) ); + + public static final Codec CODEC = ExtraCodecs.either(VIVECRAFT_ITEMSTACK_OBJECT_CODEC, CraftingRecipeCodecs.ITEMSTACK_OBJECT_CODEC) + .xmap(itemStackItemStackEither -> itemStackItemStackEither.map(stack -> stack, stack -> stack), Either::right); + } diff --git a/common/src/main/java/org/vivecraft/mixin/world/item/crafting/ShapedRecipeMixin.java b/common/src/main/java/org/vivecraft/mixin/world/item/crafting/ShapedRecipeMixin.java index d5a7dd44f..6fdee70ce 100644 --- a/common/src/main/java/org/vivecraft/mixin/world/item/crafting/ShapedRecipeMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/world/item/crafting/ShapedRecipeMixin.java @@ -1,16 +1,29 @@ package org.vivecraft.mixin.world.item.crafting; +import com.mojang.datafixers.kinds.App; +import com.mojang.datafixers.util.Either; import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.crafting.ShapedRecipe; +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.ModifyArg; import org.spongepowered.asm.mixin.injection.Redirect; import org.vivecraft.common.CustomShapedRecipe; +import java.util.function.Function; + @Mixin(targets = "net.minecraft.world.item.crafting.ShapedRecipe$Serializer$RawShapedRecipe") -public class ShapedRecipeMixin { +public abstract class ShapedRecipeMixin { + @Redirect(at = @At(value = "FIELD", target = "Lnet/minecraft/world/item/crafting/CraftingRecipeCodecs;ITEMSTACK_OBJECT_CODEC:Lcom/mojang/serialization/Codec;"), method = "method_53750") - private static Codec vivecraft$handleVivecraftRecipe() { + private static Codec vivecraft$handleVivecraftRecipe() { // CODEC needs to be external, or it isn't initialized, when the other static codec want's to access it - return CustomShapedRecipe.VIVECRAFT_ITEMSTACK_OBJECT_CODEC; + return CustomShapedRecipe.CODEC; } } From 48d8f8ccf34d5c2358d374324bb2bbe6c3c6e142 Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Sun, 1 Oct 2023 01:02:46 +0200 Subject: [PATCH 4/9] cleanup --- .../java/org/vivecraft/common/CustomShapedRecipe.java | 2 -- .../mixin/world/item/crafting/ShapedRecipeMixin.java | 11 ----------- 2 files changed, 13 deletions(-) diff --git a/common/src/main/java/org/vivecraft/common/CustomShapedRecipe.java b/common/src/main/java/org/vivecraft/common/CustomShapedRecipe.java index fc5055c9e..c5f20cf41 100644 --- a/common/src/main/java/org/vivecraft/common/CustomShapedRecipe.java +++ b/common/src/main/java/org/vivecraft/common/CustomShapedRecipe.java @@ -7,9 +7,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.util.ExtraCodecs; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.CraftingRecipeCodecs; -import net.minecraft.world.item.crafting.ShapedRecipe; public class CustomShapedRecipe { diff --git a/common/src/main/java/org/vivecraft/mixin/world/item/crafting/ShapedRecipeMixin.java b/common/src/main/java/org/vivecraft/mixin/world/item/crafting/ShapedRecipeMixin.java index 6fdee70ce..ccdfe8c64 100644 --- a/common/src/main/java/org/vivecraft/mixin/world/item/crafting/ShapedRecipeMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/world/item/crafting/ShapedRecipeMixin.java @@ -1,23 +1,12 @@ package org.vivecraft.mixin.world.item.crafting; -import com.mojang.datafixers.kinds.App; -import com.mojang.datafixers.util.Either; import com.mojang.serialization.Codec; -import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -import net.minecraft.world.item.crafting.ShapedRecipe; -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.ModifyArg; import org.spongepowered.asm.mixin.injection.Redirect; import org.vivecraft.common.CustomShapedRecipe; -import java.util.function.Function; - @Mixin(targets = "net.minecraft.world.item.crafting.ShapedRecipe$Serializer$RawShapedRecipe") public abstract class ShapedRecipeMixin { From c04786e7e75d1e5e281084e05f91d929f2c665ba Mon Sep 17 00:00:00 2001 From: fayer3 Date: Tue, 10 Oct 2023 00:29:50 +0200 Subject: [PATCH 5/9] fix forge datapack version 1.20.2 --- forge/src/main/resources/pack.mcmeta | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forge/src/main/resources/pack.mcmeta b/forge/src/main/resources/pack.mcmeta index a449b57ff..a4f28e125 100644 --- a/forge/src/main/resources/pack.mcmeta +++ b/forge/src/main/resources/pack.mcmeta @@ -1,6 +1,6 @@ { "pack": { "description": "The VR mod for any loader!", - "pack_format": 15 + "pack_format": 18 } } From a2b8b15c78c800ba3d4a6d0aed917d09306a3caf Mon Sep 17 00:00:00 2001 From: fayer3 Date: Wed, 11 Oct 2023 04:21:15 +0200 Subject: [PATCH 6/9] fix crash with forge 48.0.14+, bump to 1.1.1 --- .../mixin/client/main/MainMixin.java | 24 +++++++------------ gradle.properties | 2 +- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/common/src/main/java/org/vivecraft/mixin/client/main/MainMixin.java b/common/src/main/java/org/vivecraft/mixin/client/main/MainMixin.java index e50eb371a..dcccd58f0 100644 --- a/common/src/main/java/org/vivecraft/mixin/client/main/MainMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client/main/MainMixin.java @@ -1,31 +1,26 @@ package org.vivecraft.mixin.client.main; -import com.google.common.base.Stopwatch; import joptsimple.OptionParser; import joptsimple.OptionSet; import net.minecraft.client.main.Main; 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.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import org.vivecraft.client_vr.ClientDataHolderVR; @Mixin(Main.class) public class MainMixin { - @Inject(at = @At(value = "INVOKE", target = "Ljoptsimple/OptionParser;allowsUnrecognizedOptions()V"), method = "main", locals = LocalCapture.CAPTURE_FAILHARD, remap = false) - private static void vivecraft$options(String[] strings, CallbackInfo ci, Stopwatch stopwatch, Stopwatch stopwatch2, OptionParser optionparser) { - optionparser.accepts("kiosk"); - optionparser.accepts("viewonly"); - optionparser.accepts("katvr"); - optionparser.accepts("infinadeck"); - } - - @Redirect(at = @At(value = "INVOKE", target = "Ljoptsimple/OptionParser;parse([Ljava/lang/String;)Ljoptsimple/OptionSet;", remap = false), method = "main", remap = false) - private static OptionSet vivecraft$kiosk(OptionParser optionparser, String[] p_129642_) { - OptionSet optionset = optionparser.parse(p_129642_); + @Inject(at = @At("HEAD"), method = "main", remap = false) + private static void vivecraft$options(String[] strings, CallbackInfo ci) { + OptionParser vivecraftOptionParser = new OptionParser(); + vivecraftOptionParser.allowsUnrecognizedOptions(); + vivecraftOptionParser.accepts("kiosk"); + vivecraftOptionParser.accepts("viewonly"); + vivecraftOptionParser.accepts("katvr"); + vivecraftOptionParser.accepts("infinadeck"); + OptionSet optionset = vivecraftOptionParser.parse(strings); ClientDataHolderVR.kiosk = optionset.has("kiosk"); if (ClientDataHolderVR.kiosk) { @@ -42,6 +37,5 @@ public class MainMixin { ClientDataHolderVR.katvr = optionset.has("katvr"); ClientDataHolderVR.infinadeck = optionset.has("infinadeck"); - return optionset; } } diff --git a/gradle.properties b/gradle.properties index 9957e6ad6..a7875faee 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ minecraft_version=1.20.2 enabled_platforms=fabric,forge archives_base_name=vivecraft -mod_version=1.1.0 +mod_version=1.1.1 maven_group=org.vivecraft architectury_version=9.0.5 From 45ded58bf76dab569fa3400ed1d372e5fa8dbbcf Mon Sep 17 00:00:00 2001 From: fayer3 Date: Sun, 29 Oct 2023 23:45:49 +0100 Subject: [PATCH 7/9] Forge I hate you Fix kick on death on spigot/paper servers --- .../java/org/vivecraft/client/forge/XplatImpl.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 c7881b6ac..0bdf67c39 100644 --- a/forge/src/main/java/org/vivecraft/client/forge/XplatImpl.java +++ b/forge/src/main/java/org/vivecraft/client/forge/XplatImpl.java @@ -1,9 +1,13 @@ package org.vivecraft.client.forge; import com.mojang.blaze3d.pipeline.RenderTarget; +import io.netty.buffer.Unpooled; import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.BlockPos; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; +import net.minecraft.network.protocol.common.custom.DiscardedPayload; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.biome.Biome; @@ -15,7 +19,6 @@ import net.minecraftforge.fml.loading.FMLLoader; import net.minecraftforge.fml.loading.FMLPaths; import net.minecraftforge.fml.util.ObfuscationReflectionHelper; -import net.minecraftforge.network.ChannelListManager; import java.nio.file.Path; @@ -82,6 +85,10 @@ public static BiomeSpecialEffects getBiomeEffects(Biome biome) { } public static void addNetworkChannel(ClientPacketListener listener, ResourceLocation resourceLocation) { - ChannelListManager.addChannels(listener.getConnection(), 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())))); } } From 8c727aaa32ac133d1ea6052634d29d74abd47459 Mon Sep 17 00:00:00 2001 From: fayer3 Date: Sun, 29 Oct 2023 23:49:13 +0100 Subject: [PATCH 8/9] fix forge not running in dev, by updating arch-loom to 1.4, and gradle to 8.3 --- build.gradle | 2 +- gradle.properties | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 7cb380fff..946072105 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id "architectury-plugin" version "3.4-SNAPSHOT" - id "dev.architectury.loom" version "1.3-SNAPSHOT" apply false + id "dev.architectury.loom" version "1.4-SNAPSHOT" apply false id 'io.github.juuxel.loom-quiltflower' version '1.8.0' apply false } diff --git a/gradle.properties b/gradle.properties index 6773c1dc6..a0348b674 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ architectury_version=9.0.5 fabric_loader_version=0.14.21 fabric_api_version=0.89.2+1.20.2 -forge_version=1.20.2-48.0.10 +forge_version=1.20.2-48.0.33 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 59bc51a20..db9a6b825 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From 64f2e0ee8d113cbeb6744e94be69f81ef054af59 Mon Sep 17 00:00:00 2001 From: fayer3 Date: Wed, 1 Nov 2023 01:35:52 +0100 Subject: [PATCH 9/9] fix stupid forge 48.0.32+ issues --- ...in.java => LivingEntityRendererMixin.java} | 22 +++++++----- .../mixin/client_vr/MinecraftVRMixin.java | 29 ++++++++-------- .../renderer/GameRendererVRMixin.java | 34 +++++++++++-------- .../main/resources/vivecraft.accesswidener | 1 - .../src/main/resources/vivecraft.mixins.json | 2 +- 5 files changed, 49 insertions(+), 39 deletions(-) rename common/src/main/java/org/vivecraft/mixin/client/renderer/entity/{PlayerRendererMixin.java => LivingEntityRendererMixin.java} (91%) diff --git a/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/PlayerRendererMixin.java b/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/LivingEntityRendererMixin.java similarity index 91% rename from common/src/main/java/org/vivecraft/mixin/client/renderer/entity/PlayerRendererMixin.java rename to common/src/main/java/org/vivecraft/mixin/client/renderer/entity/LivingEntityRendererMixin.java index f991369f9..e4a10af7b 100644 --- a/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/PlayerRendererMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/LivingEntityRendererMixin.java @@ -6,6 +6,7 @@ import net.minecraft.client.model.PlayerModel; import net.minecraft.client.model.geom.EntityModelSet; import net.minecraft.client.model.geom.ModelLayers; +import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.client.renderer.entity.LivingEntityRenderer; import net.minecraft.client.renderer.entity.RenderLayerParent; @@ -14,7 +15,11 @@ import net.minecraft.client.renderer.entity.player.PlayerRenderer; import net.minecraft.world.entity.LivingEntity; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.vivecraft.client.extensions.EntityRenderDispatcherExtension; import org.vivecraft.client.extensions.RenderLayerExtension; import org.vivecraft.client.utils.RenderLayerTypes; @@ -31,16 +36,18 @@ * so mods could add it manually, but some mods hardcode only the slim/default model, * and that would mean the VRPlayerRenderers would be missing those layers completely */ -@Mixin(PlayerRenderer.class) -public abstract class PlayerRendererMixin> extends LivingEntityRenderer { +@Mixin(LivingEntityRenderer.class) +public abstract class LivingEntityRendererMixin> extends EntityRenderer { - // dummy constructor - public PlayerRendererMixin(EntityRendererProvider.Context context, M entityModel, float f) { - super(context, entityModel, f); + @Shadow + protected M model; + + protected LivingEntityRendererMixin(EntityRendererProvider.Context context) { + super(context); } - @Override - public boolean addLayer(RenderLayer renderLayer) { + @Inject(at = @At("HEAD"), method = "addLayer") + public void vivecraft$copyLayer(RenderLayer renderLayer, CallbackInfoReturnable cir) { // check if the layer gets added from the PlayerRenderer, we don't want to copy, if we add it to the VRPlayerRenderer // also check that the VRPlayerRenderers were created, this method also gets called in the constructor, // those default Layers already are added to the VRPlayerRenderer there @@ -91,7 +98,6 @@ public boolean addLayer(RenderLayer renderLayer) { } } } - return super.addLayer(renderLayer); } /** diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/MinecraftVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/MinecraftVRMixin.java index a1d1d72c3..97c983d5b 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/MinecraftVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/MinecraftVRMixin.java @@ -96,7 +96,7 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { private boolean vivecraft$lastClick; @Unique - private ItemStack vivecraft$itemInHand; //Captured item + private int vivecraft$currentHand = 0; @Unique private long vivecraft$mirroNotifyStart; @@ -570,22 +570,23 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { } } - @ModifyVariable(at = @At(value = "STORE", ordinal = 0), method = "startUseItem") - public ItemStack vivecraft$handItemStore(ItemStack itemInHand) { - this.vivecraft$itemInHand = itemInHand; - return itemInHand; - } - - @Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;hitResult:Lnet/minecraft/world/phys/HitResult;", ordinal = 1), method = "startUseItem", locals = LocalCapture.CAPTURE_FAILHARD) - public void vivecraft$activeHandSend(CallbackInfo ci, InteractionHand[] var1, int var2, int var3, InteractionHand interactionHand) { - if (VRState.vrRunning && (ClientDataHolderVR.getInstance().vrSettings.seated || !TelescopeTracker.isTelescope(vivecraft$itemInHand))) { - ClientNetworking.sendActiveHand((byte) interactionHand.ordinal()); - } + @Inject(at = @At("HEAD"), method = "startUseItem") + private void vivecraft$resetHand(CallbackInfo ci) { + vivecraft$currentHand = 0; } @Redirect(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;hitResult:Lnet/minecraft/world/phys/HitResult;", ordinal = 1), method = "startUseItem") - public HitResult vivecraft$activeHand2(Minecraft instance) { - if (!VRState.vrRunning || ClientDataHolderVR.getInstance().vrSettings.seated || !TelescopeTracker.isTelescope(vivecraft$itemInHand)) { + public HitResult vivecraft$activeHand(Minecraft instance) { + boolean isTelescope = false; + if (VRState.vrRunning) { + InteractionHand interactionHand = InteractionHand.values()[vivecraft$currentHand++]; + ItemStack itemInHand = this.player.getItemInHand(interactionHand); + isTelescope = TelescopeTracker.isTelescope(itemInHand); + if (ClientDataHolderVR.getInstance().vrSettings.seated || !isTelescope) { + ClientNetworking.sendActiveHand((byte) interactionHand.ordinal()); + } + } + if (!VRState.vrRunning || ClientDataHolderVR.getInstance().vrSettings.seated || !isTelescope) { return instance.hitResult; } return null; diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/GameRendererVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/GameRendererVRMixin.java index e29c50595..93ed5ce22 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/GameRendererVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/GameRendererVRMixin.java @@ -32,7 +32,6 @@ import org.spongepowered.asm.mixin.injection.At.Shift; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import org.vivecraft.client.Xevents; import org.vivecraft.client.Xplat; import org.vivecraft.client_vr.ClientDataHolderVR; @@ -158,6 +157,9 @@ public abstract class GameRendererVRMixin @Final private Camera mainCamera; + @Shadow + private int itemActivationTicks; + @Redirect(method = "", at = @At(value = "NEW", target = "net/minecraft/client/Camera")) public Camera vivecraft$replaceCamera() { return new XRCamera(); @@ -422,25 +424,27 @@ public abstract class GameRendererVRMixin } @Redirect(method = "renderItemActivationAnimation", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;scale(FFF)V")) - private void vivecraft$noScaleItem(PoseStack poseStack, float x, float y, float z) { + private void vivecraft$noScaleItem(PoseStack poseStack, float x, float y, float z, int width, int height, float partialTicks) { if (RenderPassType.isVanilla()) { poseStack.scale(x, y, z); - } - } - - @Inject(method = "renderItemActivationAnimation", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;scale(FFF)V"), locals = LocalCapture.CAPTURE_FAILHARD) - private void vivecraft$transformItem(int i, int j, float f, CallbackInfo ci, int k, float g, float h, float l, float m, float n, float o, float p, PoseStack posestack) { - if (!RenderPassType.isVanilla()) { + } else { + // need to do stuff twice, because redirects have no access to locals + int i = 40 - this.itemActivationTicks; + float g = ((float) i + partialTicks) / 40.0f; + float h = g * g; + float l = g * h; + float m = 10.25f * l * h - 24.95f * h * h + 25.5f * l - 13.8f * h + 4.0f * g; + float n = m * (float) Math.PI; float sinN = Mth.sin(n) * 0.5F; - posestack.translate(0, 0, sinN - 1.0); + poseStack.translate(0, 0, sinN - 1.0); if (ClientDataHolderVR.getInstance().currentPass == RenderPass.THIRD) { - sinN *= ClientDataHolderVR.getInstance().vrSettings.mixedRealityFov / 70.0; + sinN *= (float) (ClientDataHolderVR.getInstance().vrSettings.mixedRealityFov / 70.0); } - RenderHelper.applyVRModelView(ClientDataHolderVR.getInstance().currentPass, posestack); - RenderHelper.applyStereo(ClientDataHolderVR.getInstance().currentPass, posestack); - posestack.scale(sinN, sinN, sinN); - posestack.mulPose(Axis.YP.rotationDegrees(-ClientDataHolderVR.getInstance().vrPlayer.getVRDataWorld().getEye(ClientDataHolderVR.getInstance().currentPass).getYaw())); - posestack.mulPose(Axis.XP.rotationDegrees(-ClientDataHolderVR.getInstance().vrPlayer.getVRDataWorld().getEye(ClientDataHolderVR.getInstance().currentPass).getPitch())); + RenderHelper.applyVRModelView(ClientDataHolderVR.getInstance().currentPass, poseStack); + RenderHelper.applyStereo(ClientDataHolderVR.getInstance().currentPass, poseStack); + poseStack.scale(sinN, sinN, sinN); + poseStack.mulPose(Axis.YP.rotationDegrees(-ClientDataHolderVR.getInstance().vrPlayer.getVRDataWorld().getEye(ClientDataHolderVR.getInstance().currentPass).getYaw())); + poseStack.mulPose(Axis.XP.rotationDegrees(-ClientDataHolderVR.getInstance().vrPlayer.getVRDataWorld().getEye(ClientDataHolderVR.getInstance().currentPass).getPitch())); } } diff --git a/common/src/main/resources/vivecraft.accesswidener b/common/src/main/resources/vivecraft.accesswidener index 866b61e0e..abfb06579 100644 --- a/common/src/main/resources/vivecraft.accesswidener +++ b/common/src/main/resources/vivecraft.accesswidener @@ -12,7 +12,6 @@ extendable method net/minecraft/client/renderer/entity/player/PlayerRenderer set # modded layer supports accessible method net/minecraft/client/renderer/entity/LivingEntityRenderer addLayer (Lnet/minecraft/client/renderer/entity/layers/RenderLayer;)Z -extendable method net/minecraft/client/renderer/entity/LivingEntityRenderer addLayer (Lnet/minecraft/client/renderer/entity/layers/RenderLayer;)Z mutable field net/minecraft/client/renderer/entity/layers/RenderLayer renderer Lnet/minecraft/client/renderer/entity/RenderLayerParent; accessible field net/minecraft/client/renderer/entity/layers/RenderLayer renderer Lnet/minecraft/client/renderer/entity/RenderLayerParent; diff --git a/common/src/main/resources/vivecraft.mixins.json b/common/src/main/resources/vivecraft.mixins.json index 59dee5c16..5fcb2e64c 100644 --- a/common/src/main/resources/vivecraft.mixins.json +++ b/common/src/main/resources/vivecraft.mixins.json @@ -13,7 +13,7 @@ "client.renderer.block.LiquidBlockRendererMixin", "client.renderer.entity.EntityRenderDispatcherMixin", "client.renderer.entity.ItemRendererVRMixin", - "client.renderer.entity.PlayerRendererMixin", + "client.renderer.entity.LivingEntityRendererMixin", "client.renderer.entity.layers.RenderLayerMixin", "client_vr.ClientBrandRetrieverVRMixin", "client_vr.KeyboardHandlerVRMixin",