22
33import io .github .cottonmc .libcd .condition .ConditionalData ;
44import io .github .cottonmc .libcd .impl .ReloadListenersAccessor ;
5- import net .minecraft .resource .ReloadableResourceManager ;
6- import net .minecraft .resource .ReloadableResourceManagerImpl ;
7- import net .minecraft .resource .Resource ;
8- import net .minecraft .resource .ResourceReloadListener ;
5+ import io .github .cottonmc .libcd .impl .ResourceSearcher ;
6+ import net .minecraft .resource .*;
97import net .minecraft .util .Identifier ;
108import org .apache .commons .io .IOUtils ;
119import org .apache .logging .log4j .Logger ;
1715import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
1816import org .spongepowered .asm .mixin .injection .callback .LocalCapture ;
1917
18+ import java .io .FileNotFoundException ;
2019import java .io .IOException ;
2120import java .util .ArrayList ;
2221import java .util .List ;
22+ import java .util .Map ;
2323import java .util .Set ;
2424import java .util .function .Predicate ;
2525
2626@ Mixin (ReloadableResourceManagerImpl .class )
27- public abstract class MixinResourceManagerImpl implements ReloadableResourceManager , ReloadListenersAccessor {
27+ public abstract class MixinResourceManagerImpl implements ReloadableResourceManager , ReloadListenersAccessor , ResourceSearcher {
2828
2929 @ Shadow @ Final private static Logger LOGGER ;
3030
3131 @ Shadow @ Final private List <ResourceReloadListener > listeners ;
3232
33+ @ Shadow public abstract List <Resource > getAllResources (Identifier identifier_1 ) throws IOException ;
34+
35+ @ Shadow @ Final private Map <String , NamespaceResourceManager > namespaceManagers ;
36+
3337 @ Inject (method = "findResources" , at = @ At ("RETURN" ), locals = LocalCapture .CAPTURE_FAILEXCEPTION )
3438 private void checkConditioalRecipes (String parent , Predicate <String > loadFilter , CallbackInfoReturnable cir ,
3539 Set <Identifier > foundResources , List <Identifier > sortedResources ) {
@@ -38,16 +42,15 @@ private void checkConditioalRecipes(String parent, Predicate<String> loadFilter,
3842 //don't try to load for things that use mcmetas already!
3943 if (id .getPath ().contains (".mcmeta" ) || id .getPath ().contains (".png" )) continue ;
4044 Identifier metaId = new Identifier (id .getNamespace (), id .getPath () + ".mcmeta" );
41- if (containsResource (metaId )) {
42- try {
43- Resource meta = getResource (metaId );
44- String metaText = IOUtils .toString (meta .getInputStream ());
45- if (!ConditionalData .shouldLoad (id , metaText )) {
46- sortedResources .remove (id );
47- }
48- } catch (IOException e ) {
49- LOGGER .error ("Error when accessing recipe metadata for {}: {}" , id .toString (), e .getMessage ());
45+ try {
46+ Resource meta = getResource (metaId );
47+ String metaText = IOUtils .toString (meta .getInputStream ());
48+ if (!ConditionalData .shouldLoad (id , metaText )) {
49+ sortedResources .remove (id );
5050 }
51+ } catch (IOException e ) {
52+ //this is so ugly but I can't really do anything else when containsResource is client-side only for *no* reason
53+ if (!(e instanceof FileNotFoundException )) LOGGER .error ("Error when accessing recipe metadata for {}: {}" , id .toString (), e .getMessage ());
5154 }
5255 }
5356 }
@@ -56,4 +59,11 @@ private void checkConditioalRecipes(String parent, Predicate<String> loadFilter,
5659 public List <ResourceReloadListener > libcd_getListeners () {
5760 return listeners ;
5861 }
62+
63+ public boolean libcd_contains (Identifier id ) {
64+ ResourceManager manager = this .namespaceManagers .get (id .getNamespace ());
65+ return manager != null && ((ResourceSearcher ) manager ).libcd_contains (id );
66+ }
67+
68+
5969}
0 commit comments