Skip to content

Commit

Permalink
Phew. Removed Architectury dependency, moved ConsoleJS to script pack…
Browse files Browse the repository at this point in the history
…age, rewrote how registered block entity ticks and recipe component matching works, added Replaceable interface, added regex and namespace fluid ingredients, added a couple new icons, changed slightly how event handlers are registered
  • Loading branch information
LatvianModder committed Jun 25, 2024
1 parent 0f3b9e8 commit f98a525
Show file tree
Hide file tree
Showing 142 changed files with 1,235 additions and 918 deletions.
12 changes: 4 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,23 @@ dependencies {
//mappings loom.officialMojangMappings()
mappings loom.layered() {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-1.20.6:$parchment_version@zip")
parchment("org.parchmentmc.data:parchment-1.21:$parchment_version@zip")
}

neoForge("net.neoforged:neoforge:$neoforge_version")

modApi("dev.architectury:architectury-neoforge:$architectury_version")
modApi("dev.latvian.mods:rhino:$rhino_version") { transitive(false) }

modCompileOnly("dev.architectury:architectury-neoforge:$architectury_version")
modCompileOnly("mezz.jei:jei-1.21-neoforge:$jei_version")
modCompileOnly("me.shedaniel:RoughlyEnoughItems-neoforge:$rei_version")
modCompileOnly("dev.emi:emi-neoforge:$emi_version:api")
}

