switch to resource based KubeJS binding

This commit is contained in:
Relentless 2023-08-10 22:00:03 +02:00
parent ae6c979827
commit 050ce63593
No known key found for this signature in database
GPG key ID: 50C5FD225130D790
5 changed files with 66 additions and 82 deletions

View file

@ -1,12 +1,8 @@
package com.almostreliable.unified.compat; package com.almostreliable.unified.compat;
import com.almostreliable.unified.AlmostUnified; import com.almostreliable.unified.AlmostUnified;
import com.almostreliable.unified.BuildConfig;
import com.almostreliable.unified.config.UnifyConfig; import com.almostreliable.unified.config.UnifyConfig;
import com.almostreliable.unified.utils.UnifyTag; import com.almostreliable.unified.utils.UnifyTag;
import dev.latvian.mods.kubejs.KubeJSPlugin;
import dev.latvian.mods.kubejs.item.ItemStackJS;
import dev.latvian.mods.kubejs.script.BindingsEvent;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@ -17,22 +13,17 @@ import javax.annotation.Nullable;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class AlmostKube extends KubeJSPlugin { @SuppressWarnings("unused")
public final class AlmostKube {
@Override private AlmostKube() {}
public void registerBindings(BindingsEvent event) {
if (event.getType().isServer()) {
event.add(BuildConfig.MOD_NAME, UnifyWrapper.class);
}
}
public static class UnifyWrapper {
@Nullable @Nullable
public static String getPreferredTagForItem(ItemStack stack) { public static String getPreferredTagForItem(ItemStack stack) {
UnifyTag<Item> tag = AlmostUnified UnifyTag<Item> tag = AlmostUnified
.getRuntime() .getRuntime()
.getReplacementMap() .getReplacementMap()
.orElseThrow(UnifyWrapper::notLoadedException) .orElseThrow(AlmostKube::notLoadedException)
.getPreferredTagForItem(getId(stack)); .getPreferredTagForItem(getId(stack));
return tag == null ? null : tag.location().toString(); return tag == null ? null : tag.location().toString();
} }
@ -41,9 +32,9 @@ public class AlmostKube extends KubeJSPlugin {
ResourceLocation replacement = AlmostUnified ResourceLocation replacement = AlmostUnified
.getRuntime() .getRuntime()
.getReplacementMap() .getReplacementMap()
.orElseThrow(UnifyWrapper::notLoadedException) .orElseThrow(AlmostKube::notLoadedException)
.getReplacementForItem(getId(stack)); .getReplacementForItem(getId(stack));
return ItemStackJS.of(replacement); return Registry.ITEM.get(replacement).getDefaultInstance();
} }
public static ItemStack getPreferredItemForTag(ResourceLocation tag) { public static ItemStack getPreferredItemForTag(ResourceLocation tag) {
@ -51,16 +42,16 @@ public class AlmostKube extends KubeJSPlugin {
ResourceLocation item = AlmostUnified ResourceLocation item = AlmostUnified
.getRuntime() .getRuntime()
.getReplacementMap() .getReplacementMap()
.orElseThrow(UnifyWrapper::notLoadedException) .orElseThrow(AlmostKube::notLoadedException)
.getPreferredItemForTag(asUnifyTag, $ -> true); .getPreferredItemForTag(asUnifyTag, $ -> true);
return ItemStackJS.of(item); return Registry.ITEM.get(item).getDefaultInstance();
} }
public static Set<String> getTags() { public static Set<String> getTags() {
return AlmostUnified return AlmostUnified
.getRuntime() .getRuntime()
.getFilteredTagMap() .getFilteredTagMap()
.orElseThrow(UnifyWrapper::notLoadedException) .orElseThrow(AlmostKube::notLoadedException)
.getTags() .getTags()
.stream() .stream()
.map(tag -> tag.location().toString()) .map(tag -> tag.location().toString())
@ -72,15 +63,15 @@ public class AlmostKube extends KubeJSPlugin {
return AlmostUnified return AlmostUnified
.getRuntime() .getRuntime()
.getFilteredTagMap() .getFilteredTagMap()
.orElseThrow(UnifyWrapper::notLoadedException) .orElseThrow(AlmostKube::notLoadedException)
.getItemsByTag(asUnifyTag) .getEntriesByTag(asUnifyTag)
.stream() .stream()
.map(ResourceLocation::toString) .map(ResourceLocation::toString)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
public static UnifyConfig getUnifyConfig() { public static UnifyConfig getUnifyConfig() {
return AlmostUnified.getRuntime().getUnifyConfig().orElseThrow(UnifyWrapper::notLoadedException); return AlmostUnified.getRuntime().getUnifyConfig().orElseThrow(AlmostKube::notLoadedException);
} }
private static ResourceLocation getId(ItemStack stack) { private static ResourceLocation getId(ItemStack stack) {
@ -92,7 +83,7 @@ public class AlmostKube extends KubeJSPlugin {
private static IllegalStateException notLoadedException() { private static IllegalStateException notLoadedException() {
return new IllegalStateException( return new IllegalStateException(
"AlmostUnified runtime is not available in KubeJS! Possible reasons: calling runtime too early, not in a server environment"); "AlmostUnifiedRuntime is unavailable in KubeJS! Possible reasons: calling runtime too early, not in a server environment"
} );
} }
} }

View file

@ -0,0 +1 @@
* AlmostUnified com.almostreliable.unified.compat.AlmostKube

View file

@ -35,7 +35,6 @@
}, },
"suggests": { "suggests": {
"jei": ">=${jeiVersion}", "jei": ">=${jeiVersion}",
"roughlyenoughitems": ">=${reiVersion}", "roughlyenoughitems": ">=${reiVersion}"
"kubejs": ">=${kubejsVersion}"
} }
} }

View file

@ -38,10 +38,3 @@ mandatory = false
versionRange = "[${reiVersion},)" versionRange = "[${reiVersion},)"
ordering = "BEFORE" ordering = "BEFORE"
side = "BOTH" side = "BOTH"
[[dependencies."${modId}"]]
modId = "kubejs"
mandatory = false
versionRange = "[${kubejsVersion},)"
ordering = "BEFORE"
side = "BOTH"

View file

@ -30,7 +30,7 @@ fabricApiVersion = 0.76.0
fabricRecipeViewer = rei fabricRecipeViewer = rei
# Forge Dependencies # Forge Dependencies
forgeVersion = 43.2.10 forgeVersion = 43.2.0
forgeRecipeViewer = jei forgeRecipeViewer = jei
# Github # Github