Skip to content

Commit

Permalink
AbstractSimpleEntrySet & TextureInfo: Added copyMCMETA
Browse files Browse the repository at this point in the history
  • Loading branch information
Xelbayria committed Dec 25, 2024
1 parent f30970c commit eb5c97e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 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,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;
Expand Down Expand Up @@ -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<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(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(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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -44,14 +45,19 @@ public Builder copyTexture() {
return this;
}

public Builder copyMCMETA() {
this.copyMCMETA = true;
return this;
}

public Builder autoMask() {
this.autoMask = true;
return this;
}

public TextureInfo build() {
return new TextureInfo(texture, mask, keepNamespace,
copyTexture, autoMask, onAtlas);
copyTexture, copyMCMETA, autoMask, onAtlas);
}
}
}

0 comments on commit eb5c97e

Please sign in to comment.