Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.gregtechceu.gtceu.api.data.chemical.material.Material;
import com.gregtechceu.gtceu.api.recipe.ConsumedInputsData;
import com.gregtechceu.gtceu.api.recipe.GTRecipe;
import com.gregtechceu.gtceu.api.recipe.GTRecipeType;
import com.gregtechceu.gtceu.api.registry.GTRegistries;
import com.gregtechceu.gtceu.api.sync_system.SyncDataHolder;
import com.gregtechceu.gtceu.api.sync_system.TypeDeclaration;
Expand Down Expand Up @@ -177,7 +176,6 @@ public static <T> void registerGenericTransformerSupplier(Class<T> type, Supplie
registerCodecTransformer(MonitorGroup.class, MonitorGroup.CODEC, MonitorGroup.STREAM_CODEC);
registerCodecTransformer(ConsumedInputsData.class, ConsumedInputsData.CODEC, ByteBufCodecs.fromCodecWithRegistries(ConsumedInputsData.CODEC));

registerTransformer(GTRecipeType.class, new RegistryReferenceTransformer<>(GTRegistries.Keys.RECIPE_TYPE, GTRecipeType::getRegistryName));
registerTransformer(Material.class, new RegistryReferenceTransformer<>(GTRegistries.Keys.MATERIAL, Material::getResourceLocation));

// spotless:on
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,51 @@
package com.gregtechceu.gtceu.integration.kjs;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.integration.kjs.events.*;

import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;

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.util.Cast;
import dev.latvian.mods.rhino.type.TypeInfo;

public interface GTCEuStartupEvents {

EventTargetType<ResourceKey<Registry<?>>> REGISTRY_ASSUME_GT = Cast.to(EventTargetType.create(ResourceKey.class)
.transformer(GTCEuStartupEvents::toRegistryKeyAssumeGTNamespace)
.identity()
.describeType(TypeInfo.of(ResourceKey.class)
.withParams(TypeInfo.of(Registry.class))));

EventGroup GROUP = EventGroup.of("GTCEuStartupEvents");

EventHandler MATERIAL_ICON_INFO = GROUP.startup("materialIconInfo", () -> MaterialIconInfoEventJS.class);
EventHandler WORLD_GEN_LAYERS = GROUP.startup("worldGenLayers", () -> WorldGenLayerEventJS.class);

TargetedEventHandler<ResourceKey<Registry<?>>> REGISTRY = GROUP.startup("registry", () -> GTRegistryKubeEvent.class)
.requiredTarget(EventTargetType.REGISTRY);
EventHandler MATERIAL_MODIFICATION = GROUP.startup("materialModification",
() -> MaterialModificationEventJS.class);
.requiredTarget(REGISTRY_ASSUME_GT);
EventHandler MATERIAL_MODIFICATION = GROUP.startup("materialModification", () -> MaterialModificationEventJS.class);
EventHandler CRAFTING_COMPONENTS = GROUP.startup("craftingComponents", () -> CraftingComponentsEventJS.class);

EventHandler REGISTER_WOODS = GROUP.startup("registerWoods", () -> RegisterWoodsEventJS.class);
EventHandler MACHINE_MODIFICATION = GROUP.startup("machineModification", () -> ModifyMachineEventJS.class);
EventHandler REGISTER_SPOILABLES = GROUP.startup("registerSpoilables", () -> RegisterSpoilablesEventJS.class);

@SuppressWarnings("rawtypes")
private static ResourceKey<? extends Registry<?>> toRegistryKeyAssumeGTNamespace(Object object) {
return switch (object) {
case null -> null;
case ResourceKey rl -> rl;
case ResourceLocation rl -> ResourceKey.createRegistryKey(rl);
default -> {
String s = object.toString();
yield s.isBlank() ? null : ResourceKey.createRegistryKey(GTCEu.id(s));
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,15 @@
import dev.latvian.mods.kubejs.recipe.schema.RecipeSchemaRegistry;
import dev.latvian.mods.kubejs.registry.BuilderTypeRegistry;
import dev.latvian.mods.kubejs.registry.RegistryObjectStorage;
import dev.latvian.mods.kubejs.registry.RegistryType;
import dev.latvian.mods.kubejs.registry.ServerRegistryRegistry;
import dev.latvian.mods.kubejs.script.BindingRegistry;
import dev.latvian.mods.kubejs.script.TypeWrapperRegistry;
import dev.latvian.mods.kubejs.util.ID;
import dev.latvian.mods.kubejs.util.RegistryAccessContainer;
import dev.latvian.mods.rhino.Context;
import dev.latvian.mods.rhino.Wrapper;
import dev.latvian.mods.rhino.type.TypeInfo;

public class GregTechKubeJSPlugin implements KubeJSPlugin {

Expand All @@ -135,6 +139,9 @@ public void registerBuilderTypes(BuilderTypeRegistry registry) {
reg.add(GTCEu.id("ore"), OreTagPrefixBuilder.class, OreTagPrefixBuilder::new);
});

registry.of(Registries.RECIPE_TYPE, reg -> {
reg.add(GTCEu.id("machine"), GTRecipeTypeBuilder.class, GTRecipeTypeBuilder::new);
});
registry.addDefault(GTRegistries.Keys.RECIPE_TYPE, GTRecipeTypeBuilder.class, GTRecipeTypeBuilder::new);
registry.addDefault(GTRegistries.Keys.RECIPE_CATEGORY, GTRecipeCategoryBuilder.class,
GTRecipeCategoryBuilder::new);
Expand Down Expand Up @@ -339,7 +346,22 @@ private <T> void registryObjectTypeWrapper(TypeWrapperRegistry typeWrappers, Cla
public void registerTypeWrappers(TypeWrapperRegistry registry) {
registry.register(GTResourceLocation.class, GTResourceLocation::wrap);

registryObjectTypeWrapper(registry, GTRecipeType.class, GTRegistries.Keys.RECIPE_TYPE);
registry.register(GTRecipeType.class, (Context cx, Object from, TypeInfo target) -> {
if (ID.isKey(from)) {
// if it's an ID, make it default to the GT namespace
GTResourceLocation wrapper = GTResourceLocation.wrap(from);
if (wrapper != null) from = wrapper.wrapped();
}

// first convert
Object o = cx.jsToJava(from, RegistryType.ofKey(Registries.RECIPE_TYPE).type());
if (o instanceof GTRecipeType gtType) {
return gtType;
} else {
cx.reportConversionError(from, target);
return null;
}
});
registryObjectTypeWrapper(registry, GTRecipeCategory.class, GTRegistries.Keys.RECIPE_CATEGORY);
registryObjectTypeWrapper(registry, ChanceLogic.class, GTRegistries.Keys.CHANCE_LOGIC);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public GTRecipeTypeBuilder(ResourceLocation id) {
this.maxTooltips = 4;
this.smallRecipeMap = null;
this.iconSupplier = null;

this.dummyBuilder = true;
}

public GTRecipeTypeBuilder category(String category) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class KubeGTRegistryEventHandler {
@SubscribeEvent(priority = EventPriority.LOW)
public static void registerAll(RegisterEvent event) {
// only post the GT registry event for GT registries
if (!GTRegistries.getRegistries().contains(event.getRegistry())) {
if (!GTRegistries.getRegistryOrder().contains(event.getRegistryKey().location())) {
return;
}

Expand Down
Loading