mirror of
https://github.com/AlmostReliable/almostunified.git
synced 2024-11-14 19:25:13 -05:00
switch to resource based KubeJS binding
This commit is contained in:
parent
ae6c979827
commit
050ce63593
5 changed files with 66 additions and 82 deletions
|
@ -1,12 +1,8 @@
|
|||
package com.almostreliable.unified.compat;
|
||||
|
||||
import com.almostreliable.unified.AlmostUnified;
|
||||
import com.almostreliable.unified.BuildConfig;
|
||||
import com.almostreliable.unified.config.UnifyConfig;
|
||||
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.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -17,22 +13,17 @@ import javax.annotation.Nullable;
|
|||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class AlmostKube extends KubeJSPlugin {
|
||||
@SuppressWarnings("unused")
|
||||
public final class AlmostKube {
|
||||
|
||||
@Override
|
||||
public void registerBindings(BindingsEvent event) {
|
||||
if (event.getType().isServer()) {
|
||||
event.add(BuildConfig.MOD_NAME, UnifyWrapper.class);
|
||||
}
|
||||
}
|
||||
private AlmostKube() {}
|
||||
|
||||
public static class UnifyWrapper {
|
||||
@Nullable
|
||||
public static String getPreferredTagForItem(ItemStack stack) {
|
||||
UnifyTag<Item> tag = AlmostUnified
|
||||
.getRuntime()
|
||||
.getReplacementMap()
|
||||
.orElseThrow(UnifyWrapper::notLoadedException)
|
||||
.orElseThrow(AlmostKube::notLoadedException)
|
||||
.getPreferredTagForItem(getId(stack));
|
||||
return tag == null ? null : tag.location().toString();
|
||||
}
|
||||
|
@ -41,9 +32,9 @@ public class AlmostKube extends KubeJSPlugin {
|
|||
ResourceLocation replacement = AlmostUnified
|
||||
.getRuntime()
|
||||
.getReplacementMap()
|
||||
.orElseThrow(UnifyWrapper::notLoadedException)
|
||||
.orElseThrow(AlmostKube::notLoadedException)
|
||||
.getReplacementForItem(getId(stack));
|
||||
return ItemStackJS.of(replacement);
|
||||
return Registry.ITEM.get(replacement).getDefaultInstance();
|
||||
}
|
||||
|
||||
public static ItemStack getPreferredItemForTag(ResourceLocation tag) {
|
||||
|
@ -51,16 +42,16 @@ public class AlmostKube extends KubeJSPlugin {
|
|||
ResourceLocation item = AlmostUnified
|
||||
.getRuntime()
|
||||
.getReplacementMap()
|
||||
.orElseThrow(UnifyWrapper::notLoadedException)
|
||||
.orElseThrow(AlmostKube::notLoadedException)
|
||||
.getPreferredItemForTag(asUnifyTag, $ -> true);
|
||||
return ItemStackJS.of(item);
|
||||
return Registry.ITEM.get(item).getDefaultInstance();
|
||||
}
|
||||
|
||||
public static Set<String> getTags() {
|
||||
return AlmostUnified
|
||||
.getRuntime()
|
||||
.getFilteredTagMap()
|
||||
.orElseThrow(UnifyWrapper::notLoadedException)
|
||||
.orElseThrow(AlmostKube::notLoadedException)
|
||||
.getTags()
|
||||
.stream()
|
||||
.map(tag -> tag.location().toString())
|
||||
|
@ -72,15 +63,15 @@ public class AlmostKube extends KubeJSPlugin {
|
|||
return AlmostUnified
|
||||
.getRuntime()
|
||||
.getFilteredTagMap()
|
||||
.orElseThrow(UnifyWrapper::notLoadedException)
|
||||
.getItemsByTag(asUnifyTag)
|
||||
.orElseThrow(AlmostKube::notLoadedException)
|
||||
.getEntriesByTag(asUnifyTag)
|
||||
.stream()
|
||||
.map(ResourceLocation::toString)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public static UnifyConfig getUnifyConfig() {
|
||||
return AlmostUnified.getRuntime().getUnifyConfig().orElseThrow(UnifyWrapper::notLoadedException);
|
||||
return AlmostUnified.getRuntime().getUnifyConfig().orElseThrow(AlmostKube::notLoadedException);
|
||||
}
|
||||
|
||||
private static ResourceLocation getId(ItemStack stack) {
|
||||
|
@ -92,7 +83,7 @@ public class AlmostKube extends KubeJSPlugin {
|
|||
|
||||
private static IllegalStateException notLoadedException() {
|
||||
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"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
1
Common/src/main/resources/kubejs.bindings.txt
Normal file
1
Common/src/main/resources/kubejs.bindings.txt
Normal file
|
@ -0,0 +1 @@
|
|||
* AlmostUnified com.almostreliable.unified.compat.AlmostKube
|
|
@ -35,7 +35,6 @@
|
|||
},
|
||||
"suggests": {
|
||||
"jei": ">=${jeiVersion}",
|
||||
"roughlyenoughitems": ">=${reiVersion}",
|
||||
"kubejs": ">=${kubejsVersion}"
|
||||
"roughlyenoughitems": ">=${reiVersion}"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,10 +38,3 @@ mandatory = false
|
|||
versionRange = "[${reiVersion},)"
|
||||
ordering = "BEFORE"
|
||||
side = "BOTH"
|
||||
|
||||
[[dependencies."${modId}"]]
|
||||
modId = "kubejs"
|
||||
mandatory = false
|
||||
versionRange = "[${kubejsVersion},)"
|
||||
ordering = "BEFORE"
|
||||
side = "BOTH"
|
||||
|
|
|
@ -30,7 +30,7 @@ fabricApiVersion = 0.76.0
|
|||
fabricRecipeViewer = rei
|
||||
|
||||
# Forge Dependencies
|
||||
forgeVersion = 43.2.10
|
||||
forgeVersion = 43.2.0
|
||||
forgeRecipeViewer = jei
|
||||
|
||||
# Github
|
||||
|
|
Loading…
Reference in a new issue