auto reg
This commit is contained in:
@@ -31,4 +31,4 @@ registrate_version = MC1.21-1.4.1
|
|||||||
lljij = false
|
lljij = false
|
||||||
rootMod = 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) {
|
public L2Core(IEventBus bus) {
|
||||||
Handlers.register();
|
Handlers.register();
|
||||||
L2LibReg.register(bus);
|
|
||||||
|
|
||||||
REGISTRATE.addDataGenerator(L2TagGen.EFF_TAGS, L2TagGen::onEffectTagGen);
|
REGISTRATE.addDataGenerator(L2TagGen.EFF_TAGS, L2TagGen::onEffectTagGen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void onPacketReg(RegisterPayloadHandlersEvent event) {
|
|
||||||
PACKET_HANDLER.register(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ResourceLocation loc(String id) {
|
public static ResourceLocation loc(String id) {
|
||||||
return ResourceLocation.fromNamespaceAndPath(MODID, 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.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType;
|
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.conditions.ICondition;
|
||||||
import net.neoforged.neoforge.common.loot.IGlobalLootModifier;
|
import net.neoforged.neoforge.common.loot.IGlobalLootModifier;
|
||||||
import net.neoforged.neoforge.registries.NeoForgeRegistries;
|
import net.neoforged.neoforge.registries.NeoForgeRegistries;
|
||||||
|
|
||||||
public class L2LibReg {
|
public class L2LibReg {
|
||||||
|
|
||||||
public static final Reg REG = new Reg(L2Core.MODID);
|
public static final Reg REG = new Reg(L2Core.MODID);
|
||||||
|
|
||||||
// ingredients
|
// ingredients
|
||||||
public static final IngReg INGREDIENT = IngReg.of(REG);
|
public static final IngReg INGREDIENT = IngReg.of(REG);
|
||||||
public static final IngVal<EnchantmentIngredient> ING_ENCH = INGREDIENT.reg("enchantment", EnchantmentIngredient.class);
|
public static final IngVal<EnchantmentIngredient> ING_ENCH = INGREDIENT.reg("enchantment", EnchantmentIngredient.class);
|
||||||
public static final IngVal<PotionIngredient> ING_POTION = INGREDIENT.reg("potion", PotionIngredient.class);
|
public static final IngVal<PotionIngredient> ING_POTION = INGREDIENT.reg("potion", PotionIngredient.class);
|
||||||
|
|
||||||
// conditions
|
// conditions
|
||||||
public static final CdcReg<ICondition> CONDITION = CdcReg.of(REG, NeoForgeRegistries.CONDITION_SERIALIZERS);
|
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<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<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<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<StringValueCondition> CONDITION_STR = CONDITION.reg("string_config", StringValueCondition.class);
|
||||||
public static final CdcVal<ListStringValueCondition> CONDITION_LIST_STR = CONDITION.reg("string_list_config", ListStringValueCondition.class);
|
public static final CdcVal<ListStringValueCondition> CONDITION_LIST_STR = CONDITION.reg("string_list_config", ListStringValueCondition.class);
|
||||||
|
|
||||||
// attachments
|
// attachments
|
||||||
public static final AttReg ATTACHMENT = AttReg.of(REG);
|
public static final AttReg ATTACHMENT = AttReg.of(REG);
|
||||||
|
|
||||||
public static final AttVal.CapVal<LivingEntity, ClientEffectCap> EFFECT = ATTACHMENT.entity("effect",
|
public static final AttVal.CapVal<LivingEntity, ClientEffectCap> EFFECT = ATTACHMENT.entity("effect",
|
||||||
ClientEffectCap.class, ClientEffectCap::new, LivingEntity.class, e -> e.level().isClientSide());
|
ClientEffectCap.class, ClientEffectCap::new, LivingEntity.class, e -> e.level().isClientSide());
|
||||||
public static final AttVal.PlayerVal<ConditionalData> CONDITIONAL = ATTACHMENT.player("conditionals",
|
public static final AttVal.PlayerVal<ConditionalData> CONDITIONAL = ATTACHMENT.player("conditionals",
|
||||||
ConditionalData.class, ConditionalData::new, PlayerCapabilityNetworkHandler::new);
|
ConditionalData.class, ConditionalData::new, PlayerCapabilityNetworkHandler::new);
|
||||||
public static final AttVal.PlayerVal<PlayerFlagData> FLAGS = ATTACHMENT.player("flags",
|
public static final AttVal.PlayerVal<PlayerFlagData> FLAGS = ATTACHMENT.player("flags",
|
||||||
PlayerFlagData.class, PlayerFlagData::new, PlayerCapabilityNetworkHandler::new);
|
PlayerFlagData.class, PlayerFlagData::new, PlayerCapabilityNetworkHandler::new);
|
||||||
|
|
||||||
// loot modifiers
|
// loot modifiers
|
||||||
public static final CdcReg<IGlobalLootModifier> GLM = CdcReg.of(REG, NeoForgeRegistries.GLOBAL_LOOT_MODIFIER_SERIALIZERS);
|
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<AddItemModifier> ADD_ITEM = GLM.reg("add_item", AddItemModifier.MAP_CODEC);
|
||||||
public static final CdcVal<AddLootTableModifier> ADD_TABLE = GLM.reg("add_table", AddLootTableModifier.MAP_CODEC);
|
public static final CdcVal<AddLootTableModifier> ADD_TABLE = GLM.reg("add_table", AddLootTableModifier.MAP_CODEC);
|
||||||
|
|
||||||
// loot conditions
|
// loot conditions
|
||||||
public static final SR<LootItemConditionType> LIC = SR.of(REG, BuiltInRegistries.LOOT_CONDITION_TYPE);
|
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)));
|
public static final Val<LootItemConditionType> LIC_FLAG = LIC.reg("player_flag", () -> new LootItemConditionType(MapCodecAdaptor.of(PlayerFlagCondition.class)));
|
||||||
|
|
||||||
// datapack
|
// datapack
|
||||||
public static final DatapackReg<MenuLayoutConfig> MENU_LAYOUT = REG.dataReg("menu_layout", MenuLayoutConfig.class);
|
public static final DatapackReg<MenuLayoutConfig> MENU_LAYOUT = REG.dataReg("menu_layout", MenuLayoutConfig.class);
|
||||||
|
|
||||||
public static void register(IEventBus bus) {
|
public static void register() {
|
||||||
REG.register(bus);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,74 +8,66 @@ import net.minecraft.core.Registry;
|
|||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.neoforged.bus.api.IEventBus;
|
import net.neoforged.bus.api.IEventBus;
|
||||||
|
import net.neoforged.fml.ModLoadingContext;
|
||||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||||
import net.neoforged.neoforge.registries.datamaps.DataMapType;
|
import net.neoforged.neoforge.registries.datamaps.DataMapType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public final class Reg {
|
public final class Reg {
|
||||||
|
|
||||||
private final String modid;
|
private final String modid;
|
||||||
|
private final IEventBus bus;
|
||||||
|
|
||||||
public Reg(String modid) {
|
public Reg(String modid) {
|
||||||
this.modid = modid;
|
this.modid = modid;
|
||||||
}
|
|
||||||
|
|
||||||
public <T> DeferredRegister<T> make(Registry<T> reg) {
|
var cont = ModLoadingContext.get().getActiveContainer();
|
||||||
var ans = DeferredRegister.create(reg, modid);
|
if (!cont.getModId().equals(modid))
|
||||||
listen(ans::register);
|
throw new IllegalStateException("Class Initialized from wrong thread for " + modid);
|
||||||
return ans;
|
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) {
|
public <T> DeferredRegister<T> make(Registry<T> reg) {
|
||||||
var ans = DeferredRegister.create(reg, modid);
|
var ans = DeferredRegister.create(reg, modid);
|
||||||
listen(ans::register);
|
ans.register(bus);
|
||||||
return ans;
|
return ans;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> DatapackReg<T> dataReg(String id, Codec<T> codec) {
|
public <T> DeferredRegister<T> make(ResourceKey<Registry<T>> reg) {
|
||||||
var ans = new DatapackReg<>(ResourceKey.createRegistryKey(loc(id)), codec);
|
var ans = DeferredRegister.create(reg, modid);
|
||||||
listen(bus -> bus.addListener(ans::onRegister));
|
ans.register(bus);
|
||||||
return ans;
|
return ans;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> DatapackReg<T> dataReg(String id, Class<T> cls) {
|
public <T> DatapackReg<T> dataReg(String id, Codec<T> codec) {
|
||||||
return dataReg(id, new CodecAdaptor<>(cls));
|
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) {
|
public <T> DatapackReg<T> dataReg(String id, Class<T> cls) {
|
||||||
var ans = new DataMapReg<>(type);
|
return dataReg(id, new CodecAdaptor<>(cls));
|
||||||
listen(bus -> bus.addListener(ans::register));
|
}
|
||||||
return ans;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <K, V> DataMapReg<K, V> dataMap(String id, ResourceKey<Registry<K>> k, Codec<V> codec, Codec<V> network) {
|
public <K, V> DataMapReg<K, V> dataMap(DataMapType<K, V> type) {
|
||||||
return dataMap(DataMapType.builder(loc(id), k, codec).synced(network, true).build());
|
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) {
|
public <K, V> DataMapReg<K, V> dataMap(String id, ResourceKey<Registry<K>> k, Codec<V> codec, Codec<V> network) {
|
||||||
CodecAdaptor<V> codec = new CodecAdaptor<>(cls);
|
return dataMap(DataMapType.builder(loc(id), k, codec).synced(network, true).build());
|
||||||
return dataMap(id, k, codec, codec);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public ResourceLocation loc(String id) {
|
public <K, V> DataMapReg<K, V> dataMap(String id, ResourceKey<Registry<K>> k, Class<V> cls) {
|
||||||
return ResourceLocation.fromNamespaceAndPath(modid, id);
|
CodecAdaptor<V> codec = new CodecAdaptor<>(cls);
|
||||||
}
|
return dataMap(id, k, codec, codec);
|
||||||
|
}
|
||||||
|
|
||||||
private final List<Consumer<IEventBus>> list = new ArrayList<>();
|
public ResourceLocation loc(String id) {
|
||||||
private IEventBus bus;
|
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