Skip to content

Commit

Permalink
Ported to 1.21, added few new icons, replaced custom ingredient actio…
Browse files Browse the repository at this point in the history
…n callbacks with an event
  • Loading branch information
LatvianModder committed Jun 14, 2024
1 parent 849393f commit d631de5
Show file tree
Hide file tree
Showing 142 changed files with 1,485 additions and 1,556 deletions.
2 changes: 1 addition & 1 deletion .kubejs/meta.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"minecraft": 2006,
"minecraft": 2100,
"type": "neoforge",
"version": {
"file": "gradle.properties",
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ dependencies {
minecraft "com.mojang:minecraft:$minecraft_version"
mappings loom.layered() {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-$minecraft_version:$parchment_version@zip")
parchment("org.parchmentmc.data:parchment-1.20.6:$parchment_version@zip")
}

neoForge("net.neoforged:neoforge:$neoforge_version")
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ mod_author=latvian.dev
curseforge_id=238086
modrinth_id=umyGl7zF

minecraft_version=1.20.6
mod_version=2006.7.0
minecraft_version=1.21
mod_version=2100.7.0

neoforge_version=20.6.115
parchment_version=2024.05.01
rhino_version=2006.2.5-build.25
architectury_version=12.1.3
neoforge_version=21.0.6-beta
parchment_version=2024.06.02
rhino_version=2100.2.5-build.28
architectury_version=13.0.1

rei_version=15.0.728
#rei_comp_version=9.0.16
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ pluginManagement {
}
}

rootProject.name = 'KubeJS-1.20.6'
rootProject.name = 'KubeJS-1.21'
40 changes: 31 additions & 9 deletions src/main/java/dev/latvian/mods/kubejs/BuiltinKubeJSPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
import dev.latvian.mods.kubejs.block.entity.InventoryAttachment;
import dev.latvian.mods.kubejs.block.state.BlockStatePredicate;
import dev.latvian.mods.kubejs.client.painter.Painter;
import dev.latvian.mods.kubejs.client.painter.screen.AtlasTextureObject;
import dev.latvian.mods.kubejs.client.painter.screen.GradientObject;
import dev.latvian.mods.kubejs.client.painter.screen.ItemObject;
import dev.latvian.mods.kubejs.client.painter.screen.LineObject;
import dev.latvian.mods.kubejs.client.painter.screen.RectangleObject;
import dev.latvian.mods.kubejs.client.painter.screen.ScreenGroup;
import dev.latvian.mods.kubejs.client.painter.screen.TextObject;
import dev.latvian.mods.kubejs.color.Color;
import dev.latvian.mods.kubejs.core.PlayerSelector;
import dev.latvian.mods.kubejs.event.EventGroupRegistry;
Expand All @@ -61,20 +68,19 @@
import dev.latvian.mods.kubejs.item.ItemEnchantmentsWrapper;
import dev.latvian.mods.kubejs.item.ItemStackJS;
import dev.latvian.mods.kubejs.item.ItemTintFunction;
import dev.latvian.mods.kubejs.item.JukeboxSongBuilder;
import dev.latvian.mods.kubejs.item.creativetab.CreativeTabBuilder;
import dev.latvian.mods.kubejs.item.custom.ArmorItemBuilder;
import dev.latvian.mods.kubejs.item.custom.BasicItemJS;
import dev.latvian.mods.kubejs.item.custom.DiggerItemBuilder;
import dev.latvian.mods.kubejs.item.custom.ItemToolTierRegistryKubeEvent;
import dev.latvian.mods.kubejs.item.custom.RecordItemJS;
import dev.latvian.mods.kubejs.item.custom.ShearsItemBuilder;
import dev.latvian.mods.kubejs.item.custom.SmithingTemplateItemBuilder;
import dev.latvian.mods.kubejs.item.custom.SwordItemBuilder;
import dev.latvian.mods.kubejs.item.ingredient.IngredientJS;
import dev.latvian.mods.kubejs.level.ruletest.KubeJSRuleTests;
import dev.latvian.mods.kubejs.misc.BasicMobEffect;
import dev.latvian.mods.kubejs.misc.CustomStatBuilder;
import dev.latvian.mods.kubejs.misc.EnchantmentBuilder;
import dev.latvian.mods.kubejs.misc.PaintingVariantBuilder;
import dev.latvian.mods.kubejs.misc.ParticleTypeBuilder;
import dev.latvian.mods.kubejs.misc.PoiTypeBuilder;
Expand Down Expand Up @@ -145,7 +151,6 @@
import dev.latvian.mods.kubejs.util.registrypredicate.RegistryPredicate;
import dev.latvian.mods.rhino.type.RecordTypeInfo;
import dev.latvian.mods.rhino.type.TypeInfo;
import dev.latvian.mods.unit.Unit;
import net.minecraft.commands.arguments.selector.EntitySelector;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Vec3i;
Expand Down Expand Up @@ -176,11 +181,11 @@
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.component.Fireworks;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.ItemEnchantments;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.properties.BlockSetType;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.levelgen.structure.templatesystem.RuleTest;
import net.minecraft.world.level.material.MapColor;
Expand All @@ -189,7 +194,10 @@
import net.minecraft.world.level.storage.loot.providers.number.NumberProvider;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.common.ToolAction;
import net.neoforged.neoforge.common.crafting.SizedIngredient;
import net.neoforged.neoforge.fluids.FluidStack;
import net.neoforged.neoforge.fluids.crafting.FluidIngredient;
Expand Down Expand Up @@ -261,12 +269,11 @@ public void registerBuilderTypes(BuilderTypeRegistry registry) {
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);
// FIXME 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);
Expand All @@ -277,6 +284,7 @@ public void registerBuilderTypes(BuilderTypeRegistry registry) {
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);
registry.addDefault(Registries.JUKEBOX_SONG, JukeboxSongBuilder.class, JukeboxSongBuilder::new);
}