processResources {
def toReplace = [
"version" : project.version,
"rhino_version" : project.rhino_version,
"architectury_version": project.architectury_version,
"version" : project.version,
"rhino_version": project.rhino_version,
]

println("[Process Resources] Replacing properties in resources: " + toReplace)
Expand Down Expand Up @@ -157,9 +156,6 @@ unifiedPublishing {
mainPublication remapJar

relations {
depends {
curseforge = modrinth = "architectury-api"
}
depends {
curseforge = modrinth = "rhino"
}
Expand Down
6 changes: 3 additions & 3 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.21
mod_version=2100.7.0

neoforge_version=21.0.21-beta
parchment_version=2024.06.16
neoforge_version=21.0.37-beta
parchment_version=2024.06.23
rhino_version=2100.2.5-build.29
architectury_version=13.0.1

rei_version=16.0.729
jei_version=19.0.0.9
jei_version=19.0.0.11
emi_version=1.1.7+1.21
10 changes: 4 additions & 6 deletions src/main/java/dev/latvian/mods/kubejs/BuiltinKubeJSPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@
import dev.latvian.mods.kubejs.plugin.ClassFilter;
import dev.latvian.mods.kubejs.plugin.KubeJSPlugin;
import dev.latvian.mods.kubejs.plugin.KubeJSPlugins;
import dev.latvian.mods.kubejs.recipe.InputReplacement;
import dev.latvian.mods.kubejs.recipe.OutputReplacement;
import dev.latvian.mods.kubejs.recipe.ReplacementMatch;
import dev.latvian.mods.kubejs.recipe.component.BlockComponent;
import dev.latvian.mods.kubejs.recipe.component.BlockStateComponent;
import dev.latvian.mods.kubejs.recipe.component.BooleanComponent;
Expand All @@ -116,6 +113,8 @@
import dev.latvian.mods.kubejs.recipe.ingredientaction.IngredientActionTypeRegistry;
import dev.latvian.mods.kubejs.recipe.ingredientaction.KeepAction;
import dev.latvian.mods.kubejs.recipe.ingredientaction.ReplaceAction;
import dev.latvian.mods.kubejs.recipe.match.ReplacementMatch;
import dev.latvian.mods.kubejs.recipe.match.ReplacementMatchInfo;
import dev.latvian.mods.kubejs.recipe.schema.RecipeComponentFactoryRegistry;
import dev.latvian.mods.kubejs.recipe.schema.RecipeFactoryRegistry;
import dev.latvian.mods.kubejs.recipe.schema.UnknownKubeRecipe;
Expand Down Expand Up @@ -517,8 +516,6 @@ public void registerTypeWrappers(TypeWrapperRegistry registry) {
registry.register(ItemStack.class, ItemStackJS::wrap);
registry.register(Ingredient.class, IngredientJS::wrap);
registry.register(ItemPredicate.class, ItemPredicate::wrap);
registry.register(InputReplacement.class, InputReplacement::wrap);
registry.register(OutputReplacement.class, OutputReplacement::wrap);
registry.register(SizedIngredient.class, SizedIngredientWrapper::wrap);
registry.register(BlockStatePredicate.class, BlockStatePredicate::of);
registry.register(RuleTest.class, BlockStatePredicate::ruleTestOf);
Expand All @@ -530,7 +527,8 @@ public void registerTypeWrappers(TypeWrapperRegistry registry) {
registry.register(PlayerSelector.class, PlayerSelector::of);
registry.register(DamageSource.class, DamageSourceWrapper::of);
registry.register(EntitySelector.class, UtilsJS::entitySelector);
registry.register(ReplacementMatch.class, ReplacementMatch::of);
registry.register(ReplacementMatch.class, ReplacementMatch::wrap);
registry.register(ReplacementMatchInfo.class, ReplacementMatchInfo::wrap);
registry.register(Stat.class, PlayerStatsJS::statOf);
registry.register(MapColor.class, MapColorHelper::of);
registry.register(SoundType.class, SoundTypeWrapper.INSTANCE);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/dev/latvian/mods/kubejs/DevProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static void reload() {
public boolean logSkippedPlugins;
public boolean logGeneratedData;
public boolean logEventErrorStackTrace;
public boolean logChangesInChat;
public boolean strictTags;
public boolean alwaysCaptureErrors;
public String kubedexSound;
Expand All @@ -53,6 +54,7 @@ protected void load() {
logSkippedPlugins = get("log_skipped_plugins", true);
logGeneratedData = get("log_generated_data", false);
logEventErrorStackTrace = get("log_event_error_stack_trace", false);
logChangesInChat = get("log_changes_in_chat", false);
strictTags = get("strict_tags", false);
alwaysCaptureErrors = get("always_capture_errors", false);
kubedexSound = get("kubedex_sound", "entity.experience_orb.pickup");
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/dev/latvian/mods/kubejs/KubeJS.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.latvian.mods.kubejs.bindings.event.StartupEvents;
import dev.latvian.mods.kubejs.client.ClientScriptManager;
import dev.latvian.mods.kubejs.event.KubeStartupEvent;
import dev.latvian.mods.kubejs.fluid.KubeJSFluidIngredients;
import dev.latvian.mods.kubejs.gui.KubeJSMenus;
import dev.latvian.mods.kubejs.holder.KubeJSHolderSets;
import dev.latvian.mods.kubejs.ingredient.KubeJSIngredients;
Expand All @@ -17,6 +18,7 @@
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.ConsoleJS;
import dev.latvian.mods.kubejs.script.ConsoleLine;
import dev.latvian.mods.kubejs.script.PlatformWrapper;
import dev.latvian.mods.kubejs.script.ScriptFileInfo;
Expand All @@ -26,7 +28,6 @@
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.util.ConsoleJS;
import dev.latvian.mods.kubejs.util.KubeJSBackgroundThread;
import dev.latvian.mods.kubejs.util.UtilsJS;
import net.minecraft.Util;
Expand Down Expand Up @@ -169,12 +170,13 @@ public KubeJS(IEventBus bus, Dist dist, ModContainer mod) throws Throwable {
if (dist.isClient() || !CommonProperties.get().serverOnly) {
// See NeoForgeRegistriesSetup.VANILLA_SYNC_REGISTRIES
NeoForgeMod.enableMilkFluid();
KubeJSIngredients.REGISTRY.register(bus);
// KubeJSComponents.REGISTRY.register(bus);
KubeJSRecipeSerializers.REGISTRY.register(bus);
KubeJSMenus.REGISTRY.register(bus);
}

KubeJSIngredients.REGISTRY.register(bus);
KubeJSFluidIngredients.REGISTRY.register(bus);
KubeJSCreativeTabs.REGISTRY.register(bus);
KubeJSRuleTests.REGISTRY.register(bus);
KubeJSHolderSets.REGISTRY.register(bus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

@Info("Various block related helper functions")
public class BlockWrapper {
public static final TypeInfo TYPE_INFO = TypeInfo.of(Block.class);
public static final TypeInfo STATE_TYPE_INFO = TypeInfo.of(BlockState.class);
private static Collection<BlockState> ALL_STATE_CACHE = null;

public static BlockIDPredicate id(ResourceLocation id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import dev.latvian.mods.rhino.type.TypeInfo;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.core.component.DataComponentPatch;
import net.minecraft.core.component.DataComponentPredicate;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.BuiltInRegistries;
Expand Down Expand Up @@ -214,6 +215,11 @@ static DataComponentType<?> readComponentType(StringReader stringReader) throws
}
}

static DataComponentPredicate readPredicate(DynamicOps<Tag> registryOps, StringReader reader) throws CommandSyntaxException {
var map = reader.canRead() ? readMap(registryOps, reader) : DataComponentMap.EMPTY;
return map.isEmpty() ? DataComponentPredicate.EMPTY : DataComponentPredicate.allOf(map);
}

static DataComponentMap mapOf(RegistryAccessContainer registries, Object o) {
try {
return readMap(registries.nbt(), new StringReader(o.toString()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package dev.latvian.mods.kubejs.bindings;

import dev.latvian.mods.kubejs.ingredient.IngredientHelper;
import dev.latvian.mods.kubejs.ingredient.TagIngredient;
import dev.latvian.mods.kubejs.typings.Info;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.neoforged.neoforge.common.crafting.SizedIngredient;
Expand Down Expand Up @@ -35,4 +38,15 @@ static boolean isIngredient(@Nullable Object o) {
static ItemStack first(Ingredient ingredient) {
return ingredient.kjs$getFirst();
}

@Nullable
static TagKey<Item> tagKeyOf(Ingredient in) {
if (!in.isCustom() && in.getValues().length == 1 && in.getValues()[0] instanceof Ingredient.TagValue value) {
return value.tag();
} else if (in.getCustomIngredient() instanceof TagIngredient tin) {
return tin.tagKey;
} else {
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.latvian.mods.kubejs.bindings;

import dev.latvian.mods.kubejs.script.ConsoleJS;
import dev.latvian.mods.kubejs.script.KubeJSContext;
import dev.latvian.mods.kubejs.typings.Info;
import dev.latvian.mods.kubejs.util.ConsoleJS;
import org.jetbrains.annotations.Nullable;
import org.slf4j.LoggerFactory;

Expand Down
62 changes: 41 additions & 21 deletions src/main/java/dev/latvian/mods/kubejs/bindings/TextIcons.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,77 +7,97 @@

public interface TextIcons {
ResourceLocation FONT = KubeJS.id("icons");
Component NAME = Component.empty().append(Component.literal("K.").kjs$font(FONT).kjs$white()).append(Component.literal(KubeJS.MOD_NAME));
Component NAME = Component.empty().append(icons("K.").kjs$white()).append(Component.literal(KubeJS.MOD_NAME));

static MutableComponent icon(MutableComponent character) {
return character.kjs$font(FONT);
}

static MutableComponent icons(String characters) {
return Component.literal(characters).kjs$font(FONT);
}

static MutableComponent smallSpace() {
return icon(Component.literal("."));
return icons(".");
}

static MutableComponent error() {
return icons("!");
}

static MutableComponent plus() {
return icons("+");
}

static MutableComponent minus() {
return icons("-");
}

static MutableComponent tilde() {
return icons("~");
}

static MutableComponent blockTagIcon() {
return icon(Component.literal("B"));
return icons("B");
}

static MutableComponent crafting() {
return icons("A");
}

static MutableComponent copy() {
return icon(Component.literal("C"));
return icons("C");
}

static MutableComponent id() {
return icon(Component.literal("D"));
return icons("D");
}

static MutableComponent entityTypeTag() {
return icon(Component.literal("E"));
return icons("E");
}

static MutableComponent fluidTag() {
return icon(Component.literal("F"));
return icons("F");
}

static MutableComponent info() {
return icon(Component.literal("I"));
return icons("I");
}

static MutableComponent itemTag() {
return icon(Component.literal("J"));
return icons("J");
}

static MutableComponent logo() {
return icon(Component.literal("K"));
return icons("K");
}

static MutableComponent no() {
return icon(Component.literal("N"));
return icons("N");
}

static MutableComponent prototypeComponent() {
return icon(Component.literal("P"));
return icons("P");
}

static MutableComponent patchedComponent() {
return icon(Component.literal("Q"));
}

static MutableComponent error() {
return icon(Component.literal("R"));
return icons("Q");
}

static MutableComponent tag() {
return icon(Component.literal("T"));
return icons("T");
}

static MutableComponent warn() {
return icon(Component.literal("W"));
return icons("W");
}

static MutableComponent yes() {
return icon(Component.literal("Y"));
return icons("Y");
}

static MutableComponent yes(boolean yes) {
return icon(yes ? Component.literal("Y") : Component.literal("N"));
return icons(yes ? "Y" : "N");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,29 @@
import dev.latvian.mods.kubejs.block.DetectorBlockKubeEvent;
import dev.latvian.mods.kubejs.block.FarmlandTrampledKubeEvent;
import dev.latvian.mods.kubejs.block.RandomTickKubeEvent;
import dev.latvian.mods.kubejs.block.entity.BlockEntityTickKubeEvent;
import dev.latvian.mods.kubejs.event.EventGroup;
import dev.latvian.mods.kubejs.event.EventHandler;
import dev.latvian.mods.kubejs.event.Extra;
import dev.latvian.mods.kubejs.event.SpecializedEventHandler;
import dev.latvian.mods.kubejs.event.EventTargetType;
import dev.latvian.mods.kubejs.event.TargetedEventHandler;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.block.Block;

public interface BlockEvents {
EventGroup GROUP = EventGroup.of("BlockEvents");
Extra<ResourceKey<Block>> SUPPORTS_BLOCK = Extra.registryKey(Registries.BLOCK, Block.class);
EventTargetType<ResourceKey<Block>> TARGET = EventTargetType.registryKey(Registries.BLOCK, Block.class);

EventHandler MODIFICATION = GROUP.startup("modification", () -> BlockModificationKubeEvent.class);
SpecializedEventHandler<ResourceKey<Block>> RIGHT_CLICKED = GROUP.common("rightClicked", SUPPORTS_BLOCK, () -> BlockRightClickedKubeEvent.class).hasResult();
SpecializedEventHandler<ResourceKey<Block>> LEFT_CLICKED = GROUP.common("leftClicked", SUPPORTS_BLOCK, () -> BlockLeftClickedKubeEvent.class).hasResult();
SpecializedEventHandler<ResourceKey<Block>> PLACED = GROUP.common("placed", SUPPORTS_BLOCK, () -> BlockPlacedKubeEvent.class).hasResult();
SpecializedEventHandler<ResourceKey<Block>> BROKEN = GROUP.common("broken", SUPPORTS_BLOCK, () -> BlockBrokenKubeEvent.class).hasResult();
SpecializedEventHandler<ResourceKey<Block>> DROPS = GROUP.server("drops", SUPPORTS_BLOCK, () -> BlockDropsKubeEvent.class).hasResult();
SpecializedEventHandler<String> DETECTOR_CHANGED = GROUP.common("detectorChanged", Extra.STRING, () -> DetectorBlockKubeEvent.class);
SpecializedEventHandler<String> DETECTOR_POWERED = GROUP.common("detectorPowered", Extra.STRING, () -> DetectorBlockKubeEvent.class);
SpecializedEventHandler<String> DETECTOR_UNPOWERED = GROUP.common("detectorUnpowered", Extra.STRING, () -> DetectorBlockKubeEvent.class);
SpecializedEventHandler<ResourceKey<Block>> FARMLAND_TRAMPLED = GROUP.common("farmlandTrampled", SUPPORTS_BLOCK, () -> FarmlandTrampledKubeEvent.class).hasResult();
SpecializedEventHandler<ResourceKey<Block>> RANDOM_TICK = GROUP.server("randomTick", SUPPORTS_BLOCK, () -> RandomTickKubeEvent.class).hasResult().required();
TargetedEventHandler<ResourceKey<Block>> RIGHT_CLICKED = GROUP.common("rightClicked", () -> BlockRightClickedKubeEvent.class).hasResult().supportsTarget(TARGET);
TargetedEventHandler<ResourceKey<Block>> LEFT_CLICKED = GROUP.common("leftClicked", () -> BlockLeftClickedKubeEvent.class).hasResult().supportsTarget(TARGET);
TargetedEventHandler<ResourceKey<Block>> PLACED = GROUP.common("placed", () -> BlockPlacedKubeEvent.class).hasResult().supportsTarget(TARGET);
TargetedEventHandler<ResourceKey<Block>> BROKEN = GROUP.common("broken", () -> BlockBrokenKubeEvent.class).hasResult().supportsTarget(TARGET);
TargetedEventHandler<ResourceKey<Block>> DROPS = GROUP.server("drops", () -> BlockDropsKubeEvent.class).hasResult().supportsTarget(TARGET);
TargetedEventHandler<String> DETECTOR_CHANGED = GROUP.common("detectorChanged", () -> DetectorBlockKubeEvent.class).supportsTarget(EventTargetType.STRING);
TargetedEventHandler<String> DETECTOR_POWERED = GROUP.common("detectorPowered", () -> DetectorBlockKubeEvent.class).supportsTarget(EventTargetType.STRING);
TargetedEventHandler<String> DETECTOR_UNPOWERED = GROUP.common("detectorUnpowered", () -> DetectorBlockKubeEvent.class).supportsTarget(EventTargetType.STRING);
TargetedEventHandler<ResourceKey<Block>> FARMLAND_TRAMPLED = GROUP.common("farmlandTrampled", () -> FarmlandTrampledKubeEvent.class).hasResult().supportsTarget(TARGET);
TargetedEventHandler<ResourceKey<Block>> RANDOM_TICK = GROUP.server("randomTick", () -> RandomTickKubeEvent.class).hasResult().requiredTarget(TARGET);
TargetedEventHandler<ResourceKey<Block>> BLOCK_ENTITY_TICK = GROUP.common("blockEntityTick", () -> BlockEntityTickKubeEvent.class).requiredTarget(TARGET);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
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.Extra;
import dev.latvian.mods.kubejs.event.SpecializedEventHandler;
import dev.latvian.mods.kubejs.event.EventTargetType;
import dev.latvian.mods.kubejs.event.TargetedEventHandler;
import net.minecraft.resources.ResourceLocation;

public interface ClientEvents {
Expand All @@ -27,6 +27,6 @@ public interface ClientEvents {
EventHandler TICK = GROUP.client("tick", () -> ClientPlayerKubeEvent.class);
EventHandler DEBUG_LEFT = GROUP.client("leftDebugInfo", () -> DebugInfoKubeEvent.class);
EventHandler DEBUG_RIGHT = GROUP.client("rightDebugInfo", () -> DebugInfoKubeEvent.class);
SpecializedEventHandler<ResourceLocation> ATLAS_SPRITE_REGISTRY = GROUP.client("atlasSpriteRegistry", Extra.ID, () -> AtlasSpriteRegistryKubeEvent.class).required();
SpecializedEventHandler<String> LANG = GROUP.client("lang", Extra.STRING, () -> LangKubeEvent.class).required();
TargetedEventHandler<ResourceLocation> ATLAS_SPRITE_REGISTRY = GROUP.client("atlasSpriteRegistry", () -> AtlasSpriteRegistryKubeEvent.class).requiredTarget(EventTargetType.ID);
TargetedEventHandler<String> LANG = GROUP.client("lang", () -> LangKubeEvent.class).requiredTarget(EventTargetType.STRING);
}
Loading

0 comments on commit f98a525

Please sign in to comment.