From 42fefd8dd9289576653e48ccbc975b828edfefa4 Mon Sep 17 00:00:00 2001 From: Xel'Bayria <12866666+Xelbayria@users.noreply.github.com> Date: Wed, 25 Dec 2024 20:51:19 -0700 Subject: [PATCH] AbstractSimpleEntrySet: Restored a TEMP solution for MCMETA problem --- .../api/AbstractSimpleEntrySet.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/net/mehvahdjukaar/every_compat/api/AbstractSimpleEntrySet.java b/common/src/main/java/net/mehvahdjukaar/every_compat/api/AbstractSimpleEntrySet.java index 4a617910..019c59bb 100644 --- a/common/src/main/java/net/mehvahdjukaar/every_compat/api/AbstractSimpleEntrySet.java +++ b/common/src/main/java/net/mehvahdjukaar/every_compat/api/AbstractSimpleEntrySet.java @@ -3,6 +3,7 @@ import com.google.common.base.Suppliers; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; +import com.google.gson.JsonObject; import com.mojang.datafixers.util.Pair; import net.mehvahdjukaar.every_compat.EveryCompat; import net.mehvahdjukaar.every_compat.configs.ModEntriesConfigs; @@ -15,6 +16,7 @@ import net.mehvahdjukaar.moonlight.api.platform.RegHelper; import net.mehvahdjukaar.moonlight.api.resources.BlockTypeResTransformer; import net.mehvahdjukaar.moonlight.api.resources.RPUtils; +import net.mehvahdjukaar.moonlight.api.resources.ResType; import net.mehvahdjukaar.moonlight.api.resources.SimpleTagBuilder; import net.mehvahdjukaar.moonlight.api.resources.pack.DynClientResourcesGenerator; import net.mehvahdjukaar.moonlight.api.resources.pack.DynamicDataPack; @@ -31,6 +33,7 @@ import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.Resource; import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.tags.TagKey; import net.minecraft.world.item.BlockItem; @@ -39,6 +42,7 @@ import net.minecraft.world.level.block.Block; import org.jetbrains.annotations.Nullable; +import java.io.InputStream; import java.util.*; import java.util.function.BiFunction; import java.util.function.Consumer; @@ -277,6 +281,7 @@ public void generateTextures(SimpleModule module, DynClientResourcesGenerator ha try { ResourceLocation maskId = textureInfo.mask(); TextureImage main = TextureImage.open(manager, textureId); + main.getMetadata(); infoPerTextures.put(textureId, textureInfo); @@ -333,8 +338,8 @@ public void generateTextures(SimpleModule module, DynClientResourcesGenerator ha // if (!ModConfigs.isEntryEnabled(w, b)) continue; ResourceLocation blockId = Utils.getID(b); - var pal = paletteSupplier.apply(w, manager); - AnimationMetadataSection animation = pal.getSecond(); + var pal = paletteSupplier.apply(w, manager); // return the texture of: WoodType: Planks, StoneType: stone, LeavesType: leaves + AnimationMetadataSection targetAnimation = pal.getSecond(); List targetPalette = pal.getFirst(); if (targetPalette == null) { @@ -370,11 +375,28 @@ public void generateTextures(SimpleModule module, DynClientResourcesGenerator ha newId = oldTextureId.withPath(newPath).toString(); } isOnAtlas = info.onAtlas(); + + /// TEMP: do not remove this until the mcmeta problem is fixed. + if (info.copyMCMETA()) { + ResourceLocation mcmetaLoc = ResType.MCMETA.getPath(oldTextureId); + Optional getMCMETA = manager.getResource(mcmetaLoc); + + if (getMCMETA.isPresent()) { + InputStream mcmetaStream = getMCMETA.get().open(); + JsonObject mcmetaFile = RPUtils.deserializeJson(mcmetaStream); + + // Adding to the resources next to newtextures + handler.dynamicPack.addJson(ResourceLocation.tryParse(newId), mcmetaFile, ResType.MCMETA); + mcmetaStream.close(); + } + else + handler.getLogger().error("The MCMETA file may no longer existing, check @ {}", mcmetaLoc); + } } Respriter respriter = re.getValue(); - Supplier textureSupplier = () -> respriter.recolorWithAnimation(targetPalette, animation); + Supplier textureSupplier = () -> respriter.recolorWithAnimation(targetPalette, targetAnimation); textureSupplier = postProcessTexture(w, newId, manager, textureSupplier); handler.addTextureIfNotPresent(manager, newId, textureSupplier, isOnAtlas);