Skip to content

Commit

Permalink
Rewrote resource pack and server script loading again, tags should no…
Browse files Browse the repository at this point in the history
…w always error, redo of asset and data generation events, improved error screen a bit, fixed dedicated server crash, added more client properties
  • Loading branch information
LatvianModder committed Jul 5, 2024
1 parent 2d51a18 commit 03ea297
Show file tree
Hide file tree
Showing 68 changed files with 894 additions and 650 deletions.
4 changes: 2 additions & 2 deletions src/main/java/dev/latvian/mods/kubejs/DevProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void reload() {
instance = new DevProperties();
}

public boolean dataPackOutput;
public boolean virtualPackOutput;
public boolean logRegistryTypes;
public boolean logRegistryEventObjects;
public boolean logAddedRecipes;
Expand All @@ -41,7 +41,7 @@ private DevProperties() {

@Override
protected void load() {
dataPackOutput = get("data_pack_output", false);
virtualPackOutput = get("virtual_pack_output", false);
logRegistryTypes = get("log_registry_types", false);
logRegistryEventObjects = get("log_registry_event_objects", false);
logAddedRecipes = get("log_added_recipes", false);
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/dev/latvian/mods/kubejs/KubeJS.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import dev.latvian.mods.kubejs.script.ScriptPack;
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.server.ServerScriptManager;
import dev.latvian.mods.kubejs.script.data.KubeFileResourcePack;
import dev.latvian.mods.kubejs.util.RecordDefaults;
import dev.latvian.mods.kubejs.util.UtilsJS;
import net.minecraft.Util;
Expand Down Expand Up @@ -167,10 +166,10 @@ public KubeJS(IEventBus bus, Dist dist, ModContainer mod) throws Throwable {
}

if (dist.isClient()) {
GeneratedResourcePack.scanForInvalidFiles("kubejs/assets/", KubeJSPaths.ASSETS);
KubeFileResourcePack.scanForInvalidFiles("kubejs/assets/", KubeJSPaths.ASSETS);
}

GeneratedResourcePack.scanForInvalidFiles("kubejs/data/", KubeJSPaths.DATA);
KubeFileResourcePack.scanForInvalidFiles("kubejs/data/", KubeJSPaths.DATA);

if (dist.isClient() || !CommonProperties.get().serverOnly) {
// See NeoForgeRegistriesSetup.VANILLA_SYNC_REGISTRIES
Expand Down Expand Up @@ -283,14 +282,14 @@ public static void loadComplete(FMLLoadCompleteEvent event) {
@SubscribeEvent(priority = EventPriority.HIGH)
public static void addPacksFirst(AddPackFindersEvent event) {
if (event.getPackType() == PackType.SERVER_DATA) {
ServerScriptManager.addPacksFirst(event);
// ServerScriptManager.addPacksFirst(event);
}
}

@SubscribeEvent(priority = EventPriority.LOW)
public static void addPacksLast(AddPackFindersEvent event) {
if (event.getPackType() == PackType.SERVER_DATA) {
ServerScriptManager.addPacksLast(event);
// ServerScriptManager.addPacksLast(event);
}
}
}
3 changes: 3 additions & 0 deletions src/main/java/dev/latvian/mods/kubejs/bindings/KMath.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.Vec3;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import org.joml.Matrix3f;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
Expand Down Expand Up @@ -45,6 +47,7 @@ static Matrix4f m4f() {
return new Matrix4f();
}

@OnlyIn(Dist.CLIENT)
static PoseStack poseStack() {
return new PoseStack();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
import dev.latvian.mods.rhino.Context;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

public record RegistryWrapper<T>(Registry<T> registry) {
public record RegistryWrapper<T>(Registry<T> registry) implements Iterable<T> {
public static RegistryWrapper<?> of(Context cx, ResourceLocation id) {
return ((KubeJSContext) cx).getRegistries().wrapRegistry(id);
}
Expand Down Expand Up @@ -44,4 +46,10 @@ public Set<ResourceLocation> getKeys() {
public ResourceLocation getId(T value) {
return registry.getKey(value);
}

@NotNull
@Override
public ListIterator<T> iterator() {
return getValues().listIterator();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
import dev.latvian.mods.kubejs.client.ClientPlayerKubeEvent;
import dev.latvian.mods.kubejs.client.DebugInfoKubeEvent;
import dev.latvian.mods.kubejs.client.EntityRendererRegistryKubeEvent;
import dev.latvian.mods.kubejs.client.GenerateClientAssetsKubeEvent;
import dev.latvian.mods.kubejs.client.LangKubeEvent;
import dev.latvian.mods.kubejs.client.MenuScreenRegistryKubeEvent;
import dev.latvian.mods.kubejs.event.EventGroup;
import dev.latvian.mods.kubejs.event.EventHandler;
import dev.latvian.mods.kubejs.event.EventTargetType;
import dev.latvian.mods.kubejs.event.TargetedEventHandler;
import dev.latvian.mods.kubejs.generator.KubeAssetGenerator;
import dev.latvian.mods.kubejs.script.data.GeneratedDataStage;
import net.minecraft.resources.ResourceLocation;

public interface ClientEvents {
EventGroup GROUP = EventGroup.of("ClientEvents");

// add low assets
EventHandler HIGH_ASSETS = GROUP.client("highPriorityAssets", () -> GenerateClientAssetsKubeEvent.class);
TargetedEventHandler<GeneratedDataStage> GENERATE_ASSETS = GROUP.client("generateAssets", () -> KubeAssetGenerator.class).requiredTarget(GeneratedDataStage.TARGET);
EventHandler BLOCK_ENTITY_RENDERER_REGISTRY = GROUP.startup("blockEntityRendererRegistry", () -> BlockEntityRendererRegistryKubeEvent.class);
EventHandler ENTITY_RENDERER_REGISTRY = GROUP.startup("entityRendererRegistry", () -> EntityRendererRegistryKubeEvent.class);
EventHandler MENU_SCREEN_REGISTRY = GROUP.startup("menuScreenRegistry", () -> MenuScreenRegistryKubeEvent.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dev.latvian.mods.kubejs.event.EventHandler;
import dev.latvian.mods.kubejs.event.EventTargetType;
import dev.latvian.mods.kubejs.event.TargetedEventHandler;
import dev.latvian.mods.kubejs.generator.KubeDataGenerator;
import dev.latvian.mods.kubejs.item.ItemStackJS;
import dev.latvian.mods.kubejs.recipe.AfterRecipesLoadedKubeEvent;
import dev.latvian.mods.kubejs.recipe.CompostableRecipesKubeEvent;
Expand All @@ -13,7 +14,8 @@
import dev.latvian.mods.kubejs.recipe.schema.RecipeMappingRegistry;
import dev.latvian.mods.kubejs.recipe.schema.RecipeSchemaRegistry;
import dev.latvian.mods.kubejs.recipe.special.SpecialRecipeSerializerManager;
import dev.latvian.mods.kubejs.script.data.DataPackKubeEvent;
import dev.latvian.mods.kubejs.registry.ServerRegistryKubeEvent;
import dev.latvian.mods.kubejs.script.data.GeneratedDataStage;
import dev.latvian.mods.kubejs.server.BasicCommandKubeEvent;
import dev.latvian.mods.kubejs.server.CommandKubeEvent;
import dev.latvian.mods.kubejs.server.ServerKubeEvent;
Expand All @@ -24,8 +26,8 @@
public interface ServerEvents {
EventGroup GROUP = EventGroup.of("ServerEvents");

EventHandler LOW_DATA = GROUP.server("lowPriorityData", () -> DataPackKubeEvent.class);
EventHandler HIGH_DATA = GROUP.server("highPriorityData", () -> DataPackKubeEvent.class);
TargetedEventHandler<ResourceKey<Registry<?>>> REGISTRY = GROUP.server("registry", () -> ServerRegistryKubeEvent.class).requiredTarget(EventTargetType.REGISTRY);
TargetedEventHandler<GeneratedDataStage> GENERATE_DATA = GROUP.server("generateData", () -> KubeDataGenerator.class).requiredTarget(GeneratedDataStage.TARGET);
EventHandler LOADED = GROUP.server("loaded", () -> ServerKubeEvent.class);
EventHandler UNLOADED = GROUP.server("unloaded", () -> ServerKubeEvent.class);
EventHandler TICK = GROUP.server("tick", () -> ServerKubeEvent.class);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/dev/latvian/mods/kubejs/block/BlockBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import dev.latvian.mods.kubejs.block.entity.BlockEntityInfo;
import dev.latvian.mods.kubejs.client.ModelGenerator;
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.generator.KubeAssetGenerator;
import dev.latvian.mods.kubejs.generator.KubeDataGenerator;
import dev.latvian.mods.kubejs.item.ItemBuilder;
import dev.latvian.mods.kubejs.registry.AdditionalObjectRegistry;
import dev.latvian.mods.kubejs.registry.BuilderBase;
Expand Down Expand Up @@ -185,7 +185,7 @@ public BuilderBase<Block> displayName(Component name) {
}

@Override
public void generateDataJsons(DataJsonGenerator generator) {
public void generateDataJsons(KubeDataGenerator generator) {
var table = generateLootTable();

if (table != null) {
Expand Down Expand Up @@ -231,7 +231,7 @@ public LootTable generateLootTable() {
}

@Override
public void generateAssetJsons(AssetJsonGenerator generator) {
public void generateAssetJsons(KubeAssetGenerator generator) {
if (blockstateJson != null) {
generator.json(newID("blockstates/", ""), blockstateJson);
} else {
Expand Down Expand Up @@ -263,7 +263,7 @@ protected void generateItemModelJson(ModelGenerator m) {
}
}

protected void generateBlockModelJsons(AssetJsonGenerator generator) {
protected void generateBlockModelJsons(KubeAssetGenerator generator) {
generator.blockModel(id, mg -> {
var particle = textures.get("particle").getAsString();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.latvian.mods.kubejs.block;

import dev.latvian.mods.kubejs.generator.AssetJsonGenerator;
import dev.latvian.mods.kubejs.generator.KubeAssetGenerator;
import dev.latvian.mods.kubejs.item.ItemBuilder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
Expand All @@ -24,6 +24,6 @@ public String getTranslationKeyGroup() {
}

@Override
public void generateAssetJsons(AssetJsonGenerator generator) {
public void generateAssetJsons(KubeAssetGenerator generator) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import dev.latvian.mods.kubejs.KubeJS;
import dev.latvian.mods.kubejs.bindings.event.BlockEvents;
import dev.latvian.mods.kubejs.generator.AssetJsonGenerator;
import dev.latvian.mods.kubejs.generator.KubeAssetGenerator;
import dev.latvian.mods.rhino.util.ReturnsSelf;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -46,7 +46,7 @@ public Block createObject() {
}

@Override
public void generateAssetJsons(AssetJsonGenerator generator) {
public void generateAssetJsons(KubeAssetGenerator generator) {
generator.blockState(id, bs -> {
bs.simpleVariant("powered=false", "kubejs:block/detector");
bs.simpleVariant("powered=true", "kubejs:block/detector_on");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.latvian.mods.kubejs.block;

import dev.latvian.mods.kubejs.generator.AssetJsonGenerator;
import dev.latvian.mods.kubejs.generator.KubeAssetGenerator;
import dev.latvian.mods.kubejs.item.ItemBuilder;
import dev.latvian.mods.kubejs.item.custom.BasicItemJS;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -50,9 +50,9 @@ public Item createObject() {
}

@Override
public void generateAssetJsons(AssetJsonGenerator generator) {
public void generateAssetJsons(KubeAssetGenerator generator) {
if (modelJson != null) {
generator.json(AssetJsonGenerator.asItemModelLocation(id), modelJson);
generator.json(KubeAssetGenerator.asItemModelLocation(id), modelJson);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import dev.latvian.mods.kubejs.client.ModelGenerator;
import dev.latvian.mods.kubejs.client.VariantBlockStateGenerator;
import dev.latvian.mods.kubejs.generator.AssetJsonGenerator;
import dev.latvian.mods.kubejs.generator.KubeAssetGenerator;
import dev.latvian.mods.rhino.util.ReturnsSelf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
Expand Down Expand Up @@ -75,7 +75,7 @@ protected void generateBlockStateJson(VariantBlockStateGenerator bs) {
}

@Override
protected void generateBlockModelJsons(AssetJsonGenerator generator) {
protected void generateBlockModelJsons(KubeAssetGenerator generator) {
var texture = textures.get("texture").getAsString();

generator.blockModel(id, m -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.latvian.mods.kubejs.block.custom;

import dev.latvian.mods.kubejs.client.VariantBlockStateGenerator;
import dev.latvian.mods.kubejs.generator.AssetJsonGenerator;
import dev.latvian.mods.kubejs.generator.KubeAssetGenerator;
import dev.latvian.mods.rhino.util.ReturnsSelf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
Expand Down Expand Up @@ -31,7 +31,7 @@ protected void generateBlockStateJson(VariantBlockStateGenerator bs) {
}

@Override
protected void generateBlockModelJsons(AssetJsonGenerator generator) {
protected void generateBlockModelJsons(KubeAssetGenerator generator) {
var texture = textures.get("texture").getAsString();

generator.blockModel(id, m -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import dev.latvian.mods.kubejs.block.RandomTickCallbackJS;
import dev.latvian.mods.kubejs.block.SeedItemBuilder;
import dev.latvian.mods.kubejs.client.VariantBlockStateGenerator;
import dev.latvian.mods.kubejs.generator.AssetJsonGenerator;
import dev.latvian.mods.kubejs.generator.KubeAssetGenerator;
import dev.latvian.mods.kubejs.level.BlockContainerJS;
import dev.latvian.mods.kubejs.typings.Info;
import dev.latvian.mods.rhino.util.ReturnsSelf;
Expand Down Expand Up @@ -236,7 +236,7 @@ protected void generateBlockStateJson(VariantBlockStateGenerator bs) {
}

@Override
protected void generateBlockModelJsons(AssetJsonGenerator generator) {
protected void generateBlockModelJsons(KubeAssetGenerator generator) {
for (int i = 0; i <= age; i++) {
final int fi = i;
generator.blockModel(newID("", String.valueOf(i)), m -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import dev.latvian.mods.kubejs.client.ModelGenerator;
import dev.latvian.mods.kubejs.client.MultipartBlockStateGenerator;
import dev.latvian.mods.kubejs.generator.AssetJsonGenerator;
import dev.latvian.mods.kubejs.generator.KubeAssetGenerator;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.level.block.Block;
Expand Down Expand Up @@ -44,7 +44,7 @@ protected void generateItemModelJson(ModelGenerator m) {
}

@Override
protected void generateBlockModelJsons(AssetJsonGenerator generator) {
protected void generateBlockModelJsons(KubeAssetGenerator generator) {
var texture = textures.get("texture").getAsString();

generator.blockModel(newID("", "_post"), m -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import dev.latvian.mods.kubejs.client.ModelGenerator;
import dev.latvian.mods.kubejs.client.VariantBlockStateGenerator;
import dev.latvian.mods.kubejs.generator.AssetJsonGenerator;
import dev.latvian.mods.kubejs.generator.KubeAssetGenerator;
import dev.latvian.mods.rhino.util.ReturnsSelf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
Expand Down Expand Up @@ -75,7 +75,7 @@ protected void generateBlockStateJson(VariantBlockStateGenerator bs) {
}

@Override
protected void generateBlockModelJsons(AssetJsonGenerator generator) {
protected void generateBlockModelJsons(KubeAssetGenerator generator) {
var texture = textures.get("texture").getAsString();

generator.blockModel(id, m -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import dev.latvian.mods.kubejs.block.BlockBuilder;
import dev.latvian.mods.kubejs.client.ModelGenerator;
import dev.latvian.mods.kubejs.client.VariantBlockStateGenerator;
import dev.latvian.mods.kubejs.generator.AssetJsonGenerator;
import dev.latvian.mods.kubejs.generator.KubeAssetGenerator;
import dev.latvian.mods.rhino.util.ReturnsSelf;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -52,7 +52,7 @@ protected void generateBlockStateJson(VariantBlockStateGenerator bs) {
}

@Override
protected void generateBlockModelJsons(AssetJsonGenerator gen) {
protected void generateBlockModelJsons(KubeAssetGenerator gen) {
gen.blockModel(id, mg -> {
var side = getTextureOrDefault("side", newID("block/", "").toString());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.latvian.mods.kubejs.block.custom;

import dev.latvian.mods.kubejs.client.MultipartBlockStateGenerator;
import dev.latvian.mods.kubejs.generator.AssetJsonGenerator;
import dev.latvian.mods.kubejs.generator.KubeAssetGenerator;
import net.minecraft.resources.ResourceLocation;

public abstract class MultipartShapedBlockBuilder extends ShapedBlockBuilder {
Expand All @@ -10,7 +10,7 @@ public MultipartShapedBlockBuilder(ResourceLocation i, String... suffixes) {
}

@Override
public void generateAssetJsons(AssetJsonGenerator generator) {
public void generateAssetJsons(KubeAssetGenerator generator) {
if (blockstateJson != null) {
generator.json(newID("blockstates/", ""), blockstateJson);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import dev.latvian.mods.kubejs.client.ModelGenerator;
import dev.latvian.mods.kubejs.client.VariantBlockStateGenerator;
import dev.latvian.mods.kubejs.generator.AssetJsonGenerator;
import dev.latvian.mods.kubejs.generator.KubeAssetGenerator;
import dev.latvian.mods.rhino.util.ReturnsSelf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
Expand Down Expand Up @@ -55,7 +55,7 @@ protected void generateBlockStateJson(VariantBlockStateGenerator bs) {
}

@Override
protected void generateBlockModelJsons(AssetJsonGenerator generator) {
protected void generateBlockModelJsons(KubeAssetGenerator generator) {
var texture = textures.get("texture").getAsString();

generator.blockModel(newID("", "_down"), m -> {
Expand Down
Loading

0 comments on commit 03ea297

Please sign in to comment.