Fixed Incorrect Registry Loading

This commit is contained in:
Rabbitminers 2023-03-25 10:20:50 +00:00
parent c7d899369a
commit 17432c9113
5 changed files with 41 additions and 21 deletions

View file

@ -11,19 +11,19 @@ import com.tterrag.registrate.util.entry.RegistryEntry;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import static com.simibubi.create.Create.LOGGER;
import static com.simibubi.create.Create.REGISTRATE;
@SuppressWarnings("unused")
public class AllBogeyStyles {
public static final DeferredRegister<BogeyStyle> BOGEYS = DeferredRegister.create(AllRegistries.BOGEY_NAME, Create.ID);
public static final RegistryEntry<BogeyStyle> STANDARD = REGISTRATE
.bogeyStyle("standard", new BogeyStyle(StandardBogeyInstance.class))
.block(BogeyRenderer.BogeySize.SMALL, AllBlocks.SMALL_BOGEY.get())
.block(BogeyRenderer.BogeySize.LARGE, AllBlocks.LARGE_BOGEY.get())
.block(BogeyRenderer.BogeySize.SMALL, AllBlocks.SMALL_BOGEY)
.block(BogeyRenderer.BogeySize.LARGE, AllBlocks.LARGE_BOGEY)
.register();
public static void register() {
BOGEYS.register(FMLJavaModLoadingContext.get().getModEventBus());
LOGGER.info("Registered bogey styles from " + Create.ID);
AllRegistries.DEFERRED_BOGEY_REGISTRY.register(FMLJavaModLoadingContext.get().getModEventBus());
}
}

View file

@ -2,19 +2,42 @@ package com.simibubi.create;
import com.simibubi.create.content.logistics.trains.entity.BogeyStyle;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.IForgeRegistryEntry;
import net.minecraftforge.registries.NewRegistryEvent;
import net.minecraftforge.registries.RegistryBuilder;
import java.util.function.Supplier;
@Mod.EventBusSubscriber(modid = Create.ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class AllRegistries {
public static final ResourceLocation BOGEY_NAME = new ResourceLocation(Create.ID, "bogeys");
static final DeferredRegister<BogeyStyle> DEFERRED_BOGEY_REGISTRY = DeferredRegister
.create(Keys.BOGEYS, Keys.BOGEYS.location().getNamespace());
public static Supplier<IForgeRegistry<BogeyStyle>> BOGEY_STYLES;
public static final Supplier<IForgeRegistry<BogeyStyle>> BOGEY_REGISTRY = DEFERRED_BOGEY_REGISTRY
.makeRegistry(BogeyStyle.class, AllRegistries::getBogeyRegistryBuilder);
public static void register(final NewRegistryEvent event) {
BOGEY_STYLES = event.create(new RegistryBuilder<BogeyStyle>().setName(BOGEY_NAME));
public static RegistryBuilder<BogeyStyle> getBogeyRegistryBuilder() {
return makeRegistry(Keys.BOGEYS, BogeyStyle.class);
}
private static <T extends IForgeRegistryEntry<T>> RegistryBuilder<T> makeRegistry(ResourceKey<? extends Registry<T>> key, Class<T> type) {
return new RegistryBuilder<T>().setName(key.location()).setType(type);
}
@SubscribeEvent
public void onRegistryNewRegistry(final NewRegistryEvent event) {
event.create(getBogeyRegistryBuilder());
}
public static class Keys {
public static final ResourceKey<Registry<BogeyStyle>> BOGEYS = ResourceKey
.createRegistryKey(new ResourceLocation(Create.ID, "bogeys"));
}
}

View file

@ -119,9 +119,9 @@ public class Create {
AllEntityDataSerializers.register(modEventBus);
AllOreFeatureConfigEntries.init();
AllFeatures.register(modEventBus);
AllBogeyStyles.register();
AllPlacementModifiers.register(modEventBus);
BuiltinRegistration.register(modEventBus);
AllBogeyStyles.register();
AllConfigs.register(modLoadingContext);
@ -144,8 +144,6 @@ public class Create {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> CreateClient.onCtorClient(modEventBus, forgeEventBus));
Mods.CURIOS.executeIfInstalled(() -> () -> Curios.init(modEventBus, forgeEventBus));
System.out.println(AllRegistries.BOGEY_STYLES.get().getValues());
}
public static void init(final FMLCommonSetupEvent event) {

View file

@ -231,10 +231,6 @@ public class CommonEvents {
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
public static class ModBusEvents {
@SubscribeEvent
public static void registerRegistries(final NewRegistryEvent event) {
AllRegistries.register(event);
}
@SubscribeEvent
public static void registerCapabilities(RegisterCapabilitiesEvent event) {

View file

@ -13,6 +13,8 @@ import com.tterrag.registrate.builders.AbstractBuilder;
import com.tterrag.registrate.builders.BuilderCallback;
import com.tterrag.registrate.util.entry.BlockEntry;
import com.tterrag.registrate.util.entry.RegistryEntry;
import com.tterrag.registrate.util.nullness.NonNullSupplier;
import net.minecraft.core.particles.ParticleType;
@ -31,7 +33,8 @@ import java.util.function.Supplier;
public class BogeyStyleBuilder<T extends BogeyStyle, P> extends AbstractBuilder<BogeyStyle, T, P, BogeyStyleBuilder<T, P>> {
private final T style;
private NonNullSupplier<Map<BogeyRenderer.BogeySize, IBogeyBlock>> bogeyBlocks = () -> new EnumMap<>(BogeyRenderer.BogeySize.class);
private NonNullSupplier<Map<BogeyRenderer.BogeySize, BlockEntry<? extends IBogeyBlock>>> bogeyBlocks
= () -> new EnumMap<>(BogeyRenderer.BogeySize.class);
private Supplier<AllSoundEvents.SoundEntry> sounds;
private Supplier<CompoundTag> data;
private Supplier<ParticleType<?>> particles;
@ -41,11 +44,11 @@ public class BogeyStyleBuilder<T extends BogeyStyle, P> extends AbstractBuilder<
}
protected BogeyStyleBuilder(AbstractRegistrate<?> owner, P parent, String name, BuilderCallback callback, T style) {
super(owner, parent, name, callback, AllRegistries.BOGEY_STYLES.get().getRegistryKey());
super(owner, parent, name, callback, AllRegistries.Keys.BOGEYS);
this.style = style;
bogeyBlocks.get().put(BogeyRenderer.BogeySize.SMALL, AllBlocks.SMALL_BOGEY.get());
bogeyBlocks.get().put(BogeyRenderer.BogeySize.LARGE, AllBlocks.LARGE_BOGEY.get());
// bogeyBlocks.get().put(BogeyRenderer.BogeySize.SMALL, AllBlocks.SMALL_BOGEY.get());
// bogeyBlocks.get().put(BogeyRenderer.BogeySize.LARGE, AllBlocks.LARGE_BOGEY.get());
}
public BogeyStyleBuilder<T, P> defaultData(CompoundTag data) {
@ -63,7 +66,7 @@ public class BogeyStyleBuilder<T extends BogeyStyle, P> extends AbstractBuilder<
return this;
}
public BogeyStyleBuilder<T, P> block(BogeyRenderer.BogeySize size, IBogeyBlock block) {
public BogeyStyleBuilder<T, P> block(BogeyRenderer.BogeySize size, BlockEntry<? extends IBogeyBlock> block) {
this.bogeyBlocks.get().put(size, block);
return this;
}