From 8f8674884c7713c3614d396e0991c9ab4694fe29 Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Wed, 25 Jan 2023 20:07:36 +0000 Subject: [PATCH] feat: port to 1.19.2 --- CHANGELOG.md | 4 +-- build.gradle | 4 +-- gradle.properties | 6 ++--- .../kubeutils/kubejs/KubeUtilsPlugin.java | 2 +- .../kubeutils/kubejs/modules/Fluids.java | 6 ++--- .../kubeutils/kubejs/modules/LevelUtils.java | 25 +++++++++---------- .../kubeutils/kubejs/modules/ListActions.java | 18 +++++++------ .../kubejs/modules/StreamsHelper.java | 6 ++--- .../mikey/kubeutils/kubejs/modules/Utils.java | 5 +--- src/main/resources/META-INF/mods.toml | 10 +++----- 10 files changed, 42 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e488ad..dd8c2f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Kube Utils Changelog -## [0.1.3] +## [1.0.0] ### Added -- Released for 1.18.2 +- Ported 1.19.2 diff --git a/build.gradle b/build.gradle index de8c1a0..e6843f4 100644 --- a/build.gradle +++ b/build.gradle @@ -48,8 +48,8 @@ dependencies { forge "net.minecraftforge:forge:${project.forge_version}" - modApi "dev.latvian.mods:kubejs-forge:1802.5.4-build.533" - modApi "dev.latvian.mods:rhino-forge:1802.1.14-build.206" + modApi "dev.latvian.mods:kubejs-forge:1902.6.0-build.140" + modApi "dev.latvian.mods:rhino-forge:1902.2.2-build.264" } processResources { diff --git a/gradle.properties b/gradle.properties index 54a8843..561fd52 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,10 @@ org.gradle.jvmargs=-Xmx1G loom.platform=forge -minecraft_version=1.18.2 -forge_version=1.18.2-40.1.54 +minecraft_version=1.19.2 +forge_version=1.19.2-43.2.3 -mod_version=0.1.3 +mod_version=1.0.0 maven_group=pro.mikey.mods archives_base_name=kube-utils mod_id=kubeutils diff --git a/src/main/java/pro/mikey/kubeutils/kubejs/KubeUtilsPlugin.java b/src/main/java/pro/mikey/kubeutils/kubejs/KubeUtilsPlugin.java index 9dfbc21..9abcb8f 100644 --- a/src/main/java/pro/mikey/kubeutils/kubejs/KubeUtilsPlugin.java +++ b/src/main/java/pro/mikey/kubeutils/kubejs/KubeUtilsPlugin.java @@ -5,7 +5,7 @@ public class KubeUtilsPlugin extends KubeJSPlugin { @Override - public void addBindings(BindingsEvent event) { + public void registerBindings(BindingsEvent event) { event.add("Ku", BaseBindings.class); } } diff --git a/src/main/java/pro/mikey/kubeutils/kubejs/modules/Fluids.java b/src/main/java/pro/mikey/kubeutils/kubejs/modules/Fluids.java index 297867c..f288344 100644 --- a/src/main/java/pro/mikey/kubeutils/kubejs/modules/Fluids.java +++ b/src/main/java/pro/mikey/kubeutils/kubejs/modules/Fluids.java @@ -27,7 +27,7 @@ public List getFluidsByNamespace(@Nullable String namespace) { } return ForgeRegistries.FLUIDS.getValues().stream() - .filter(e -> e.getRegistryName().getNamespace().equals(namespace)) + .filter(e -> ForgeRegistries.FLUIDS.getKey(e).getNamespace().equals(namespace)) .filter(this::notEmpty) .toList(); } @@ -40,13 +40,13 @@ public List getFluidsByNamespace(@Nullable String namespace) { * @return a list of fluids that belong to that namespace */ @Nullable - public List getFluidsByNamespaces(@Nullable ListJS namespaces) { + public List getFluidsByNamespaces(@Nullable List namespaces) { if (namespaces == null || namespaces.isEmpty()) { return List.of(); } return ForgeRegistries.FLUIDS.getValues().stream() - .filter(e -> namespaces.stream().anyMatch(x -> e.getRegistryName().getNamespace().equals(x))) + .filter(e -> namespaces.stream().anyMatch(x -> ForgeRegistries.FLUIDS.getKey(e).getNamespace().equals(x))) .filter(this::notEmpty) .toList(); } diff --git a/src/main/java/pro/mikey/kubeutils/kubejs/modules/LevelUtils.java b/src/main/java/pro/mikey/kubeutils/kubejs/modules/LevelUtils.java index b954e4d..31d6c9f 100644 --- a/src/main/java/pro/mikey/kubeutils/kubejs/modules/LevelUtils.java +++ b/src/main/java/pro/mikey/kubeutils/kubejs/modules/LevelUtils.java @@ -1,6 +1,5 @@ package pro.mikey.kubeutils.kubejs.modules; -import dev.latvian.mods.kubejs.level.ServerLevelJS; import net.minecraft.core.BlockPos; import net.minecraft.core.Registry; import net.minecraft.core.Vec3i; @@ -11,11 +10,12 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.levelgen.structure.Structure; import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; import net.minecraft.world.phys.AABB; +import net.minecraftforge.registries.ForgeRegistries; import pro.mikey.kubeutils.KubeUtils; import javax.annotation.Nullable; @@ -26,8 +26,8 @@ public class LevelUtils { private static final ResourceLocation UNKNOWN = new ResourceLocation(KubeUtils.getId(), "unknown"); private final ServerLevel level; - public LevelUtils(ServerLevelJS level) { - this.level = level.getMinecraftLevel(); + public LevelUtils(ServerLevel level) { + this.level = level.getLevel(); } /** @@ -62,7 +62,7 @@ public List findEntitiesWithinRadius(ResourceLocation entityId, Bl continue; } - ResourceLocation registryName = current.getType().getRegistryName(); + ResourceLocation registryName = ForgeRegistries.ENTITY_TYPES.getKey(current.getType()); if (registryName == null || !registryName.equals(entityId)) { continue; } @@ -178,29 +178,28 @@ public List seekCollectionOfBlocks(BlockPos startingPos, int range, Pr * @return if the structure is there. */ public boolean isStructureAtLocation(BlockPos pos, ResourceLocation structureId) { - ConfiguredStructureFeature configuredStructureFeature = level.getServer().registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY).get(structureId); - if (configuredStructureFeature == null) { + Structure structure = level.getServer().registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY).get(structureId); + if (structure == null) { return false; } - return level.structureFeatureManager().getStructureAt(pos, configuredStructureFeature).isValid(); + return level.structureManager().getStructureAt(pos, structure).isValid(); } /** * Gets all the structures at a given block location * - * @param pos the block location you want to check - * + * @param pos the block location you want to check * @return a list (set) of the structures at that location */ - public Set> getStructuresAtLocation(BlockPos pos) { - return level.structureFeatureManager().getAllStructuresAt(pos).keySet(); + public Set getStructuresAtLocation(BlockPos pos) { + return level.structureManager().getAllStructuresAt(pos).keySet(); } /** * Gets all the structure ids at a given location, just like {@link #getRandomLocation(BlockPos, int, int)} */ public List getStructureIdsAtLocation(BlockPos pos) { - return getStructuresAtLocation(pos).stream().map(e -> e.feature.getRegistryName() == null ? UNKNOWN : e.feature.getRegistryName()).toList(); + return getStructuresAtLocation(pos).stream().map(e -> Registry.STRUCTURE_TYPES.getKey(e.type())).toList(); } } diff --git a/src/main/java/pro/mikey/kubeutils/kubejs/modules/ListActions.java b/src/main/java/pro/mikey/kubeutils/kubejs/modules/ListActions.java index 259ec64..64170bb 100644 --- a/src/main/java/pro/mikey/kubeutils/kubejs/modules/ListActions.java +++ b/src/main/java/pro/mikey/kubeutils/kubejs/modules/ListActions.java @@ -5,6 +5,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.List; +import java.util.Map; + public class ListActions { private static final Logger LOGGER = LoggerFactory.getLogger(ListActions.class); @@ -16,22 +19,23 @@ public ListActions() { * which is type cast to a double. This method will then use the weight to find a single item based on * a random selection that takes the items weight into consideration * - * @param items {@link MapJS} of {@link Object} entry, and a {@link Object} weight + * @param items List of Map<{weight: double, entry: any}> * * @return one of the items from the array */ - public Object getEntryBasedOnWeight(ListJS items) { + public Object getEntryBasedOnWeight(Object... items) { double totalWeight = 0.0; - for (Object i : items) { - totalWeight += ((Number) ((MapJS) i).get("weight")).doubleValue(); + var inputs = ListJS.orSelf(items).stream().map(MapJS::of).toList(); + for (Map input : inputs) { + totalWeight += ((Number) input.get("weight")).doubleValue(); } int idx = 0; - for (double r = Math.random() * totalWeight; idx < items.size() - 1; ++idx) { - r -= ((Number) ((MapJS) items.get(idx)).get("weight")).doubleValue(); + for (double r = Math.random() * totalWeight; idx < inputs.size() - 1; ++idx) { + r -= ((Number) inputs.get(idx).get("weight")).doubleValue(); if (r <= 0.0) break; } - return ((MapJS) items.get(idx)).get("entry"); + return inputs.get(idx).get("entry"); } } diff --git a/src/main/java/pro/mikey/kubeutils/kubejs/modules/StreamsHelper.java b/src/main/java/pro/mikey/kubeutils/kubejs/modules/StreamsHelper.java index d5bd84a..0d2af51 100644 --- a/src/main/java/pro/mikey/kubeutils/kubejs/modules/StreamsHelper.java +++ b/src/main/java/pro/mikey/kubeutils/kubejs/modules/StreamsHelper.java @@ -1,8 +1,8 @@ package pro.mikey.kubeutils.kubejs.modules; import dev.latvian.mods.kubejs.level.BlockContainerJS; -import dev.latvian.mods.kubejs.level.ServerLevelJS; import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; import java.util.List; @@ -18,7 +18,7 @@ public StreamsHelper() { * * @return List of {@link BlockContainerJS} */ - public List mapToBlock(ServerLevelJS level, List locations) { - return locations.stream().map(level::getBlock).toList(); + public List mapToBlock(ServerLevel level, List locations) { + return locations.stream().map(level::kjs$getBlock).toList(); } } diff --git a/src/main/java/pro/mikey/kubeutils/kubejs/modules/Utils.java b/src/main/java/pro/mikey/kubeutils/kubejs/modules/Utils.java index 2ac8a55..9ffdc41 100644 --- a/src/main/java/pro/mikey/kubeutils/kubejs/modules/Utils.java +++ b/src/main/java/pro/mikey/kubeutils/kubejs/modules/Utils.java @@ -1,12 +1,9 @@ package pro.mikey.kubeutils.kubejs.modules; -import dev.latvian.mods.kubejs.entity.EntityJS; import dev.latvian.mods.kubejs.item.ItemStackJS; import dev.latvian.mods.kubejs.level.BlockContainerJS; import dev.latvian.mods.rhino.Undefined; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -55,7 +52,7 @@ public boolean nullOrEmpty(Object entry) { return ((ItemEntity) entry).isRemoved() || ((ItemEntity) entry).getItem().isEmpty(); } - return entry instanceof ItemStackJS && entry == ItemStackJS.EMPTY; + return false; } /** diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 797354a..907ea10 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader = "javafml" -loaderVersion = "[40,)" +loaderVersion = "[43,)" license = "GPL3" [[mods]] @@ -14,22 +14,20 @@ Provides extra methods and tools to the standard KubeJS mod [[dependencies.kubeutils]] modId = "forge" mandatory = true -versionRange = "[40,)" +versionRange = "[43,)" ordering = "NONE" side = "BOTH" [[dependencies.kubeutils]] modId = "minecraft" mandatory = true -versionRange = "[1.18.2,)" +versionRange = "[1.19.2,)" ordering = "NONE" side = "BOTH" [[dependencies.kubeutils]] modId = "kubejs" mandatory = true -# See above for how to read this notation, this essentially means any -# version of Minecraft from 1.18.2 (inclusive). -versionRange = "[1802.5.4-build.533,)" +versionRange = "[1902.6.0-build.140,)" ordering = "NONE" side = "BOTH"