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

This commit is contained in:
embeddedt 2023-05-05 12:03:15 -04:00
commit 3b4354fbe5
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
2 changed files with 90 additions and 2 deletions

View File

@ -26,6 +26,7 @@ import net.minecraft.world.level.block.state.properties.Property;
import org.embeddedt.modernfix.ModernFix;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;
@ -97,6 +98,12 @@ public class ModelBakeryHelpers {
List<PackResources> allPackResources = new ArrayList<>(manager.listPacks().collect(Collectors.toList()));
Collections.reverse(allPackResources);
ObjectOpenHashSet<ResourceLocation> allAvailableModels = new ObjectOpenHashSet<>(), allAvailableStates = new ObjectOpenHashSet<>();
/* try to fix CME in some runtime packs by forcing generation */
for(PackResources pack : allPackResources) {
try(InputStream stream = pack.getResource(PackType.CLIENT_RESOURCES, new ResourceLocation("modernfix", "dummy.json"))) {
} catch(Exception ignored) {
}
}
allPackResources.removeIf(pack -> {
if(isTrustedPack.test(pack)) {
for(String namespace : pack.getNamespaces(PackType.CLIENT_RESOURCES)) {
@ -124,10 +131,18 @@ public class ModelBakeryHelpers {
ConcurrentLinkedQueue<Pair<ResourceLocation, JsonElement>> blockStateLoadedFiles = new ConcurrentLinkedQueue<>();
List<CompletableFuture<Void>> blockStateData = new ArrayList<>();
for(ResourceLocation blockstate : blockStateFiles) {
ResourceLocation fileLocation = new ResourceLocation(blockstate.getNamespace(), "blockstates/" + blockstate.getPath() + ".json");
List<Resource> resources;
try {
resources = manager.getResources(fileLocation);
if(resources.isEmpty())
continue;
} catch(IOException e) {
logOrSuppressError(blockstateErrors, "blockstate", blockstate, e);
continue;
}
blockStateData.add(CompletableFuture.runAsync(() -> {
ResourceLocation fileLocation = new ResourceLocation(blockstate.getNamespace(), "blockstates/" + blockstate.getPath() + ".json");
try {
List<Resource> resources = manager.getResources(fileLocation);
for(Resource resource : resources) {
JsonParser parser = new JsonParser();
try {

View File

@ -0,0 +1,73 @@
package org.embeddedt.modernfix.forge.mixin.safety;
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraftforge.fml.client.registry.IRenderFactory;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import org.embeddedt.modernfix.ModernFix;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
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;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Mixin(value = EntityRenderDispatcher.class, priority = 1500)
public class EntityRenderDispatcherMixin {
@Shadow @Final @Mutable private Map<EntityType<?>, EntityRenderer<?>> renderers;
private static Map<EntityType<? extends Entity>, IRenderFactory<? extends Entity>> RENDER_FACTORIES;
static {
RenderingRegistry instance = ObfuscationReflectionHelper.getPrivateValue(RenderingRegistry.class, null, "INSTANCE");
RENDER_FACTORIES = ObfuscationReflectionHelper.getPrivateValue(RenderingRegistry.class, instance, "entityRenderers");
}
@Inject(method = "<init>", at = @At("RETURN"))
private void makeRenderersConcurrent(CallbackInfo ci) {
renderers = new ConcurrentHashMap<>(renderers);
}
@Inject(method = "getRenderer", at = @At("RETURN"), cancellable = true)
private <T extends Entity> void checkRenderer(T entity, CallbackInfoReturnable<EntityRenderer<?>> cir) {
if(cir.getReturnValue() == null) {
synchronized (EntityRenderDispatcher.class) {
EntityType<?> type = entity.getType();
if(type == null) {
throw new IllegalStateException("Entity with class " + entity.getClass().getName() + " UUID " + entity.getName() + " has no type???");
}
ResourceLocation key = Registry.ENTITY_TYPE.getKey(type);
EntityRenderer<?> renderer = null;
if(RENDER_FACTORIES != null) {
IRenderFactory<? extends Entity> factory = RENDER_FACTORIES.get(type);
if(factory != null) {
try {
renderer = factory.createRenderFor((EntityRenderDispatcher)(Object)this);
} catch(RuntimeException e) {
ModernFix.LOGGER.error("Failed to create fallback renderer", e);
}
if(renderer != null) {
this.renderers.put(type, renderer);
ModernFix.LOGGER.warn("Entity renderer for {} was somehow not registered, injecting.", key);
cir.setReturnValue(renderer);
}
}
}
if(cir.getReturnValue() == null) {
ModernFix.LOGGER.error("Backing renderer map is a " + renderers.getClass().getName());
throw new IllegalStateException("No renderer for entity with type " + key);
}
}
}
}
}