From b9bcabc385a26c75d618e45d66925206f529bfdf Mon Sep 17 00:00:00 2001 From: LatvianModder Date: Fri, 31 May 2024 14:49:25 +0300 Subject: [PATCH] Rewrote registries, added few new icons --- gradle.properties | 8 +- .../mods/kubejs/BuiltinKubeJSPlugin.java | 116 ++++++----- .../java/dev/latvian/mods/kubejs/KubeJS.java | 47 ++--- .../dev/latvian/mods/kubejs/KubeJSCommon.java | 6 +- .../dev/latvian/mods/kubejs/KubeJSPlugin.java | 4 + .../mods/kubejs/KubeJSTypeWrappers.java | 48 ----- .../mods/kubejs/bindings/TextWrapper.java | 24 +++ .../mods/kubejs/block/BlockBuilder.java | 7 +- .../kubejs/client/ClientInitKubeEvent.java | 4 + .../mods/kubejs/client/ClientKubeEvent.java | 11 +- .../kubejs/client/DebugInfoKubeEvent.java | 4 +- .../mods/kubejs/client/KubeJSClient.java | 30 +-- .../client/KubeJSClientEventHandler.java | 70 +++---- .../kubejs/client/painter/PaintKubeEvent.java | 1 + .../mods/kubejs/client/painter/Painter.java | 12 +- .../latvian/mods/kubejs/core/BlockKJS.java | 2 +- .../mods/kubejs/core/BlockStateKJS.java | 7 +- .../mods/kubejs/core/EntityTypeKJS.java | 2 +- .../latvian/mods/kubejs/core/FluidKJS.java | 2 +- .../dev/latvian/mods/kubejs/core/ItemKJS.java | 2 +- .../mods/kubejs/core/ItemStackKJS.java | 37 +++- .../latvian/mods/kubejs/core/MenuTypeKJS.java | 2 +- ...stryKeyKJS.java => RegistryObjectKJS.java} | 14 +- .../kubejs/core/mixin/EntityTypeMixin.java | 37 ++++ .../core/mixin/EventHandlerBridgeMixin.java | 25 --- .../core/mixin/EventHandlerInvoker.java | 18 -- .../mods/kubejs/core/mixin/MenuTypeMixin.java | 25 +++ .../core/mixin/MinecraftClientMixin.java | 9 +- .../mixin/ReloadableServerResourcesMixin.java | 2 + .../dev/latvian/mods/kubejs/event/Extra.java | 4 +- .../mods/kubejs/fluid/FluidBuilder.java | 9 +- .../kubejs/neoforge/KubeJSNeoForgeClient.java | 65 +++--- .../latvian/mods/kubejs/net/KubeJSNet.java | 4 + .../player/KubeJSPlayerEventHandler.java | 19 +- .../recipe/component/RecipeComponent.java | 2 +- .../recipe/component/RegistryComponent.java | 49 +++-- .../recipe/component/TimeComponent.java | 14 +- .../registry/AdditionalObjectRegistry.java | 13 ++ .../mods/kubejs/registry/BuilderBase.java | 2 +- .../kubejs/registry/BuilderTypeRegistry.java | 21 ++ .../registry/BuilderTypeRegistryHandler.java | 41 ++++ .../kubejs/registry/RegistryEventHandler.java | 60 ++++++ .../mods/kubejs/registry/RegistryInfo.java | 193 +----------------- .../kubejs/registry/RegistryKubeEvent.java | 63 +++++- .../mods/kubejs/registry/RegistryType.java | 75 +++++++ .../mods/kubejs/script/KubeJSContext.java | 84 +++++++- .../mods/kubejs/script/ScriptManager.java | 21 +- .../server/KubeJSServerEventHandler.java | 3 + .../kubejs/server/ServerScriptManager.java | 4 +- .../java/dev/latvian/mods/kubejs/util/ID.java | 4 +- .../mods/kubejs/util/KubeJSPlugins.java | 2 +- .../dev/latvian/mods/kubejs/util/UtilsJS.java | 2 + .../registrypredicate/RegistryPredicate.java | 25 ++- .../resources/assets/kubejs/font/icons.json | 21 +- .../assets/kubejs/textures/font/icons/k.png | Bin 7097 -> 6813 bytes .../assets/kubejs/textures/font/icons/n.png | Bin 0 -> 192 bytes .../textures/font/icons/small_space.png | Bin 0 -> 124 bytes .../assets/kubejs/textures/font/icons/y.png | Bin 0 -> 187 bytes src/main/resources/kubejs.mixins.json | 2 - 59 files changed, 795 insertions(+), 583 deletions(-) rename src/main/java/dev/latvian/mods/kubejs/core/{WithRegistryKeyKJS.java => RegistryObjectKJS.java} (71%) delete mode 100644 src/main/java/dev/latvian/mods/kubejs/core/mixin/EventHandlerBridgeMixin.java delete mode 100644 src/main/java/dev/latvian/mods/kubejs/core/mixin/EventHandlerInvoker.java create mode 100644 src/main/java/dev/latvian/mods/kubejs/registry/AdditionalObjectRegistry.java create mode 100644 src/main/java/dev/latvian/mods/kubejs/registry/BuilderTypeRegistry.java create mode 100644 src/main/java/dev/latvian/mods/kubejs/registry/BuilderTypeRegistryHandler.java create mode 100644 src/main/java/dev/latvian/mods/kubejs/registry/RegistryEventHandler.java create mode 100644 src/main/java/dev/latvian/mods/kubejs/registry/RegistryType.java create mode 100644 src/main/resources/assets/kubejs/textures/font/icons/n.png create mode 100644 src/main/resources/assets/kubejs/textures/font/icons/small_space.png create mode 100644 src/main/resources/assets/kubejs/textures/font/icons/y.png diff --git a/gradle.properties b/gradle.properties index d57232a8a..566ef23ea 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,11 +13,11 @@ modrinth_id=umyGl7zF minecraft_version=1.20.6 mod_version=2006.7.0 -neoforge_version=20.6.98-beta +neoforge_version=20.6.99-beta parchment_version=2024.05.01 -rhino_version=2006.2.4-build.13 -min_rhino_version=2006.2.4-build.13 -architectury_version=12.1.2 +rhino_version=2006.2.4-build.15 +min_rhino_version=2006.2.4-build.15 +architectury_version=12.1.3 rei_version=15.0.728 #rei_comp_version=9.0.16 diff --git a/src/main/java/dev/latvian/mods/kubejs/BuiltinKubeJSPlugin.java b/src/main/java/dev/latvian/mods/kubejs/BuiltinKubeJSPlugin.java index 0b4d8d094..aa9b89b5d 100644 --- a/src/main/java/dev/latvian/mods/kubejs/BuiltinKubeJSPlugin.java +++ b/src/main/java/dev/latvian/mods/kubejs/BuiltinKubeJSPlugin.java @@ -103,7 +103,7 @@ import dev.latvian.mods.kubejs.recipe.schema.minecraft.SmithingTransformRecipeSchema; import dev.latvian.mods.kubejs.recipe.schema.minecraft.SmithingTrimRecipeSchema; import dev.latvian.mods.kubejs.recipe.schema.minecraft.StonecuttingRecipeSchema; -import dev.latvian.mods.kubejs.registry.RegistryInfo; +import dev.latvian.mods.kubejs.registry.BuilderTypeRegistry; import dev.latvian.mods.kubejs.script.BindingsEvent; import dev.latvian.mods.kubejs.script.PlatformWrapper; import dev.latvian.mods.kubejs.script.ScriptType; @@ -129,11 +129,11 @@ import dev.latvian.mods.unit.Unit; import net.minecraft.commands.arguments.selector.EntitySelector; import net.minecraft.core.BlockPos; -import net.minecraft.core.Holder; import net.minecraft.core.Vec3i; import net.minecraft.core.component.DataComponentMap; import net.minecraft.core.component.DataComponentPatch; import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CollectionTag; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; @@ -142,7 +142,6 @@ import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.TextColor; -import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.stats.Stat; import net.minecraft.stats.Stats; @@ -191,55 +190,6 @@ public class BuiltinKubeJSPlugin implements KubeJSPlugin { public static final HashMap GLOBAL = new HashMap<>(); - @Override - public void init() { - RegistryInfo.SOUND_EVENT.addType("basic", SoundEventBuilder.class, SoundEventBuilder::new); - - RegistryInfo.BLOCK.addType("basic", BasicBlockJS.Builder.class, BasicBlockJS.Builder::new); - RegistryInfo.BLOCK.addType("detector", DetectorBlock.Builder.class, DetectorBlock.Builder::new); - RegistryInfo.BLOCK.addType("slab", SlabBlockBuilder.class, SlabBlockBuilder::new); - RegistryInfo.BLOCK.addType("stairs", StairBlockBuilder.class, StairBlockBuilder::new); - RegistryInfo.BLOCK.addType("fence", FenceBlockBuilder.class, FenceBlockBuilder::new); - RegistryInfo.BLOCK.addType("wall", WallBlockBuilder.class, WallBlockBuilder::new); - RegistryInfo.BLOCK.addType("fence_gate", FenceGateBlockBuilder.class, FenceGateBlockBuilder::new); - RegistryInfo.BLOCK.addType("pressure_plate", PressurePlateBlockBuilder.class, PressurePlateBlockBuilder::new); - RegistryInfo.BLOCK.addType("button", ButtonBlockBuilder.class, ButtonBlockBuilder::new); - RegistryInfo.BLOCK.addType("falling", FallingBlockBuilder.class, FallingBlockBuilder::new); - RegistryInfo.BLOCK.addType("crop", CropBlockBuilder.class, CropBlockBuilder::new); - RegistryInfo.BLOCK.addType("cardinal", HorizontalDirectionalBlockBuilder.class, HorizontalDirectionalBlockBuilder::new); - RegistryInfo.BLOCK.addType("carpet", CarpetBlockBuilder.class, CarpetBlockBuilder::new); - - RegistryInfo.ITEM.addType("basic", BasicItemJS.Builder.class, BasicItemJS.Builder::new); - RegistryInfo.ITEM.addType("sword", SwordItemBuilder.class, SwordItemBuilder::new); - RegistryInfo.ITEM.addType("pickaxe", DiggerItemBuilder.Pickaxe.class, DiggerItemBuilder.Pickaxe::new); - RegistryInfo.ITEM.addType("axe", DiggerItemBuilder.Axe.class, DiggerItemBuilder.Axe::new); - RegistryInfo.ITEM.addType("shovel", DiggerItemBuilder.Shovel.class, DiggerItemBuilder.Shovel::new); - RegistryInfo.ITEM.addType("hoe", DiggerItemBuilder.Hoe.class, DiggerItemBuilder.Hoe::new); - RegistryInfo.ITEM.addType("shears", ShearsItemBuilder.class, ShearsItemBuilder::new); - RegistryInfo.ITEM.addType("helmet", ArmorItemBuilder.Helmet.class, ArmorItemBuilder.Helmet::new); - RegistryInfo.ITEM.addType("chestplate", ArmorItemBuilder.Chestplate.class, ArmorItemBuilder.Chestplate::new); - RegistryInfo.ITEM.addType("leggings", ArmorItemBuilder.Leggings.class, ArmorItemBuilder.Leggings::new); - RegistryInfo.ITEM.addType("boots", ArmorItemBuilder.Boots.class, ArmorItemBuilder.Boots::new); - RegistryInfo.ITEM.addType("animal_armor", ArmorItemBuilder.AnimalArmor.class, ArmorItemBuilder.AnimalArmor::new); - RegistryInfo.ITEM.addType("music_disc", RecordItemJS.Builder.class, RecordItemJS.Builder::new); - RegistryInfo.ITEM.addType("smithing_template", SmithingTemplateItemBuilder.class, SmithingTemplateItemBuilder::new); - - RegistryInfo.FLUID.addType("basic", FluidBuilder.class, FluidBuilder::new); - RegistryInfo.ENCHANTMENT.addType("basic", EnchantmentBuilder.class, EnchantmentBuilder::new); - RegistryInfo.MOB_EFFECT.addType("basic", BasicMobEffect.Builder.class, BasicMobEffect.Builder::new); - // ENTITY_TYPE - // BLOCK_ENTITY_TYPE - RegistryInfo.POTION.addType("basic", PotionBuilder.class, PotionBuilder::new); - RegistryInfo.PARTICLE_TYPE.addType("basic", ParticleTypeBuilder.class, ParticleTypeBuilder::new); - RegistryInfo.PAINTING_VARIANT.addType("basic", PaintingVariantBuilder.class, PaintingVariantBuilder::new); - RegistryInfo.CUSTOM_STAT.addType("basic", CustomStatBuilder.class, CustomStatBuilder::new); - RegistryInfo.POINT_OF_INTEREST_TYPE.addType("basic", PoiTypeBuilder.class, PoiTypeBuilder::new); - RegistryInfo.VILLAGER_TYPE.addType("basic", VillagerTypeBuilder.class, VillagerTypeBuilder::new); - RegistryInfo.VILLAGER_PROFESSION.addType("basic", VillagerProfessionBuilder.class, VillagerProfessionBuilder::new); - RegistryInfo.CREATIVE_MODE_TAB.addType("basic", CreativeTabBuilder.class, CreativeTabBuilder::new); - RegistryInfo.ARMOR_MATERIAL.addType("basic", ArmorMaterialBuilder.class, ArmorMaterialBuilder::new); - } - @Override public void initStartup() { ItemEvents.TOOL_TIER_REGISTRY.post(ScriptType.STARTUP, new ItemToolTierRegistryKubeEvent(ItemBuilder.TOOL_TIERS)); @@ -252,6 +202,59 @@ public void initStartup() { */ } + @Override + public void registerBuilderTypes(BuilderTypeRegistry registry) { + registry.addDefault(Registries.SOUND_EVENT, SoundEventBuilder.class, SoundEventBuilder::new); + + registry.addDefault(Registries.BLOCK, BasicBlockJS.Builder.class, BasicBlockJS.Builder::new); + + registry.of(Registries.BLOCK, reg -> { + reg.add("detector", DetectorBlock.Builder.class, DetectorBlock.Builder::new); + reg.add("slab", SlabBlockBuilder.class, SlabBlockBuilder::new); + reg.add("stairs", StairBlockBuilder.class, StairBlockBuilder::new); + reg.add("fence", FenceBlockBuilder.class, FenceBlockBuilder::new); + reg.add("wall", WallBlockBuilder.class, WallBlockBuilder::new); + reg.add("fence_gate", FenceGateBlockBuilder.class, FenceGateBlockBuilder::new); + reg.add("pressure_plate", PressurePlateBlockBuilder.class, PressurePlateBlockBuilder::new); + reg.add("button", ButtonBlockBuilder.class, ButtonBlockBuilder::new); + reg.add("falling", FallingBlockBuilder.class, FallingBlockBuilder::new); + reg.add("crop", CropBlockBuilder.class, CropBlockBuilder::new); + reg.add("cardinal", HorizontalDirectionalBlockBuilder.class, HorizontalDirectionalBlockBuilder::new); + reg.add("carpet", CarpetBlockBuilder.class, CarpetBlockBuilder::new); + }); + + registry.addDefault(Registries.ITEM, BasicItemJS.Builder.class, BasicItemJS.Builder::new); + + registry.of(Registries.ITEM, reg -> { + reg.add("sword", SwordItemBuilder.class, SwordItemBuilder::new); + reg.add("pickaxe", DiggerItemBuilder.Pickaxe.class, DiggerItemBuilder.Pickaxe::new); + reg.add("axe", DiggerItemBuilder.Axe.class, DiggerItemBuilder.Axe::new); + reg.add("shovel", DiggerItemBuilder.Shovel.class, DiggerItemBuilder.Shovel::new); + reg.add("hoe", DiggerItemBuilder.Hoe.class, DiggerItemBuilder.Hoe::new); + reg.add("shears", ShearsItemBuilder.class, ShearsItemBuilder::new); + reg.add("helmet", ArmorItemBuilder.Helmet.class, ArmorItemBuilder.Helmet::new); + reg.add("chestplate", ArmorItemBuilder.Chestplate.class, ArmorItemBuilder.Chestplate::new); + reg.add("leggings", ArmorItemBuilder.Leggings.class, ArmorItemBuilder.Leggings::new); + reg.add("boots", ArmorItemBuilder.Boots.class, ArmorItemBuilder.Boots::new); + reg.add("animal_armor", ArmorItemBuilder.AnimalArmor.class, ArmorItemBuilder.AnimalArmor::new); + reg.add("music_disc", RecordItemJS.Builder.class, RecordItemJS.Builder::new); + reg.add("smithing_template", SmithingTemplateItemBuilder.class, SmithingTemplateItemBuilder::new); + }); + + registry.addDefault(Registries.FLUID, FluidBuilder.class, FluidBuilder::new); + registry.addDefault(Registries.ENCHANTMENT, EnchantmentBuilder.class, EnchantmentBuilder::new); + registry.addDefault(Registries.MOB_EFFECT, BasicMobEffect.Builder.class, BasicMobEffect.Builder::new); + registry.addDefault(Registries.POTION, PotionBuilder.class, PotionBuilder::new); + registry.addDefault(Registries.PARTICLE_TYPE, ParticleTypeBuilder.class, ParticleTypeBuilder::new); + registry.addDefault(Registries.PAINTING_VARIANT, PaintingVariantBuilder.class, PaintingVariantBuilder::new); + registry.addDefault(Registries.CUSTOM_STAT, CustomStatBuilder.class, CustomStatBuilder::new); + registry.addDefault(Registries.POINT_OF_INTEREST_TYPE, PoiTypeBuilder.class, PoiTypeBuilder::new); + registry.addDefault(Registries.VILLAGER_TYPE, VillagerTypeBuilder.class, VillagerTypeBuilder::new); + registry.addDefault(Registries.VILLAGER_PROFESSION, VillagerProfessionBuilder.class, VillagerProfessionBuilder::new); + registry.addDefault(Registries.CREATIVE_MODE_TAB, CreativeTabBuilder.class, CreativeTabBuilder::new); + registry.addDefault(Registries.ARMOR_MATERIAL, ArmorMaterialBuilder.class, ArmorMaterialBuilder::new); + } + @Override public void registerEvents(EventGroupRegistry registry) { registry.register(StartupEvents.GROUP); @@ -420,14 +423,17 @@ public void registerBindings(BindingsEvent event) { if (event.type().isStartup()) { event.add("NativeEvents", new NativeEventWrapper("NativeEvents", NeoForge.EVENT_BUS)); - KubeJS.eventBus().ifPresent(bus -> event.add("NativeModEvents", new NativeEventWrapper("NativeModEvents", bus))); + + var modBus = KubeJS.thisMod.getEventBus(); + + if (modBus != null) { + event.add("NativeModEvents", new NativeEventWrapper("NativeModEvents", modBus)); + } } } @Override public void registerTypeWrappers(WrapperRegistry registry) { - registry.register(Holder.class, KubeJSTypeWrappers::holderOf); - registry.register(ResourceKey.class, KubeJSTypeWrappers::resourceKeyOf); registry.register(RegistryPredicate.class, RegistryPredicate::of); // Java / Minecraft // diff --git a/src/main/java/dev/latvian/mods/kubejs/KubeJS.java b/src/main/java/dev/latvian/mods/kubejs/KubeJS.java index ecd84bdd7..065299cb5 100644 --- a/src/main/java/dev/latvian/mods/kubejs/KubeJS.java +++ b/src/main/java/dev/latvian/mods/kubejs/KubeJS.java @@ -9,11 +9,11 @@ import dev.latvian.mods.kubejs.item.creativetab.CreativeTabCallbackForge; import dev.latvian.mods.kubejs.item.creativetab.CreativeTabKubeEvent; import dev.latvian.mods.kubejs.item.creativetab.KubeJSCreativeTabs; -import dev.latvian.mods.kubejs.neoforge.KubeJSNeoForgeClient; -import dev.latvian.mods.kubejs.net.KubeJSNet; import dev.latvian.mods.kubejs.recipe.KubeJSRecipeSerializers; import dev.latvian.mods.kubejs.recipe.schema.RecipeNamespace; -import dev.latvian.mods.kubejs.registry.RegistryInfo; +import dev.latvian.mods.kubejs.registry.BuilderTypeRegistryHandler; +import dev.latvian.mods.kubejs.registry.RegistryKubeEvent; +import dev.latvian.mods.kubejs.registry.RegistryType; import dev.latvian.mods.kubejs.script.ConsoleLine; import dev.latvian.mods.kubejs.script.PlatformWrapper; import dev.latvian.mods.kubejs.script.ScriptFileInfo; @@ -22,14 +22,12 @@ import dev.latvian.mods.kubejs.script.ScriptType; import dev.latvian.mods.kubejs.script.ScriptsLoadedEvent; import dev.latvian.mods.kubejs.script.data.GeneratedResourcePack; -import dev.latvian.mods.kubejs.util.Cast; import dev.latvian.mods.kubejs.util.ConsoleJS; import dev.latvian.mods.kubejs.util.KubeJSBackgroundThread; import dev.latvian.mods.kubejs.util.KubeJSPlugins; import dev.latvian.mods.kubejs.util.UtilsJS; import net.minecraft.Util; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.Style; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.neoforged.api.distmarker.Dist; @@ -39,6 +37,7 @@ import net.neoforged.fml.DistExecutor; import net.neoforged.fml.ModContainer; import net.neoforged.fml.ModList; +import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.fml.common.Mod; import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; import net.neoforged.fml.event.lifecycle.FMLLoadCompleteEvent; @@ -46,7 +45,6 @@ import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.common.NeoForgeMod; import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent; -import net.neoforged.neoforge.registries.RegisterEvent; import net.neoforged.neoforgespi.language.IModFileInfo; import net.neoforged.neoforgespi.language.IModInfo; import org.slf4j.Logger; @@ -65,9 +63,9 @@ import java.nio.file.Path; import java.time.Duration; import java.util.ArrayList; -import java.util.Optional; @Mod(KubeJS.MOD_ID) +@EventBusSubscriber(modid = KubeJS.MOD_ID, bus = EventBusSubscriber.Bus.MOD) public class KubeJS { public static final String MOD_ID = "kubejs"; public static final String MOD_NAME = "KubeJS"; @@ -76,13 +74,8 @@ public class KubeJS { public static final String MC_VERSION_STRING = "1.20.6"; public static String QUERY; public static final ResourceLocation ICONS_FONT = id("icons"); - public static final Component NAME_COMPONENT = Component.empty().append(Component.literal("K").withStyle(Style.EMPTY.withFont(ICONS_FONT))).append(" ").append(Component.literal(MOD_NAME)); + public static final Component NAME_COMPONENT = Component.empty().append(Component.literal("K.").kjs$font(ICONS_FONT).kjs$white()).append(Component.literal(MOD_NAME)); public static String VERSION = "0"; - private static final ThreadLocal BUS = new ThreadLocal<>(); - - public static Optional eventBus() { - return Optional.ofNullable(BUS.get()); - } public static ResourceLocation id(String path) { return new ResourceLocation(MOD_ID, path); @@ -131,10 +124,6 @@ public KubeJS(IEventBus bus, Dist dist, ModContainer mod) throws Throwable { } } - bus.addListener(KubeJSNet::register); - - BUS.set(bus); - //noinspection removal PROXY = DistExecutor.safeRunForDist(() -> KubeJSClient::new, () -> KubeJSCommon::new); @@ -144,6 +133,9 @@ public KubeJS(IEventBus bus, Dist dist, ModContainer mod) throws Throwable { ScriptType.STARTUP.console.setCapturingErrors(true); } + LOGGER.info("Loading vanilla registries..."); + RegistryType.init(); + var pluginTimer = Stopwatch.createStarted(); LOGGER.info("Looking for KubeJS plugins..."); var allMods = new ArrayList<>(ModList.get().getMods().stream().map(IModInfo::getOwningFile).map(IModFileInfo::getFile).toList()); @@ -153,6 +145,7 @@ public KubeJS(IEventBus bus, Dist dist, ModContainer mod) throws Throwable { LOGGER.info("Done in " + pluginTimer.stop()); KubeJSPlugins.forEachPlugin(KubeJSPlugin::init); + KubeJSPlugins.forEachPlugin(new BuilderTypeRegistryHandler(), KubeJSPlugin::registerBuilderTypes); startupScriptManager = new ScriptManager(ScriptType.STARTUP); clientScriptManager = new ScriptManager(ScriptType.CLIENT); @@ -161,12 +154,10 @@ public KubeJS(IEventBus bus, Dist dist, ModContainer mod) throws Throwable { KubeJSPlugins.forEachPlugin(KubeJSPlugin::initStartup); - PROXY.init(bus); + PROXY.init(); - for (var extraId : StartupEvents.REGISTRY.findUniqueExtraIds(ScriptType.STARTUP)) { - if (extraId instanceof ResourceKey key) { - RegistryInfo.of((ResourceKey) key).fireRegistryEvent(); - } + for (var key : StartupEvents.REGISTRY.findUniqueExtraIds(ScriptType.STARTUP)) { + StartupEvents.REGISTRY.post(new RegistryKubeEvent<>((ResourceKey) key), key); } GeneratedResourcePack.scanForInvalidFiles("kubejs/assets/", KubeJSPaths.ASSETS); @@ -175,17 +166,15 @@ public KubeJS(IEventBus bus, Dist dist, ModContainer mod) throws Throwable { if (CommonProperties.get().serverOnly) { // FIXME ModLoadingContext.get().registerExtensionPoint(DisplayTest.class, () -> new DisplayTest(() -> DisplayTest.IGNORESERVERONLY, (a, b) -> true)); } else { + // See NeoForgeRegistriesSetup.VANILLA_SYNC_REGISTRIES NeoForgeMod.enableMilkFluid(); KubeJSIngredients.REGISTRY.register(bus); - KubeJSCreativeTabs.REGISTRY.register(bus); // KubeJSComponents.REGISTRY.register(bus); KubeJSRecipeSerializers.REGISTRY.register(bus); KubeJSMenus.REGISTRY.register(bus); } - if (dist == Dist.CLIENT) { - new KubeJSNeoForgeClient(bus); - } + KubeJSCreativeTabs.REGISTRY.register(bus); StartupEvents.INIT.post(ScriptType.STARTUP, KubeStartupEvent.BASIC); // KubeJSRegistries.chunkGenerators().register(new ResourceLocation(KubeJS.MOD_ID, "flat"), () -> KJSFlatLevelSource.CODEC); @@ -219,12 +208,6 @@ public static Path verifyFilePath(Path path) throws IOException { return path; } - @SubscribeEvent(priority = EventPriority.LOW) - public static void initRegistries(RegisterEvent event) { - var info = RegistryInfo.of((ResourceKey) event.getRegistryKey()); - info.registerObjects((id, supplier) -> event.register(Cast.to(info.key), id, supplier)); - } - @SubscribeEvent(priority = EventPriority.LOW) public static void commonSetup(FMLCommonSetupEvent event) { } diff --git a/src/main/java/dev/latvian/mods/kubejs/KubeJSCommon.java b/src/main/java/dev/latvian/mods/kubejs/KubeJSCommon.java index fbcb71d3b..bf99989f1 100644 --- a/src/main/java/dev/latvian/mods/kubejs/KubeJSCommon.java +++ b/src/main/java/dev/latvian/mods/kubejs/KubeJSCommon.java @@ -6,16 +6,12 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.entity.player.Player; -import net.neoforged.bus.api.IEventBus; import org.jetbrains.annotations.Nullable; import java.util.List; public class KubeJSCommon { - public void init(IEventBus bus) { - } - - public void clientSetup() { + public void init() { } public void reloadClientInternal() { diff --git a/src/main/java/dev/latvian/mods/kubejs/KubeJSPlugin.java b/src/main/java/dev/latvian/mods/kubejs/KubeJSPlugin.java index 0199b124c..8e96b6974 100644 --- a/src/main/java/dev/latvian/mods/kubejs/KubeJSPlugin.java +++ b/src/main/java/dev/latvian/mods/kubejs/KubeJSPlugin.java @@ -10,6 +10,7 @@ import dev.latvian.mods.kubejs.recipe.RecipesKubeEvent; import dev.latvian.mods.kubejs.recipe.schema.RecipeComponentFactoryRegistryEvent; import dev.latvian.mods.kubejs.recipe.schema.RegisterRecipeSchemasEvent; +import dev.latvian.mods.kubejs.registry.BuilderTypeRegistry; import dev.latvian.mods.kubejs.script.BindingsEvent; import dev.latvian.mods.kubejs.script.ScriptType; import dev.latvian.mods.kubejs.script.WrapperRegistry; @@ -42,6 +43,9 @@ default void afterInit() { default void onServerReload() { } + default void registerBuilderTypes(BuilderTypeRegistry registry) { + } + /** * Call {@link EventGroupRegistry#register(EventGroup)} for event groups your mod adds */ diff --git a/src/main/java/dev/latvian/mods/kubejs/KubeJSTypeWrappers.java b/src/main/java/dev/latvian/mods/kubejs/KubeJSTypeWrappers.java index 7ed0c74d6..4f97cf827 100644 --- a/src/main/java/dev/latvian/mods/kubejs/KubeJSTypeWrappers.java +++ b/src/main/java/dev/latvian/mods/kubejs/KubeJSTypeWrappers.java @@ -1,17 +1,11 @@ package dev.latvian.mods.kubejs; -import dev.latvian.mods.kubejs.core.WithRegistryKeyKJS; import dev.latvian.mods.kubejs.level.BlockContainerJS; -import dev.latvian.mods.kubejs.registry.RegistryInfo; -import dev.latvian.mods.kubejs.util.ID; import dev.latvian.mods.kubejs.util.NBTUtils; import dev.latvian.mods.kubejs.util.UtilsJS; import dev.latvian.mods.rhino.Context; -import dev.latvian.mods.rhino.type.TypeInfo; import net.minecraft.core.BlockPos; -import net.minecraft.core.Holder; import net.minecraft.nbt.NbtOps; -import net.minecraft.resources.ResourceKey; import net.minecraft.util.valueproviders.ClampedInt; import net.minecraft.util.valueproviders.ClampedNormalInt; import net.minecraft.util.valueproviders.ConstantInt; @@ -31,48 +25,6 @@ import java.util.Map; public interface KubeJSTypeWrappers { - static Holder holderOf(Context cx, Object from, TypeInfo target) { - if (from == null) { - return null; - } else if (from instanceof Holder h) { - return h; - } else if (from instanceof WithRegistryKeyKJS w) { - return w.kjs$asHolder(); - } - - var reg = RegistryInfo.ofClass(target.param(0).asClass()); - - if (reg != null) { - return reg.getHolder(ID.mc(from)); - } - - return new Holder.Direct<>(from); - } - - static ResourceKey resourceKeyOf(Context cx, Object from, TypeInfo target) { - if (from == null) { - return null; - } else if (from instanceof ResourceKey k) { - return k; - } else if (from instanceof WithRegistryKeyKJS w) { - return w.kjs$getRegistryKey(); - } - - var cl = target.param(0).asClass(); - - if (cl == ResourceKey.class) { - return ResourceKey.createRegistryKey(ID.mc(from)); - } - - var reg = RegistryInfo.ofClass(cl); - - if (reg != null) { - return ResourceKey.create(reg.key, ID.mc(from)); - } - - throw new IllegalArgumentException("Can't parse " + from + " as ResourceKey!"); - } - @SuppressWarnings("unchecked") static IntProvider intProviderOf(Context cx, Object o) { if (o instanceof Number n) { diff --git a/src/main/java/dev/latvian/mods/kubejs/bindings/TextWrapper.java b/src/main/java/dev/latvian/mods/kubejs/bindings/TextWrapper.java index a4e031123..e3ebfe61a 100644 --- a/src/main/java/dev/latvian/mods/kubejs/bindings/TextWrapper.java +++ b/src/main/java/dev/latvian/mods/kubejs/bindings/TextWrapper.java @@ -332,6 +332,10 @@ private static MutableComponent icon(String character) { return of(character).kjs$font(KubeJS.ICONS_FONT); } + static MutableComponent smallSpace() { + return icon("."); + } + static MutableComponent logoIcon() { return icon("K"); } @@ -340,7 +344,27 @@ static MutableComponent infoIcon() { return icon("I"); } + static MutableComponent info(Component text) { + return Component.empty().append(infoIcon()).append(smallSpace()).append(text); + } + static MutableComponent warnIcon() { return icon("W"); } + + static MutableComponent warn(Component text) { + return Component.empty().append(warnIcon()).append(smallSpace()).append(text); + } + + static MutableComponent yesIcon() { + return icon("Y"); + } + + static MutableComponent noIcon() { + return icon("N"); + } + + static MutableComponent yesIcon(boolean yes) { + return icon(yes ? "Y" : "N"); + } } \ No newline at end of file diff --git a/src/main/java/dev/latvian/mods/kubejs/block/BlockBuilder.java b/src/main/java/dev/latvian/mods/kubejs/block/BlockBuilder.java index d1c4c70c6..7b59df877 100644 --- a/src/main/java/dev/latvian/mods/kubejs/block/BlockBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/block/BlockBuilder.java @@ -19,6 +19,7 @@ import dev.latvian.mods.kubejs.client.VariantBlockStateGenerator; import dev.latvian.mods.kubejs.generator.AssetJsonGenerator; import dev.latvian.mods.kubejs.generator.DataJsonGenerator; +import dev.latvian.mods.kubejs.registry.AdditionalObjectRegistry; import dev.latvian.mods.kubejs.registry.BuilderBase; import dev.latvian.mods.kubejs.registry.RegistryInfo; import dev.latvian.mods.kubejs.script.ScriptType; @@ -148,13 +149,13 @@ public Block transformObject(Block obj) { } @Override - public void createAdditionalObjects() { + public void createAdditionalObjects(AdditionalObjectRegistry registry) { if (itemBuilder != null) { - RegistryInfo.ITEM.addBuilder(itemBuilder); + registry.add(RegistryInfo.ITEM, itemBuilder); } if (blockEntityInfo != null) { - RegistryInfo.BLOCK_ENTITY_TYPE.addBuilder(new BlockEntityBuilder(id, blockEntityInfo)); + registry.add(RegistryInfo.BLOCK_ENTITY_TYPE, new BlockEntityBuilder(id, blockEntityInfo)); } } diff --git a/src/main/java/dev/latvian/mods/kubejs/client/ClientInitKubeEvent.java b/src/main/java/dev/latvian/mods/kubejs/client/ClientInitKubeEvent.java index 0511baeeb..deb6614ee 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/ClientInitKubeEvent.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/ClientInitKubeEvent.java @@ -12,6 +12,10 @@ @SuppressWarnings({"rawtypes", "unchecked"}) public class ClientInitKubeEvent extends ClientKubeEvent { + public ClientInitKubeEvent() { + super(null); + } + public void registerBlockEntityRenderer(BlockEntityType type, BlockEntityRendererProvider renderer) { BlockEntityRendererRegistryImpl.register(type, renderer); } diff --git a/src/main/java/dev/latvian/mods/kubejs/client/ClientKubeEvent.java b/src/main/java/dev/latvian/mods/kubejs/client/ClientKubeEvent.java index 208b878b4..1bb31012d 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/ClientKubeEvent.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/ClientKubeEvent.java @@ -1,17 +1,22 @@ package dev.latvian.mods.kubejs.client; import dev.latvian.mods.kubejs.player.KubePlayerEvent; -import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; public class ClientKubeEvent implements KubePlayerEvent { + private final LocalPlayer player; + + public ClientKubeEvent(LocalPlayer player) { + this.player = player; + } + @Override public LocalPlayer getEntity() { - return Minecraft.getInstance().player; + return player; } @Override public LocalPlayer getPlayer() { - return Minecraft.getInstance().player; + return player; } } diff --git a/src/main/java/dev/latvian/mods/kubejs/client/DebugInfoKubeEvent.java b/src/main/java/dev/latvian/mods/kubejs/client/DebugInfoKubeEvent.java index 4b1303af0..c44250e4c 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/DebugInfoKubeEvent.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/DebugInfoKubeEvent.java @@ -2,6 +2,7 @@ import dev.latvian.mods.kubejs.typings.Info; import net.minecraft.client.Minecraft; +import net.minecraft.client.player.LocalPlayer; import java.util.List; @@ -11,7 +12,8 @@ public class DebugInfoKubeEvent extends ClientKubeEvent { private final List lines; - public DebugInfoKubeEvent(List l) { + public DebugInfoKubeEvent(LocalPlayer player, List l) { + super(player); lines = l; } diff --git a/src/main/java/dev/latvian/mods/kubejs/client/KubeJSClient.java b/src/main/java/dev/latvian/mods/kubejs/client/KubeJSClient.java index 26b85433e..2d337e537 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/KubeJSClient.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/KubeJSClient.java @@ -1,18 +1,12 @@ package dev.latvian.mods.kubejs.client; -import dev.architectury.hooks.forge.PackRepositoryHooksImpl; import dev.latvian.mods.kubejs.KubeJS; import dev.latvian.mods.kubejs.KubeJSCommon; import dev.latvian.mods.kubejs.KubeJSPaths; import dev.latvian.mods.kubejs.KubeJSPlugin; -import dev.latvian.mods.kubejs.bindings.event.ClientEvents; -import dev.latvian.mods.kubejs.bindings.event.ItemEvents; import dev.latvian.mods.kubejs.bindings.event.NetworkEvents; import dev.latvian.mods.kubejs.client.painter.Painter; -import dev.latvian.mods.kubejs.fluid.FluidBuilder; -import dev.latvian.mods.kubejs.item.ItemModelPropertiesKubeEvent; import dev.latvian.mods.kubejs.net.NetworkKubeEvent; -import dev.latvian.mods.kubejs.registry.RegistryInfo; import dev.latvian.mods.kubejs.script.ConsoleLine; import dev.latvian.mods.kubejs.script.ScriptType; import dev.latvian.mods.kubejs.script.data.ExportablePackResources; @@ -20,7 +14,6 @@ import dev.latvian.mods.kubejs.util.KubeJSPlugins; import net.minecraft.Util; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.commands.CommandSourceStack; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; @@ -28,7 +21,6 @@ import net.minecraft.util.profiling.InactiveProfiler; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.CreativeModeTabs; -import net.neoforged.bus.api.IEventBus; import org.jetbrains.annotations.Nullable; import java.io.File; @@ -39,7 +31,7 @@ public class KubeJSClient extends KubeJSCommon { @Override - public void init(IEventBus bus) { + public void init() { var mc = Minecraft.getInstance(); // You'd think that this is impossible, but not when you use runData gradle task if (mc == null) { @@ -48,7 +40,6 @@ public void init(IEventBus bus) { reloadClientScripts(mc); - new KubeJSClientEventHandler().init(bus); mc.getResourcePackRepository().addPackFinder(new KubeJSResourcePackFinder()); KubeJSPlugins.forEachPlugin(KubeJSPlugin::clientInit); @@ -82,25 +73,6 @@ public static void copyDefaultOptionsFile(File optionsFile) { } } - @Override - public void clientSetup() { - ClientEvents.INIT.post(ScriptType.STARTUP, new ClientInitKubeEvent()); - ItemEvents.MODEL_PROPERTIES.post(ScriptType.STARTUP, new ItemModelPropertiesKubeEvent()); - - ClientEvents.ATLAS_SPRITE_REGISTRY.listenJava(ScriptType.CLIENT, TextureAtlas.LOCATION_BLOCKS, event -> { - var e = (AtlasSpriteRegistryKubeEvent) event; - - for (var builder : RegistryInfo.FLUID) { - if (builder instanceof FluidBuilder b) { - e.register(b.stillTexture); - e.register(b.flowingTexture); - } - } - - return null; - }); - } - @Override public void handleDataFromServerPacket(String channel, @Nullable CompoundTag data) { if (NetworkEvents.DATA_RECEIVED.hasListeners(channel)) { diff --git a/src/main/java/dev/latvian/mods/kubejs/client/KubeJSClientEventHandler.java b/src/main/java/dev/latvian/mods/kubejs/client/KubeJSClientEventHandler.java index 03aba29ab..937f02d7e 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/KubeJSClientEventHandler.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/KubeJSClientEventHandler.java @@ -1,16 +1,11 @@ package dev.latvian.mods.kubejs.client; -import dev.architectury.event.events.client.ClientGuiEvent; -import dev.architectury.event.events.client.ClientPlayerEvent; -import dev.architectury.hooks.client.screen.ScreenAccess; import dev.architectury.hooks.fluid.FluidBucketHooks; import dev.latvian.mods.kubejs.CommonProperties; import dev.latvian.mods.kubejs.KubeJS; import dev.latvian.mods.kubejs.bindings.event.ClientEvents; import dev.latvian.mods.kubejs.bindings.event.ItemEvents; import dev.latvian.mods.kubejs.client.painter.Painter; -import dev.latvian.mods.kubejs.gui.KubeJSMenus; -import dev.latvian.mods.kubejs.gui.KubeJSScreen; import dev.latvian.mods.kubejs.item.ItemTooltipKubeEvent; import dev.latvian.mods.kubejs.script.ScriptType; import dev.latvian.mods.kubejs.util.ConsoleJS; @@ -29,51 +24,45 @@ import net.minecraft.world.item.SpawnEggItem; import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.Fluids; -import net.neoforged.bus.api.IEventBus; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.EventPriority; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.neoforge.client.event.ClientPlayerNetworkEvent; import net.neoforged.neoforge.client.event.CustomizeGuiOverlayEvent; -import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent; import net.neoforged.neoforge.client.event.RenderGuiEvent; import net.neoforged.neoforge.client.event.ScreenEvent; import net.neoforged.neoforge.event.entity.player.ItemTooltipEvent; import org.jetbrains.annotations.Nullable; -import java.awt.Paint; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.function.Consumer; -@EventBusSubscriber(modid = KubeJS.MOD_ID) +@EventBusSubscriber(modid = KubeJS.MOD_ID, value = Dist.CLIENT) public class KubeJSClientEventHandler { private static final ResourceLocation RECIPE_BUTTON_TEXTURE = new ResourceLocation("textures/gui/recipe_button.png"); public static Map> staticItemTooltips = null; - private final Map tempTagNames = new LinkedHashMap<>(); - - public void init(IEventBus bus) { - bus.addListener(this::registerMenuScreens); - - //ClientTextureStitchEvent.POST.register(this::postAtlasStitch); - } + private static final Map tempTagNames = new LinkedHashMap<>(); @SubscribeEvent - private void debugInfo(CustomizeGuiOverlayEvent.DebugText event) { + public static void debugInfo(CustomizeGuiOverlayEvent.DebugText event) { var mc = Minecraft.getInstance(); + if (mc.player != null) { if (ClientEvents.DEBUG_LEFT.hasListeners()) { - ClientEvents.DEBUG_LEFT.post(new DebugInfoKubeEvent(event.getLeft())); + ClientEvents.DEBUG_LEFT.post(new DebugInfoKubeEvent(mc.player, event.getLeft())); } if (ClientEvents.DEBUG_RIGHT.hasListeners()) { - ClientEvents.DEBUG_RIGHT.post(new DebugInfoKubeEvent(event.getRight())); + ClientEvents.DEBUG_RIGHT.post(new DebugInfoKubeEvent(mc.player, event.getRight())); } } } @SubscribeEvent - public void onItemTooltip(ItemTooltipEvent event) { + public static void onItemTooltip(ItemTooltipEvent event) { var stack = event.getItemStack(); var lines = event.getToolTip(); var tooltipContext = event.getContext(); @@ -137,28 +126,23 @@ public void onItemTooltip(ItemTooltipEvent event) { } @SubscribeEvent - public void onClientPlayerNetwork(ClientPlayerNetworkEvent event) { - switch (event) { - case ClientPlayerNetworkEvent.LoggingIn loggingIn -> { - ClientEvents.LOGGED_IN.post(ScriptType.CLIENT, new ClientKubeEvent()); - } - case ClientPlayerNetworkEvent.LoggingOut loggingOut -> { - ClientEvents.LOGGED_OUT.post(ScriptType.CLIENT, new ClientKubeEvent()); - Painter.INSTANCE.clear(); - } - default -> { - // clone does not have a handler currently - } - } + public static void loggingIn(ClientPlayerNetworkEvent.LoggingIn event) { + ClientEvents.LOGGED_IN.post(ScriptType.CLIENT, new ClientKubeEvent(event.getPlayer())); } @SubscribeEvent - public void onRenderGuiPost(RenderGuiEvent.Post event) { + public static void loggingOut(ClientPlayerNetworkEvent.LoggingOut event) { + ClientEvents.LOGGED_OUT.post(ScriptType.CLIENT, new ClientKubeEvent(event.getPlayer())); + Painter.INSTANCE.clear(); + } + + @SubscribeEvent + public static void onRenderGuiPost(RenderGuiEvent.Post event) { Painter.INSTANCE.inGameScreenDraw(event.getGuiGraphics(), event.getPartialTick()); } @SubscribeEvent - public void onRenderPost(ScreenEvent.Render.Post event) { + public static void onRenderPost(ScreenEvent.Render.Post event) { Painter.INSTANCE.guiScreenDraw(event.getScreen(), event.getGuiGraphics(), event.getMouseX(), event.getMouseY(), event.getPartialTick()); } @@ -172,7 +156,7 @@ public static Screen setScreen(Screen screen) { } @SubscribeEvent - public void guiPostInit(ScreenEvent.Init.Post event) { + public static void guiPostInit(ScreenEvent.Init.Post event) { var screen = event.getScreen(); if (ClientProperties.get().getDisableRecipeBook() && screen instanceof RecipeUpdateListener) { @@ -238,7 +222,17 @@ public void guiPostInit(ScreenEvent.Init.Post event) { } }*/ - private void registerMenuScreens(RegisterMenuScreensEvent event) { - event.register(KubeJSMenus.MENU.get(), KubeJSScreen::new); + // FIXME: implement + /*private void textureStitch(TextureStitchEvent.Pre event) { + ClientEvents.ATLAS_SPRITE_REGISTRY.post(new AtlasSpriteRegistryEventJS(event::addSprite), event.getAtlas().location()); + }*/ + + @SubscribeEvent(priority = EventPriority.LOW) + public static void openScreenEvent(ScreenEvent.Opening event) { + var s = KubeJSClientEventHandler.setScreen(event.getScreen()); + + if (s != null && event.getScreen() != s) { + event.setNewScreen(s); + } } } \ No newline at end of file diff --git a/src/main/java/dev/latvian/mods/kubejs/client/painter/PaintKubeEvent.java b/src/main/java/dev/latvian/mods/kubejs/client/painter/PaintKubeEvent.java index ebb864634..0989faa9b 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/painter/PaintKubeEvent.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/painter/PaintKubeEvent.java @@ -31,6 +31,7 @@ public class PaintKubeEvent extends ClientKubeEvent { public final Screen screen; public PaintKubeEvent(Minecraft m, GuiGraphics g, float d, @Nullable Screen s) { + super(m.player); mc = m; font = mc.font; graphics = g; diff --git a/src/main/java/dev/latvian/mods/kubejs/client/painter/Painter.java b/src/main/java/dev/latvian/mods/kubejs/client/painter/Painter.java index 33ab8c425..6f7a09493 100644 --- a/src/main/java/dev/latvian/mods/kubejs/client/painter/Painter.java +++ b/src/main/java/dev/latvian/mods/kubejs/client/painter/Painter.java @@ -127,26 +127,30 @@ public PainterObject getObject(String key) { } public void paint(CompoundTag root) { - Minecraft.getInstance().execute(() -> { + var mc = Minecraft.getInstance(); + + mc.execute(() -> { synchronized (lock) { storage.handle(root); screenObjects = null; if (ClientEvents.PAINTER_UPDATED.hasListeners()) { - ClientEvents.PAINTER_UPDATED.post(ScriptType.CLIENT, new ClientKubeEvent()); + ClientEvents.PAINTER_UPDATED.post(ScriptType.CLIENT, new ClientKubeEvent(mc.player)); } } }); } public void clear() { - Minecraft.getInstance().execute(() -> { + var mc = Minecraft.getInstance(); + + mc.execute(() -> { synchronized (lock) { storage.clear(); screenObjects = null; if (ClientEvents.PAINTER_UPDATED.hasListeners()) { - ClientEvents.PAINTER_UPDATED.post(ScriptType.CLIENT, new ClientKubeEvent()); + ClientEvents.PAINTER_UPDATED.post(ScriptType.CLIENT, new ClientKubeEvent(mc.player)); } } }); diff --git a/src/main/java/dev/latvian/mods/kubejs/core/BlockKJS.java b/src/main/java/dev/latvian/mods/kubejs/core/BlockKJS.java index 4e14bfb50..b2e157b78 100644 --- a/src/main/java/dev/latvian/mods/kubejs/core/BlockKJS.java +++ b/src/main/java/dev/latvian/mods/kubejs/core/BlockKJS.java @@ -13,7 +13,7 @@ import java.util.function.Consumer; @RemapPrefixForJS("kjs$") -public interface BlockKJS extends BlockBuilderProvider, WithRegistryKeyKJS { +public interface BlockKJS extends BlockBuilderProvider, RegistryObjectKJS { default void kjs$setBlockBuilder(BlockBuilder b) { throw new NoMixinException(); } diff --git a/src/main/java/dev/latvian/mods/kubejs/core/BlockStateKJS.java b/src/main/java/dev/latvian/mods/kubejs/core/BlockStateKJS.java index 65a1c50f2..21aa36483 100644 --- a/src/main/java/dev/latvian/mods/kubejs/core/BlockStateKJS.java +++ b/src/main/java/dev/latvian/mods/kubejs/core/BlockStateKJS.java @@ -8,7 +8,7 @@ import net.minecraft.world.level.block.state.BlockState; @RemapPrefixForJS("kjs$") -public interface BlockStateKJS extends WithRegistryKeyKJS { +public interface BlockStateKJS extends RegistryObjectKJS { @Override default RegistryInfo kjs$getKubeRegistry() { return RegistryInfo.BLOCK; @@ -24,6 +24,11 @@ public interface BlockStateKJS extends WithRegistryKeyKJS { return ((BlockState) this).getBlock().kjs$getRegistryKey(); } + @Override + default String kjs$getId() { + return ((BlockState) this).getBlock().kjs$getId(); + } + default void kjs$setDestroySpeed(float v) { throw new NoMixinException(); } diff --git a/src/main/java/dev/latvian/mods/kubejs/core/EntityTypeKJS.java b/src/main/java/dev/latvian/mods/kubejs/core/EntityTypeKJS.java index 089cf8102..88e230326 100644 --- a/src/main/java/dev/latvian/mods/kubejs/core/EntityTypeKJS.java +++ b/src/main/java/dev/latvian/mods/kubejs/core/EntityTypeKJS.java @@ -3,7 +3,7 @@ import dev.latvian.mods.kubejs.registry.RegistryInfo; import net.minecraft.world.entity.EntityType; -public interface EntityTypeKJS extends WithRegistryKeyKJS> { +public interface EntityTypeKJS extends RegistryObjectKJS> { @Override default RegistryInfo> kjs$getKubeRegistry() { return RegistryInfo.ENTITY_TYPE; diff --git a/src/main/java/dev/latvian/mods/kubejs/core/FluidKJS.java b/src/main/java/dev/latvian/mods/kubejs/core/FluidKJS.java index 2a6bd13d2..c7bc0f230 100644 --- a/src/main/java/dev/latvian/mods/kubejs/core/FluidKJS.java +++ b/src/main/java/dev/latvian/mods/kubejs/core/FluidKJS.java @@ -5,7 +5,7 @@ import net.minecraft.world.level.material.Fluid; @RemapPrefixForJS("kjs$") -public interface FluidKJS extends WithRegistryKeyKJS { +public interface FluidKJS extends RegistryObjectKJS { default Fluid kjs$self() { return (Fluid) this; } diff --git a/src/main/java/dev/latvian/mods/kubejs/core/ItemKJS.java b/src/main/java/dev/latvian/mods/kubejs/core/ItemKJS.java index 2bfb9f909..f1eb1f316 100644 --- a/src/main/java/dev/latvian/mods/kubejs/core/ItemKJS.java +++ b/src/main/java/dev/latvian/mods/kubejs/core/ItemKJS.java @@ -11,7 +11,7 @@ import org.jetbrains.annotations.Nullable; @RemapPrefixForJS("kjs$") -public interface ItemKJS extends IngredientSupplierKJS, WithRegistryKeyKJS { +public interface ItemKJS extends IngredientSupplierKJS, RegistryObjectKJS { @RemapForJS("getItem") default Item kjs$self() { return (Item) this; diff --git a/src/main/java/dev/latvian/mods/kubejs/core/ItemStackKJS.java b/src/main/java/dev/latvian/mods/kubejs/core/ItemStackKJS.java index b5a1f6665..f007c54e5 100644 --- a/src/main/java/dev/latvian/mods/kubejs/core/ItemStackKJS.java +++ b/src/main/java/dev/latvian/mods/kubejs/core/ItemStackKJS.java @@ -13,21 +13,22 @@ import dev.latvian.mods.kubejs.util.ID; import dev.latvian.mods.kubejs.util.JsonSerializable; import dev.latvian.mods.kubejs.util.NBTSerializable; -import dev.latvian.mods.kubejs.util.Tags; import dev.latvian.mods.rhino.Context; import dev.latvian.mods.rhino.util.RemapForJS; import dev.latvian.mods.rhino.util.RemapPrefixForJS; import dev.latvian.mods.rhino.util.SpecialEquality; import dev.latvian.mods.rhino.util.ToStringJS; +import net.minecraft.core.Holder; import net.minecraft.core.HolderLookup; import net.minecraft.core.component.DataComponentMap; import net.minecraft.core.component.DataComponentPatch; import net.minecraft.core.component.DataComponents; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.TagKey; import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.component.ItemLore; import net.minecraft.world.item.crafting.Ingredient; @@ -36,14 +37,18 @@ import net.minecraft.world.level.block.Blocks; import org.jetbrains.annotations.Nullable; -import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; @SuppressWarnings("unused") @RemapPrefixForJS("kjs$") -public interface ItemStackKJS extends SpecialEquality, NBTSerializable, JsonSerializable, IngredientSupplierKJS, ToStringJS { +public interface ItemStackKJS extends + SpecialEquality, + NBTSerializable, + JsonSerializable, + IngredientSupplierKJS, + ToStringJS, + RegistryObjectKJS { default ItemStack kjs$self() { return (ItemStack) this; } @@ -71,20 +76,29 @@ default boolean specialEquals(Context cx, Object o, boolean shallow) { return ItemStack.isSameItemSameComponents(self, stack); } + @Override + default RegistryInfo kjs$getKubeRegistry() { + return RegistryInfo.ITEM; + } + + @Override default ResourceLocation kjs$getIdLocation() { return kjs$self().getItem().kjs$getIdLocation(); } - default String kjs$getId() { - return kjs$self().getItem().kjs$getId(); + @Override + default Holder kjs$asHolder() { + return kjs$self().getItem().kjs$asHolder(); } - default Collection kjs$getTags(Context cx) { - return Tags.byItem(cx, kjs$self().getItem()).map(TagKey::location).collect(Collectors.toSet()); + @Override + default ResourceKey kjs$getRegistryKey() { + return kjs$self().getItem().kjs$getRegistryKey(); } - default boolean kjs$hasTag(ResourceLocation tag) { - return kjs$self().is(Tags.item(tag)); + @Override + default String kjs$getId() { + return kjs$self().getItem().kjs$getId(); } default boolean kjs$isBlock() { @@ -164,6 +178,7 @@ default boolean specialEquals(Context cx, Object o, boolean shallow) { return is; } + @Override default String kjs$getMod() { return kjs$self().getItem().kjs$getMod(); } diff --git a/src/main/java/dev/latvian/mods/kubejs/core/MenuTypeKJS.java b/src/main/java/dev/latvian/mods/kubejs/core/MenuTypeKJS.java index bc6c8b2d6..ab41d59d0 100644 --- a/src/main/java/dev/latvian/mods/kubejs/core/MenuTypeKJS.java +++ b/src/main/java/dev/latvian/mods/kubejs/core/MenuTypeKJS.java @@ -3,7 +3,7 @@ import dev.latvian.mods.kubejs.registry.RegistryInfo; import net.minecraft.world.inventory.MenuType; -public interface MenuTypeKJS extends WithRegistryKeyKJS> { +public interface MenuTypeKJS extends RegistryObjectKJS> { @Override default RegistryInfo> kjs$getKubeRegistry() { return RegistryInfo.MENU; diff --git a/src/main/java/dev/latvian/mods/kubejs/core/WithRegistryKeyKJS.java b/src/main/java/dev/latvian/mods/kubejs/core/RegistryObjectKJS.java similarity index 71% rename from src/main/java/dev/latvian/mods/kubejs/core/WithRegistryKeyKJS.java rename to src/main/java/dev/latvian/mods/kubejs/core/RegistryObjectKJS.java index d502df7ef..686b65da6 100644 --- a/src/main/java/dev/latvian/mods/kubejs/core/WithRegistryKeyKJS.java +++ b/src/main/java/dev/latvian/mods/kubejs/core/RegistryObjectKJS.java @@ -2,13 +2,17 @@ import dev.latvian.mods.kubejs.registry.RegistryInfo; import dev.latvian.mods.kubejs.util.Cast; +import dev.latvian.mods.rhino.Context; import dev.latvian.mods.rhino.util.RemapPrefixForJS; import net.minecraft.core.Holder; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; + +import java.util.Collection; @RemapPrefixForJS("kjs$") -public interface WithRegistryKeyKJS { +public interface RegistryObjectKJS { default RegistryInfo kjs$getKubeRegistry() { throw new NoMixinException(); } @@ -37,4 +41,12 @@ public interface WithRegistryKeyKJS { default String kjs$getMod() { return kjs$getIdLocation().getNamespace(); } + + default Collection kjs$getTags(Context cx) { + return kjs$asHolder().tags().map(TagKey::location).toList(); + } + + default boolean kjs$hasTag(ResourceLocation tag) { + return kjs$asHolder().is(TagKey.create(kjs$getKubeRegistry().key, tag)); + } } diff --git a/src/main/java/dev/latvian/mods/kubejs/core/mixin/EntityTypeMixin.java b/src/main/java/dev/latvian/mods/kubejs/core/mixin/EntityTypeMixin.java index c3496dcff..51d10256f 100644 --- a/src/main/java/dev/latvian/mods/kubejs/core/mixin/EntityTypeMixin.java +++ b/src/main/java/dev/latvian/mods/kubejs/core/mixin/EntityTypeMixin.java @@ -1,9 +1,46 @@ package dev.latvian.mods.kubejs.core.mixin; import dev.latvian.mods.kubejs.core.EntityTypeKJS; +import net.minecraft.core.Holder; +import net.minecraft.resources.ResourceKey; import net.minecraft.world.entity.EntityType; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; @Mixin(EntityType.class) public abstract class EntityTypeMixin implements EntityTypeKJS { + @Shadow + @Final + private Holder.Reference> builtInRegistryHolder; + + @Unique + private ResourceKey> kjs$registryKey; + + @Unique + private String kjs$id; + + @Override + public Holder> kjs$asHolder() { + return builtInRegistryHolder; + } + + @Override + public ResourceKey> kjs$getRegistryKey() { + if (kjs$registryKey == null) { + kjs$registryKey = EntityTypeKJS.super.kjs$getRegistryKey(); + } + + return kjs$registryKey; + } + + @Override + public String kjs$getId() { + if (kjs$id == null) { + kjs$id = EntityTypeKJS.super.kjs$getId(); + } + + return kjs$id; + } } diff --git a/src/main/java/dev/latvian/mods/kubejs/core/mixin/EventHandlerBridgeMixin.java b/src/main/java/dev/latvian/mods/kubejs/core/mixin/EventHandlerBridgeMixin.java deleted file mode 100644 index 9c0fe6527..000000000 --- a/src/main/java/dev/latvian/mods/kubejs/core/mixin/EventHandlerBridgeMixin.java +++ /dev/null @@ -1,25 +0,0 @@ -package dev.latvian.mods.kubejs.core.mixin; - -import dev.latvian.mods.kubejs.event.EventHandler; -import dev.latvian.mods.kubejs.event.KubeEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; - -@SuppressWarnings("ReferenceToMixin") -@Mixin(value = EventHandler.class, remap = false) -public abstract class EventHandlerBridgeMixin { - @Unique - public EventHandler cancelable() { - return ((EventHandlerInvoker) this).callHasResult(); - } - - @Unique - public boolean post(Object extraId, KubeEvent event) { - return ((EventHandlerInvoker) this).callPost(event, extraId).interruptFalse(); - } - - @Unique - public boolean post(KubeEvent event) { - return ((EventHandlerInvoker) this).callPost(event, null).interruptFalse(); - } -} diff --git a/src/main/java/dev/latvian/mods/kubejs/core/mixin/EventHandlerInvoker.java b/src/main/java/dev/latvian/mods/kubejs/core/mixin/EventHandlerInvoker.java deleted file mode 100644 index 58e1ca930..000000000 --- a/src/main/java/dev/latvian/mods/kubejs/core/mixin/EventHandlerInvoker.java +++ /dev/null @@ -1,18 +0,0 @@ -package dev.latvian.mods.kubejs.core.mixin; - -import dev.latvian.mods.kubejs.event.EventHandler; -import dev.latvian.mods.kubejs.event.EventResult; -import dev.latvian.mods.kubejs.event.KubeEvent; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Invoker; - -@Mixin(value = EventHandler.class, remap = false) -public interface EventHandlerInvoker { - - @Invoker(remap = false) - EventHandler callHasResult(); - - @Invoker(remap = false) - EventResult callPost(KubeEvent event, @Nullable Object extraId); -} diff --git a/src/main/java/dev/latvian/mods/kubejs/core/mixin/MenuTypeMixin.java b/src/main/java/dev/latvian/mods/kubejs/core/mixin/MenuTypeMixin.java index 55fa1de73..2b89af8bd 100644 --- a/src/main/java/dev/latvian/mods/kubejs/core/mixin/MenuTypeMixin.java +++ b/src/main/java/dev/latvian/mods/kubejs/core/mixin/MenuTypeMixin.java @@ -1,9 +1,34 @@ package dev.latvian.mods.kubejs.core.mixin; import dev.latvian.mods.kubejs.core.MenuTypeKJS; +import net.minecraft.resources.ResourceKey; import net.minecraft.world.inventory.MenuType; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; @Mixin(MenuType.class) public abstract class MenuTypeMixin implements MenuTypeKJS { + @Unique + private ResourceKey> kjs$registryKey; + + @Unique + private String kjs$id; + + @Override + public ResourceKey> kjs$getRegistryKey() { + if (kjs$registryKey == null) { + kjs$registryKey = MenuTypeKJS.super.kjs$getRegistryKey(); + } + + return kjs$registryKey; + } + + @Override + public String kjs$getId() { + if (kjs$id == null) { + kjs$id = MenuTypeKJS.super.kjs$getId(); + } + + return kjs$id; + } } diff --git a/src/main/java/dev/latvian/mods/kubejs/core/mixin/MinecraftClientMixin.java b/src/main/java/dev/latvian/mods/kubejs/core/mixin/MinecraftClientMixin.java index 899190fc6..8ba1f2db7 100644 --- a/src/main/java/dev/latvian/mods/kubejs/core/mixin/MinecraftClientMixin.java +++ b/src/main/java/dev/latvian/mods/kubejs/core/mixin/MinecraftClientMixin.java @@ -11,19 +11,26 @@ import dev.latvian.mods.kubejs.util.ScheduledEvents; import dev.latvian.mods.rhino.util.RemapPrefixForJS; import net.minecraft.client.Minecraft; +import net.minecraft.client.player.LocalPlayer; import net.minecraft.server.packs.PackResources; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import javax.annotation.Nullable; import java.util.List; import java.util.concurrent.CompletableFuture; @Mixin(Minecraft.class) @RemapPrefixForJS("kjs$") public abstract class MinecraftClientMixin implements MinecraftClientKJS { + @Shadow + @Nullable + public LocalPlayer player; + @Inject(method = "", at = @At("RETURN")) private void kjs$init(CallbackInfo ci) { CompletableFuture.runAsync(() -> kjs$afterResourcesLoaded(false), kjs$self()); @@ -63,7 +70,7 @@ public abstract class MinecraftClientMixin implements MinecraftClientKJS { if (ClientEvents.TICK.hasListeners()) { try { - ClientEvents.TICK.post(ScriptType.CLIENT, new ClientKubeEvent()); + ClientEvents.TICK.post(ScriptType.CLIENT, new ClientKubeEvent(player)); } catch (IllegalStateException ignored) { // FIXME: Replace with rhino exception when it gets updated } diff --git a/src/main/java/dev/latvian/mods/kubejs/core/mixin/ReloadableServerResourcesMixin.java b/src/main/java/dev/latvian/mods/kubejs/core/mixin/ReloadableServerResourcesMixin.java index 417b9fd70..6725ab0f8 100644 --- a/src/main/java/dev/latvian/mods/kubejs/core/mixin/ReloadableServerResourcesMixin.java +++ b/src/main/java/dev/latvian/mods/kubejs/core/mixin/ReloadableServerResourcesMixin.java @@ -5,6 +5,7 @@ import dev.latvian.mods.kubejs.core.TagManagerKJS; import dev.latvian.mods.kubejs.item.ingredient.TagContext; import dev.latvian.mods.kubejs.server.ServerScriptManager; +import dev.latvian.mods.kubejs.util.UtilsJS; import net.minecraft.commands.Commands; import net.minecraft.core.RegistryAccess; import net.minecraft.server.ReloadableServerResources; @@ -34,6 +35,7 @@ public abstract class ReloadableServerResourcesMixin implements ReloadableServer @Inject(method = "", at = @At("RETURN")) private void init(RegistryAccess.Frozen registryAccess, FeatureFlagSet featureFlagSet, Commands.CommandSelection commandSelection, int functionCompilationLevel, CallbackInfo ci) { + UtilsJS.staticRegistries = registryAccess; kjs$serverScriptManager = new ServerScriptManager((ReloadableServerResources) (Object) this, registryAccess); ((TagManagerKJS) tagManager).kjs$setResources(this); ((RecipeManagerKJS) recipes).kjs$setResources(this); diff --git a/src/main/java/dev/latvian/mods/kubejs/event/Extra.java b/src/main/java/dev/latvian/mods/kubejs/event/Extra.java index fd2c5576e..5f0546cb2 100644 --- a/src/main/java/dev/latvian/mods/kubejs/event/Extra.java +++ b/src/main/java/dev/latvian/mods/kubejs/event/Extra.java @@ -1,6 +1,6 @@ package dev.latvian.mods.kubejs.event; -import dev.latvian.mods.kubejs.core.WithRegistryKeyKJS; +import dev.latvian.mods.kubejs.core.RegistryObjectKJS; import dev.latvian.mods.kubejs.util.Cast; import dev.latvian.mods.kubejs.util.UtilsJS; import dev.latvian.mods.rhino.type.TypeInfo; @@ -57,7 +57,7 @@ private static ResourceKey toKey(ResourceKey registry, Object object) { return null; } else if (object instanceof ResourceKey rl) { return rl; - } else if (object instanceof WithRegistryKeyKJS wrk) { + } else if (object instanceof RegistryObjectKJS wrk) { return wrk.kjs$getRegistryKey(); } else if (object instanceof ResourceLocation rl) { return ResourceKey.create(registry, rl); diff --git a/src/main/java/dev/latvian/mods/kubejs/fluid/FluidBuilder.java b/src/main/java/dev/latvian/mods/kubejs/fluid/FluidBuilder.java index 79817ed00..7028010c6 100644 --- a/src/main/java/dev/latvian/mods/kubejs/fluid/FluidBuilder.java +++ b/src/main/java/dev/latvian/mods/kubejs/fluid/FluidBuilder.java @@ -5,6 +5,7 @@ import dev.architectury.core.fluid.SimpleArchitecturyFluidAttributes; import dev.latvian.mods.kubejs.KubeJS; import dev.latvian.mods.kubejs.color.Color; +import dev.latvian.mods.kubejs.registry.AdditionalObjectRegistry; import dev.latvian.mods.kubejs.registry.BuilderBase; import dev.latvian.mods.kubejs.registry.RegistryInfo; import dev.latvian.mods.kubejs.util.Cast; @@ -89,15 +90,15 @@ public ArchitecturyFluidAttributes createAttributes() { } @Override - public void createAdditionalObjects() { - RegistryInfo.FLUID.addBuilder(flowingFluid); + public void createAdditionalObjects(AdditionalObjectRegistry registry) { + registry.add(RegistryInfo.FLUID, flowingFluid); if (block != null) { - RegistryInfo.BLOCK.addBuilder(block); + registry.add(RegistryInfo.BLOCK, block); } if (bucketItem != null) { - RegistryInfo.ITEM.addBuilder(bucketItem); + registry.add(RegistryInfo.ITEM, bucketItem); } } diff --git a/src/main/java/dev/latvian/mods/kubejs/neoforge/KubeJSNeoForgeClient.java b/src/main/java/dev/latvian/mods/kubejs/neoforge/KubeJSNeoForgeClient.java index 4985e38fa..dc05e9ac3 100644 --- a/src/main/java/dev/latvian/mods/kubejs/neoforge/KubeJSNeoForgeClient.java +++ b/src/main/java/dev/latvian/mods/kubejs/neoforge/KubeJSNeoForgeClient.java @@ -1,34 +1,55 @@ package dev.latvian.mods.kubejs.neoforge; import dev.latvian.mods.kubejs.KubeJS; +import dev.latvian.mods.kubejs.bindings.event.ClientEvents; +import dev.latvian.mods.kubejs.bindings.event.ItemEvents; import dev.latvian.mods.kubejs.block.BlockBuilder; +import dev.latvian.mods.kubejs.client.AtlasSpriteRegistryKubeEvent; import dev.latvian.mods.kubejs.client.BlockTintFunctionWrapper; +import dev.latvian.mods.kubejs.client.ClientInitKubeEvent; import dev.latvian.mods.kubejs.client.ItemTintFunctionWrapper; -import dev.latvian.mods.kubejs.client.KubeJSClientEventHandler; import dev.latvian.mods.kubejs.fluid.FluidBucketItemBuilder; import dev.latvian.mods.kubejs.fluid.FluidBuilder; +import dev.latvian.mods.kubejs.gui.KubeJSMenus; +import dev.latvian.mods.kubejs.gui.KubeJSScreen; import dev.latvian.mods.kubejs.item.ItemBuilder; +import dev.latvian.mods.kubejs.item.ItemModelPropertiesKubeEvent; import dev.latvian.mods.kubejs.registry.RegistryInfo; +import dev.latvian.mods.kubejs.script.ScriptType; import net.minecraft.client.renderer.ItemBlockRenderTypes; import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.texture.TextureAtlas; +import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.EventPriority; -import net.neoforged.bus.api.IEventBus; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent; -import net.neoforged.neoforge.client.event.ScreenEvent; -import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent; +@EventBusSubscriber(modid = KubeJS.MOD_ID, value = Dist.CLIENT, bus = EventBusSubscriber.Bus.MOD) public class KubeJSNeoForgeClient { - public KubeJSNeoForgeClient(IEventBus bus) { - bus.addListener(EventPriority.LOW, this::setupClient); - bus.addListener(this::blockColors); - bus.addListener(this::itemColors); - //bus.addListener(this::textureStitch); - NeoForge.EVENT_BUS.addListener(EventPriority.LOW, this::openScreenEvent); + @SubscribeEvent(priority = EventPriority.LOW) + public static void setupClient(FMLClientSetupEvent event) { + event.enqueueWork(KubeJSNeoForgeClient::setupClient0); } - private void setupClient(FMLClientSetupEvent event) { - KubeJS.PROXY.clientSetup(); + private static void setupClient0() { + ClientEvents.INIT.post(ScriptType.STARTUP, new ClientInitKubeEvent()); + ItemEvents.MODEL_PROPERTIES.post(ScriptType.STARTUP, new ItemModelPropertiesKubeEvent()); + + ClientEvents.ATLAS_SPRITE_REGISTRY.listenJava(ScriptType.CLIENT, TextureAtlas.LOCATION_BLOCKS, event -> { + var e = (AtlasSpriteRegistryKubeEvent) event; + + for (var builder : RegistryInfo.FLUID) { + if (builder instanceof FluidBuilder b) { + e.register(b.stillTexture); + e.register(b.flowingTexture); + } + } + + return null; + }); for (var builder : RegistryInfo.BLOCK) { if (builder instanceof BlockBuilder b) { @@ -60,7 +81,8 @@ private void setupClient(FMLClientSetupEvent event) { } } - private void blockColors(RegisterColorHandlersEvent.Block event) { + @SubscribeEvent + public static void blockColors(RegisterColorHandlersEvent.Block event) { for (var builder : RegistryInfo.BLOCK) { if (builder instanceof BlockBuilder b && b.tint != null) { event.register(new BlockTintFunctionWrapper(b.tint), b.get()); @@ -68,7 +90,8 @@ private void blockColors(RegisterColorHandlersEvent.Block event) { } } - private void itemColors(RegisterColorHandlersEvent.Item event) { + @SubscribeEvent + public static void itemColors(RegisterColorHandlersEvent.Item event) { for (var builder : RegistryInfo.ITEM) { if (builder instanceof ItemBuilder b && b.tint != null) { event.register(new ItemTintFunctionWrapper(b.tint), b.get()); @@ -80,16 +103,8 @@ private void itemColors(RegisterColorHandlersEvent.Item event) { } } - // FIXME: implement - /*private void textureStitch(TextureStitchEvent.Pre event) { - ClientEvents.ATLAS_SPRITE_REGISTRY.post(new AtlasSpriteRegistryEventJS(event::addSprite), event.getAtlas().location()); - }*/ - - private void openScreenEvent(ScreenEvent.Opening event) { - var s = KubeJSClientEventHandler.setScreen(event.getScreen()); - - if (s != null && event.getScreen() != s) { - event.setNewScreen(s); - } + @SubscribeEvent + public static void registerMenuScreens(RegisterMenuScreensEvent event) { + event.register(KubeJSMenus.MENU.get(), KubeJSScreen::new); } } diff --git a/src/main/java/dev/latvian/mods/kubejs/net/KubeJSNet.java b/src/main/java/dev/latvian/mods/kubejs/net/KubeJSNet.java index 8d3f6c664..b3d2e47c2 100644 --- a/src/main/java/dev/latvian/mods/kubejs/net/KubeJSNet.java +++ b/src/main/java/dev/latvian/mods/kubejs/net/KubeJSNet.java @@ -2,8 +2,11 @@ import dev.latvian.mods.kubejs.KubeJS; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; +@EventBusSubscriber(modid = KubeJS.MOD_ID, bus = EventBusSubscriber.Bus.MOD) public interface KubeJSNet { private static CustomPacketPayload.Type type(String id) { return new CustomPacketPayload.Type<>(KubeJS.id(id)); @@ -21,6 +24,7 @@ private static CustomPacketPayload.Type type( CustomPacketPayload.Type DISPLAY_SERVER_ERRORS = type("display_server_errors"); CustomPacketPayload.Type DISPLAY_CLIENT_ERRORS = type("display_client_errors"); + @SubscribeEvent static void register(RegisterPayloadHandlersEvent event) { var reg = event.registrar("1"); diff --git a/src/main/java/dev/latvian/mods/kubejs/player/KubeJSPlayerEventHandler.java b/src/main/java/dev/latvian/mods/kubejs/player/KubeJSPlayerEventHandler.java index 6d232c194..f885a1c68 100644 --- a/src/main/java/dev/latvian/mods/kubejs/player/KubeJSPlayerEventHandler.java +++ b/src/main/java/dev/latvian/mods/kubejs/player/KubeJSPlayerEventHandler.java @@ -6,9 +6,11 @@ import dev.latvian.mods.kubejs.core.MenuTypeKJS; import dev.latvian.mods.kubejs.script.ScriptType; import dev.latvian.mods.kubejs.util.ConsoleJS; +import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.inventory.ChestMenu; import net.minecraft.world.inventory.InventoryMenu; +import net.minecraft.world.inventory.MenuType; import net.neoforged.bus.api.EventPriority; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.EventBusSubscriber; @@ -97,7 +99,13 @@ public static void inventoryOpened(PlayerContainerEvent.Open event) { menu.addSlotListener(player.kjs$getInventoryChangeListener()); } - var key = ((MenuTypeKJS) menu.getType()).kjs$getRegistryKey(); + ResourceKey> key; + + try { + key = ((MenuTypeKJS) menu.getType()).kjs$getRegistryKey(); + } catch (Exception ex) { + return; + } if (key != null) { if (PlayerEvents.INVENTORY_OPENED.hasListeners(key)) { @@ -115,7 +123,14 @@ public static void inventoryOpened(PlayerContainerEvent.Open event) { public static void inventoryClosed(PlayerContainerEvent.Close event) { if (event.getEntity() instanceof ServerPlayer player) { var menu = event.getContainer(); - var key = ((MenuTypeKJS) menu.getType()).kjs$getRegistryKey(); + + ResourceKey> key; + + try { + key = ((MenuTypeKJS) menu.getType()).kjs$getRegistryKey(); + } catch (Exception ex) { + return; + } if (key != null) { if (PlayerEvents.INVENTORY_CLOSED.hasListeners(key)) { diff --git a/src/main/java/dev/latvian/mods/kubejs/recipe/component/RecipeComponent.java b/src/main/java/dev/latvian/mods/kubejs/recipe/component/RecipeComponent.java index b145040c0..7ec206473 100644 --- a/src/main/java/dev/latvian/mods/kubejs/recipe/component/RecipeComponent.java +++ b/src/main/java/dev/latvian/mods/kubejs/recipe/component/RecipeComponent.java @@ -68,7 +68,7 @@ default RecipeKey key(String name) { * Defines the {@link ComponentRole role} of this component. *

