mirror of
https://github.com/PuzzleMC/Puzzle.git
synced 2025-12-15 19:35:10 +01:00
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)
74 lines
2.7 KiB
Java
74 lines
2.7 KiB
Java
package net.puzzlemc.predicates;
|
|
|
|
import com.google.gson.JsonArray;
|
|
import com.google.gson.JsonElement;
|
|
import com.google.gson.JsonObject;
|
|
import com.google.gson.JsonParser;
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.client.render.entity.state.EntityRenderState;
|
|
import net.minecraft.resource.Resource;
|
|
import net.minecraft.resource.ResourceManager;
|
|
import net.minecraft.util.Identifier;
|
|
import net.puzzlemc.core.PuzzleModule;
|
|
import net.puzzlemc.predicates.data.logic.When;
|
|
import net.puzzlemc.predicates.util.Utils;
|
|
import org.slf4j.Logger;
|
|
|
|
import java.util.*;
|
|
|
|
public class PuzzlePredicates implements PuzzleModule {
|
|
public static final PuzzlePredicates INSTANCE = new PuzzlePredicates();
|
|
public static EntityRenderState currentEntityRenderState;
|
|
|
|
@Override
|
|
public String getModuleId() {
|
|
return "predicates";
|
|
}
|
|
|
|
public static Logger logger() {
|
|
return INSTANCE.getLogger();
|
|
}
|
|
|
|
public static Identifier id(String path) {
|
|
return Identifier.of("mbp", path);
|
|
}
|
|
|
|
@Override
|
|
public void init() {
|
|
// TODO
|
|
//ModelLoadingPluginManager.registerPlugin(new MBPModelLoadingPlugin.ModelIdLoader(), new MBPModelLoadingPlugin());
|
|
}
|
|
@Override
|
|
public void reloadResources(ResourceManager manager) {
|
|
MBPData.PREDICATES.clear();
|
|
|
|
Map<Identifier, Resource> map = manager.findResources("mbp", id -> id.getPath().endsWith(".json"));
|
|
for (Identifier id : map.keySet()) {
|
|
getLogger().info("Loading MBP: " + id);
|
|
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");
|
|
List<When> whenList = new ArrayList<>();
|
|
for(JsonElement overrideEntry : overrides) {
|
|
When when = When.parse(overrideEntry);
|
|
whenList.add(when);
|
|
}
|
|
MBPData.PREDICATES.put(block.get(), Collections.unmodifiableList(whenList));
|
|
getLogger().info(MBPData.PREDICATES.toString());
|
|
} else {
|
|
getLogger().error("Block entry not found in file %s: %s ".formatted(id, blockTarget));
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
getLogger().error("Error in file: %s".formatted(id));
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|