Skip to content

Commit

Permalink
Fix connection with NeoForge client
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeregorix committed Sep 29, 2024
1 parent eedf044 commit fa51bab
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.neoforge.accessor.neoforge.registries;

import it.unimi.dsi.fastutil.ints.Int2ObjectSortedMap;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.registries.RegistrySnapshot;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(RegistrySnapshot.class)
public interface RegistrySnapshotAccessor_Neo {

@Accessor("ids")
Int2ObjectSortedMap<ResourceLocation> accessor$ids();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"parent": "mixins.sponge.parent.json",
"package": "org.spongepowered.neoforge.accessor",
"mixins": [
"neoforge.registries.RegistrySnapshotAccessor_Neo"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.neoforge.mixin.core.neoforge.registries;

import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.registries.RegistryManager;
import net.neoforged.neoforge.registries.RegistrySnapshot;
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.spongepowered.neoforge.accessor.neoforge.registries.RegistrySnapshotAccessor_Neo;

import java.util.Map;

@SuppressWarnings("UnstableApiUsage")
@Mixin(RegistryManager.class)
public class RegistryManagerMixin_Neo {

@Inject(method = "takeSnapshot", at = @At("RETURN"))
private static void forge$dontSendSpongeDataToClient(RegistryManager.SnapshotType snapshotType, CallbackInfoReturnable<Map<ResourceLocation, RegistrySnapshot>> cir) {
if (snapshotType != RegistryManager.SnapshotType.SYNC_TO_CLIENT) {
return;
}

for (RegistrySnapshot snapshot : cir.getReturnValue().values()) {
((RegistrySnapshotAccessor_Neo) snapshot).accessor$ids().values().removeIf(loc -> loc.getNamespace().equals("sponge"));
}
}
}
1 change: 1 addition & 0 deletions neoforge/src/mixins/resources/mixins.spongeneo.core.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"neoforge.event.world.BlockEvent_BreakEventMixin_Neo",
"neoforge.event.world.BlockEventMixin_Neo",
"neoforge.internal.BrandingControlMixin_Neo",
"neoforge.registries.RegistryManagerMixin_Neo",
"network.ConnectionMixin_Neo",
"server.BootstrapMixin_Neo",
"server.MinecraftServerMixin_Neo",
Expand Down

0 comments on commit fa51bab

Please sign in to comment.