mirror of
https://github.com/PuzzleMC/Puzzle.git
synced 2025-12-16 20:05:09 +01:00
feat: integrate MBP – Part I
I received permission from the author of MoreBlockPredicates to integrate their mod's functionality into Puzzle. Thanks again :) This is far from ready yet. The MBP codebase is stuck on 1.20.1 and only for Fabric, so I'm basically porting it to 1.21.5 and multiloader at the same time. (There have been LOTS of changes related to block models, too)
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package net.puzzlemc.fabric;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin;
|
||||
import net.fabricmc.fabric.api.client.model.loading.v1.PreparableModelLoadingPlugin;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.resource.Resource;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.puzzlemc.predicates.PuzzlePredicates;
|
||||
import net.puzzlemc.predicates.data.logic.When;
|
||||
import net.puzzlemc.predicates.util.Utils;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
|
||||
public class MBPModelLoadingPlugin implements PreparableModelLoadingPlugin<HashSet<Identifier>> {
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize(HashSet<Identifier> data, ModelLoadingPlugin.Context pluginContext) {
|
||||
//pluginContext.addModels(data);
|
||||
}
|
||||
|
||||
public static class ModelIdLoader implements DataLoader<HashSet<Identifier>> {
|
||||
@Override
|
||||
public CompletableFuture<HashSet<Identifier>> load(ResourceManager manager, Executor executor) {
|
||||
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
HashSet<Identifier> wantedModels = new HashSet<>();
|
||||
|
||||
Map<Identifier, Resource> map = manager.findResources("mbp", id -> id.getPath().endsWith(".json"));
|
||||
for (Identifier id : map.keySet()) {
|
||||
|
||||
try {
|
||||
Identifier blockTarget = Identifier.of(id.toString().substring(0,id.toString().length()-5).replace("mbp/", ""));
|
||||
JsonObject asset = JsonParser.parseReader(map.get(id).getReader()).getAsJsonObject();
|
||||
|
||||
Optional<Block> block = Utils.getBlock(blockTarget);
|
||||
|
||||
if (block.isPresent()) {
|
||||
JsonArray overrides = asset.getAsJsonArray("overrides");
|
||||
PuzzlePredicates.logger().info("* Model Loader: "+blockTarget+ " " + overrides);
|
||||
for(JsonElement overrideEntry : overrides) {
|
||||
When when = When.parse(overrideEntry);
|
||||
|
||||
wantedModels.addAll(when.getModels());
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
PuzzlePredicates.logger().error("Error found in file: " + id, e);
|
||||
}
|
||||
}
|
||||
return wantedModels;
|
||||
}, executor);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,17 @@ package net.puzzlemc.fabric;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
|
||||
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
|
||||
import net.fabricmc.fabric.impl.client.model.loading.ModelLoadingPluginManager;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.resource.ResourceType;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.puzzlemc.core.PuzzleCore;
|
||||
import net.puzzlemc.splashscreen.PuzzleSplashScreen;
|
||||
|
||||
public class PuzzleFabric implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
PuzzleCore.initModules();
|
||||
ModelLoadingPluginManager.registerPlugin(new MBPModelLoadingPlugin.ModelIdLoader(), new MBPModelLoadingPlugin());
|
||||
|
||||
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
|
||||
@Override
|
||||
@@ -21,7 +22,7 @@ public class PuzzleFabric implements ClientModInitializer {
|
||||
}
|
||||
@Override
|
||||
public void reload(ResourceManager manager) {
|
||||
PuzzleSplashScreen.ReloadListener.INSTANCE.reload(manager);
|
||||
PuzzleCore.PuzzleResourceManager.INSTANCE.reload(manager);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -32,7 +32,9 @@
|
||||
"mixins": [
|
||||
"puzzle-gui.mixins.json",
|
||||
"puzzle-models.mixins.json",
|
||||
"puzzle-splashscreen.mixins.json"
|
||||
"puzzle-splashscreen.mixins.json",
|
||||
"puzzle-predicates.mixins.json",
|
||||
"puzzle-predicates_compat.mixins.json"
|
||||
],
|
||||
|
||||
"depends": {
|
||||
|
||||
Reference in New Issue
Block a user