From db42ff2fe50268bf901f2f99ee95a77097fe67c0 Mon Sep 17 00:00:00 2001 From: Yeregorix Date: Sat, 4 Nov 2023 14:49:46 +0100 Subject: [PATCH] Fix connection for Forge clients --- .../registries/ForgeRegistryMixin_Forge.java | 3 +-- .../RegistryManagerMixin_Forge.java} | 26 ++++++++++++++++--- .../resources/mixins.spongeforge.core.json | 3 ++- .../service/server/ban/SpongeIPBanList.java | 6 ++++- 4 files changed, 30 insertions(+), 8 deletions(-) rename forge/src/{main/java/org/spongepowered/forge/bridge/minecraftforge/registries/ForgeRegistryBridge.java => mixins/java/org/spongepowered/forge/mixin/core/minecraftforge/registries/RegistryManagerMixin_Forge.java} (54%) diff --git a/forge/src/mixins/java/org/spongepowered/forge/mixin/core/minecraftforge/registries/ForgeRegistryMixin_Forge.java b/forge/src/mixins/java/org/spongepowered/forge/mixin/core/minecraftforge/registries/ForgeRegistryMixin_Forge.java index 0ef16dbc122..a7fdaf43857 100644 --- a/forge/src/mixins/java/org/spongepowered/forge/mixin/core/minecraftforge/registries/ForgeRegistryMixin_Forge.java +++ b/forge/src/mixins/java/org/spongepowered/forge/mixin/core/minecraftforge/registries/ForgeRegistryMixin_Forge.java @@ -40,13 +40,12 @@ import org.spongepowered.common.bridge.core.RegistryBridge; import org.spongepowered.common.registry.SpongeRegistryEntry; import org.spongepowered.common.registry.SpongeRegistryType; -import org.spongepowered.forge.bridge.minecraftforge.registries.ForgeRegistryBridge; import java.util.Map; import java.util.StringJoiner; @Mixin(ForgeRegistry.class) -public abstract class ForgeRegistryMixin_Forge implements ForgeRegistryBridge { +public abstract class ForgeRegistryMixin_Forge { // @formatter:off @Shadow @Final private net.minecraft.resources.ResourceKey> key; diff --git a/forge/src/main/java/org/spongepowered/forge/bridge/minecraftforge/registries/ForgeRegistryBridge.java b/forge/src/mixins/java/org/spongepowered/forge/mixin/core/minecraftforge/registries/RegistryManagerMixin_Forge.java similarity index 54% rename from forge/src/main/java/org/spongepowered/forge/bridge/minecraftforge/registries/ForgeRegistryBridge.java rename to forge/src/mixins/java/org/spongepowered/forge/mixin/core/minecraftforge/registries/RegistryManagerMixin_Forge.java index 66eda668cda..f591b0f1463 100644 --- a/forge/src/main/java/org/spongepowered/forge/bridge/minecraftforge/registries/ForgeRegistryBridge.java +++ b/forge/src/mixins/java/org/spongepowered/forge/mixin/core/minecraftforge/registries/RegistryManagerMixin_Forge.java @@ -22,12 +22,30 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.forge.bridge.minecraftforge.registries; +package org.spongepowered.forge.mixin.core.minecraftforge.registries; -import org.spongepowered.common.bridge.core.RegistryBridge; +import net.minecraft.resources.ResourceLocation; +import net.minecraftforge.registries.ForgeRegistry; +import net.minecraftforge.registries.RegistryManager; +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; -public interface ForgeRegistryBridge { +import java.util.Map; - RegistryBridge bridge$parent(); +@Mixin(RegistryManager.class) +public class RegistryManagerMixin_Forge { + @SuppressWarnings("UnstableApiUsage") + @Inject(method = "takeSnapshot", at = @At("RETURN")) + public void forge$dontSendSpongeDataToClient(boolean savingToDisc, CallbackInfoReturnable> cir) { + if (savingToDisc) { + return; + } + + for (ForgeRegistry.Snapshot snapshot : cir.getReturnValue().values()) { + snapshot.ids.keySet().removeIf(loc -> loc.getNamespace().equals("sponge")); + } + } } diff --git a/forge/src/mixins/resources/mixins.spongeforge.core.json b/forge/src/mixins/resources/mixins.spongeforge.core.json index aff69f27cc9..0a94c1c8e9e 100644 --- a/forge/src/mixins/resources/mixins.spongeforge.core.json +++ b/forge/src/mixins/resources/mixins.spongeforge.core.json @@ -14,13 +14,14 @@ "api.event.entity.ChangeEventWorldEvent_PostMixin_Forge", "commands.CommandsMixin_Forge", "minecraftforge.MinecraftForgeMixin_Forge", - "minecraftforge.registries.ForgeRegistryMixin_Forge", "minecraftforge.event.entity.EntityTravelToDimensionEventMixin_Forge", "minecraftforge.event.entity.player.PlayerEvent_PlayerChangedDimensionEventMixin_Forge", "minecraftforge.event.world.BlockEvent_BreakEventMixin_Forge", "minecraftforge.event.world.BlockEventMixin_Forge", "minecraftforge.internal.BrandingControlMixin_Forge", "minecraftforge.network.NetworkHooksMixin_Forge", + "minecraftforge.registries.ForgeRegistryMixin_Forge", + "minecraftforge.registries.RegistryManagerMixin_Forge", "minecraftforge.util.ITeleporterMixin_Forge", "network.ConnectionMixin_Forge", "network.FriendlyByteBufMixin_Forge", diff --git a/src/main/java/org/spongepowered/common/service/server/ban/SpongeIPBanList.java b/src/main/java/org/spongepowered/common/service/server/ban/SpongeIPBanList.java index 6ee8716ff4a..85e93e7a20b 100644 --- a/src/main/java/org/spongepowered/common/service/server/ban/SpongeIPBanList.java +++ b/src/main/java/org/spongepowered/common/service/server/ban/SpongeIPBanList.java @@ -33,6 +33,7 @@ import org.spongepowered.api.Sponge; import org.spongepowered.api.service.ban.Ban; import org.spongepowered.api.service.ban.BanService; +import org.spongepowered.common.SpongeCommon; import org.spongepowered.common.util.BanUtil; import org.spongepowered.common.util.NetworkUtil; @@ -63,7 +64,10 @@ protected boolean contains(final String entry) { try { return Sponge.server().serviceProvider().banService().find(InetAddress.getByName(entry)).join().isPresent(); } catch (final UnknownHostException e) { - throw new IllegalArgumentException("Error parsing Ban IP address!", e); + // TODO SF 1.19.4 + SpongeCommon.logger().info("Error parsing Ban IP address!", e); + return false; + // throw new IllegalArgumentException("Error parsing Ban IP address!", e); } }