Merge remote-tracking branch 'origin/1.18' into 1.19.2
This commit is contained in:
commit
cd069c016b
|
|
@ -62,6 +62,7 @@ import java.io.InputStreamReader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
@ -248,7 +249,6 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
|
||||||
*/
|
*/
|
||||||
private void gatherModelMaterials(Set<Material> materialSet) {
|
private void gatherModelMaterials(Set<Material> materialSet) {
|
||||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||||
List<CompletableFuture<Pair<ResourceLocation, JsonElement>>> blockStateData = new ArrayList<>();
|
|
||||||
final Object2IntOpenHashMap<String> blockstateErrors = new Object2IntOpenHashMap<>();
|
final Object2IntOpenHashMap<String> blockstateErrors = new Object2IntOpenHashMap<>();
|
||||||
/*
|
/*
|
||||||
* First, gather all vanilla packs, and use listResources on them. This will allow us to (hopefully) avoid
|
* 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.clear();
|
||||||
allAvailableStates.trim();
|
allAvailableStates.trim();
|
||||||
|
|
||||||
|
ConcurrentLinkedQueue<Pair<ResourceLocation, JsonElement>> blockStateLoadedFiles = new ConcurrentLinkedQueue<>();
|
||||||
|
List<CompletableFuture<Void>> blockStateData = new ArrayList<>();
|
||||||
for(ResourceLocation blockstate : blockStateFiles) {
|
for(ResourceLocation blockstate : blockStateFiles) {
|
||||||
blockStateData.add(CompletableFuture.supplyAsync(() -> {
|
blockStateData.add(CompletableFuture.runAsync(() -> {
|
||||||
ResourceLocation fileLocation = new ResourceLocation(blockstate.getNamespace(), "blockstates/" + blockstate.getPath() + ".json");
|
ResourceLocation fileLocation = new ResourceLocation(blockstate.getNamespace(), "blockstates/" + blockstate.getPath() + ".json");
|
||||||
Optional<Resource> resource = this.resourceManager.getResource(fileLocation);
|
try {
|
||||||
if(resource.isPresent()) {
|
List<Resource> resources = this.resourceManager.getResourceStack(fileLocation);
|
||||||
try(InputStream stream = resource.get().open()) {
|
for(Resource resource : resources) {
|
||||||
JsonParser parser = new JsonParser();
|
JsonParser parser = new JsonParser();
|
||||||
return Pair.of(blockstate, parser.parse(new InputStreamReader(stream, StandardCharsets.UTF_8)));
|
try(InputStream stream = resource.open()) {
|
||||||
} catch(IOException | JsonParseException e) {
|
blockStateLoadedFiles.add(Pair.of(blockstate, parser.parse(new InputStreamReader(stream, StandardCharsets.UTF_8))));
|
||||||
logOrSuppressError(blockstateErrors, "blockstate", blockstate, e);
|
} catch(JsonParseException e) {
|
||||||
|
logOrSuppressError(blockstateErrors, "blockstate", blockstate, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch(IOException e) {
|
||||||
|
logOrSuppressError(blockstateErrors, "blockstate", blockstate, e);
|
||||||
}
|
}
|
||||||
return Pair.of(blockstate, null);
|
|
||||||
}, ModernFix.resourceReloadExecutor()));
|
}, ModernFix.resourceReloadExecutor()));
|
||||||
}
|
}
|
||||||
blockStateFiles = null;
|
blockStateFiles = null;
|
||||||
CompletableFuture.allOf(blockStateData.toArray(new CompletableFuture[0])).join();
|
CompletableFuture.allOf(blockStateData.toArray(new CompletableFuture[0])).join();
|
||||||
for(CompletableFuture<Pair<ResourceLocation, JsonElement>> result : blockStateData) {
|
for(Pair<ResourceLocation, JsonElement> pair : blockStateLoadedFiles) {
|
||||||
Pair<ResourceLocation, JsonElement> pair = result.join();
|
|
||||||
if(pair.getSecond() != null) {
|
if(pair.getSecond() != null) {
|
||||||
try {
|
try {
|
||||||
JsonObject obj = pair.getSecond().getAsJsonObject();
|
JsonObject obj = pair.getSecond().getAsJsonObject();
|
||||||
|
|
@ -353,6 +356,7 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
|
||||||
});
|
});
|
||||||
blockstateErrors.clear();
|
blockstateErrors.clear();
|
||||||
blockStateData = null;
|
blockStateData = null;
|
||||||
|
blockStateLoadedFiles.clear();
|
||||||
|
|
||||||
/* figure out which models we should actually load */
|
/* figure out which models we should actually load */
|
||||||
gatherAdditionalViaManualScan(allPackResources, allAvailableModels, modelFiles, "models/");
|
gatherAdditionalViaManualScan(allPackResources, allAvailableModels, modelFiles, "models/");
|
||||||
|
|
|
||||||
|
|
@ -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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -67,6 +67,7 @@
|
||||||
"perf.dynamic_resources.ItemRendererMixin",
|
"perf.dynamic_resources.ItemRendererMixin",
|
||||||
"perf.dynamic_resources.ModelBakeryMixin",
|
"perf.dynamic_resources.ModelBakeryMixin",
|
||||||
"perf.dynamic_resources.ae2.RegistrationMixin",
|
"perf.dynamic_resources.ae2.RegistrationMixin",
|
||||||
|
"perf.dynamic_resources.rs.ClientSetupMixin",
|
||||||
"perf.dynamic_resources.ctm.TextureMetadataHandlerMixin",
|
"perf.dynamic_resources.ctm.TextureMetadataHandlerMixin",
|
||||||
"perf.dynamic_resources.ctm.CTMPackReloadListenerMixin",
|
"perf.dynamic_resources.ctm.CTMPackReloadListenerMixin",
|
||||||
"perf.dynamic_resources.supermartijncore.ClientRegistrationHandlerMixin",
|
"perf.dynamic_resources.supermartijncore.ClientRegistrationHandlerMixin",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user