Skip to content

Commit

Permalink
AbstractSimpleEntrySet: Restored a TEMP solution for MCMETA problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Xelbayria committed Dec 26, 2024
1 parent 22275a4 commit 42fefd8
Showing 1 changed file with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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<Palette> targetPalette = pal.getFirst();

if (targetPalette == null) {
Expand Down Expand Up @@ -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<Resource> 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<TextureImage> textureSupplier = () -> respriter.recolorWithAnimation(targetPalette, animation);
Supplier<TextureImage> textureSupplier = () -> respriter.recolorWithAnimation(targetPalette, targetAnimation);
textureSupplier = postProcessTexture(w, newId, manager, textureSupplier);

handler.addTextureIfNotPresent(manager, newId, textureSupplier, isOnAtlas);
Expand Down

0 comments on commit 42fefd8

Please sign in to comment.