Merge remote-tracking branch 'origin/1.18' into 1.19.2

This commit is contained in:
embeddedt 2023-04-29 11:41:24 -04:00
commit cd069c016b
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
3 changed files with 47 additions and 12 deletions

View File

@ -62,6 +62,7 @@ import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
@ -248,7 +249,6 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
*/
private void gatherModelMaterials(Set<Material> materialSet) {
Stopwatch stopwatch = Stopwatch.createStarted();
List<CompletableFuture<Pair<ResourceLocation, JsonElement>>> blockStateData = new ArrayList<>();
final Object2IntOpenHashMap<String> blockstateErrors = new Object2IntOpenHashMap<>();
/*
* First, gather all vanilla packs, and use listResources on them. This will allow us to (hopefully) avoid
@ -281,26 +281,29 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
allAvailableStates.clear();
allAvailableStates.trim();
ConcurrentLinkedQueue<Pair<ResourceLocation, JsonElement>> blockStateLoadedFiles = new ConcurrentLinkedQueue<>();
List<CompletableFuture<Void>> blockStateData = new ArrayList<>();
for(ResourceLocation blockstate : blockStateFiles) {
blockStateData.add(CompletableFuture.supplyAsync(() -> {
blockStateData.add(CompletableFuture.runAsync(() -> {
ResourceLocation fileLocation = new ResourceLocation(blockstate.getNamespace(), "blockstates/" + blockstate.getPath() + ".json");
Optional<Resource> resource = this.resourceManager.getResource(fileLocation);
if(resource.isPresent()) {
try(InputStream stream = resource.get().open()) {
try {
List<Resource> resources = this.resourceManager.getResourceStack(fileLocation);
for(Resource resource : resources) {
JsonParser parser = new JsonParser();
return Pair.of(blockstate, parser.parse(new InputStreamReader(stream, StandardCharsets.UTF_8)));
} catch(IOException | JsonParseException e) {
logOrSuppressError(blockstateErrors, "blockstate", blockstate, e);
try(InputStream stream = resource.open()) {
blockStateLoadedFiles.add(Pair.of(blockstate, parser.parse(new InputStreamReader(stream, StandardCharsets.UTF_8))));
} catch(JsonParseException e) {
logOrSuppressError(blockstateErrors, "blockstate", blockstate, e);
}
}
} catch(IOException e) {
logOrSuppressError(blockstateErrors, "blockstate", blockstate, e);
}
return Pair.of(blockstate, null);
}, ModernFix.resourceReloadExecutor()));
}
blockStateFiles = null;
CompletableFuture.allOf(blockStateData.toArray(new CompletableFuture[0])).join();
for(CompletableFuture<Pair<ResourceLocation, JsonElement>> result : blockStateData) {
Pair<ResourceLocation, JsonElement> pair = result.join();
for(Pair<ResourceLocation, JsonElement> pair : blockStateLoadedFiles) {
if(pair.getSecond() != null) {
try {
JsonObject obj = pair.getSecond().getAsJsonObject();
@ -353,6 +356,7 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
});
blockstateErrors.clear();
blockStateData = null;
blockStateLoadedFiles.clear();
/* figure out which models we should actually load */
gatherAdditionalViaManualScan(allPackResources, allAvailableModels, modelFiles, "models/");

View File

@ -0,0 +1,30 @@
package org.embeddedt.modernfix.mixin.perf.dynamic_resources.rs;
import com.refinedmods.refinedstorage.render.BakedModelOverrideRegistry;
import com.refinedmods.refinedstorage.setup.ClientSetup;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import org.embeddedt.modernfix.dynamicresources.DynamicModelBakeEvent;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ClientSetup.class)
public class ClientSetupMixin {
@Shadow @Final private static BakedModelOverrideRegistry BAKED_MODEL_OVERRIDE_REGISTRY;
@Inject(method = "onClientSetup", at = @At("RETURN"), remap = false)
private static void addDynamicListener(CallbackInfo ci) {
MinecraftForge.EVENT_BUS.addListener(ClientSetupMixin::onDynamicModelBake);
}
private static void onDynamicModelBake(DynamicModelBakeEvent event) {
BakedModelOverrideRegistry.BakedModelOverrideFactory factory = BAKED_MODEL_OVERRIDE_REGISTRY.get(event.getLocation() instanceof ModelResourceLocation ? new ResourceLocation(event.getLocation().getNamespace(), event.getLocation().getPath()) : event.getLocation());
if(factory != null)
event.setModel(factory.create(event.getModel(), event.getModelLoader().getBakedTopLevelModels()));
}
}

View File

@ -67,6 +67,7 @@
"perf.dynamic_resources.ItemRendererMixin",
"perf.dynamic_resources.ModelBakeryMixin",
"perf.dynamic_resources.ae2.RegistrationMixin",
"perf.dynamic_resources.rs.ClientSetupMixin",
"perf.dynamic_resources.ctm.TextureMetadataHandlerMixin",
"perf.dynamic_resources.ctm.CTMPackReloadListenerMixin",
"perf.dynamic_resources.supermartijncore.ClientRegistrationHandlerMixin",