Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.mattidragon.jsonpatcher.mixin;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import dev.mattidragon.jsonpatcher.JsonPatcher;
import dev.mattidragon.jsonpatcher.metapatch.MetapatchResourcePack;
import dev.mattidragon.jsonpatcher.misc.MetaPatchPackAccess;
import dev.mattidragon.jsonpatcher.patch.PatchingContext;
Expand All @@ -16,7 +17,7 @@
import java.util.function.Predicate;

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
@Mixin(LifecycledResourceManagerImpl.class)
@Mixin(value = LifecycledResourceManagerImpl.class, priority = 500)
public class LifecycledResourceManagerImplMixin implements MetaPatchPackAccess {
@Unique
private MetapatchResourcePack jsonpatcher$metaPatchPack;
Expand Down Expand Up @@ -46,6 +47,11 @@ private List<Resource> injectResourcesIntoGetAll(List<Resource> original, Identi
if (jsonpatcher$metaPatchPack.isDeleted(id)) {
return new ArrayList<>();
}
if (!jsonpatcher$context.loaded()) {
var message = "Loading unmodified resource \""+id.toString()+"\" before PatchingContext could be loaded";
JsonPatcher.RELOAD_LOGGER.warn(message);
return original;
}
var list = new ArrayList<>(original);
var metaResource = jsonpatcher$metaPatchPack.makeResource(id);
if (metaResource != null) list.add(metaResource);
Expand All @@ -58,6 +64,11 @@ private Optional<Resource> injectResourcesIntoGet(Optional<Resource> original, I
if (jsonpatcher$metaPatchPack.isDeleted(id)) {
return Optional.empty();
}
if (!jsonpatcher$context.loaded()) {
var message = "Loading unmodified resource \""+id.toString()+"\" before PatchingContext could be loaded";
JsonPatcher.RELOAD_LOGGER.warn(message);
return original;
}
return Optional.ofNullable(jsonpatcher$metaPatchPack.makeResource(id))
.or(() -> original)
.map(resource -> {
Expand All @@ -70,6 +81,11 @@ private Optional<Resource> injectResourcesIntoGet(Optional<Resource> original, I
private Map<Identifier, Resource> injectResourcesIntoFind(Map<Identifier, Resource> map, String startingPath, Predicate<Identifier> allowedPathPredicate) {
map.putAll(jsonpatcher$metaPatchPack.findResources(startingPath, allowedPathPredicate));
map.keySet().removeIf(jsonpatcher$metaPatchPack::isDeleted);
if (!jsonpatcher$context.loaded()) {
var message = "Loading unmodified resources from \""+startingPath+"\" before PatchingContext could be loaded";
JsonPatcher.RELOAD_LOGGER.warn(message);
return map;
}
map.forEach(jsonpatcher$context::patchResource);
return map;
}
Expand All @@ -79,6 +95,11 @@ private Map<Identifier, List<Resource>> injectResourcesIntoFindAll(Map<Identifie
jsonpatcher$metaPatchPack.findResources(startingPath, allowedPathPredicate)
.forEach((id, resource) -> map.computeIfAbsent(id, i -> new ArrayList<>()).add(resource));
map.keySet().removeIf(jsonpatcher$metaPatchPack::isDeleted);
if (!jsonpatcher$context.loaded()) {
var message = "Loading unmodified resources from \""+startingPath+"\" before PatchingContext could be loaded";
JsonPatcher.RELOAD_LOGGER.warn(message);
return map;
}
map.forEach((id, resources) -> resources.forEach(resource -> jsonpatcher$context.patchResource(id, resource)));
return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public void load(ResourceManager manager) {
loaded = true;
}

public boolean loaded() {
return loaded;
}

public void patchResource(Identifier id, Resource resource) {
if (!id.getPath().endsWith(".json")) return;
if (DISABLED.get() != null) return;
Expand Down