Skip to content

Commit c2ce6c8

Browse files
committed
Restore BTATweaker plugin
1 parent 91c9ae7 commit c2ce6c8

5 files changed

Lines changed: 121 additions & 0 deletions

File tree

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ lwjgl {
5454
dependencies {
5555
minecraft("::${libs.versions.bta.get()}")
5656

57+
implementation(project.files("libs/btatweaker-1.1.1.jar"))
58+
compileOnly("org.luaj:luaj-jse:3.0.1")
59+
5760
runtimeOnly(libs.clientJar)
5861
implementation(libs.loader)
5962
// If you do not need Halplibe you can comment out or delete this line.

libs/btatweaker-1.1.1.jar

1.15 MB
Binary file not shown.

src/main/java/turing/tmb/TMB.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import turing.tmb.api.recipe.IRecipeTranslator;
2222
import turing.tmb.api.recipe.RecipeIngredientRole;
2323
import turing.tmb.api.runtime.ITMBRuntime;
24+
import turing.tmb.plugin.BTATweaker;
2425
import turing.tmb.vanilla.VanillaPlugin;
2526
import turniplabs.halplibe.HalpLibe;
2627
import turniplabs.halplibe.event.defs.ClientEvents;
@@ -221,6 +222,9 @@ public static void reloadTMB() {
221222
gatherPlugins(true);
222223
loadTMB();
223224
runtime.gatherIngredients();
225+
if (FabricLoader.getInstance().isModLoaded("btatweaker")) {
226+
BTATweaker.onReload();
227+
}
224228
}
225229

226230
public static void registerPlugin(ITMBPlugin plugin) {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package turing.tmb.plugin;
2+
3+
import net.minecraft.core.util.collection.Pair;
4+
import org.luaj.vm2.lib.LibFunction;
5+
import turing.btatweaker.BTATweakerEntrypoint;
6+
import turing.btatweaker.IBTATweaker;
7+
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
import java.util.function.Consumer;
11+
12+
public class BTATweaker implements BTATweakerEntrypoint {
13+
public static final TMBLib lib = new TMBLib();
14+
15+
@Override
16+
public void initPlugin(IBTATweaker registry) {
17+
registry.addModLibrary(lib);
18+
}
19+
20+
public static void onReload() {
21+
List<Pair<LibFunction, Consumer<LibFunction>>> list = new ArrayList<>(TMBLib.scriptActions);
22+
TMBLib.scriptActions.clear();
23+
for (Pair<LibFunction, Consumer<LibFunction>> pair : list) {
24+
pair.getRight().accept(pair.getLeft());
25+
}
26+
list.clear();
27+
}
28+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package turing.tmb.plugin;
2+
3+
import net.minecraft.core.lang.I18n;
4+
import net.minecraft.core.util.collection.Pair;
5+
import org.luaj.vm2.LuaTable;
6+
import org.luaj.vm2.LuaValue;
7+
import org.luaj.vm2.lib.LibFunction;
8+
import org.luaj.vm2.lib.OneArgFunction;
9+
import org.luaj.vm2.lib.ThreeArgFunction;
10+
import org.luaj.vm2.lib.TwoArgFunction;
11+
import turing.btatweaker.api.ModLibrary;
12+
import turing.docs.Argument;
13+
import turing.docs.Function;
14+
import turing.docs.FunctionExample;
15+
import turing.docs.Library;
16+
import turing.tmb.*;
17+
import turing.tmb.api.ingredient.ITypedIngredient;
18+
19+
import java.util.ArrayList;
20+
import java.util.Collections;
21+
import java.util.List;
22+
import java.util.Optional;
23+
import java.util.function.Consumer;
24+
25+
@Library(value = "mods.tmb", className = "Too Many Blocks")
26+
public class TMBLib extends ModLibrary {
27+
public static final List<Pair<LibFunction, Consumer<LibFunction>>> scriptActions = new ArrayList<>();
28+
29+
@Override
30+
public void setupLib(LuaTable t, LuaValue env) {
31+
t.set("hideCategory", new HideCategory());
32+
t.set("hideIngredient", new HideIngredient());
33+
t.set("addInfo", new AddInfo());
34+
}
35+
36+
@Override
37+
public List<String> getAliases() {
38+
return Collections.singletonList(TMB.MOD_ID);
39+
}
40+
41+
@Function(value = "hideCategory", arguments = @Argument(value = "string", name = "categoryName"), examples = @FunctionExample("guidebook.section.furnace"))
42+
protected static final class HideCategory extends OneArgFunction {
43+
@Override
44+
public LuaValue call(LuaValue arg) {
45+
String name = arg.checkjstring();
46+
TMB.getRuntime().getRecipeIndex().hideCategory(name);
47+
scriptActions.add(Pair.of(this, f -> f.call(arg)));
48+
return NIL;
49+
}
50+
}
51+
52+
@Function(value = "hideIngredient", arguments = {@Argument(value = "string", name = "namespace"), @Argument(value = "string", name = "name")})
53+
protected static final class HideIngredient extends TwoArgFunction {
54+
@Override
55+
public LuaValue call(LuaValue arg1, LuaValue arg2) {
56+
String namespace = arg1.checkjstring();
57+
String name = arg2.checkjstring();
58+
TMB.getRuntime().getIngredientIndex().hideIngredient(new TypedIngredient<>(namespace, name, null, null));
59+
if (name.contains(".")) {
60+
TMB.getRuntime().getIngredientIndex().hideIngredient(new TypedIngredient<>(namespace, I18n.getInstance().translateKey(name), null, null));
61+
scriptActions.add(Pair.of(this, f -> f.call(arg1, arg2)));
62+
}
63+
return NIL;
64+
}
65+
}
66+
67+
@Function(value = "addInfo", arguments = {
68+
@Argument(value = "string", name = "namespace"),
69+
@Argument(value = "string", name = "name"),
70+
@Argument(value = "string", name = "infoText")
71+
}, examples = @FunctionExample({"\"minecraft\"", "\"Iron Ingot\"", "This is a cool item!!!"}))
72+
protected static final class AddInfo extends ThreeArgFunction {
73+
@Override
74+
public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) {
75+
String namespace = arg1.checkjstring();
76+
String name = arg2.checkjstring();
77+
String text = arg3.checkjstring();
78+
Optional<ITypedIngredient<Object>> ingredient = TMB.getRuntime().getIngredientIndex().getIngredient(namespace, name);
79+
ingredient.ifPresent(i -> {
80+
TMB.getRuntime().getRecipeIndex().registerRecipe(BaseTMBPlugin.infoCategory, new IngredientInfo(i, text, false), InfoRecipeTranslator::new);
81+
scriptActions.add(Pair.of(this, f -> f.call(arg1, arg2, arg3)));
82+
});
83+
return NIL;
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)