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,7 +17,6 @@ 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;
|
||||||
@@ -61,8 +60,7 @@ public class L2LibReg {
|
|||||||
// 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,36 +8,41 @@ 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;
|
||||||
|
|
||||||
|
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(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> DeferredRegister<T> make(ResourceKey<Registry<T>> reg) {
|
public <T> DeferredRegister<T> make(ResourceKey<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> DatapackReg<T> dataReg(String id, Codec<T> codec) {
|
||||||
var ans = new DatapackReg<>(ResourceKey.createRegistryKey(loc(id)), codec);
|
var ans = new DatapackReg<>(ResourceKey.createRegistryKey(loc(id)), codec);
|
||||||
listen(bus -> bus.addListener(ans::onRegister));
|
bus.addListener(ans::onRegister);
|
||||||
return ans;
|
return ans;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +52,7 @@ public final class Reg {
|
|||||||
|
|
||||||
public <K, V> DataMapReg<K, V> dataMap(DataMapType<K, V> type) {
|
public <K, V> DataMapReg<K, V> dataMap(DataMapType<K, V> type) {
|
||||||
var ans = new DataMapReg<>(type);
|
var ans = new DataMapReg<>(type);
|
||||||
listen(bus -> bus.addListener(ans::register));
|
bus.addListener(ans::register);
|
||||||
return ans;
|
return ans;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,18 +69,5 @@ public final class Reg {
|
|||||||
return ResourceLocation.fromNamespaceAndPath(modid, id);
|
return ResourceLocation.fromNamespaceAndPath(modid, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final List<Consumer<IEventBus>> list = new ArrayList<>();
|
|
||||||
private IEventBus bus;
|
|
||||||
|
|
||||||
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