From e27cbd36c93f2cad0fa02e0a8dc677d10eccd53d Mon Sep 17 00:00:00 2001 From: fayer3 Date: Wed, 28 Feb 2024 22:21:09 +0100 Subject: [PATCH] backport to 1.20.2 --- common/build.gradle | 12 ++--- .../gui/screens/GarbageCollectorScreen.java | 2 +- .../client/gui/screens/UpdateScreen.java | 4 +- .../gui/settings/GuiQuickCommandsList.java | 2 +- .../gui/settings/GuiRadialItemsList.java | 2 +- .../client/gui/widgets/SettingsList.java | 2 +- .../vivecraft/common/CustomShapedRecipe.java | 8 +-- .../ClientPacketListenerVRMixin.java | 10 ++-- .../ClientboundCustomPayloadPacketMixin.java | 3 +- .../ServerboundCustomPayloadPacketMixin.java | 3 +- .../ServerCommonPacketListenerImplMixin.java | 2 - .../entity/projectile/AbstractArrowMixin.java | 5 +- .../item/crafting/ShapedRecipeMixin.java | 4 +- fabric/build.gradle | 16 +++--- fabric/src/main/resources/fabric.mod.json | 2 +- forge/src/main/resources/META-INF/mods.toml | 6 +-- gradle.properties | 10 ++-- .../vivecraft/client/neoforge/XplatImpl.java | 18 ++++++- .../neoforge/event/CommonModEvents.java | 50 ------------------- .../network/NeoForgeOpenContainerVRMixin.java | 13 +++-- .../src/main/resources/META-INF/mods.toml | 11 ++-- 21 files changed, 74 insertions(+), 111 deletions(-) delete mode 100644 neoforge/src/main/java/org/vivecraft/neoforge/event/CommonModEvents.java diff --git a/common/build.gradle b/common/build.gradle index dc9575ff5..53d2acf7b 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -15,13 +15,13 @@ dependencies { modApi("dev.architectury:architectury-fabric:${rootProject.architectury_version}") { exclude group: "net.fabricmc" exclude group: "net.fabricmc.fabric-api" } // for sodium compat - modCompileOnly "maven.modrinth:sodium:mc1.20.4-0.5.8" + modCompileOnly "maven.modrinth:sodium:mc1.20.2-0.5.5" // for iris compat - modCompileOnly "maven.modrinth:iris:1.6.17+1.20.4" + modCompileOnly "maven.modrinth:iris:1.6.14+1.20.2" // for REI compat - modCompileOnly("me.shedaniel:RoughlyEnoughItems-fabric:14.0.688") { exclude group: "net.fabricmc" exclude group: "net.fabricmc.fabric-api" exclude group: "dev.architectury" } + modCompileOnly("me.shedaniel:RoughlyEnoughItems-fabric:13.0.685") { exclude group: "net.fabricmc" exclude group: "net.fabricmc.fabric-api" exclude group: "dev.architectury" } // for Pehkui compat modApi("com.github.Virtuoel:Pehkui:3.7.12") { exclude group: "net.fabricmc" exclude group: "net.fabricmc.fabric-api" } @@ -29,13 +29,13 @@ dependencies { // other mods modCompileOnly "maven.modrinth:dynamic-fps:3.4.1" // modCompileOnly("com.simibubi.create:create-fabric-1.19.2:0.5.0.i-969+1.19.2") - // modCompileOnly "maven.modrinth:lithium:mc1.20.4-0.12.1" - // modCompileOnly "maven.modrinth:indium:1.0.30+mc1.20.4" + // modCompileOnly "maven.modrinth:lithium:mc1.20.2-0.12.0" + // modCompileOnly "maven.modrinth:indium:1.0.28+mc1.20.4" modCompileOnly "maven.modrinth:resolution-control-plus:3.0.0" modCompileOnly "maven.modrinth:better-combat:1.8.3+1.20.1-fabric" // for immersive portals compat - modCompileOnly('com.github.iPortalTeam:ImmersivePortalsMod:v5.1.7-mc1.20.4') { exclude group: "net.fabricmc" exclude group: "net.fabricmc.fabric-api" } + modCompileOnly('com.github.iPortalTeam.ImmersivePortalsMod:imm_ptl_core:v4.1.4-mc1.20.2') { transitive false } //for epic fight compat modCompileOnly("maven.modrinth:epic-fight:20.6.3") diff --git a/common/src/main/java/org/vivecraft/client/gui/screens/GarbageCollectorScreen.java b/common/src/main/java/org/vivecraft/client/gui/screens/GarbageCollectorScreen.java index 848c1f1c3..b9add7cd1 100644 --- a/common/src/main/java/org/vivecraft/client/gui/screens/GarbageCollectorScreen.java +++ b/common/src/main/java/org/vivecraft/client/gui/screens/GarbageCollectorScreen.java @@ -59,7 +59,7 @@ protected void init() { .build()); this.addRenderableWidget(new Button.Builder(Component.translatable("vivecraft.gui.openguide"), - ConfirmLinkScreen.confirmLink(this, guideURL)) + ConfirmLinkScreen.confirmLink(guideURL, this, true)) .pos(this.width / 2 - 75, this.height - 32) .size(150, 20) .build()); 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 d6b845e82..7a6230a93 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 @@ -25,13 +25,13 @@ protected void init() { this.addRenderableWidget(new TextScrollWidget(this.width / 2 - 155, 30, 310, this.height - 30 - 60, UpdateChecker.changelog)); this.addRenderableWidget(new Button.Builder(Component.translatable("vivecraft.gui.downloadfrom", Component.literal("Modrinth")), - ConfirmLinkScreen.confirmLink(this, "https://modrinth.com/mod/vivecraft")) + ConfirmLinkScreen.confirmLink("https://modrinth.com/mod/vivecraft", this, true)) .pos(this.width / 2 - 155, this.height - 56) .size(150, 20) .build()); this.addRenderableWidget(new Button.Builder(Component.translatable("vivecraft.gui.downloadfrom", Component.literal("CurseForge")), - ConfirmLinkScreen.confirmLink(this, "https://www.curseforge.com/minecraft/mc-mods/vivecraft")) + ConfirmLinkScreen.confirmLink("https://www.curseforge.com/minecraft/mc-mods/vivecraft", this, true)) .pos(this.width / 2 + 5, this.height - 56) .size(150, 20) .build()); 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 7d6097f3f..feb9533dd 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 @@ -14,7 +14,7 @@ public class GuiQuickCommandsList extends ObjectSelectionList entries) { - super(minecraft, parent.width + 45, parent.height - 52, 20, 20); + super(minecraft, parent.width + 45, parent.height, 20, parent.height - 32, 20); this.parent = parent; for (SettingsList.BaseEntry entry : entries) { int i; diff --git a/common/src/main/java/org/vivecraft/common/CustomShapedRecipe.java b/common/src/main/java/org/vivecraft/common/CustomShapedRecipe.java index effe5f2a3..854abb9ad 100644 --- a/common/src/main/java/org/vivecraft/common/CustomShapedRecipe.java +++ b/common/src/main/java/org/vivecraft/common/CustomShapedRecipe.java @@ -5,9 +5,9 @@ import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.ComponentSerialization; import net.minecraft.util.ExtraCodecs; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.CraftingRecipeCodecs; public class CustomShapedRecipe { @@ -20,10 +20,10 @@ public class CustomShapedRecipe { .strictOptionalField(ExtraCodecs.POSITIVE_INT, "count", 1) .forGetter(ItemStack::getCount), ExtraCodecs - .strictOptionalField(ComponentSerialization.CODEC, "name", Component.empty()) + .strictOptionalField(ExtraCodecs.COMPONENT, "name", Component.empty()) .forGetter(ItemStack::getHoverName), ExtraCodecs - .strictOptionalField(ComponentSerialization.CODEC, "fallbackname", Component.empty()) + .strictOptionalField(ExtraCodecs.COMPONENT, "fallbackname", Component.empty()) .forGetter(ItemStack::getHoverName), ExtraCodecs .strictOptionalField(Codec.BOOL, "unbreakable", false) @@ -54,6 +54,6 @@ public class CustomShapedRecipe { }) ); - public static final Codec CODEC = ExtraCodecs.either(VIVECRAFT_ITEMSTACK_OBJECT_CODEC, ItemStack.ITEM_WITH_COUNT_CODEC) + 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/client_vr/multiplayer/ClientPacketListenerVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/multiplayer/ClientPacketListenerVRMixin.java index 7aaebbc85..8a715347a 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 @@ -140,12 +140,16 @@ protected ClientPacketListenerVRMixin(Minecraft minecraft, Connection connection } /** - * this is just needed so that neoforge doesn't crash. - * packets are handled with their events. - * {@link org.vivecraft.neoforge.event.ClientEvents#handleVivePacket} + * this is just needed for neoforge. */ @Surrogate public void vivecraft$handlepacket(ClientboundCustomPayloadPacket packet, CustomPacketPayload customPacketPayload, CallbackInfo info) { + if (customPacketPayload instanceof VivecraftDataPacket dataPacket) { + FriendlyByteBuf buffer = new FriendlyByteBuf(Unpooled.buffer()).writeBytes(dataPacket.buffer()); + ClientNetworking.handlePacket(dataPacket.packetid(), buffer); + buffer.release(); + info.cancel(); + } } @Inject(at = @At("HEAD"), method = "handleOpenScreen") diff --git a/common/src/main/java/org/vivecraft/mixin/network/ClientboundCustomPayloadPacketMixin.java b/common/src/main/java/org/vivecraft/mixin/network/ClientboundCustomPayloadPacketMixin.java index 5811a01fd..896737bc9 100644 --- a/common/src/main/java/org/vivecraft/mixin/network/ClientboundCustomPayloadPacketMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/network/ClientboundCustomPayloadPacketMixin.java @@ -16,9 +16,8 @@ public class ClientboundCustomPayloadPacketMixin { /** * catches the vivecraft client bound packets so that they don't get discarded. - * Neoforge handles that with the network events in {@link org.vivecraft.neoforge.event.ClientEvents#handleVivePacket} */ - @Inject(at = @At("HEAD"), method = "readPayload(Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/network/FriendlyByteBuf;)Lnet/minecraft/network/protocol/common/custom/CustomPacketPayload;", cancellable = true) + @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(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 index 43c37f8d1..2c6f76bd2 100644 --- a/common/src/main/java/org/vivecraft/mixin/network/ServerboundCustomPayloadPacketMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/network/ServerboundCustomPayloadPacketMixin.java @@ -16,9 +16,8 @@ public class ServerboundCustomPayloadPacketMixin { /** * catches the vivecraft server bound packets and processes them. - * Neoforge handles that in {@link org.vivecraft.neoforge.event.ServerEvents#handleVivePacket} */ - @Inject(at = @At("HEAD"), method = "readPayload(Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/network/FriendlyByteBuf;)Lnet/minecraft/network/protocol/common/custom/CustomPacketPayload;", cancellable = true) + @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(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 index a3af329a2..ac631c10b 100644 --- a/common/src/main/java/org/vivecraft/mixin/server/ServerCommonPacketListenerImplMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/server/ServerCommonPacketListenerImplMixin.java @@ -27,8 +27,6 @@ public abstract class ServerCommonPacketListenerImplMixin { /** * handle server bound vivecraft packets - * on neoforge those are handled in {@link org.vivecraft.neoforge.event.ServerEvents#handleVivePacket} - * if connected to spigot they are still handled here */ @Inject(at = @At("HEAD"), method = "handleCustomPayload", cancellable = true) public void vivecraft$handleVivecraftPackets(ServerboundCustomPayloadPacket payloadPacket, CallbackInfo ci) { diff --git a/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/AbstractArrowMixin.java b/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/AbstractArrowMixin.java index 3511c67f3..e16333e60 100644 --- a/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/AbstractArrowMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/world/entity/projectile/AbstractArrowMixin.java @@ -13,7 +13,6 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.AbstractArrow; import net.minecraft.world.entity.projectile.Projectile; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.EntityHitResult; @@ -40,8 +39,8 @@ protected AbstractArrowMixin(EntityType p_37248_, Level p_ @Shadow private double baseDamage; - @Inject(at = @At("RETURN"), method = "(Lnet/minecraft/world/entity/EntityType;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/item/ItemStack;)V") - public void vivecraft$pickup(EntityType p_36717_, LivingEntity p_36718_, Level p_36719_, ItemStack itemStack, CallbackInfo info) { + @Inject(at = @At("RETURN"), method = "(Lnet/minecraft/world/entity/EntityType;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/level/Level;)V") + public void vivecraft$pickup(EntityType p_36717_, LivingEntity p_36718_, Level p_36719_, CallbackInfo info) { if (p_36718_ instanceof ServerPlayer player) { ServerVivePlayer serverviveplayer = ServerVRPlayers.getVivePlayer(player); if (serverviveplayer != null && serverviveplayer.isVR()) { 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 0040f1f3a..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 @@ -7,10 +7,10 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.vivecraft.common.CustomShapedRecipe; -@Mixin(targets = "net.minecraft.world.item.crafting.ShapedRecipe$Serializer") +@Mixin(targets = "net.minecraft.world.item.crafting.ShapedRecipe$Serializer$RawShapedRecipe") public abstract class ShapedRecipeMixin { - @Redirect(at = @At(value = "FIELD", target = "Lnet/minecraft/world/item/ItemStack;ITEM_WITH_COUNT_CODEC:Lcom/mojang/serialization/Codec;"), method = "method_55071") + @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.CODEC; diff --git a/fabric/build.gradle b/fabric/build.gradle index 68b4d45a4..32731f9c7 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -29,29 +29,31 @@ dependencies { modApi("dev.architectury:architectury-fabric:${rootProject.architectury_version}") { exclude group: "net.fabricmc" exclude group: "net.fabricmc.fabric-api" } // for sodium compat - modRuntimeOnly "maven.modrinth:sodium:mc1.20.4-0.5.8" + modRuntimeOnly "maven.modrinth:sodium:mc1.20.2-0.5.5" // for iris compat - modRuntimeOnly "maven.modrinth:iris:1.6.17+1.20.4" + modRuntimeOnly "maven.modrinth:iris:1.6.14+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:14.0.688") { exclude group: "net.fabricmc" exclude group: "net.fabricmc.fabric-api" exclude group: "dev.architectury" } + modRuntimeOnly("me.shedaniel:RoughlyEnoughItems-fabric:13.0.685") { exclude group: "net.fabricmc" exclude group: "net.fabricmc.fabric-api" exclude group: "dev.architectury" } // for Pehkui compat modCompileOnly("com.github.Virtuoel:Pehkui:3.7.12") { exclude group: "net.fabricmc" exclude group: "net.fabricmc.fabric-api" } // 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.4-0.12.1" - // modCompileOnly "maven.modrinth:indium:1.0.30+mc1.20.4" + // modCompileOnly "maven.modrinth:lithium:mc1.20.2-0.12.0" + // modCompileOnly "maven.modrinth:indium:1.0.28+mc1.20.4" //mod menu - modApi("com.terraformersmc:modmenu:9.0.0") { exclude group: "net.fabricmc" exclude group: "net.fabricmc.fabric-api" } + modApi("com.terraformersmc:modmenu:8.0.1") { exclude group: "net.fabricmc" exclude group: "net.fabricmc.fabric-api" } // for immersive portals compat - modCompileOnly('com.github.iPortalTeam:ImmersivePortalsMod:v5.1.7-mc1.20.4') { exclude group: "net.fabricmc" exclude group: "net.fabricmc.fabric-api" } + modCompileOnly('com.github.iPortalTeam.ImmersivePortalsMod:imm_ptl_core:v4.1.4-mc1.20.2') { transitive false } + modCompileOnly('com.github.iPortalTeam.ImmersivePortalsMod:q_misc_util:v4.1.4-mc1.20.2') { transitive false } + modCompileOnly('com.github.iPortalTeam.ImmersivePortalsMod:build:v4.1.4-mc1.20.2') { transitive false } // needed for resource loading include(modImplementation(fabricApi.module("fabric-resource-loader-v0", rootProject.fabric_api_version))) diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index e235eb601..3f05fabae 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -46,7 +46,7 @@ ], "depends": { "fabricloader": ">=0.14.14", - "minecraft": ["1.20.3", "1.20.4"], + "minecraft": ["1.20.2"], "java": ">=17" }, "breaks": { diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index 57e1f85b0..b45043cdb 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader = "javafml" -loaderVersion = "[49,)" +loaderVersion = "[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 = "[49,)" +versionRange = "[48,)" ordering = "NONE" side = "BOTH" [[dependencies.vivecraft]] modId = "minecraft" mandatory = true -versionRange = "[1.20.3,1.20.4]" +versionRange = "[1.20.2,1.20.3)" ordering = "NONE" side = "BOTH" diff --git a/gradle.properties b/gradle.properties index b04cb876e..f26196424 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,19 +1,19 @@ org.gradle.jvmargs=-Xmx4G -minecraft_version=1.20.4 +minecraft_version=1.20.2 enabled_platforms=fabric,forge,neoforge archives_base_name=vivecraft mod_version=1.1.7 maven_group=org.vivecraft -architectury_version=11.0.5 +architectury_version=10.0.18 fabric_loader_version=0.15.7 -fabric_api_version=0.91.1+1.20.4 +fabric_api_version=0.91.6+1.20.2 -forge_version=1.20.4-49.0.30 -neoforge_version=20.4.164-beta +forge_version=1.20.2-48.1.0 +neoforge_version=20.2.88 diff --git a/neoforge/src/main/java/org/vivecraft/client/neoforge/XplatImpl.java b/neoforge/src/main/java/org/vivecraft/client/neoforge/XplatImpl.java index b93e4494d..1ed17a326 100644 --- a/neoforge/src/main/java/org/vivecraft/client/neoforge/XplatImpl.java +++ b/neoforge/src/main/java/org/vivecraft/client/neoforge/XplatImpl.java @@ -4,6 +4,9 @@ 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.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.ai.attributes.AttributeModifier; @@ -98,7 +101,18 @@ public static double getItemEntityReach(double baseRange, ItemStack itemStack, E } public static void addNetworkChannel(ClientPacketListener listener, ResourceLocation resourceLocation) { - // neoforge does that automatically, since we use their networking system - // at least I have been told this + 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/neoforge/src/main/java/org/vivecraft/neoforge/event/CommonModEvents.java b/neoforge/src/main/java/org/vivecraft/neoforge/event/CommonModEvents.java deleted file mode 100644 index dacf99657..000000000 --- a/neoforge/src/main/java/org/vivecraft/neoforge/event/CommonModEvents.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.vivecraft.neoforge.event; - -import io.netty.buffer.Unpooled; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.server.level.ServerPlayer; -import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.Mod; -import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent; -import net.neoforged.neoforge.network.handling.IPayloadContext; -import net.neoforged.neoforge.network.registration.IPayloadRegistrar; -import org.vivecraft.client.network.ClientNetworking; -import org.vivecraft.common.network.CommonNetworkHelper; -import org.vivecraft.common.network.packets.VivecraftDataPacket; -import org.vivecraft.neoforge.Vivecraft; -import org.vivecraft.server.ServerNetworking; - -@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, modid = Vivecraft.MODID) -public class CommonModEvents { - - @SubscribeEvent - public static void register(RegisterPayloadHandlerEvent event) { - final IPayloadRegistrar registrar = event.registrar("vivecraft") - .optional(); - registrar.play(CommonNetworkHelper.CHANNEL, - VivecraftDataPacket::new, - (packet, context) -> { - if (context.flow().isClientbound()) { - handleClientVivePacket(packet, context); - } else { - handleServerVivePacket(packet, context); - } - }); - } - - public static void handleClientVivePacket(VivecraftDataPacket packet, IPayloadContext context) { - context.workHandler().execute(() -> { - FriendlyByteBuf buffer = new FriendlyByteBuf(Unpooled.buffer()).writeBytes(packet.buffer()); - ClientNetworking.handlePacket(packet.packetid(), buffer); - buffer.release(); - }); - } - - public static void handleServerVivePacket(VivecraftDataPacket packet, IPayloadContext context) { - context.workHandler().execute(() -> { - FriendlyByteBuf buffer = new FriendlyByteBuf(Unpooled.buffer()).writeBytes(packet.buffer()); - ServerNetworking.handlePacket(packet.packetid(), buffer, (ServerPlayer) context.player().get(), p -> context.replyHandler().send(p.payload())); - buffer.release(); - }); - } -} diff --git a/neoforge/src/main/java/org/vivecraft/neoforge/mixin/network/NeoForgeOpenContainerVRMixin.java b/neoforge/src/main/java/org/vivecraft/neoforge/mixin/network/NeoForgeOpenContainerVRMixin.java index 2a047c17c..752e71689 100644 --- a/neoforge/src/main/java/org/vivecraft/neoforge/mixin/network/NeoForgeOpenContainerVRMixin.java +++ b/neoforge/src/main/java/org/vivecraft/neoforge/mixin/network/NeoForgeOpenContainerVRMixin.java @@ -1,18 +1,17 @@ package org.vivecraft.neoforge.mixin.network; -import net.neoforged.neoforge.network.handlers.ClientPayloadHandler; -import net.neoforged.neoforge.network.handling.PlayPayloadContext; -import net.neoforged.neoforge.network.payload.AdvancedOpenScreenPayload; +import net.neoforged.neoforge.network.NetworkEvent; +import net.neoforged.neoforge.network.PlayMessages; 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.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.vivecraft.client_vr.gameplay.screenhandlers.GuiHandler; -@Mixin(ClientPayloadHandler.class) +@Mixin(PlayMessages.OpenContainer.class) public class NeoForgeOpenContainerVRMixin { - @Inject(at = @At("HEAD"), method = "handle(Lnet/neoforged/neoforge/network/payload/AdvancedOpenScreenPayload;Lnet/neoforged/neoforge/network/handling/PlayPayloadContext;)V", remap = false) - private void vivecraft$markScreenActiveNeoForge(AdvancedOpenScreenPayload msg, PlayPayloadContext context, CallbackInfo ci) { + @Inject(at = @At("HEAD"), method = "handle", remap = false) + private static void vivecraft$markScreenActiveNeoForge(PlayMessages.OpenContainer msg, NetworkEvent.Context ctx, CallbackInfoReturnable cir) { GuiHandler.guiAppearOverBlockActive = true; } } diff --git a/neoforge/src/main/resources/META-INF/mods.toml b/neoforge/src/main/resources/META-INF/mods.toml index 322df39e2..a00023448 100644 --- a/neoforge/src/main/resources/META-INF/mods.toml +++ b/neoforge/src/main/resources/META-INF/mods.toml @@ -5,8 +5,7 @@ license = "LGPLv3" [[mods]] modId = "vivecraft" -version = "${version}" -displayName = "Vivecraft" +version = "${version}"displayName = "Vivecraft" displayURL = "https://modrinth.com/mod/vivecraft" logoFile = "vivecraft_icon.png" authors = "fayer3, Ferri_Arnus, IMS, jrbudda, minecraft player, Techjar" @@ -22,15 +21,15 @@ updateJSONURL = "https://raw.githubusercontent.com/Vivecraft/VivecraftMod/forge- [[dependencies.vivecraft]] modId = "neoforge" -type = "required" -versionRange = "[20.4.70-beta,)" +mandatory = true +versionRange = "[20.2.88,)" ordering = "NONE" side = "BOTH" [[dependencies.vivecraft]] modId = "minecraft" -type = "required" -versionRange = "[1.20.4]" +mandatory = true +versionRange = "[1.20.2,1.20.3)" ordering = "NONE" side = "BOTH"