* This is used during input / output replacement to determine which components are eligible for replacement, - * as well as populating the {@link KubeRecipe#inputValues} and {@link KubeRecipe#outputValues} arrays. + * as well as populating the {@link KubeRecipe#inputValues()} and {@link KubeRecipe#outputValues()} arrays. * * @return The role of this component */ diff --git a/src/main/java/dev/latvian/mods/kubejs/recipe/component/RegistryComponent.java b/src/main/java/dev/latvian/mods/kubejs/recipe/component/RegistryComponent.java index d1959c2ec..5d758460e 100644 --- a/src/main/java/dev/latvian/mods/kubejs/recipe/component/RegistryComponent.java +++ b/src/main/java/dev/latvian/mods/kubejs/recipe/component/RegistryComponent.java @@ -5,28 +5,29 @@ import dev.latvian.mods.kubejs.recipe.KubeRecipe; import dev.latvian.mods.kubejs.recipe.schema.DynamicRecipeComponent; import dev.latvian.mods.kubejs.registry.RegistryInfo; +import dev.latvian.mods.kubejs.registry.RegistryType; import dev.latvian.mods.kubejs.typings.desc.DescriptionContext; import dev.latvian.mods.kubejs.typings.desc.TypeDescJS; import dev.latvian.mods.kubejs.util.ID; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.fluids.FluidStack; -public record RegistryComponent(RegistryInfo registry) implements RecipeComponent { - @SuppressWarnings("unchecked") +public record RegistryComponent(ResourceKey> registryKey) implements RecipeComponent { + @SuppressWarnings({"unchecked", "rawtypes", "DataFlowIssue"}) public static final DynamicRecipeComponent DYNAMIC = new DynamicRecipeComponent(TypeDescJS.object(1).add("registry", TypeDescJS.STRING.or(DescriptionContext.DEFAULT.javaType(RegistryInfo.class))), (ctx, scope, args) -> { - Object registry = args.get("registry"); - RegistryInfo regInfo; - if (registry instanceof RegistryInfo registryInfo) { - regInfo = registryInfo; - } else if (registry instanceof ResourceKey resourceKey) { - regInfo = RegistryInfo.of((ResourceKey) resourceKey); - } else { - regInfo = RegistryInfo.of(ResourceKey.createRegistryKey(new ResourceLocation(String.valueOf(registry)))); - } + Object from = args.get("registry"); - return new RegistryComponent<>(regInfo); + return new RegistryComponent<>((ResourceKey) switch (from) { + case RegistryType registryType -> registryType.key(); + case RegistryInfo registryInfo -> registryInfo.key; + case ResourceKey resourceKey -> resourceKey; + case Registry registry -> registry.key(); + case null, default -> ResourceKey.createRegistryKey(ID.mc(from)); + }); }); @Override @@ -36,48 +37,54 @@ public String componentType() { @Override public TypeDescJS constructorDescription(DescriptionContext ctx) { - return TypeDescJS.STRING.or(ctx.javaType(registry.objectBaseClass)); + var t = RegistryType.ofKey(registryKey); + return t == null ? TypeDescJS.STRING : TypeDescJS.STRING.or(ctx.javaType(t.baseClass())); } @Override public Class componentClass() { - return registry.objectBaseClass; + return Registry.class; } @Override public JsonElement write(KubeRecipe recipe, T value) { - return new JsonPrimitive(registry.getId(value).toString()); + var reg = RegistryInfo.of(registryKey); + return new JsonPrimitive(reg.getId(value).toString()); } @SuppressWarnings("unchecked") @Override public T read(KubeRecipe recipe, Object from) { - if (registry.objectBaseClass != Object.class && registry.objectBaseClass.isInstance(from)) { + var key = (ResourceKey) registryKey; + var regType = RegistryType.ofKey(key); + + if (regType != null && regType.baseClass().isInstance(from)) { return (T) from; } else if (!(from instanceof CharSequence) && !(from instanceof JsonPrimitive) && !(from instanceof ResourceLocation)) { - if (registry == RegistryInfo.ITEM) { + if (key == Registries.ITEM) { if (from instanceof ItemStack is) { return (T) is.getItem(); } else { return (T) recipe.readOutputItem(from).item.getItem(); } - } else if (registry == RegistryInfo.FLUID) { + } else if (key == Registries.FLUID) { if (from instanceof FluidStack fs) { return (T) fs.getFluid(); } } } - return registry.getValue(ID.mc(from)); + return RegistryInfo.of(registryKey).getValue(ID.mc(from)); } @Override public boolean hasPriority(KubeRecipe recipe, Object from) { - return (registry.objectBaseClass != Object.class && registry.objectBaseClass.isInstance(from)) || (from instanceof CharSequence && ID.mc(from.toString()) != null) || (from instanceof JsonPrimitive json && json.isString() && ID.mc(json.getAsString()) != null); + var regType = RegistryType.ofKey(registryKey); + return (regType != null && regType.baseClass().isInstance(from)) || (from instanceof CharSequence && ID.mc(from.toString()) != null) || (from instanceof JsonPrimitive json && json.isString() && ID.mc(json.getAsString()) != null); } @Override public String toString() { - return "%s{%s}".formatted(componentType(), registry); + return "%s{%s}".formatted(componentType(), registryKey.location()); } } diff --git a/src/main/java/dev/latvian/mods/kubejs/recipe/component/TimeComponent.java b/src/main/java/dev/latvian/mods/kubejs/recipe/component/TimeComponent.java index d08e57ce7..f5f8d4449 100644 --- a/src/main/java/dev/latvian/mods/kubejs/recipe/component/TimeComponent.java +++ b/src/main/java/dev/latvian/mods/kubejs/recipe/component/TimeComponent.java @@ -15,14 +15,12 @@ public record TimeComponent(String name, long scale) implements RecipeComponent< public static final TimeComponent SECONDS = new TimeComponent("seconds", 20L); public static final TimeComponent MINUTES = new TimeComponent("minutes", 1200L); - public static final DynamicRecipeComponent DYNAMIC = new DynamicRecipeComponent(TypeDescJS.object() - .add("name", TypeDescJS.STRING, true) - .add("scale", TypeDescJS.NUMBER), - (cx, scope, args) -> { - var name = String.valueOf(Wrapper.unwrapped(args.getOrDefault("name", "unnamed"))); - var scale = (long) ScriptRuntime.toNumber(cx, Wrapper.unwrapped(args.getOrDefault("scale", 1L))); - return new TimeComponent(name, scale); - }); + // public static final DynamicRecipeComponent DYNAMIC = new DynamicRecipeComponent(JSObjectTypeInfo.of("name", TypeInfo.STRING, "scale", TypeInfo.NUMBER), (cx, scope, args) -> { + public static final DynamicRecipeComponent DYNAMIC = new DynamicRecipeComponent(TypeDescJS.object().add("name", TypeDescJS.STRING, true).add("scale", TypeDescJS.NUMBER), (cx, scope, args) -> { + var name = String.valueOf(Wrapper.unwrapped(args.getOrDefault("name", "unnamed"))); + var scale = (long) ScriptRuntime.toNumber(cx, Wrapper.unwrapped(args.getOrDefault("scale", 1L))); + return new TimeComponent(name, scale); + }); @Override public String componentType() { diff --git a/src/main/java/dev/latvian/mods/kubejs/registry/AdditionalObjectRegistry.java b/src/main/java/dev/latvian/mods/kubejs/registry/AdditionalObjectRegistry.java new file mode 100644 index 000000000..2cee453aa --- /dev/null +++ b/src/main/java/dev/latvian/mods/kubejs/registry/AdditionalObjectRegistry.java @@ -0,0 +1,13 @@ +package dev.latvian.mods.kubejs.registry; + +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceKey; + +@FunctionalInterface +public interface AdditionalObjectRegistry { + void add(ResourceKey> registry, BuilderBase builder); + + default void add(RegistryInfo registryInfo, BuilderBase builder) { + add(registryInfo.key, builder); + } +} diff --git a/src/main/java/dev/latvian/mods/kubejs/registry/BuilderBase.java b/src/main/java/dev/latvian/mods/kubejs/registry/BuilderBase.java index fc072855b..92935cbd5 100644 --- a/src/main/java/dev/latvian/mods/kubejs/registry/BuilderBase.java +++ b/src/main/java/dev/latvian/mods/kubejs/registry/BuilderBase.java @@ -53,7 +53,7 @@ public final T get() { } } - public void createAdditionalObjects() { + public void createAdditionalObjects(AdditionalObjectRegistry registry) { } public String getTranslationKeyGroup() { diff --git a/src/main/java/dev/latvian/mods/kubejs/registry/BuilderTypeRegistry.java b/src/main/java/dev/latvian/mods/kubejs/registry/BuilderTypeRegistry.java new file mode 100644 index 000000000..c08eb5582 --- /dev/null +++ b/src/main/java/dev/latvian/mods/kubejs/registry/BuilderTypeRegistry.java @@ -0,0 +1,21 @@ +package dev.latvian.mods.kubejs.registry; + +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceKey; + +import java.util.function.Consumer; + +@FunctionalInterface +public interface BuilderTypeRegistry { + interface Callback { + void addDefault(Class> builderType, BuilderFactory factory); + + void add(String type, Class> builderType, BuilderFactory factory); + } + + void of(ResourceKey> registry, Consumer> callback); + + default void addDefault(ResourceKey> registry, Class> builderType, BuilderFactory factory) { + of(registry, reg -> reg.addDefault(builderType, factory)); + } +} diff --git a/src/main/java/dev/latvian/mods/kubejs/registry/BuilderTypeRegistryHandler.java b/src/main/java/dev/latvian/mods/kubejs/registry/BuilderTypeRegistryHandler.java new file mode 100644 index 000000000..c4eaad612 --- /dev/null +++ b/src/main/java/dev/latvian/mods/kubejs/registry/BuilderTypeRegistryHandler.java @@ -0,0 +1,41 @@ +package dev.latvian.mods.kubejs.registry; + +import dev.latvian.mods.kubejs.util.ConsoleJS; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceKey; + +import java.util.LinkedHashMap; +import java.util.function.Consumer; + +public class BuilderTypeRegistryHandler implements BuilderTypeRegistry { + @Override + public void of(ResourceKey> registry, Consumer> callback) { + callback.accept(new RegConsumer<>(RegistryInfo.of(registry))); + } + + private record RegConsumer(RegistryInfo registryInfo) implements BuilderTypeRegistry.Callback { + @Override + public void addDefault(Class> builderType, BuilderFactory factory) { + if (registryInfo.defaultType != null) { + ConsoleJS.STARTUP.warn("Previous default type '" + registryInfo.defaultType.builderClass().getName() + "' for registry '" + registryInfo + "' replaced with '" + builderType.getName() + "'!"); + } + + registryInfo.defaultType = new BuilderType<>("default", builderType, factory); + } + + @Override + public void add(String type, Class> builderType, BuilderFactory factory) { + if (registryInfo.types == null) { + registryInfo.types = new LinkedHashMap<>(); + } + + var prev = registryInfo.types.get(type); + + if (prev != null) { + ConsoleJS.STARTUP.warn("Previous '" + type + "' type '" + prev.builderClass().getName() + "' for registry '" + registryInfo + "' replaced with '" + builderType.getName() + "'!"); + } + + registryInfo.types.put(type, new BuilderType<>(type, builderType, factory)); + } + } +} diff --git a/src/main/java/dev/latvian/mods/kubejs/registry/RegistryEventHandler.java b/src/main/java/dev/latvian/mods/kubejs/registry/RegistryEventHandler.java new file mode 100644 index 000000000..ef8471690 --- /dev/null +++ b/src/main/java/dev/latvian/mods/kubejs/registry/RegistryEventHandler.java @@ -0,0 +1,60 @@ +package dev.latvian.mods.kubejs.registry; + +import dev.latvian.mods.kubejs.CommonProperties; +import dev.latvian.mods.kubejs.DevProperties; +import dev.latvian.mods.kubejs.KubeJS; +import dev.latvian.mods.kubejs.util.ConsoleJS; +import net.minecraft.resources.ResourceKey; +import net.neoforged.bus.api.EventPriority; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.registries.RegisterEvent; + +@EventBusSubscriber(modid = KubeJS.MOD_ID, bus = EventBusSubscriber.Bus.MOD) +public class RegistryEventHandler { + @SuppressWarnings({"rawtypes", "unchecked"}) + @SubscribeEvent(priority = EventPriority.LOW) + public static void registerAll(RegisterEvent event) { + handleRegistryEvent(RegistryInfo.of((ResourceKey) event.getRegistryKey()), event); + } + + private static void handleRegistryEvent(RegistryInfo registryInfo, RegisterEvent event) { + if (!registryInfo.bypassServerOnly && CommonProperties.get().serverOnly) { + if (DevProperties.get().debugInfo) { + KubeJS.LOGGER.info("Skipping " + registryInfo + " registry - server only"); + } + + return; + } + + if (registryInfo.objects.isEmpty()) { + if (DevProperties.get().debugInfo) { + KubeJS.LOGGER.info("Skipping " + registryInfo + " registry - no objects to build"); + } + + return; + } + + if (DevProperties.get().debugInfo) { + KubeJS.LOGGER.info("Building " + registryInfo.objects.size() + " objects of " + registryInfo + " registry"); + } + + int added = 0; + + for (var builder : registryInfo) { + if (!builder.dummyBuilder) { + event.register(registryInfo.key, builder.id, builder::createTransformedObject); + + if (DevProperties.get().debugInfo) { + ConsoleJS.STARTUP.info("+ " + registryInfo + " | " + builder.id); + } + + added++; + } + } + + if (!registryInfo.objects.isEmpty() && DevProperties.get().debugInfo) { + KubeJS.LOGGER.info("Registered " + added + "/" + registryInfo.objects.size() + " objects of " + registryInfo); + } + } +} diff --git a/src/main/java/dev/latvian/mods/kubejs/registry/RegistryInfo.java b/src/main/java/dev/latvian/mods/kubejs/registry/RegistryInfo.java index fa4a1f685..a193c98d1 100644 --- a/src/main/java/dev/latvian/mods/kubejs/registry/RegistryInfo.java +++ b/src/main/java/dev/latvian/mods/kubejs/registry/RegistryInfo.java @@ -1,16 +1,7 @@ package dev.latvian.mods.kubejs.registry; -import com.mojang.serialization.Codec; -import dev.latvian.mods.kubejs.CommonProperties; -import dev.latvian.mods.kubejs.DevProperties; -import dev.latvian.mods.kubejs.KubeJS; -import dev.latvian.mods.kubejs.bindings.event.StartupEvents; import dev.latvian.mods.kubejs.util.Cast; -import dev.latvian.mods.kubejs.util.ConsoleJS; import dev.latvian.mods.kubejs.util.ID; -import dev.latvian.mods.rhino.Context; -import dev.latvian.mods.rhino.type.TypeInfo; -import dev.latvian.mods.rhino.util.wrap.TypeWrapperFactory; import net.minecraft.commands.synchronization.ArgumentTypeInfo; import net.minecraft.core.Holder; import net.minecraft.core.Registry; @@ -37,80 +28,26 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.material.Fluid; +import net.neoforged.neoforge.registries.DeferredRegister; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.lang.ref.WeakReference; -import java.lang.reflect.ParameterizedType; -import java.util.ArrayList; import java.util.IdentityHashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Set; -public final class RegistryInfo implements Iterable>, TypeWrapperFactory { +public final class RegistryInfo implements Iterable> { private static final Object LOCK = new Object(); private static final Map>, RegistryInfo> MAP = new IdentityHashMap<>(); - private static final Map, List>> CLASS_MAP = new IdentityHashMap<>(); public static final List> ALL_BUILDERS = new LinkedList<>(); - @SuppressWarnings({"rawtypes", "unchecked"}) - public static RegistryInfo of(ResourceKey> key, Class type) { - synchronized (LOCK) { - var r = MAP.get(key); - - if (r == null) { - var reg = new RegistryInfo(key, type); - MAP.put(key, reg); - CLASS_MAP.computeIfAbsent(type, k -> new ArrayList<>(1)).add(reg); - return reg; - } - - return (RegistryInfo) r; - } - } - public static RegistryInfo of(ResourceKey> key) { synchronized (LOCK) { - return Cast.to(Objects.requireNonNull(MAP.get(key))); - } - } - - @Nullable - public static RegistryInfo ofClass(Class type) { - if (type == Object.class) { - return null; - } else if (type == Block.class) { - return BLOCK; - } else if (type == Item.class) { - return ITEM; - } else { - var list = CLASS_MAP.get(type); - return list == null || list.size() != 1 ? null : list.getFirst(); - } - } - - public static List> allOfClass(Class type) { - return CLASS_MAP.getOrDefault(type, List.of()); - } - - static { - // FIXME: Reflection cursedness - - try { - for (var field : Registries.class.getDeclaredFields()) { - if (field.getType() == ResourceKey.class && field.getGenericType() instanceof ParameterizedType t1 && t1.getActualTypeArguments()[0] instanceof ParameterizedType t2) { - var type = t2.getActualTypeArguments()[0]; - var typeInfo = TypeInfo.of(type); - KubeJS.LOGGER.info(typeInfo + ": " + field); - } - } - } catch (Exception ex) { - ex.printStackTrace(); + return Cast.to(MAP.computeIfAbsent(key, RegistryInfo::new)); } } @@ -120,7 +57,7 @@ public static List> allOfClass(Class type) { public static final RegistryInfo BLOCK = of(Registries.BLOCK); public static final RegistryInfo ENCHANTMENT = of(Registries.ENCHANTMENT); public static final RegistryInfo> ENTITY_TYPE = of(Registries.ENTITY_TYPE); - public static final RegistryInfo ITEM = of(Registries.ITEM).noAutoWrap(); + public static final RegistryInfo ITEM = of(Registries.ITEM); public static final RegistryInfo POTION = of(Registries.POTION); public static final RegistryInfo> PARTICLE_TYPE = of(Registries.PARTICLE_TYPE); public static final RegistryInfo> BLOCK_ENTITY_TYPE = of(Registries.BLOCK_ENTITY_TYPE); @@ -137,25 +74,21 @@ public static List> allOfClass(Class type) { public static final RegistryInfo CREATIVE_MODE_TAB = of(Registries.CREATIVE_MODE_TAB); public final ResourceKey> key; - public final Class objectBaseClass; - public final Map> types; + BuilderType defaultType; + Map> types; + DeferredRegister deferredRegister; public final Map> objects; public final ResourceKey unknownKey; public boolean hasDefaultTags = false; - private BuilderType defaultType; public boolean bypassServerOnly; - public boolean autoWrap; public String languageKeyPrefix; private WeakReference> vanillaRegistry; - private RegistryInfo(ResourceKey> key, Class objectBaseClass) { + private RegistryInfo(ResourceKey key) { this.key = key; - this.objectBaseClass = objectBaseClass; - this.types = new LinkedHashMap<>(); this.objects = new LinkedHashMap<>(); this.unknownKey = ResourceKey.create(key, ID.UNKNOWN); this.bypassServerOnly = false; - this.autoWrap = objectBaseClass != Codec.class && objectBaseClass != ResourceLocation.class && objectBaseClass != String.class; this.languageKeyPrefix = key.location().getPath().replace('/', '.'); } @@ -164,61 +97,11 @@ public RegistryInfo bypassServerOnly() { return this; } - public RegistryInfo noAutoWrap() { - this.autoWrap = false; - return this; - } - public RegistryInfo languageKeyPrefix(String prefix) { this.languageKeyPrefix = prefix; return this; } - public void addType(String type, Class> builderType, BuilderFactory factory, boolean isDefault) { - var b = new BuilderType<>(type, builderType, factory); - types.put(type, b); - - if (isDefault) { - if (defaultType != null) { - ConsoleJS.STARTUP.warn("Previous default type '" + defaultType.type() + "' for registry '" + key.location() + "' replaced with '" + type + "'!"); - } - - defaultType = b; - } - } - - public void addType(String type, Class> builderType, BuilderFactory factory) { - addType(type, builderType, factory, type.equals("basic")); - } - - public void addBuilder(BuilderBase builder) { - if (builder == null) { - throw new IllegalArgumentException("Can't add null builder in registry '" + key.location() + "'!"); - } - - if (DevProperties.get().debugInfo) { - ConsoleJS.STARTUP.info("~ " + key.location() + " | " + builder.id); - } - - if (objects.containsKey(builder.id)) { - throw new IllegalArgumentException("Duplicate key '" + builder.id + "' in registry '" + key.location() + "'!"); - } - - objects.put(builder.id, builder); - ALL_BUILDERS.add(builder); - } - - @Nullable - public BuilderType getDefaultType() { - if (types.isEmpty()) { - return null; - } else if (defaultType == null) { - defaultType = types.values().iterator().next(); - } - - return defaultType; - } - @Override public int hashCode() { return key.hashCode(); @@ -234,40 +117,6 @@ public String toString() { return key.location().toString(); } - public int registerObjects(RegistryCallback function) { - if (DevProperties.get().debugInfo) { - if (objects.isEmpty()) { - KubeJS.LOGGER.info("Skipping " + this + " registry"); - } else { - KubeJS.LOGGER.info("Building " + objects.size() + " objects of " + this + " registry"); - } - } - - if (objects.isEmpty()) { - return 0; - } - - int added = 0; - - for (var builder : this) { - if (!builder.dummyBuilder && (builder.getRegistryType().bypassServerOnly || !CommonProperties.get().serverOnly)) { - function.accept(builder.id, builder::createTransformedObject); - - if (DevProperties.get().debugInfo) { - ConsoleJS.STARTUP.info("+ " + this + " | " + builder.id); - } - - added++; - } - } - - if (!objects.isEmpty() && DevProperties.get().debugInfo) { - KubeJS.LOGGER.info("Registered " + added + "/" + objects.size() + " objects of " + this); - } - - return added; - } - @NotNull @Override public Iterator> iterator() { @@ -319,30 +168,4 @@ public boolean hasValue(ResourceLocation id) { public ResourceKey getKeyOf(T value) { return getVanillaRegistry().getResourceKey(value).orElse(unknownKey); } - - @Override - public T wrap(Context cx, Object o, TypeInfo target) { - if (o == null) { - return null; - } else if (objectBaseClass.isInstance(o)) { - return (T) o; - } - - var id = ID.mc(o); - var value = getValue(id); - - if (value == null) { - var npe = new NullPointerException("No such element with id %s in registry %s!".formatted(id, this)); - ConsoleJS.getCurrent(cx).error("Error while wrapping registry element type!", npe); - throw npe; - } - - return value; - } - - public void fireRegistryEvent() { - var event = new RegistryKubeEvent<>(this); - StartupEvents.REGISTRY.post(event, (ResourceKey) key); - event.created.forEach(BuilderBase::createAdditionalObjects); - } } diff --git a/src/main/java/dev/latvian/mods/kubejs/registry/RegistryKubeEvent.java b/src/main/java/dev/latvian/mods/kubejs/registry/RegistryKubeEvent.java index e4a7856c7..19b27b396 100644 --- a/src/main/java/dev/latvian/mods/kubejs/registry/RegistryKubeEvent.java +++ b/src/main/java/dev/latvian/mods/kubejs/registry/RegistryKubeEvent.java @@ -1,23 +1,28 @@ package dev.latvian.mods.kubejs.registry; +import dev.latvian.mods.kubejs.DevProperties; +import dev.latvian.mods.kubejs.event.EventResult; import dev.latvian.mods.kubejs.event.KubeStartupEvent; +import dev.latvian.mods.kubejs.util.ConsoleJS; import dev.latvian.mods.kubejs.util.ID; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceKey; import java.util.LinkedList; import java.util.List; import java.util.function.Supplier; -public class RegistryKubeEvent implements KubeStartupEvent { - private final RegistryInfo registry; +public class RegistryKubeEvent implements KubeStartupEvent, AdditionalObjectRegistry { + private final RegistryInfo registryInfo; public final List> created; - public RegistryKubeEvent(RegistryInfo r) { - this.registry = r; + public RegistryKubeEvent(ResourceKey> registryKey) { + this.registryInfo = RegistryInfo.of(registryKey); this.created = new LinkedList<>(); } public BuilderBase create(String id, String type) { - var t = registry.types.get(type); + var t = registryInfo.types == null ? null : registryInfo.types.get(type); if (t == null) { throw new IllegalArgumentException("Unknown type '" + type + "' for object '" + id + "'!"); @@ -28,7 +33,7 @@ public BuilderBase create(String id, String type) { if (b == null) { throw new IllegalArgumentException("Unknown type '" + type + "' for object '" + id + "'!"); } else { - registry.addBuilder(b); + addBuilder(registryInfo, b); created.add(b); } @@ -36,10 +41,10 @@ public BuilderBase create(String id, String type) { } public BuilderBase create(String id) { - var t = registry.getDefaultType(); + var t = registryInfo.defaultType; if (t == null) { - throw new IllegalArgumentException("Registry for type '" + registry.key.location() + "' doesn't have any builders registered!"); + throw new IllegalArgumentException("Registry '" + registryInfo.key.location() + "' doesn't have a default type registered!"); } var b = t.factory().createBuilder(ID.kjs(id)); @@ -47,7 +52,7 @@ public BuilderBase create(String id) { if (b == null) { throw new IllegalArgumentException("Unknown type '" + t.type() + "' for object '" + id + "'!"); } else { - registry.addBuilder(b); + addBuilder(registryInfo, b); created.add(b); } @@ -60,9 +65,45 @@ public CustomBuilderObject createCustom(String id, Supplier object) { } var rl = ID.kjs(id); - var b = new CustomBuilderObject(rl, object, registry); - registry.addBuilder(b); + var b = new CustomBuilderObject(rl, object, registryInfo); + addBuilder(registryInfo, b); created.add(b); return b; } + + @Override + public void afterPosted(EventResult result) { + for (var c : created) { + c.createAdditionalObjects(this); + } + } + + @Override + public void add(ResourceKey> registry, BuilderBase builder) { + addBuilder(RegistryInfo.of(registry), builder); + } + + @Override + public void add(RegistryInfo registry, BuilderBase builder) { + addBuilder(registry, builder); + } + + private void addBuilder(RegistryInfo registry, BuilderBase builder) { + if (builder == null) { + throw new IllegalArgumentException("Can't add null builder in registry '" + registry + "'!"); + } + + if (DevProperties.get().debugInfo) { + ConsoleJS.STARTUP.info("~ " + registry + " | " + builder.id); + } + + if (registry.objects.containsKey(builder.id)) { + throw new IllegalArgumentException("Duplicate key '" + builder.id + "' in registry '" + registry + "'!"); + } + + registry.objects.put(builder.id, builder); + RegistryInfo.ALL_BUILDERS.add(builder); + + // registry.deferredRegister.register() + } } \ No newline at end of file diff --git a/src/main/java/dev/latvian/mods/kubejs/registry/RegistryType.java b/src/main/java/dev/latvian/mods/kubejs/registry/RegistryType.java new file mode 100644 index 000000000..b6f1a3eb2 --- /dev/null +++ b/src/main/java/dev/latvian/mods/kubejs/registry/RegistryType.java @@ -0,0 +1,75 @@ +package dev.latvian.mods.kubejs.registry; + +import dev.latvian.mods.kubejs.KubeJS; +import dev.latvian.mods.rhino.type.TypeInfo; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceKey; +import net.neoforged.fml.loading.FMLLoader; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Modifier; +import java.lang.reflect.ParameterizedType; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; + +public record RegistryType(ResourceKey> key, Class baseClass, TypeInfo type) { + private static final Map, RegistryType> KEY_MAP = new IdentityHashMap<>(); + private static final Map> TYPE_MAP = new HashMap<>(); + private static final Map, List>> CLASS_MAP = new IdentityHashMap<>(); + + // This is cursed, but it's better than manually registering every type + public static synchronized void init() { + try { + for (var field : Registries.class.getDeclaredFields()) { + if (field.getType() == ResourceKey.class + && Modifier.isPublic(field.getModifiers()) + && Modifier.isStatic(field.getModifiers()) + && field.getGenericType() instanceof ParameterizedType t1 + && t1.getActualTypeArguments()[0] instanceof ParameterizedType t2 + ) { + var key = (ResourceKey) field.get(null); + var type = t2.getActualTypeArguments()[0]; + var typeInfo = TypeInfo.of(type); + register(key, typeInfo); + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public static synchronized void register(ResourceKey> key, TypeInfo type) { + var t = new RegistryType<>(key, type.asClass(), type); + KEY_MAP.put(key, t); + TYPE_MAP.put(type, t); + CLASS_MAP.computeIfAbsent(t.baseClass, c -> new ArrayList<>(1)).add(t); + + if (!FMLLoader.isProduction()) { + KubeJS.LOGGER.info("Registered RegistryType '" + key.location() + "': " + type); + } + } + + @Nullable + public static synchronized RegistryType ofKey(ResourceKey key) { + return KEY_MAP.get(key); + } + + @Nullable + public static synchronized RegistryType ofType(TypeInfo typeInfo) { + return TYPE_MAP.get(typeInfo); + } + + @Nullable + public static synchronized RegistryType ofClass(Class type) { + var list = CLASS_MAP.get(type); + return list != null && list.size() == 1 ? list.getFirst() : null; + } + + public static synchronized List> allOfClass(Class type) { + return CLASS_MAP.getOrDefault(type, List.of()); + } +} diff --git a/src/main/java/dev/latvian/mods/kubejs/script/KubeJSContext.java b/src/main/java/dev/latvian/mods/kubejs/script/KubeJSContext.java index 85272ad34..d04047fa6 100644 --- a/src/main/java/dev/latvian/mods/kubejs/script/KubeJSContext.java +++ b/src/main/java/dev/latvian/mods/kubejs/script/KubeJSContext.java @@ -2,6 +2,7 @@ import com.mojang.datafixers.util.Either; import dev.latvian.mods.kubejs.KubeJS; +import dev.latvian.mods.kubejs.registry.RegistryType; import dev.latvian.mods.kubejs.util.ConsoleJS; import dev.latvian.mods.kubejs.util.KubeJSPlugins; import dev.latvian.mods.rhino.Context; @@ -60,15 +61,88 @@ public DamageSources getDamageSources() { return kjsFactory.manager.getDamageSources(); } + /* + static Holder holderOf(Context cx, Object from, TypeInfo target) { + if (from == null) { + return null; + } else if (from instanceof Holder h) { + return h; + } else if (from instanceof RegistryObjectKJS w) { + return w.kjs$asHolder(); + } + + var reg = RegistryInfo.ofClass(target.param(0).asClass()); + + if (reg != null) { + return reg.getHolder(ID.mc(from)); + } + + return new Holder.Direct<>(from); + } + + static ResourceKey resourceKeyOf(Context cx, Object from, TypeInfo target) { + if (from == null) { + return null; + } else if (from instanceof ResourceKey k) { + return k; + } else if (from instanceof RegistryObjectKJS w) { + return w.kjs$getRegistryKey(); + } + + var cl = target.param(0).asClass(); + + if (cl == ResourceKey.class) { + return ResourceKey.createRegistryKey(ID.mc(from)); + } + + var reg = RegistryInfo.ofClass(cl); + + if (reg != null) { + return ResourceKey.create(reg.key, ID.mc(from)); + } + + throw new IllegalArgumentException("Can't parse " + from + " as ResourceKey!"); + } + */ + @Override - protected Object internalJsToJava(Object from, TypeInfo target) { - var w = super.internalJsToJava(from, target); + protected Object internalJsToJavaLast(Object from, TypeInfo target) { + // handle ResourceKey, Holder, TagKey, registry object + + var reg = RegistryType.allOfClass(target.asClass()); + + if (!reg.isEmpty()) { + throw new RuntimeException("AAAAAAA"); - if (from == w && from != null && target != null) { - // registries + /* + var id = ID.mc(o); + var value = getValue(id); + + if (value == null) { + var npe = new NullPointerException("No such element with id %s in registry %s!".formatted(id, this)); + ConsoleJS.getCurrent(cx).error("Error while wrapping registry element type!", npe); + throw npe; + } + */ + + /* + @Override + @SuppressWarnings({"unchecked", "rawtypes"}) + public T wrap(Context cx, Object from, TypeInfo target) { + if (from instanceof RegistryObjectKJS k && k.kjs$getKubeRegistry().key == key || baseClass.isInstance(from)) { + return (T) from; + } + + if (from instanceof CharSequence || from instanceof ResourceLocation || from instanceof ResourceKey || from instanceof RegistryObjectKJS) { + return RegistryInfo.of(key).getValue(ID.mc(from)); + } + + return (T) from; + } + */ } - return w; + return from; } public NativeJavaClass loadJavaClass(String name, boolean error) { diff --git a/src/main/java/dev/latvian/mods/kubejs/script/ScriptManager.java b/src/main/java/dev/latvian/mods/kubejs/script/ScriptManager.java index a73b4aa59..f91e23257 100644 --- a/src/main/java/dev/latvian/mods/kubejs/script/ScriptManager.java +++ b/src/main/java/dev/latvian/mods/kubejs/script/ScriptManager.java @@ -2,14 +2,11 @@ import dev.latvian.mods.kubejs.KubeJS; import dev.latvian.mods.kubejs.KubeJSPlugin; -import dev.latvian.mods.kubejs.registry.RegistryInfo; import dev.latvian.mods.kubejs.util.ClassFilter; import dev.latvian.mods.kubejs.util.KubeJSPlugins; import dev.latvian.mods.kubejs.util.LogType; -import net.minecraft.core.HolderLookup; +import dev.latvian.mods.kubejs.util.UtilsJS; import net.minecraft.core.RegistryAccess; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.world.damagesource.DamageSources; @@ -39,8 +36,8 @@ public ScriptManager(ScriptType t) { classFilter = KubeJSPlugins.createClassFilter(scriptType); } - public HolderLookup.Provider getRegistries() { - return RegistryAccess.EMPTY; + public RegistryAccess getRegistries() { + return UtilsJS.staticRegistries; } public DamageSources getDamageSources() { @@ -168,18 +165,6 @@ public void load() { plugin.registerTypeWrappers(typeWrappers); } - for (var reg : BuiltInRegistries.REGISTRY.registryKeySet()) { - var info = RegistryInfo.of((ResourceKey) reg); - - if (info.autoWrap && info.objectBaseClass != Object.class && info.objectBaseClass != null) { - try { - typeWrappers.register(info.objectBaseClass, info); - } catch (IllegalArgumentException ignored) { - scriptType.console.info("Skipped registry type wrapper for " + info.key.location()); - } - } - } - var i = 0; var t = 0; diff --git a/src/main/java/dev/latvian/mods/kubejs/server/KubeJSServerEventHandler.java b/src/main/java/dev/latvian/mods/kubejs/server/KubeJSServerEventHandler.java index 2d9c264bf..5c8d25843 100644 --- a/src/main/java/dev/latvian/mods/kubejs/server/KubeJSServerEventHandler.java +++ b/src/main/java/dev/latvian/mods/kubejs/server/KubeJSServerEventHandler.java @@ -7,7 +7,9 @@ import dev.latvian.mods.kubejs.command.KubeJSCommands; import dev.latvian.mods.kubejs.level.SimpleLevelKubeEvent; import dev.latvian.mods.kubejs.script.ScriptType; +import dev.latvian.mods.kubejs.util.UtilsJS; import net.minecraft.Util; +import net.minecraft.core.RegistryAccess; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.NbtAccounter; @@ -96,6 +98,7 @@ public static void serverStopping(ServerStoppingEvent event) { @SubscribeEvent public static void serverStopped(ServerStoppedEvent event) { + UtilsJS.staticRegistries = RegistryAccess.EMPTY; } @SubscribeEvent diff --git a/src/main/java/dev/latvian/mods/kubejs/server/ServerScriptManager.java b/src/main/java/dev/latvian/mods/kubejs/server/ServerScriptManager.java index 76e6b01b8..610abd318 100644 --- a/src/main/java/dev/latvian/mods/kubejs/server/ServerScriptManager.java +++ b/src/main/java/dev/latvian/mods/kubejs/server/ServerScriptManager.java @@ -45,7 +45,7 @@ public static ServerScriptManager getScriptManager() { } public final ReloadableServerResources resources; - public final HolderLookup.Provider registries; + public final RegistryAccess registries; public final Map, PreTagKubeEvent> preTagEvents; public ServerScriptManager(ReloadableServerResources resources, RegistryAccess registryAccess) { @@ -66,7 +66,7 @@ public ServerScriptManager(ReloadableServerResources resources, RegistryAccess r } @Override - public HolderLookup.Provider getRegistries() { + public RegistryAccess getRegistries() { return registries; } diff --git a/src/main/java/dev/latvian/mods/kubejs/util/ID.java b/src/main/java/dev/latvian/mods/kubejs/util/ID.java index e0d804ea7..da2b79081 100644 --- a/src/main/java/dev/latvian/mods/kubejs/util/ID.java +++ b/src/main/java/dev/latvian/mods/kubejs/util/ID.java @@ -2,7 +2,7 @@ import com.google.gson.JsonPrimitive; import dev.latvian.mods.kubejs.KubeJS; -import dev.latvian.mods.kubejs.core.WithRegistryKeyKJS; +import dev.latvian.mods.kubejs.core.RegistryObjectKJS; import net.minecraft.ResourceLocationException; import net.minecraft.core.Holder; import net.minecraft.resources.ResourceKey; @@ -63,7 +63,7 @@ static ResourceLocation of(@Nullable Object o, boolean preferKJS) { return key.location(); } else if (o instanceof Holder holder) { return holder.unwrapKey().get().location(); - } else if (o instanceof WithRegistryKeyKJS key) { + } else if (o instanceof RegistryObjectKJS key) { return key.kjs$getIdLocation(); } diff --git a/src/main/java/dev/latvian/mods/kubejs/util/KubeJSPlugins.java b/src/main/java/dev/latvian/mods/kubejs/util/KubeJSPlugins.java index d4007885e..e3021620a 100644 --- a/src/main/java/dev/latvian/mods/kubejs/util/KubeJSPlugins.java +++ b/src/main/java/dev/latvian/mods/kubejs/util/KubeJSPlugins.java @@ -69,7 +69,7 @@ private static void loadFromFile(Stream contents, String source, boolean } } else if (!ModList.get().isLoaded(line[i])) { if (DevProperties.get().logSkippedPlugins) { - KubeJS.LOGGER.warn("Plugin " + line[0] + " does not have required mod " + line[i] + " loaded, skipping"); + KubeJS.LOGGER.warn("Plugin " + line[0] + " does not have required mod '" + line[i] + "' loaded, skipping"); } return Stream.empty(); diff --git a/src/main/java/dev/latvian/mods/kubejs/util/UtilsJS.java b/src/main/java/dev/latvian/mods/kubejs/util/UtilsJS.java index 84f33bfe5..222e37ffb 100644 --- a/src/main/java/dev/latvian/mods/kubejs/util/UtilsJS.java +++ b/src/main/java/dev/latvian/mods/kubejs/util/UtilsJS.java @@ -18,6 +18,7 @@ import net.minecraft.advancements.critereon.MinMaxBounds; import net.minecraft.commands.arguments.selector.EntitySelector; import net.minecraft.commands.arguments.selector.EntitySelectorParser; +import net.minecraft.core.RegistryAccess; import net.minecraft.nbt.EndTag; import net.minecraft.nbt.NumericTag; import net.minecraft.nbt.StringTag; @@ -54,6 +55,7 @@ public class UtilsJS { public static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; public static final String[] EMPTY_STRING_ARRAY = new String[0]; public static final Predicate ALWAYS_TRUE = o -> true; + public static RegistryAccess staticRegistries = RegistryAccess.EMPTY; private static final Map ENTITY_SELECTOR_CACHE = new HashMap<>(); private static final EntitySelector ALL_ENTITIES_SELECTOR = new EntitySelector(EntitySelector.INFINITE, true, false, e -> true, MinMaxBounds.Doubles.ANY, Function.identity(), null, EntitySelectorParser.ORDER_RANDOM, false, null, null, null, true); diff --git a/src/main/java/dev/latvian/mods/kubejs/util/registrypredicate/RegistryPredicate.java b/src/main/java/dev/latvian/mods/kubejs/util/registrypredicate/RegistryPredicate.java index b14941a92..f343bd0f8 100644 --- a/src/main/java/dev/latvian/mods/kubejs/util/registrypredicate/RegistryPredicate.java +++ b/src/main/java/dev/latvian/mods/kubejs/util/registrypredicate/RegistryPredicate.java @@ -1,7 +1,7 @@ package dev.latvian.mods.kubejs.util.registrypredicate; import com.google.gson.JsonPrimitive; -import dev.latvian.mods.kubejs.registry.RegistryInfo; +import dev.latvian.mods.kubejs.registry.RegistryType; import dev.latvian.mods.kubejs.util.ID; import dev.latvian.mods.kubejs.util.RegExpJS; import dev.latvian.mods.rhino.BaseFunction; @@ -10,6 +10,8 @@ import dev.latvian.mods.rhino.type.TypeInfo; import net.minecraft.core.Holder; import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceKey; import net.minecraft.tags.TagKey; import java.util.List; @@ -18,6 +20,7 @@ @FunctionalInterface public interface RegistryPredicate extends Predicate> { + @SuppressWarnings({"rawtypes", "unchecked"}) static RegistryPredicate of(Context cx, Object from, TypeInfo target) { if (from == null) { return EntireRegistryPredicate.FALSE; @@ -33,11 +36,11 @@ static RegistryPredicate of(Context cx, Object from, TypeInfo target) { } else if (s.equals("-")) { return EntireRegistryPredicate.FALSE; } else if (s.startsWith("#")) { - var reg = RegistryInfo.ofClass(target.param(0).asClass()); + var reg = RegistryType.ofType(target.param(0)); var tag = ID.mc(s.substring(1)); if (reg != null) { - return new RegistryTagKeyPredicate<>(TagKey.create(reg.key, tag)); + return new RegistryTagKeyPredicate<>(TagKey.create(reg.key(), tag)); } else { return new RegistryTagIDPredicate<>(tag); } @@ -49,14 +52,22 @@ static RegistryPredicate of(Context cx, Object from, TypeInfo target) { if (pattern != null) { return new RegistryRegExpPredicate<>(pattern); } else { - var reg = RegistryInfo.ofClass(target.param(0).asClass()); + var reg = RegistryType.ofType(target.param(0)); var id = ID.mc(s); if (reg != null) { - return new RegistryHolderPredicate<>(reg.getHolder(id)); - } else { - return new RegistryIDPredicate<>(id); + var registry = BuiltInRegistries.REGISTRY.get((ResourceKey) reg.key()); + + if (registry != null) { + var opt = registry.getHolder(id); + + if (opt.isPresent()) { + return new RegistryHolderPredicate<>((Holder) opt.get()); + } + } } + + return new RegistryIDPredicate<>(id); } } } else if (from instanceof BaseFunction) { diff --git a/src/main/resources/assets/kubejs/font/icons.json b/src/main/resources/assets/kubejs/font/icons.json index f474bd66a..fa7d248d2 100644 --- a/src/main/resources/assets/kubejs/font/icons.json +++ b/src/main/resources/assets/kubejs/font/icons.json @@ -3,10 +3,15 @@ { "type": "bitmap", "file": "kubejs:font/icons/k.png", - "ascent": 9, - "height": 10, + "ascent": 7, "chars": ["K"] }, + { + "type": "bitmap", + "file": "kubejs:font/icons/small_space.png", + "ascent": 7, + "chars": ["."] + }, { "type": "bitmap", "file": "kubejs:font/icons/i.png", @@ -18,6 +23,18 @@ "file": "kubejs:font/icons/w.png", "ascent": 7, "chars": ["W"] + }, + { + "type": "bitmap", + "file": "kubejs:font/icons/y.png", + "ascent": 7, + "chars": ["Y"] + }, + { + "type": "bitmap", + "file": "kubejs:font/icons/n.png", + "ascent": 7, + "chars": ["N"] } ] } \ No newline at end of file diff --git a/src/main/resources/assets/kubejs/textures/font/icons/k.png b/src/main/resources/assets/kubejs/textures/font/icons/k.png index 95373e54aa50f27214e5892056fa279a17b81449..e442f2ddc0436198470511829d73c7d5554d54e3 100644 GIT binary patch delta 6787 zcmV-}8hqusH=Q+*Reu^XNklwCk|@)%WJi`{ zTUN$$?2(-~W$ZXJ&SacXW>O}yHJPy|iECsh8rhN+l}MHtixnin0+8q+3ekJVVi&uM zZ8_iF!UedXKq=NQec<84zJ2fBd(J)e-U|&rAVQ%K4i|nc@_%U&l7vh`xk4L+wh3(# zDig{U$`Y~&g@l|!6GCG`-9k;$a9tn}YH1%G9UZ}&o=|5f_{GmXi_0|)@F9TGyd0bw z`Vlmm4?OfmxT99c^u5CLseylA$~@b#2~`Lk5IQWhM~Fg52)4x^^-q2e2BH*%-xD12 z!hg|_={uE~YJWcGoCw`GKicU$lz&$!DJe-ke^SN}9m|Ii#vQ$RZ{ag)zyTSgR?CT2 z?`I0_6Z*8!19B%{&20oS*ibMitOkP`b&WDAOz^oRtp+-?He@myV6|G1Y_n_J9wYJcEIkq>u{4&`O4Sc>e9 zIY_C{HKB3d`9K1oy+@EQ^bbOh_<#KYq@|~Xa`Q7ZEp0u>%1%a6c5&F=mjTD6*BM|j zTi^;!_UGn^i?{Nnc=z6j-8t|yYJeAk*NW6-hb%E>Q&`P zv!&m5;1q(%V3y=28QaAK_HEma_3J7ikqr%(+Ht+N1A21^h1rElSSt|%$HS27(Kyjk z-vvvuQQa1b3V~@iuN1-pg;18V1KqPVc=p+6<-0mM5!0bhPn=x>Ge(qU-I;nW=5 zvlpAn?h-u=;=Rk4C5h2vReyfD3|yyrz8%D2iW4kCepVrhb4szUbUjMS3(!B_kLw*b zkdu>%{EPz5MC6U-L7_70Sj=X0kKTaG;fBtroN&AlwhHwMF;7rf&M7J#X2^&GU;axW zvrx$I^J`MAR%E7R!YH%3sbVwsZ{LU$=c~~<&?b*8ZwB$uFxipWqkrwwH*8s5iDUOX zi1~33+I!pKmL!Y*U?rgAEzB&!zR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Qh;GsL^Dd!Pjd9nNze0M%M$i z;YQn4eD~Ckk)FrN*vJVDcra@E=!J(jt@WlG%8D~B%3Tpenx>>4&z8nQk5oOW$R8%Rfa-3 z^LGn&G$f{Zt@$#B21a1AstFLC2Rgk!6ADEZgDfwRIXlEPg$lfotFFHw#CZblujrA* zVZ!y=o9G(6B`23;qnHVbHy@iGL%(|(Wq(Dbs@CVrOrE1-;(2Nfw{?bpr;z7x{?FOp zr~0YnsqsKwIQryGb^5JAjb|kQGQtJLksF8xAuc>7RtSM9^8EAyt~Om!&PFeQ$RsB^ zS$!>t-RslYdK7pspq1y780nwjyFi_Jg1qP}$-~i$r#1zj~F;FLLYW*v$pE<>}Xm~rmvJE|V1r={|^W~QW;AH|EoEs@WFqsu1LMCWSmFMmK|>__^FbGR8?=6O<5W*N!YJ&Yi!E-VvvoeeE0WLx$w?Iq7^=rA?>37oh)<41X{@;T|_k zO?VhqIr3ccu9m~`nz#Da{;KRY0T7x$P@Cj{TWp98M*D=YT9GMCUZ{UZy?p2!9KiOR zZ1Mi7YD9k5Afs$oFT}L@KvgYB7g_;__4u? zORI&rl3XpRWe52cms<*^CqDQ-9NT+BjZm}+=*%s3L~l+mp|Eu(>3_(4{slEV#I?gL zm^kx1>7G)xgxf8(gp|IlP52g@TCunoK2tY4`h}0*cYni;^UcUCPDa4%$C=^Z;-jgR z&;+sk!K4DK60R*EmCy-tO~D_1#nuiwCj`agJY+Zos&X zO$va}KBy2QFgo$ehpb3(K#8Z-J?{oXTeDJMDI1 zN@#k@gBj5pe;^=D7!Vg9i}(bwZ~5gUrpBmxjtEqHSOm9(__wI*l<6xDxlY^q}a?uy5@mu`Dp7(O^TJsInn6&3b~y-v?z-sKBRu#_xZ$`DhG zAub_SWtFTi=u9IWS!p#Z!D%ec>u2k`OYYFxcU)Bpeg M07*qoM6N<$f}+EwrvLx| diff --git a/src/main/resources/assets/kubejs/textures/font/icons/n.png b/src/main/resources/assets/kubejs/textures/font/icons/n.png new file mode 100644 index 0000000000000000000000000000000000000000..1306852978940a22fd5e683e31fd2cc2c8332c35 GIT binary patch literal 192 zcmeAS@N?(olHy`uVBq!ia0vp^93afW3?x5a^xFxf7>k44ofy`glX(f`u%tWsIx;Y9 z?C1WI$O`211o(uwUS<&d&%m&XK^G`cYF=CeQdbh>7ySSKe+CDwm0y5-&H|6fVg?4j z{UFR}!5XXr6x8)}aSV|Nmpy$@kimfCutD?p`#be&l!_P@^KHtEFr2D5b>ZLpvHy>L dy&Zn>1+#!TLv7ocU4}r744$rjF6*2UngHa@IAZ_+ literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/kubejs/textures/font/icons/small_space.png b/src/main/resources/assets/kubejs/textures/font/icons/small_space.png new file mode 100644 index 0000000000000000000000000000000000000000..f2fb963d8477d3ca55965ebd485196f03ab6c595 GIT binary patch literal 124 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sEXgD|57Yp@DXP|(xGF+?LcS;DMA&}%ZYgaiYl8w1m9=KF7f Ok_?`%elF{r5}E+lKN?T~ literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/kubejs/textures/font/icons/y.png b/src/main/resources/assets/kubejs/textures/font/icons/y.png new file mode 100644 index 0000000000000000000000000000000000000000..16653b5ef1feae6700d61f9ad8d621602cc1211f GIT binary patch literal 187 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sEXgD|57Yp@DXFu>ErF+?Lc`2cIpKjS~_7kv`sq!>K+S-)pZ zGd>t{h{5O6aotRV`J6`@HJzr}h#SrpT*CljPiJ8?IGo}7s-AD_a*0VA3`;mpsjwOt aFfe4zHrU|Hom&7jo59o7&t;ucLK6VKg){sB literal 0 HcmV?d00001 diff --git a/src/main/resources/kubejs.mixins.json b/src/main/resources/kubejs.mixins.json index 2babd8a38..1b130636e 100644 --- a/src/main/resources/kubejs.mixins.json +++ b/src/main/resources/kubejs.mixins.json @@ -23,8 +23,6 @@ "DyeColorMixin", "EntityMixin", "EntityTypeMixin", - "EventHandlerBridgeMixin", - "EventHandlerInvoker", "FireworkRocketEntityMixin", "FluidMixin", "GameRulesMixin",