From eb5c97e65e7f16e710ada1781f8648280757024b Mon Sep 17 00:00:00 2001 From: Xel'Bayria <12866666+Xelbayria@users.noreply.github.com> Date: Wed, 25 Dec 2024 01:57:22 -0700 Subject: [PATCH] AbstractSimpleEntrySet & TextureInfo: Added copyMCMETA --- .../api/AbstractSimpleEntrySet.java | 31 +++++++++++++++---- .../every_compat/api/TextureInfo.java | 10 ++++-- 2 files changed, 33 insertions(+), 8 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 a58f2cc2e..3a8058231 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,8 @@ import net.minecraft.world.level.block.Block; import org.jetbrains.annotations.Nullable; +import java.io.IOException; +import java.io.InputStream; import java.util.*; import java.util.function.BiFunction; import java.util.function.Consumer; @@ -374,32 +379,46 @@ public void generateTextures(SimpleModule module, DynClientResourcesGenerator ha ResourceLocation oldTextureId = re.getKey(); String oldPath = oldTextureId.getPath(); - //// BlockTypeResTransformer.replaceFullGenericType(oldPath, w, blockId, baseType.get().getTypeName(), null, 2); Solve Boatload's texture issue - // boatload's texture path has 2 folder String newPath = (oldPath.startsWith("entity/") && module.modId.equals("boatload")) ? BlockTypeResTransformer.replaceFullGenericType(oldPath, w, blockId, baseType.get().getTypeName(), null, 2) // Default : BlockTypeResTransformer.replaceTypeNoNamespace(oldPath, w, blockId, baseType.get().getTypeName()); - String newId = new ResourceLocation(blockId.getNamespace(), newPath).toString(); + ResourceLocation newId = new ResourceLocation(blockId.getNamespace(), newPath); boolean isOnAtlas = true; for (var info : infoPerTextures.get(oldTextureId)) { if (info != null) { if (info.keepNamespace()) { - newId = oldTextureId.withPath(newPath).toString(); + newId = oldTextureId.withPath(newPath); } isOnAtlas = info.onAtlas(); + + 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(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(finalTargetPalette, finalAnimation); - textureSupplier = postProcessTexture(w, newId, manager, textureSupplier); + textureSupplier = postProcessTexture(w, newId.toString(), manager, textureSupplier); - handler.addTextureIfNotPresent(manager, newId, textureSupplier, isOnAtlas); + handler.addTextureIfNotPresent(manager, newId.toString(), textureSupplier, isOnAtlas); } } } diff --git a/common/src/main/java/net/mehvahdjukaar/every_compat/api/TextureInfo.java b/common/src/main/java/net/mehvahdjukaar/every_compat/api/TextureInfo.java index 30f6d7b71..7b2759ffb 100644 --- a/common/src/main/java/net/mehvahdjukaar/every_compat/api/TextureInfo.java +++ b/common/src/main/java/net/mehvahdjukaar/every_compat/api/TextureInfo.java @@ -4,7 +4,7 @@ import org.jetbrains.annotations.Nullable; public record TextureInfo(ResourceLocation texture, @Nullable ResourceLocation mask, - boolean keepNamespace, boolean copyTexture, boolean autoMask, + boolean keepNamespace, boolean copyTexture, boolean copyMCMETA, boolean autoMask, boolean onAtlas) { public static Builder of(ResourceLocation res) { return new Builder(res); @@ -15,6 +15,7 @@ public static final class Builder { private ResourceLocation mask; private boolean keepNamespace = false; private boolean copyTexture = false; + private boolean copyMCMETA = false; private boolean autoMask = false; private boolean onAtlas; @@ -44,6 +45,11 @@ public Builder copyTexture() { return this; } + public Builder copyMCMETA() { + this.copyMCMETA = true; + return this; + } + public Builder autoMask() { this.autoMask = true; return this; @@ -51,7 +57,7 @@ public Builder autoMask() { public TextureInfo build() { return new TextureInfo(texture, mask, keepNamespace, - copyTexture, autoMask, onAtlas); + copyTexture, copyMCMETA, autoMask, onAtlas); } } }