Skip to content

Commit

Permalink
Fix registry events on modded platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeregorix committed Mar 10, 2025
1 parent c1c8907 commit 434571a
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.common.entity.SpongeEntityTypes;
import org.spongepowered.common.launch.Launch;

@Mixin(GameData.class)
public class GameDataMixin_Forge {
Expand All @@ -45,4 +46,9 @@ public class GameDataMixin_Forge {
SpongeEntityTypes.register((Registry<EntityType<?>>) vanillaRegistry);
}
}

@Inject(method = "postRegisterEvents", at = @At("HEAD"))
private static void forge$onRegisterEvents(final CallbackInfo ci) {
Launch.instance().lifecycle().establishGlobalRegistries();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.common.entity.SpongeEntityTypes;
import org.spongepowered.common.launch.Launch;

@Mixin(GameData.class)
public class GameDataMixin_Neo {
Expand All @@ -44,4 +45,9 @@ public class GameDataMixin_Neo {
SpongeEntityTypes.register((Registry<EntityType<?>>) registry);
}
}

@Inject(method = "postRegisterEvents", at = @At("HEAD"))
private static void neo$onRegisterEvents(final CallbackInfo ci) {
Launch.instance().lifecycle().establishGlobalRegistries();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public interface Lifecycle {

void establishEarlyGlobalRegistries();

void establishGlobalRegistries();

void establishDataProviders();

void callRegisterDataEvent();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/spongepowered/common/SpongeLifecycle.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ public void establishEarlyGlobalRegistries() {
holder.setRootMinecraftRegistry((Registry<Registry<?>>) BuiltInRegistries.REGISTRY);

SpongeRegistries.registerEarlyGlobalRegistries(holder);
}

@Override
public void establishGlobalRegistries() {
final SpongeRegistryHolder holder = (SpongeRegistryHolder) this.game;

// Plugin registries
this.game.eventManager().post(new AbstractRegisterRegistryEvent.GameScopedImpl(Cause.of(EventContext.empty(), this.game), this.game));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,18 @@
*/
package org.spongepowered.common.mixin.core.registries;


import net.minecraft.core.registries.BuiltInRegistries;
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.common.launch.Launch;


@Mixin(BuiltInRegistries.class)
public abstract class BuiltInRegistriesMixin {

// We hook in here if we extend existing vanilla BuiltInRegistries with our own
// This methods should then be called during bootstrap

@Inject(method = "freeze", at = @At(value = "HEAD"))
private static void impl$onFreeze(final CallbackInfo ci) {
@Inject(method = "bootStrap", at = @At(value = "HEAD"))
private static void impl$beforeCreateContents(final CallbackInfo ci) {
Launch.instance().lifecycle().establishEarlyGlobalRegistries();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.vanilla.mixin.core.registries;

import net.minecraft.core.registries.BuiltInRegistries;
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.common.launch.Launch;

@Mixin(BuiltInRegistries.class)
public abstract class BuiltInRegistriesMixin_Vanilla {

@Inject(method = "bootStrap", at = @At(value = "INVOKE", target = "Lnet/minecraft/core/registries/BuiltInRegistries;freeze()V"))
private static void impl$beforeFreeze(final CallbackInfo ci) {
Launch.instance().lifecycle().establishGlobalRegistries();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"network.ConnectionMixin_Vanilla",
"network.protocol.common.ClientboundCustomPayloadPacketMixin_Vanilla",
"network.protocol.common.ServerboundCustomPayloadPacketMixin_Vanilla",
"registries.BuiltInRegistriesMixin_Vanilla",
"server.BootstrapMixin_Vanilla",
"server.MinecraftServerMixin_Vanilla",
"server.commands.SpreadPlayersCommandMixin_Vanilla",
Expand Down

0 comments on commit 434571a

Please sign in to comment.