Skip to content

Commit

Permalink
fix: Update to work with latest Forge
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Oct 9, 2024
1 parent 7ff65a1 commit 03f94f0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ public void initialize(String modId, EmptyLoadContext context, Runnable initiali
((ForgeBalmItems) items).register();
((ForgeBalmEntities) entities).register();
((ForgeBalmWorldGen) worldGen).register();
((ForgeBalmComponents) components).register();
((ForgeBalmStats) stats).register();

initializer.run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,20 @@

import net.blay09.mods.balm.api.DeferredObject;
import net.blay09.mods.balm.api.component.BalmComponents;
import net.minecraft.core.Registry;
import net.blay09.mods.balm.forge.DeferredRegisters;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

public class ForgeBalmComponents implements BalmComponents {

private static class Registrations {
public final List<DeferredObject<?>> dataComponentTypes = new ArrayList<>();

@SubscribeEvent
public void commonSetup(FMLCommonSetupEvent event) {
event.enqueueWork(() -> dataComponentTypes.forEach(DeferredObject::resolve));
}
}

private final Map<String, ForgeBalmComponents.Registrations> registrations = new ConcurrentHashMap<>();

@Override
public <TComponent> DeferredObject<DataComponentType<TComponent>> registerComponent(Supplier<DataComponentType<TComponent>> supplier, ResourceLocation identifier) {
DeferredObject<DataComponentType<TComponent>> deferredObject = new DeferredObject<>(identifier, () -> {
DataComponentType<TComponent> dataComponentType = supplier.get();
Registry.register(BuiltInRegistries.DATA_COMPONENT_TYPE, identifier, dataComponentType);
return dataComponentType;
});
getActiveRegistrations().dataComponentTypes.add(deferredObject);
return deferredObject;
final var register = DeferredRegisters.get(Registries.DATA_COMPONENT_TYPE, identifier.getNamespace());
final var registryObject = register.register(identifier.getPath(), supplier);
return new DeferredObject<>(identifier, registryObject, registryObject::isPresent);
}

public void register() {
FMLJavaModLoadingContext.get().getModEventBus().register(getActiveRegistrations());
}

private ForgeBalmComponents.Registrations getActiveRegistrations() {
return registrations.computeIfAbsent(ModLoadingContext.get().getActiveNamespace(), it -> new ForgeBalmComponents.Registrations());
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ parchment_minecraft=1.21
parchment_version=2024.06.23

# Forge
forge_version = 52.0.2
forge_version = 52.0.18
forge_version_range = [51,)
forge_loader_version_range = [51,)

Expand Down

0 comments on commit 03f94f0

Please sign in to comment.