Skip to content

Commit

Permalink
feat: port to 1.19.2
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHillcox committed Jan 25, 2023
1 parent 33ab39b commit 8f86748
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 44 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Kube Utils Changelog

## [0.1.3]
## [1.0.0]

### Added

- Released for 1.18.2
- Ported 1.19.2
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
6 changes: 3 additions & 3 deletions src/main/java/pro/mikey/kubeutils/kubejs/modules/Fluids.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public List<Fluid> 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();
}
Expand All @@ -40,13 +40,13 @@ public List<Fluid> getFluidsByNamespace(@Nullable String namespace) {
* @return a list of fluids that belong to that namespace
*/
@Nullable
public List<Fluid> getFluidsByNamespaces(@Nullable ListJS namespaces) {
public List<Fluid> getFluidsByNamespaces(@Nullable List<String> 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();
}
Expand Down
25 changes: 12 additions & 13 deletions src/main/java/pro/mikey/kubeutils/kubejs/modules/LevelUtils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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();
}

/**
Expand Down Expand Up @@ -62,7 +62,7 @@ public List<LivingEntity> 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;
}
Expand Down Expand Up @@ -178,29 +178,28 @@ public List<BlockPos> 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<ConfiguredStructureFeature<?, ?>> getStructuresAtLocation(BlockPos pos) {
return level.structureFeatureManager().getAllStructuresAt(pos).keySet();
public Set<Structure> 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<ResourceLocation> 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();
}
}
18 changes: 11 additions & 7 deletions src/main/java/pro/mikey/kubeutils/kubejs/modules/ListActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -18,7 +18,7 @@ public StreamsHelper() {
*
* @return List of {@link BlockContainerJS}
*/
public List<BlockContainerJS> mapToBlock(ServerLevelJS level, List<BlockPos> locations) {
return locations.stream().map(level::getBlock).toList();
public List<BlockContainerJS> mapToBlock(ServerLevel level, List<BlockPos> locations) {
return locations.stream().map(level::kjs$getBlock).toList();
}
}
5 changes: 1 addition & 4 deletions src/main/java/pro/mikey/kubeutils/kubejs/modules/Utils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}

/**
Expand Down
10 changes: 4 additions & 6 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
modLoader = "javafml"
loaderVersion = "[40,)"
loaderVersion = "[43,)"
license = "GPL3"

[[mods]]
Expand All @@ -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"

0 comments on commit 8f86748

Please sign in to comment.