auto reg
This commit is contained in:
@@ -31,4 +31,4 @@ registrate_version = MC1.21-1.4.1
|
||||
lljij = false
|
||||
rootMod = false
|
||||
|
||||
l2serial_ver = 3.0.0
|
||||
l2serial_ver = 3.0.1
|
||||
Binary file not shown.
Binary file not shown.
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<EnchantmentIngredient> ING_ENCH = INGREDIENT.reg("enchantment", EnchantmentIngredient.class);
|
||||
public static final IngVal<PotionIngredient> ING_POTION = INGREDIENT.reg("potion", PotionIngredient.class);
|
||||
// ingredients
|
||||
public static final IngReg INGREDIENT = IngReg.of(REG);
|
||||
public static final IngVal<EnchantmentIngredient> ING_ENCH = INGREDIENT.reg("enchantment", EnchantmentIngredient.class);
|
||||
public static final IngVal<PotionIngredient> ING_POTION = INGREDIENT.reg("potion", PotionIngredient.class);
|
||||
|
||||
// conditions
|
||||
public static final CdcReg<ICondition> CONDITION = CdcReg.of(REG, NeoForgeRegistries.CONDITION_SERIALIZERS);
|
||||
public static final CdcVal<BooleanValueCondition> CONDITION_BOOL = CONDITION.reg("bool_config", BooleanValueCondition.class);
|
||||
public static final CdcVal<IntValueCondition> CONDITION_INT = CONDITION.reg("int_config", IntValueCondition.class);
|
||||
public static final CdcVal<DoubleValueCondition> CONDITION_DOUBLE = CONDITION.reg("double_config", DoubleValueCondition.class);
|
||||
public static final CdcVal<StringValueCondition> CONDITION_STR = CONDITION.reg("string_config", StringValueCondition.class);
|
||||
public static final CdcVal<ListStringValueCondition> CONDITION_LIST_STR = CONDITION.reg("string_list_config", ListStringValueCondition.class);
|
||||
// conditions
|
||||
public static final CdcReg<ICondition> CONDITION = CdcReg.of(REG, NeoForgeRegistries.CONDITION_SERIALIZERS);
|
||||
public static final CdcVal<BooleanValueCondition> CONDITION_BOOL = CONDITION.reg("bool_config", BooleanValueCondition.class);
|
||||
public static final CdcVal<IntValueCondition> CONDITION_INT = CONDITION.reg("int_config", IntValueCondition.class);
|
||||
public static final CdcVal<DoubleValueCondition> CONDITION_DOUBLE = CONDITION.reg("double_config", DoubleValueCondition.class);
|
||||
public static final CdcVal<StringValueCondition> CONDITION_STR = CONDITION.reg("string_config", StringValueCondition.class);
|
||||
public static final CdcVal<ListStringValueCondition> 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<LivingEntity, ClientEffectCap> EFFECT = ATTACHMENT.entity("effect",
|
||||
ClientEffectCap.class, ClientEffectCap::new, LivingEntity.class, e -> e.level().isClientSide());
|
||||
public static final AttVal.PlayerVal<ConditionalData> CONDITIONAL = ATTACHMENT.player("conditionals",
|
||||
ConditionalData.class, ConditionalData::new, PlayerCapabilityNetworkHandler::new);
|
||||
public static final AttVal.PlayerVal<PlayerFlagData> FLAGS = ATTACHMENT.player("flags",
|
||||
PlayerFlagData.class, PlayerFlagData::new, PlayerCapabilityNetworkHandler::new);
|
||||
public static final AttVal.CapVal<LivingEntity, ClientEffectCap> EFFECT = ATTACHMENT.entity("effect",
|
||||
ClientEffectCap.class, ClientEffectCap::new, LivingEntity.class, e -> e.level().isClientSide());
|
||||
public static final AttVal.PlayerVal<ConditionalData> CONDITIONAL = ATTACHMENT.player("conditionals",
|
||||
ConditionalData.class, ConditionalData::new, PlayerCapabilityNetworkHandler::new);
|
||||
public static final AttVal.PlayerVal<PlayerFlagData> FLAGS = ATTACHMENT.player("flags",
|
||||
PlayerFlagData.class, PlayerFlagData::new, PlayerCapabilityNetworkHandler::new);
|
||||
|
||||
// loot modifiers
|
||||
public static final CdcReg<IGlobalLootModifier> GLM = CdcReg.of(REG, NeoForgeRegistries.GLOBAL_LOOT_MODIFIER_SERIALIZERS);
|
||||
public static final CdcVal<AddItemModifier> ADD_ITEM = GLM.reg("add_item", AddItemModifier.MAP_CODEC);
|
||||
public static final CdcVal<AddLootTableModifier> ADD_TABLE = GLM.reg("add_table", AddLootTableModifier.MAP_CODEC);
|
||||
// loot modifiers
|
||||
public static final CdcReg<IGlobalLootModifier> GLM = CdcReg.of(REG, NeoForgeRegistries.GLOBAL_LOOT_MODIFIER_SERIALIZERS);
|
||||
public static final CdcVal<AddItemModifier> ADD_ITEM = GLM.reg("add_item", AddItemModifier.MAP_CODEC);
|
||||
public static final CdcVal<AddLootTableModifier> ADD_TABLE = GLM.reg("add_table", AddLootTableModifier.MAP_CODEC);
|
||||
|
||||
// loot conditions
|
||||
public static final SR<LootItemConditionType> LIC = SR.of(REG, BuiltInRegistries.LOOT_CONDITION_TYPE);
|
||||
public static final Val<LootItemConditionType> LIC_FLAG = LIC.reg("player_flag", () -> new LootItemConditionType(MapCodecAdaptor.of(PlayerFlagCondition.class)));
|
||||
// loot conditions
|
||||
public static final SR<LootItemConditionType> LIC = SR.of(REG, BuiltInRegistries.LOOT_CONDITION_TYPE);
|
||||
public static final Val<LootItemConditionType> LIC_FLAG = LIC.reg("player_flag", () -> new LootItemConditionType(MapCodecAdaptor.of(PlayerFlagCondition.class)));
|
||||
|
||||
// datapack
|
||||
public static final DatapackReg<MenuLayoutConfig> MENU_LAYOUT = REG.dataReg("menu_layout", MenuLayoutConfig.class);
|
||||
// datapack
|
||||
public static final DatapackReg<MenuLayoutConfig> MENU_LAYOUT = REG.dataReg("menu_layout", MenuLayoutConfig.class);
|
||||
|
||||
public static void register(IEventBus bus) {
|
||||
REG.register(bus);
|
||||
}
|
||||
public static void register() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 <T> DeferredRegister<T> make(Registry<T> 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 <T> DeferredRegister<T> make(ResourceKey<Registry<T>> reg) {
|
||||
var ans = DeferredRegister.create(reg, modid);
|
||||
listen(ans::register);
|
||||
return ans;
|
||||
}
|
||||
public <T> DeferredRegister<T> make(Registry<T> reg) {
|
||||
var ans = DeferredRegister.create(reg, modid);
|
||||
ans.register(bus);
|
||||
return ans;
|
||||
}
|
||||
|
||||
public <T> DatapackReg<T> dataReg(String id, Codec<T> codec) {
|
||||
var ans = new DatapackReg<>(ResourceKey.createRegistryKey(loc(id)), codec);
|
||||
listen(bus -> bus.addListener(ans::onRegister));
|
||||
return ans;
|
||||
}
|
||||
public <T> DeferredRegister<T> make(ResourceKey<Registry<T>> reg) {
|
||||
var ans = DeferredRegister.create(reg, modid);
|
||||
ans.register(bus);
|
||||
return ans;
|
||||
}
|
||||
|
||||
public <T> DatapackReg<T> dataReg(String id, Class<T> cls) {
|
||||
return dataReg(id, new CodecAdaptor<>(cls));
|
||||
}
|
||||
public <T> DatapackReg<T> dataReg(String id, Codec<T> codec) {
|
||||
var ans = new DatapackReg<>(ResourceKey.createRegistryKey(loc(id)), codec);
|
||||
bus.addListener(ans::onRegister);
|
||||
return ans;
|
||||
}
|
||||
|
||||
public <K, V> DataMapReg<K, V> dataMap(DataMapType<K, V> type) {
|
||||
var ans = new DataMapReg<>(type);
|
||||
listen(bus -> bus.addListener(ans::register));
|
||||
return ans;
|
||||
}
|
||||
public <T> DatapackReg<T> dataReg(String id, Class<T> cls) {
|
||||
return dataReg(id, new CodecAdaptor<>(cls));
|
||||
}
|
||||
|
||||
public <K, V> DataMapReg<K, V> dataMap(String id, ResourceKey<Registry<K>> k, Codec<V> codec, Codec<V> network) {
|
||||
return dataMap(DataMapType.builder(loc(id), k, codec).synced(network, true).build());
|
||||
}
|
||||
public <K, V> DataMapReg<K, V> dataMap(DataMapType<K, V> type) {
|
||||
var ans = new DataMapReg<>(type);
|
||||
bus.addListener(ans::register);
|
||||
return ans;
|
||||
}
|
||||
|
||||
public <K, V> DataMapReg<K, V> dataMap(String id, ResourceKey<Registry<K>> k, Class<V> cls) {
|
||||
CodecAdaptor<V> codec = new CodecAdaptor<>(cls);
|
||||
return dataMap(id, k, codec, codec);
|
||||
}
|
||||
public <K, V> DataMapReg<K, V> dataMap(String id, ResourceKey<Registry<K>> k, Codec<V> codec, Codec<V> network) {
|
||||
return dataMap(DataMapType.builder(loc(id), k, codec).synced(network, true).build());
|
||||
}
|
||||
|
||||
public ResourceLocation loc(String id) {
|
||||
return ResourceLocation.fromNamespaceAndPath(modid, id);
|
||||
}
|
||||
public <K, V> DataMapReg<K, V> dataMap(String id, ResourceKey<Registry<K>> k, Class<V> cls) {
|
||||
CodecAdaptor<V> codec = new CodecAdaptor<>(cls);
|
||||
return dataMap(id, k, codec, codec);
|
||||
}
|
||||
|
||||
private final List<Consumer<IEventBus>> list = new ArrayList<>();
|
||||
private IEventBus bus;
|
||||
public ResourceLocation loc(String id) {
|
||||
return ResourceLocation.fromNamespaceAndPath(modid, id);
|
||||
}
|
||||
|
||||
private void listen(Consumer<IEventBus> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user