Fix compile errors
This commit is contained in:
parent
a8e92871c2
commit
0aeab7ef69
|
|
@ -57,7 +57,7 @@ public class ModernFixEarlyConfig {
|
|||
this.addMixinRule("safety", true);
|
||||
this.addMixinRule("launch.transformer_cache", false);
|
||||
this.addMixinRule("launch.class_search_cache", true);
|
||||
boolean isDevEnv = !FMLLoader.isProduction() && FMLLoader.getLoadingModList().getModFileById("modernfix").getFile().getLocator() instanceof ExplodedDirectoryLocator;
|
||||
boolean isDevEnv = !FMLLoader.isProduction() && FMLLoader.getLoadingModList().getModFileById("modernfix").getFile().getProvider() instanceof ExplodedDirectoryLocator;
|
||||
this.addMixinRule("devenv", isDevEnv);
|
||||
|
||||
/* Mod compat */
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package org.embeddedt.modernfix.dynamicresources;
|
||||
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.client.model.ForgeModelBakery;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
|
||||
|
|
@ -19,8 +19,8 @@ public class DynamicModelBakeEvent extends Event implements IModBusEvent {
|
|||
private final ResourceLocation location;
|
||||
private BakedModel model;
|
||||
private final UnbakedModel unbakedModel;
|
||||
private final ForgeModelBakery modelLoader;
|
||||
public DynamicModelBakeEvent(ResourceLocation location, UnbakedModel unbakedModel, BakedModel model, ForgeModelBakery loader) {
|
||||
private final ModelBakery modelLoader;
|
||||
public DynamicModelBakeEvent(ResourceLocation location, UnbakedModel unbakedModel, BakedModel model, ModelBakery loader) {
|
||||
this.location = location;
|
||||
this.model = model;
|
||||
this.unbakedModel = unbakedModel;
|
||||
|
|
@ -39,7 +39,7 @@ public class DynamicModelBakeEvent extends Event implements IModBusEvent {
|
|||
return this.unbakedModel;
|
||||
}
|
||||
|
||||
public ForgeModelBakery getModelLoader() {
|
||||
public ModelBakery getModelLoader() {
|
||||
return this.modelLoader;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ package org.embeddedt.modernfix.mixin.devenv;
|
|||
|
||||
import com.mojang.text2speech.Narrator;
|
||||
import com.mojang.text2speech.NarratorDummy;
|
||||
import net.minecraft.client.gui.chat.NarratorChatListener;
|
||||
import net.minecraft.client.GameNarrator;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(NarratorChatListener.class)
|
||||
@Mixin(GameNarrator.class)
|
||||
public class NarratorMixin {
|
||||
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lcom/mojang/text2speech/Narrator;getNarrator()Lcom/mojang/text2speech/Narrator;", remap = false))
|
||||
private Narrator useDummyNarrator() {
|
||||
|
|
|
|||
|
|
@ -4,9 +4,10 @@ import net.minecraft.client.renderer.ItemModelShaper;
|
|||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraftforge.client.ItemModelMesherForge;
|
||||
import net.minecraftforge.registries.IRegistryDelegate;
|
||||
import net.minecraftforge.client.model.ForgeItemModelShaper;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
|
|
@ -14,9 +15,9 @@ import org.spongepowered.asm.mixin.Shadow;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(ItemModelMesherForge.class)
|
||||
@Mixin(ForgeItemModelShaper.class)
|
||||
public abstract class ItemModelShaperMixin extends ItemModelShaper {
|
||||
@Shadow @Final private Map<IRegistryDelegate<Item>, ModelResourceLocation> locations;
|
||||
@Shadow @Final private Map<Holder.Reference<Item>, ModelResourceLocation> locations;
|
||||
|
||||
public ItemModelShaperMixin(ModelManager arg) {
|
||||
super(arg);
|
||||
|
|
@ -29,7 +30,7 @@ public abstract class ItemModelShaperMixin extends ItemModelShaper {
|
|||
@Overwrite
|
||||
@Override
|
||||
public BakedModel getItemModel(Item item) {
|
||||
ModelResourceLocation map = locations.get(item.delegate);
|
||||
ModelResourceLocation map = locations.get(ForgeRegistries.ITEMS.getDelegateOrThrow(item));
|
||||
return map == null ? null : getModelManager().getModel(map);
|
||||
}
|
||||
|
||||
|
|
@ -40,7 +41,7 @@ public abstract class ItemModelShaperMixin extends ItemModelShaper {
|
|||
@Overwrite
|
||||
@Override
|
||||
public void register(Item item, ModelResourceLocation location) {
|
||||
locations.put(item.delegate, location);
|
||||
locations.put(ForgeRegistries.ITEMS.getDelegateOrThrow(item), location);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ import net.minecraft.world.level.block.Block;
|
|||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.client.model.ForgeModelBakery;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.client.model.ExtendedBlockModelDeserializer;
|
||||
import net.minecraftforge.client.model.geometry.GeometryLoaderManager;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
|
|
@ -49,6 +49,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
|
@ -92,8 +93,9 @@ public abstract class ModelBakeryMixin {
|
|||
private Cache<ResourceLocation, UnbakedModel> loadedModels;
|
||||
|
||||
|
||||
@Inject(method = "<init>(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/client/color/block/BlockColors;Z)V", at = @At("RETURN"))
|
||||
private void replaceTopLevelBakedModels(ResourceManager manager, BlockColors colors, boolean vanillaBakery, CallbackInfo ci) {
|
||||
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/model/geometry/GeometryLoaderManager;init()V", remap = false))
|
||||
private void replaceTopLevelBakedModels() {
|
||||
GeometryLoaderManager.init();
|
||||
this.loadedBakedModels = CacheBuilder.newBuilder()
|
||||
.expireAfterAccess(3, TimeUnit.MINUTES)
|
||||
.maximumSize(1000)
|
||||
|
|
@ -132,30 +134,24 @@ public abstract class ModelBakeryMixin {
|
|||
|
||||
private UnbakedModel missingModel;
|
||||
|
||||
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resources/model/ModelBakery;loadBlockModel(Lnet/minecraft/resources/ResourceLocation;)Lnet/minecraft/client/renderer/block/model/BlockModel;", ordinal = 0))
|
||||
private BlockModel captureMissingModel(ModelBakery bakery, ResourceLocation location) throws IOException {
|
||||
this.missingModel = this.loadBlockModel(location);
|
||||
return (BlockModel)this.missingModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author embeddedt
|
||||
* @reason don't load any models initially, just set up initial data structures
|
||||
* @reason only used by constructor to load models at startup, which we don't do here
|
||||
*/
|
||||
@Overwrite(remap = false)
|
||||
protected void processLoading(ProfilerFiller arg, int maxMipLevels) {
|
||||
ModelLoaderRegistry.onModelLoadingStart();
|
||||
try {
|
||||
this.missingModel = this.loadBlockModel(MISSING_MODEL_LOCATION);
|
||||
} catch (IOException var10) {
|
||||
ModernFix.LOGGER.error("Error loading missing model, should never happen :(", var10);
|
||||
throw new RuntimeException(var10);
|
||||
}
|
||||
// Gather model materials
|
||||
Set<Material> initialMaterials = new HashSet<>(UNREFERENCED_TEXTURES);
|
||||
gatherModelMaterials(initialMaterials);
|
||||
ForgeHooksClient.gatherFluidTextures(initialMaterials);
|
||||
Map<ResourceLocation, List<Material>> map = initialMaterials.stream().collect(Collectors.groupingBy(Material::atlasLocation));
|
||||
this.atlasPreparations = Maps.newHashMap();
|
||||
for(Map.Entry<ResourceLocation, List<Material>> entry : map.entrySet()) {
|
||||
TextureAtlas atlas = new TextureAtlas(entry.getKey());
|
||||
TextureAtlas.Preparations atlastexture$sheetdata = atlas.prepareToStitch(this.resourceManager, entry.getValue().stream().map(Material::texture), arg, maxMipLevels);
|
||||
this.atlasPreparations.put(entry.getKey(), Pair.of(atlas, atlastexture$sheetdata));
|
||||
}
|
||||
@Overwrite
|
||||
private void loadTopLevel(ModelResourceLocation location) {
|
||||
}
|
||||
|
||||
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/ForgeHooksClient;gatherFluidTextures(Ljava/util/Set;)V", remap = false))
|
||||
private void gatherModelTextures(Set<Material> materialSet) {
|
||||
ForgeHooksClient.gatherFluidTextures(materialSet);
|
||||
gatherModelMaterials(materialSet);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -163,21 +159,23 @@ public abstract class ModelBakeryMixin {
|
|||
*/
|
||||
private void gatherModelMaterials(Set<Material> materialSet) {
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
List<ResourceLocation> allModels = new ArrayList<>(this.resourceManager.listResources("models", path -> path.endsWith(".json")));
|
||||
List<ResourceLocation> allModels = new ArrayList<>(this.resourceManager.listResources("models", path -> path.getPath().endsWith(".json")).keySet());
|
||||
// for KubeJS, etc.
|
||||
allModels.addAll(ResourcePackHandler.getExtraResources(this.resourceManager, "models", path -> path.endsWith(".json")));
|
||||
List<CompletableFuture<Pair<ResourceLocation, JsonElement>>> modelBytes = new ArrayList<>();
|
||||
for(ResourceLocation fileLocation : allModels) {
|
||||
modelBytes.add(CompletableFuture.supplyAsync(() -> {
|
||||
try(Resource resource = this.resourceManager.getResource(fileLocation)) {
|
||||
JsonParser parser = new JsonParser();
|
||||
// strip models/ and .json from the name
|
||||
ResourceLocation model = new ResourceLocation(fileLocation.getNamespace(), fileLocation.getPath().substring(7, fileLocation.getPath().length()-5));
|
||||
return Pair.of(model, parser.parse(new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8)));
|
||||
} catch(IOException | JsonParseException e) {
|
||||
ModernFix.LOGGER.error("Error reading model {}: {}", fileLocation, e);
|
||||
return Pair.of(fileLocation, null);
|
||||
Optional<Resource> resourceOpt = this.resourceManager.getResource(fileLocation);
|
||||
if(resourceOpt.isPresent()) {
|
||||
try(InputStream resourceStream = resourceOpt.get().open()) {
|
||||
// strip models/ and .json from the name
|
||||
ResourceLocation model = new ResourceLocation(fileLocation.getNamespace(), fileLocation.getPath().substring(7, fileLocation.getPath().length()-5));
|
||||
return Pair.of(model, JsonParser.parseReader(new InputStreamReader(resourceStream, StandardCharsets.UTF_8)));
|
||||
} catch(IOException | JsonParseException e) {
|
||||
ModernFix.LOGGER.error("Error reading model {}: {}", fileLocation, e);
|
||||
}
|
||||
}
|
||||
return Pair.of(fileLocation, null);
|
||||
}, Util.backgroundExecutor()));
|
||||
}
|
||||
allModels.clear();
|
||||
|
|
@ -195,7 +193,7 @@ public abstract class ModelBakeryMixin {
|
|||
Pair<ResourceLocation, JsonElement> pair = future.join();
|
||||
try {
|
||||
if(pair.getSecond() != null) {
|
||||
BlockModel model = ModelLoaderRegistry.ExpandedBlockModelDeserializer.INSTANCE.fromJson(pair.getSecond(), BlockModel.class);
|
||||
BlockModel model = ExtendedBlockModelDeserializer.INSTANCE.fromJson(pair.getSecond(), BlockModel.class);
|
||||
model.name = pair.getFirst().toString();
|
||||
basicModels.put(pair.getFirst(), model);
|
||||
}
|
||||
|
|
@ -301,7 +299,7 @@ public abstract class ModelBakeryMixin {
|
|||
if(ibakedmodel == null) {
|
||||
ibakedmodel = iunbakedmodel.bake((ModelBakery) (Object) this, textureGetter, arg2, arg);
|
||||
}
|
||||
DynamicModelBakeEvent event = new DynamicModelBakeEvent(arg, iunbakedmodel, ibakedmodel, (ForgeModelBakery)(Object)this);
|
||||
DynamicModelBakeEvent event = new DynamicModelBakeEvent(arg, iunbakedmodel, ibakedmodel, (ModelBakery)(Object)this);
|
||||
ModLoader.get().postEvent(event);
|
||||
this.bakedCache.put(triple, event.getModel());
|
||||
return event.getModel();
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@ import net.minecraft.client.resources.model.BakedModel;
|
|||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.client.resources.model.MultiPartBakedModel;
|
||||
import net.minecraft.client.resources.model.WeightedBakedModel;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.IRegistryDelegate;
|
||||
import org.embeddedt.modernfix.dynamicresources.DynamicModelBakeEvent;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
|
@ -31,7 +31,7 @@ import java.util.function.Predicate;
|
|||
|
||||
@Mixin(CTMPackReloadListener.class)
|
||||
public abstract class CTMPackReloadListenerMixin {
|
||||
@Shadow @Final private static Map<IRegistryDelegate<Block>, Predicate<RenderType>> blockRenderChecks;
|
||||
@Shadow @Final private static Map<Holder.Reference<Block>, Predicate<RenderType>> blockRenderChecks;
|
||||
|
||||
@Shadow protected abstract Predicate<RenderType> getLayerCheck(BlockState state, BakedModel model);
|
||||
|
||||
|
|
@ -64,11 +64,12 @@ public abstract class CTMPackReloadListenerMixin {
|
|||
if(state == null)
|
||||
return;
|
||||
Block block = state.getBlock();
|
||||
if(blockRenderChecks.containsKey(block.delegate))
|
||||
Holder.Reference<Block> delegate = ForgeRegistries.BLOCKS.getDelegateOrThrow(block);
|
||||
if(blockRenderChecks.containsKey(delegate))
|
||||
return;
|
||||
Predicate<RenderType> newPredicate = this.getLayerCheck(state, event.getModel());
|
||||
if(newPredicate != null) {
|
||||
blockRenderChecks.put(block.delegate, this.getExistingRenderCheck(block));
|
||||
blockRenderChecks.put(delegate, this.getExistingRenderCheck(block));
|
||||
ItemBlockRenderTypes.setRenderLayer(block, newPredicate);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ import com.mojang.datafixers.util.Pair;
|
|||
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.client.model.ForgeModelBakery;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import org.embeddedt.modernfix.dynamicresources.DynamicModelBakeEvent;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
|
|
@ -25,7 +25,7 @@ import java.util.*;
|
|||
@Mixin(TextureMetadataHandler.class)
|
||||
public abstract class TextureMetadataHandlerMixin {
|
||||
|
||||
@Shadow @Nonnull protected abstract BakedModel wrap(ResourceLocation loc, UnbakedModel model, BakedModel object, ForgeModelBakery loader) throws IOException;
|
||||
@Shadow @Nonnull protected abstract BakedModel wrap(ResourceLocation loc, UnbakedModel model, BakedModel object, ModelBakery loader) throws IOException;
|
||||
|
||||
@SubscribeEvent
|
||||
public void onDynamicModelBake(DynamicModelBakeEvent event) {
|
||||
|
|
@ -55,7 +55,7 @@ public abstract class TextureMetadataHandlerMixin {
|
|||
IMetadataSectionCTM meta = null;
|
||||
// Cache all dependent texture metadata
|
||||
try {
|
||||
meta = ResourceUtil.getMetadata(ResourceUtil.spriteToAbsolute(tex.texture()));
|
||||
meta = ResourceUtil.getMetadata(ResourceUtil.spriteToAbsolute(tex.texture())).orElse(null); // TODO, lazy
|
||||
} catch (IOException e) {} // Fallthrough
|
||||
if (meta != null) {
|
||||
// At least one texture has CTM metadata, so we should wrap this model
|
||||
|
|
|
|||
|
|
@ -60,7 +60,6 @@
|
|||
"perf.cache_model_materials.VanillaModelMixin",
|
||||
"perf.cache_model_materials.MultipartMixin",
|
||||
"perf.faster_texture_stitching.StitcherMixin",
|
||||
"perf.use_integrated_resources.LootTableHelperMixin",
|
||||
"perf.skip_first_datapack_reload.CreateWorldScreenMixin",
|
||||
"perf.faster_singleplayer_load.MinecraftServerMixin",
|
||||
"devenv.MinecraftMixin",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user