Possible NPE fixes for KubeJS

This commit is contained in:
embeddedt 2023-08-30 18:49:25 -04:00
parent 20a15a587c
commit fcde6104eb
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
2 changed files with 16 additions and 6 deletions

View File

@ -24,8 +24,11 @@ public class IDFilterMixin {
@Overwrite(remap = false)
public boolean test(RecipeJS recipe) {
if(!_targetSearched) {
_target = KubeUtil.originalRecipesByHash.get(this.id);
_targetSearched = true;
if(KubeUtil.originalRecipesByHash.size() > 0) {
_target = KubeUtil.originalRecipesByHash.get(this.id);
_targetSearched = true;
} else
return recipe.getOrCreateId().equals(this.id); // fallback
}
return recipe == _target;
}

View File

@ -4,6 +4,7 @@ import dev.latvian.kubejs.server.TagEventJS;
import dev.latvian.kubejs.util.UtilsJS;
import me.shedaniel.architectury.registry.Registry;
import net.minecraft.resources.ResourceLocation;
import org.embeddedt.modernfix.ModernFix;
import org.embeddedt.modernfix.annotation.RequiresMod;
import org.embeddedt.modernfix.forge.util.KubeUtil;
import org.spongepowered.asm.mixin.Mixin;
@ -29,15 +30,21 @@ public class TagWrapperMixin<T> {
@Redirect(method = "add", at = @At(value = "INVOKE", target = "Lme/shedaniel/architectury/registry/Registry;getIds()Ljava/util/Set;", ordinal = 0), remap = false)
private Set<ResourceLocation> getCachedIds(Registry<T> registryIn) {
String currentPatternStr = this.currentPatternStr;
if(currentPatternStr == null)
throw new AssertionError();
Set<ResourceLocation> cachedSet = KubeUtil.matchedIdsForRegex.get(currentPatternStr);
if(cachedSet == null) {
Pattern thePattern = UtilsJS.parseRegex(currentPatternStr);
ArrayList<ResourceLocation> locations = new ArrayList<>(registryIn.getIds());
cachedSet = locations.parallelStream()
.filter(rLoc -> thePattern.matcher(rLoc.toString()).find())
.collect(Collectors.toSet());
if(thePattern != null) {
ArrayList<ResourceLocation> locations = new ArrayList<>(registryIn.getIds());
cachedSet = locations.parallelStream()
.filter(rLoc -> thePattern.matcher(rLoc.toString()).find())
.collect(Collectors.toSet());
} else {
ModernFix.LOGGER.error("Empty pattern for '{}' somehow... ignoring...", currentPatternStr);
cachedSet = new HashSet<>();
}
KubeUtil.matchedIdsForRegex.put(currentPatternStr, cachedSet);
}
return cachedSet;