diff --git a/gradle.properties b/gradle.properties index 8502fb1..f3841cd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -31,4 +31,4 @@ registrate_version = MC1.21-1.4.1 lljij = false rootMod = false -l2serial_ver = 3.0.0 \ No newline at end of file +l2serial_ver = 3.0.1 \ No newline at end of file diff --git a/libs/l2serial-3.0.0-sources.jar b/libs/l2serial-3.0.1-sources.jar similarity index 93% rename from libs/l2serial-3.0.0-sources.jar rename to libs/l2serial-3.0.1-sources.jar index 5a121a7..754ae7b 100644 Binary files a/libs/l2serial-3.0.0-sources.jar and b/libs/l2serial-3.0.1-sources.jar differ diff --git a/libs/l2serial-3.0.0.jar b/libs/l2serial-3.0.1.jar similarity index 86% rename from libs/l2serial-3.0.0.jar rename to libs/l2serial-3.0.1.jar index bec74a0..3b61687 100644 Binary files a/libs/l2serial-3.0.0.jar and b/libs/l2serial-3.0.1.jar differ diff --git a/src/main/java/dev/xkmc/l2core/init/L2Core.java b/src/main/java/dev/xkmc/l2core/init/L2Core.java index b0625ed..d07baa3 100644 --- a/src/main/java/dev/xkmc/l2core/init/L2Core.java +++ b/src/main/java/dev/xkmc/l2core/init/L2Core.java @@ -35,16 +35,9 @@ public class L2Core { public L2Core(IEventBus bus) { Handlers.register(); - L2LibReg.register(bus); - REGISTRATE.addDataGenerator(L2TagGen.EFF_TAGS, L2TagGen::onEffectTagGen); } - @SubscribeEvent - public static void onPacketReg(RegisterPayloadHandlersEvent event) { - PACKET_HANDLER.register(event); - } - public static ResourceLocation loc(String id) { return ResourceLocation.fromNamespaceAndPath(MODID, id); } diff --git a/src/main/java/dev/xkmc/l2core/init/L2LibReg.java b/src/main/java/dev/xkmc/l2core/init/L2LibReg.java index deec60e..19f1f64 100644 --- a/src/main/java/dev/xkmc/l2core/init/L2LibReg.java +++ b/src/main/java/dev/xkmc/l2core/init/L2LibReg.java @@ -17,52 +17,50 @@ import dev.xkmc.l2serial.serialization.codec.MapCodecAdaptor; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType; -import net.neoforged.bus.api.IEventBus; import net.neoforged.neoforge.common.conditions.ICondition; import net.neoforged.neoforge.common.loot.IGlobalLootModifier; import net.neoforged.neoforge.registries.NeoForgeRegistries; public class L2LibReg { - public static final Reg REG = new Reg(L2Core.MODID); + public static final Reg REG = new Reg(L2Core.MODID); - // ingredients - public static final IngReg INGREDIENT = IngReg.of(REG); - public static final IngVal ING_ENCH = INGREDIENT.reg("enchantment", EnchantmentIngredient.class); - public static final IngVal ING_POTION = INGREDIENT.reg("potion", PotionIngredient.class); + // ingredients + public static final IngReg INGREDIENT = IngReg.of(REG); + public static final IngVal ING_ENCH = INGREDIENT.reg("enchantment", EnchantmentIngredient.class); + public static final IngVal ING_POTION = INGREDIENT.reg("potion", PotionIngredient.class); - // conditions - public static final CdcReg CONDITION = CdcReg.of(REG, NeoForgeRegistries.CONDITION_SERIALIZERS); - public static final CdcVal CONDITION_BOOL = CONDITION.reg("bool_config", BooleanValueCondition.class); - public static final CdcVal CONDITION_INT = CONDITION.reg("int_config", IntValueCondition.class); - public static final CdcVal CONDITION_DOUBLE = CONDITION.reg("double_config", DoubleValueCondition.class); - public static final CdcVal CONDITION_STR = CONDITION.reg("string_config", StringValueCondition.class); - public static final CdcVal CONDITION_LIST_STR = CONDITION.reg("string_list_config", ListStringValueCondition.class); + // conditions + public static final CdcReg CONDITION = CdcReg.of(REG, NeoForgeRegistries.CONDITION_SERIALIZERS); + public static final CdcVal CONDITION_BOOL = CONDITION.reg("bool_config", BooleanValueCondition.class); + public static final CdcVal CONDITION_INT = CONDITION.reg("int_config", IntValueCondition.class); + public static final CdcVal CONDITION_DOUBLE = CONDITION.reg("double_config", DoubleValueCondition.class); + public static final CdcVal CONDITION_STR = CONDITION.reg("string_config", StringValueCondition.class); + public static final CdcVal CONDITION_LIST_STR = CONDITION.reg("string_list_config", ListStringValueCondition.class); - // attachments - public static final AttReg ATTACHMENT = AttReg.of(REG); + // attachments + public static final AttReg ATTACHMENT = AttReg.of(REG); - public static final AttVal.CapVal EFFECT = ATTACHMENT.entity("effect", - ClientEffectCap.class, ClientEffectCap::new, LivingEntity.class, e -> e.level().isClientSide()); - public static final AttVal.PlayerVal CONDITIONAL = ATTACHMENT.player("conditionals", - ConditionalData.class, ConditionalData::new, PlayerCapabilityNetworkHandler::new); - public static final AttVal.PlayerVal FLAGS = ATTACHMENT.player("flags", - PlayerFlagData.class, PlayerFlagData::new, PlayerCapabilityNetworkHandler::new); + public static final AttVal.CapVal EFFECT = ATTACHMENT.entity("effect", + ClientEffectCap.class, ClientEffectCap::new, LivingEntity.class, e -> e.level().isClientSide()); + public static final AttVal.PlayerVal CONDITIONAL = ATTACHMENT.player("conditionals", + ConditionalData.class, ConditionalData::new, PlayerCapabilityNetworkHandler::new); + public static final AttVal.PlayerVal FLAGS = ATTACHMENT.player("flags", + PlayerFlagData.class, PlayerFlagData::new, PlayerCapabilityNetworkHandler::new); - // loot modifiers - public static final CdcReg GLM = CdcReg.of(REG, NeoForgeRegistries.GLOBAL_LOOT_MODIFIER_SERIALIZERS); - public static final CdcVal ADD_ITEM = GLM.reg("add_item", AddItemModifier.MAP_CODEC); - public static final CdcVal ADD_TABLE = GLM.reg("add_table", AddLootTableModifier.MAP_CODEC); + // loot modifiers + public static final CdcReg GLM = CdcReg.of(REG, NeoForgeRegistries.GLOBAL_LOOT_MODIFIER_SERIALIZERS); + public static final CdcVal ADD_ITEM = GLM.reg("add_item", AddItemModifier.MAP_CODEC); + public static final CdcVal ADD_TABLE = GLM.reg("add_table", AddLootTableModifier.MAP_CODEC); - // loot conditions - public static final SR LIC = SR.of(REG, BuiltInRegistries.LOOT_CONDITION_TYPE); - public static final Val LIC_FLAG = LIC.reg("player_flag", () -> new LootItemConditionType(MapCodecAdaptor.of(PlayerFlagCondition.class))); + // loot conditions + public static final SR LIC = SR.of(REG, BuiltInRegistries.LOOT_CONDITION_TYPE); + public static final Val LIC_FLAG = LIC.reg("player_flag", () -> new LootItemConditionType(MapCodecAdaptor.of(PlayerFlagCondition.class))); - // datapack - public static final DatapackReg MENU_LAYOUT = REG.dataReg("menu_layout", MenuLayoutConfig.class); + // datapack + public static final DatapackReg MENU_LAYOUT = REG.dataReg("menu_layout", MenuLayoutConfig.class); - public static void register(IEventBus bus) { - REG.register(bus); - } + public static void register() { + } } diff --git a/src/main/java/dev/xkmc/l2core/init/reg/simple/Reg.java b/src/main/java/dev/xkmc/l2core/init/reg/simple/Reg.java index 27f2622..56ff07a 100644 --- a/src/main/java/dev/xkmc/l2core/init/reg/simple/Reg.java +++ b/src/main/java/dev/xkmc/l2core/init/reg/simple/Reg.java @@ -8,74 +8,66 @@ import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.ModLoadingContext; import net.neoforged.neoforge.registries.DeferredRegister; import net.neoforged.neoforge.registries.datamaps.DataMapType; -import java.util.ArrayList; -import java.util.List; -import java.util.function.Consumer; - public final class Reg { - private final String modid; + private final String modid; + private final IEventBus bus; - public Reg(String modid) { - this.modid = modid; - } + public Reg(String modid) { + this.modid = modid; - public DeferredRegister make(Registry reg) { - var ans = DeferredRegister.create(reg, modid); - listen(ans::register); - return ans; - } + var cont = ModLoadingContext.get().getActiveContainer(); + if (!cont.getModId().equals(modid)) + throw new IllegalStateException("Class Initialized from wrong thread for " + modid); + var bus = cont.getEventBus(); + if (bus != null) this.bus = bus; + else throw new IllegalStateException("Event bus is null for " + modid); + } - public DeferredRegister make(ResourceKey> reg) { - var ans = DeferredRegister.create(reg, modid); - listen(ans::register); - return ans; - } + public DeferredRegister make(Registry reg) { + var ans = DeferredRegister.create(reg, modid); + ans.register(bus); + return ans; + } - public DatapackReg dataReg(String id, Codec codec) { - var ans = new DatapackReg<>(ResourceKey.createRegistryKey(loc(id)), codec); - listen(bus -> bus.addListener(ans::onRegister)); - return ans; - } + public DeferredRegister make(ResourceKey> reg) { + var ans = DeferredRegister.create(reg, modid); + ans.register(bus); + return ans; + } - public DatapackReg dataReg(String id, Class cls) { - return dataReg(id, new CodecAdaptor<>(cls)); - } + public DatapackReg dataReg(String id, Codec codec) { + var ans = new DatapackReg<>(ResourceKey.createRegistryKey(loc(id)), codec); + bus.addListener(ans::onRegister); + return ans; + } - public DataMapReg dataMap(DataMapType type) { - var ans = new DataMapReg<>(type); - listen(bus -> bus.addListener(ans::register)); - return ans; - } + public DatapackReg dataReg(String id, Class cls) { + return dataReg(id, new CodecAdaptor<>(cls)); + } - public DataMapReg dataMap(String id, ResourceKey> k, Codec codec, Codec network) { - return dataMap(DataMapType.builder(loc(id), k, codec).synced(network, true).build()); - } + public DataMapReg dataMap(DataMapType type) { + var ans = new DataMapReg<>(type); + bus.addListener(ans::register); + return ans; + } - public DataMapReg dataMap(String id, ResourceKey> k, Class cls) { - CodecAdaptor codec = new CodecAdaptor<>(cls); - return dataMap(id, k, codec, codec); - } + public DataMapReg dataMap(String id, ResourceKey> k, Codec codec, Codec network) { + return dataMap(DataMapType.builder(loc(id), k, codec).synced(network, true).build()); + } - public ResourceLocation loc(String id) { - return ResourceLocation.fromNamespaceAndPath(modid, id); - } + public DataMapReg dataMap(String id, ResourceKey> k, Class cls) { + CodecAdaptor codec = new CodecAdaptor<>(cls); + return dataMap(id, k, codec, codec); + } - private final List> list = new ArrayList<>(); - private IEventBus bus; + public ResourceLocation loc(String id) { + return ResourceLocation.fromNamespaceAndPath(modid, id); + } - private void listen(Consumer cons) { - if (bus == null) list.add(cons); - else cons.accept(bus); - } - - public void register(IEventBus bus) { - for (var e : list) e.accept(bus); - list.clear(); - this.bus = bus; - } }