@Override
Expand Down Expand Up @@ -383,7 +391,8 @@ public void registerBindings(BindingRegistry bindings) {
}

bindings.add("JavaMath", Math.class);
bindings.add("ResourceLocation", ResourceLocation.class);
bindings.add("ID", ID.class);

bindings.add("Duration", Duration.class);

// event.add("onEvent", new LegacyCodeHandler("onEvent()"));
Expand Down Expand Up @@ -472,7 +481,6 @@ public void registerTypeWrappers(TypeWrapperRegistry registry) {
registry.register(JsonPrimitive.class, JsonUtils::primitiveOf);
registry.register(Path.class, KubeJSTypeWrappers::pathOf);
registry.register(File.class, KubeJSTypeWrappers::fileOf);
registry.register(Unit.class, Painter.INSTANCE::unitOf);
registry.register(TemporalAmount.class, TimeJS::temporalAmountOf);
registry.register(Duration.class, TimeJS::durationOf);

Expand All @@ -499,8 +507,10 @@ public void registerTypeWrappers(TypeWrapperRegistry registry) {
registry.register(NumberProvider.class, KubeJSTypeWrappers::numberProviderOf);
registry.registerEnumFromStringCodec(LootContext.EntityTarget.class, LootContext.EntityTarget.CODEC);
registry.registerEnumFromStringCodec(CopyNameFunction.NameSource.class, CopyNameFunction.NameSource.CODEC);
registry.register(Enchantment.Cost.class, EnchantmentBuilder::costOf);
// FIXME registry.register(Enchantment.Cost.class, EnchantmentBuilder::costOf);
registry.registerEnumFromStringCodec(ArmorItem.Type.class, ArmorItem.Type.CODEC);
registry.register(BlockSetType.class, BlockWrapper::setTypeOf);
registry.register(ToolAction.class, ItemWrapper::toolActionOf);

// KubeJS //
registry.register(Map.class, MapJS::of);
Expand Down Expand Up @@ -621,6 +631,18 @@ public void registerIngredientActionTypes(IngredientActionTypeRegistry registry)
registry.register(ReplaceAction.TYPE);
}

@Override
@OnlyIn(Dist.CLIENT)
public void painterRegistry(Painter painter) {
painter.registerObject("screen_group", ScreenGroup::new);
painter.registerObject("rectangle", RectangleObject::new);
painter.registerObject("text", TextObject::new);
painter.registerObject("atlas_texture", AtlasTextureObject::new);
painter.registerObject("gradient", GradientObject::new);
painter.registerObject("item", ItemObject::new);
painter.registerObject("line", LineObject::new);
}

@Override
public void clearCaches() {
ItemStackJS.CACHED_ITEM_MAP.forget();
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/dev/latvian/mods/kubejs/KubeJS.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import net.neoforged.bus.api.EventPriority;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.DistExecutor;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModList;
import net.neoforged.fml.common.EventBusSubscriber;
Expand Down Expand Up @@ -80,12 +79,12 @@ public class KubeJS {
public static String VERSION = "0";

public static ResourceLocation id(String path) {
return new ResourceLocation(MOD_ID, path);
return ResourceLocation.fromNamespaceAndPath(MOD_ID, path);
}

public static ModContainer thisMod;

public static KubeJSCommon PROXY;
public static KubeJSCommon PROXY = new KubeJSCommon();

private static ScriptManager startupScriptManager, clientScriptManager;

Expand Down Expand Up @@ -126,8 +125,7 @@ public KubeJS(IEventBus bus, Dist dist, ModContainer mod) throws Throwable {
}
}

//noinspection removal
PROXY = DistExecutor.safeRunForDist(() -> KubeJSClient::new, () -> KubeJSCommon::new);
PROXY = new KubeJSClient();

if (!PlatformWrapper.isGeneratingData()) {
new KubeJSBackgroundThread().start();
Expand Down Expand Up @@ -156,8 +154,6 @@ public KubeJS(IEventBus bus, Dist dist, ModContainer mod) throws Throwable {

KubeJSPlugins.forEachPlugin(KubeJSPlugin::initStartup);

PROXY.init();

for (var key : StartupEvents.REGISTRY.findUniqueExtraIds(ScriptType.STARTUP)) {
StartupEvents.REGISTRY.post(new RegistryKubeEvent<>((ResourceKey) key), key);
}
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/dev/latvian/mods/kubejs/KubeJSCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
import java.util.List;

public class KubeJSCommon {
public void init() {
}

public void reloadClientInternal() {
}

Expand Down
10 changes: 7 additions & 3 deletions src/main/java/dev/latvian/mods/kubejs/KubeJSPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dev.latvian.mods.kubejs.block.entity.BlockEntityAttachmentType;
import dev.latvian.mods.kubejs.client.LangKubeEvent;
import dev.latvian.mods.kubejs.client.painter.Painter;
import dev.latvian.mods.kubejs.core.RecipeManagerKJS;
import dev.latvian.mods.kubejs.event.EventGroup;
import dev.latvian.mods.kubejs.event.EventGroupRegistry;
Expand All @@ -26,6 +27,8 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.level.Level;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;

import java.util.List;
import java.util.Map;
Expand All @@ -37,9 +40,6 @@ default void init() {
default void initStartup() {
}

default void clientInit() {
}

default void afterInit() {
}

Expand Down Expand Up @@ -82,6 +82,10 @@ default void registerBlockEntityAttachments(List<BlockEntityAttachmentType> type
default void registerIngredientActionTypes(IngredientActionTypeRegistry registry) {
}

@OnlyIn(Dist.CLIENT)
default void painterRegistry(Painter painter) {
}

default void attachServerData(AttachedData<MinecraftServer> event) {
}

Expand Down
44 changes: 24 additions & 20 deletions src/main/java/dev/latvian/mods/kubejs/bindings/BlockWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
import dev.latvian.mods.kubejs.block.predicate.BlockPredicate;
import dev.latvian.mods.kubejs.registry.RegistryInfo;
import dev.latvian.mods.kubejs.typings.Info;
import dev.latvian.mods.kubejs.util.Cast;
import dev.latvian.mods.kubejs.util.Tags;
import dev.latvian.mods.rhino.Context;
import dev.latvian.mods.rhino.type.RecordTypeInfo;
import dev.latvian.mods.rhino.type.TypeInfo;
import net.minecraft.Util;
import net.minecraft.commands.arguments.blocks.BlockStateParser;
import net.minecraft.core.Direction;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockSetType;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
Expand All @@ -25,7 +29,6 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;

@Info("Various block related helper functions")
public class BlockWrapper {
Expand Down Expand Up @@ -118,28 +121,29 @@ public static BlockState parseBlockState(String string) {
return Blocks.AIR.defaultBlockState();
}

var i = string.indexOf('[');
var hasProperties = i >= 0 && string.indexOf(']') == string.length() - 1;
var state = RegistryInfo.BLOCK.getValue(new ResourceLocation(hasProperties ? string.substring(0, i) : string)).defaultBlockState();

if (hasProperties) {
for (var s : string.substring(i + 1, string.length() - 1).split(",")) {
var s1 = s.split("=", 2);

if (s1.length == 2 && !s1[0].isEmpty() && !s1[1].isEmpty()) {
var p = state.getBlock().getStateDefinition().getProperty(s1[0]);
try {
return BlockStateParser.parseForBlock(BuiltInRegistries.BLOCK.asLookup(), string, false).blockState();
} catch (Exception ex) {
return Blocks.AIR.defaultBlockState();
}
}

if (p != null) {
Optional<?> o = p.getValue(s1[1]);
public static BlockSetType setTypeOf(Context cx, Object from, TypeInfo target) {
return switch (from) {
case null -> null;
case BlockSetType type -> type;
case CharSequence charSequence -> {
var str = charSequence.toString();

if (o.isPresent()) {
state = state.setValue(p, Cast.to(o.get()));
}
for (var type : BlockSetType.values().toList()) {
if (type.name().equalsIgnoreCase(str)) {
yield type;
}
}
}
}

return state;
yield null;
}
default -> (BlockSetType) ((RecordTypeInfo) target).wrap(cx, from, target);
};
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package dev.latvian.mods.kubejs.bindings;

import dev.latvian.mods.kubejs.helpers.IngredientHelper;
import dev.latvian.mods.kubejs.recipe.ingredientaction.CustomIngredientAction;
import dev.latvian.mods.kubejs.recipe.ingredientaction.CustomIngredientActionCallback;
import dev.latvian.mods.kubejs.typings.Info;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
Expand All @@ -26,11 +24,6 @@ static SizedIngredient of(Ingredient ingredient, int count) {
return ingredient.kjs$withCount(count);
}

@Info("Register a custom ingredient action for use in recipes with Recipe#customIngredientAction")
static void registerCustomIngredientAction(String id, CustomIngredientActionCallback callback) {
CustomIngredientAction.MAP.put(id, callback);
}

@Info("""
Checks if the passed in object is an Ingredient.
Note that this does not mean it will not function as an Ingredient if passed to something that requests one.
Expand Down
Loading

0 comments on commit d631de5

Please sign in to comment.