Skip to content

Commit

Permalink
Rewrote registries, added few new icons
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed May 31, 2024
1 parent efcccf2 commit b9bcabc
Show file tree
Hide file tree
Showing 59 changed files with 795 additions and 583 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
116 changes: 61 additions & 55 deletions src/main/java/dev/latvian/mods/kubejs/BuiltinKubeJSPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -191,55 +190,6 @@
public class BuiltinKubeJSPlugin implements KubeJSPlugin {
public static final HashMap<String, Object> 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));
Expand All @@ -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);
Expand Down Expand Up @@ -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 //
Expand Down
47 changes: 15 additions & 32 deletions src/main/java/dev/latvian/mods/kubejs/KubeJS.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -39,14 +37,14 @@
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;
import net.neoforged.fml.loading.FMLLoader;
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;
Expand All @@ -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";
Expand All @@ -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<IEventBus> BUS = new ThreadLocal<>();

public static Optional<IEventBus> eventBus() {
return Optional.ofNullable(BUS.get());
}

public static ResourceLocation id(String path) {
return new ResourceLocation(MOD_ID, path);
Expand Down Expand Up @@ -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);

Expand All @@ -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());
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
}
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/dev/latvian/mods/kubejs/KubeJSCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/dev/latvian/mods/kubejs/KubeJSPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down
Loading

0 comments on commit b9bcabc

Please sign in to comment.