Skip to content

Commit

Permalink
Fix Asset/Data Cache breaking
Browse files Browse the repository at this point in the history
Fix Runtime Pack Icon
Delete old invalid model file
Fix Broken translation for Config Option, improved description for runtime packs
  • Loading branch information
UnlikePaladin committed Nov 10, 2023
1 parent a2fb735 commit 363aa69
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public PathPackRPWrapper(Supplier<ResourcePack> delegate, PackResourceMetadata p
@Nullable
@Override
public InputStream openRoot(String fileName) throws IOException {
if (fileName.equals("pack.png")) {
return delegate.get().openRoot(fileName);
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.unlikepaladin.pfm.config.option.AbstractConfigOption;
import com.unlikepaladin.pfm.config.option.BooleanConfigOption;
import com.unlikepaladin.pfm.config.option.Side;
import com.unlikepaladin.pfm.runtime.PFMAssetGenerator;
import com.unlikepaladin.pfm.runtime.PFMDataGenerator;
import com.unlikepaladin.pfm.runtime.PFMRuntimeResources;
import com.unlikepaladin.pfm.utilities.PFMFileUtil;
Expand Down Expand Up @@ -62,7 +63,7 @@ public PFMOptionListWidget(PFMConfigScreen parent, MinecraftClient client) {
this.addEntry(new CategoryEntry(new LiteralText("")));
this.addEntry(new ButtonEntry(Side.CLIENT, new TranslatableText("pfm.option.regenAssets"), new TranslatableText("pfm.config.regen"), new TranslatableText("pfm.option.regenAssets.tooltip"), button -> {
PFMFileUtil.deleteDir(PFMRuntimeResources.getAssetPackDirectory().toFile());
PFMDataGenerator.FROZEN = false;
PFMAssetGenerator.FROZEN = false;
PFMRuntimeResources.prepareAsyncAssetGen(true);
PFMRuntimeResources.runAsyncResourceGen();
MinecraftClient.getInstance().reloadResourcesConcurrently();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.concurrent.TimeUnit;

public class PFMAssetGenerator extends PFMGenerator {
private static boolean FROZEN = false;
public static boolean FROZEN = false;
public PFMAssetGenerator(Path output, boolean logOrDebug) {
super(output, logOrDebug, LogManager.getLogger("PFM-Asset-Generation"));
}
Expand All @@ -47,7 +47,7 @@ public void run() throws IOException {
Files.deleteIfExists(hashPath);
Files.createFile(hashPath);
}
List<String> hashToCompare = hashDirectory(output.toFile(), true);
List<String> hashToCompare = hashDirectory(output.toFile(), false);
List<String> oldHash = Files.readAllLines(hashPath);
List<String> modList = Files.readAllLines(modListPath);
if (!hashToCompare.toString().equals(oldHash.toString()) || !modList.toString().replace("[", "").replace("]", "").equals(PaladinFurnitureMod.getVersionMap().toString())) {
Expand Down Expand Up @@ -81,16 +81,15 @@ public void run() throws IOException {

getLogger().info("Asset providers took: {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
dataCache.write();
this.createPackIcon();
Files.deleteIfExists(hashPath);
Files.createFile(hashPath);
List<String> newDataHash = hashDirectory(output.toFile(), true);
List<String> newDataHash = hashDirectory(output.toFile(), false);
Files.writeString(PFMRuntimeResources.createDirIfNeeded(hashPath), newDataHash.toString().replace("[", "").replace("]", ""), StandardOpenOption.APPEND);

Files.deleteIfExists(modListPath);
Files.createFile(modListPath);
Files.writeString(PFMRuntimeResources.createDirIfNeeded(modListPath), PaladinFurnitureMod.getVersionMap().toString().replace("[", "").replace("]", ""), StandardOpenOption.APPEND);

this.createPackIcon();
this.setRunning(false);
} else {
log("Data Hash and Mod list matched, skipping generation");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

public class PFMDataGenerator extends PFMGenerator {
public static boolean FROZEN = false;

public PFMDataGenerator(Path output, boolean logOrDebug) {
super(output, logOrDebug, LogManager.getLogger("PFM-DataGen"));
}
Expand All @@ -49,7 +48,7 @@ public void run() throws IOException {
Files.deleteIfExists(hashPath);
Files.createFile(hashPath);
}
List<String> hashToCompare = hashDirectory(output.toFile(), true);
List<String> hashToCompare = hashDirectory(output.toFile(), false);
List<String> oldHash = Files.readAllLines(hashPath);
List<String> modList = Files.readAllLines(modListPath);
if (!hashToCompare.toString().equals(oldHash.toString()) || !modList.toString().replace("[", "").replace("]", "").equals(PaladinFurnitureMod.getVersionMap().toString())) {
Expand Down Expand Up @@ -93,7 +92,7 @@ public void run() throws IOException {

Files.deleteIfExists(hashPath);
Files.createFile(hashPath);
List<String> newDataHash = hashDirectory(output.toFile(), true);
List<String> newDataHash = hashDirectory(output.toFile(), false);
Files.writeString(PFMRuntimeResources.createDirIfNeeded(hashPath), newDataHash.toString().replace("[", "").replace("]", ""), StandardOpenOption.APPEND);

Files.deleteIfExists(modListPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import com.google.gson.GsonBuilder;
import org.apache.logging.log4j.Logger;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Vector;
import java.util.*;
import java.util.stream.Collectors;

public abstract class PFMGenerator {
protected final Path output;
Expand All @@ -31,9 +31,11 @@ protected PFMGenerator(Path output, boolean logOrDebug, Logger logger) {
}

protected void createPackIcon() {
File file = new File(output.toFile(), "icon.png");
try (OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file))) {
outputStream.write(PFMRuntimeResources.getImageData());
File file = new File(output.toFile(), "pack.png");
try {
BufferedImage image = ImageIO.read(new ByteArrayInputStream(PFMRuntimeResources.getImageData()));
ImageIO.write(image, "png", file);
image.flush();
} catch (IOException e) {
logger.warn("Failed to create resource icon {}", e.getMessage());
}
Expand Down Expand Up @@ -88,11 +90,15 @@ public List<String> hashDirectory(File directory, boolean includeHiddenFiles) th

private void collectFiles(File directory, List<String> hashList,
boolean includeHiddenFiles) throws IOException {
File[] files = directory.listFiles();
if (files != null) {
Arrays.sort(files, Comparator.comparing(File::getName));
File[] fileArray = directory.listFiles();
if (fileArray != null) {
List<File> files = new ArrayList<>(Arrays.asList(fileArray));
files.removeIf(file -> file.getName().contains("dataHash") || file.getName().contains("modsList"));
files.sort(Comparator.comparing(File::getName));

for (File file : files) {
if (file.getName().contains("dataHash") || file.getName().contains("modsList") || file == null)
continue;
if (includeHiddenFiles || !Files.isHidden(file.toPath())) {
if (file.isDirectory()) {
collectFiles(file, hashList, includeHiddenFiles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.concurrent.CompletableFuture;

public class PFMRuntimeResources {
public static final String base64Icon = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD/2wBDABwcHBwcHDAcHDBEMDAwRFxEREREXHRcXFxcXHSMdHR0dHR0jIyMjIyMjIyoqKioqKjExMTExNzc3Nzc3Nzc3Nz/2wBDASIkJDg0OGA0NGDmnICc5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ub/wAARCAEAAQADASIAAhEBAxEB/8QAGQABAAMBAQAAAAAAAAAAAAAAAAEDBAUC/8QAKBABAQABAwQBBAIDAQAAAAAAAAECAxExBCEycVESIjNBYYETkaGx/8QAGAEBAAMBAAAAAAAAAAAAAAAAAAEDBAL/xAAcEQEBAAMBAQEBAAAAAAAAAAAAAQIDETEhUUH/2gAMAwEAAhEDEQA/ANADG2gAAAAAAAAAAAAAAt/w6n0/V9NVFliJZfAASAAAAAAAAAAAAAAAAAAAAAAAADRp9Nnn3y+2Nuno4afE7/LvHXary2SMWn02effL7Y26ejhp8Tv8rkWxdjhIpyztSo1NLTz5ndbvUOrHMci9rshN5qGRrABIAAAAAAAAAAAAAAAAAANGn02efe/bG3DRw0+J3+XeOu1XlskYsOmzz737Y26ejhp8Tv8AK5FsXY4SKcs7UotkRah05TbUAkAEJci81CbzUMjUACQAAAAAAAAAAAAAAABM5iEzmEQ6szs/l7mUsUveLWy2PdqASgAAAAAQlyLzUJvNQyNQAJAAAAAAAAAAAAAAAAEzmITOYRDpPeLw94tbNXoBLkAAAAAQlyLzUJvNQyNQAJAAAAAAAAA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WsnDSz1GXjfTkutl4305Knas1ACpctw1sse17xbl1N22wm381lHUzrm4yptuV3t3qAcpABIAAAAAAAAAAAAAAAAAAu0LJld7tvFImXl6izs46aycOZjqZYcXt8Lr1N22xm1XTZFNwrVqZTHG73bs5ablcrvld0Ks8urMMeADl2AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//2Q==";
public static final DirectoryResourcePack ASSETS_PACK = new DirectoryResourcePack(getAssetPackDirectory().toFile());
public static final DirectoryResourcePack DATA_PACK = new DirectoryResourcePack(getDataPackDirectory().toFile());

Expand Down

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions common/src/main/resources/assets/pfm/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -1193,8 +1193,8 @@
"pfm.option.shaderSolidFix.tooltip": "Makes furniture with translucent parts opaque to prevent rendering issues with shaders like Seus if shaders are on. Works both with Optifine and Iris/Oculus.",
"pfm.option.spawnImmersivePortalsMirror": "Spawn Immersive Portals Mirrors",
"pfm.option.spawnImmersivePortalsMirror.tooltip": "If true the mod's mirrors work if immersive portals is present, if the server sets this to false, it won't work for the players.",
"pfm.option.renderImmersivePortalsMirror": "Immersive Portals Mirror Rendering",
"pfm.option.renderImmersivePortalsMirror.tooltip": "If true mirrors will render if immersive portals is installed.",
"pfm.option.renderImmersivePortalsMirrors": "Immersive Portals Mirror Rendering",
"pfm.option.renderImmersivePortalsMirrors.tooltip": "If true mirrors will render if immersive portals is installed.",

"pfm.config.title": "Paladin's Furniture Mod Config",
"pfm.option.resetAll": "Reset All Options",
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public class PFMModResourcePackCreatorMixin {
@Inject(method = "register(Ljava/util/function/Consumer;Lnet/minecraft/resource/ResourcePackProfile$Factory;)V", at = @At("TAIL"))
private void addPFMResources(Consumer<ResourcePackProfile> consumer, ResourcePackProfile.Factory factory, CallbackInfo ci) {
if (type == ResourceType.CLIENT_RESOURCES) {
PackResourceMetadata packResourceMetadata = new PackResourceMetadata(new LiteralText("pfm-runtime-resources"), SharedConstants.getGameVersion().getPackVersion(PackType.RESOURCE));
PackResourceMetadata packResourceMetadata = new PackResourceMetadata(new LiteralText("Runtime Generated Assets for PFM"), SharedConstants.getGameVersion().getPackVersion(PackType.RESOURCE));
consumer.accept(factory.create("pfm-asset-resources", new LiteralText("PFM Assets"), true,
() -> new PathPackRPWrapper(Suppliers.memoize(() -> {
PFMRuntimeResources.prepareAndRunAssetGen(false); return PFMRuntimeResources.ASSETS_PACK;}), packResourceMetadata)
, packResourceMetadata, ResourcePackProfile.InsertionPosition.BOTTOM, ResourcePackSource.PACK_SOURCE_NONE));
} else if (type == ResourceType.SERVER_DATA) {
PackResourceMetadata packResourceMetadata = new PackResourceMetadata(new LiteralText("pfm-runtime-data"), SharedConstants.getGameVersion().getPackVersion(PackType.DATA));
PackResourceMetadata packResourceMetadata = new PackResourceMetadata(new LiteralText("Runtime Generated Data for PFM"), SharedConstants.getGameVersion().getPackVersion(PackType.DATA));
consumer.accept(factory.create("pfm-data-resources", new LiteralText("PFM Data"), true,
() -> new PathPackRPWrapper(Suppliers.memoize(() -> {
PFMRuntimeResources.prepareAndRunDataGen(false); return PFMRuntimeResources.DATA_PACK;}), packResourceMetadata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ public PaladinFurnitureModForge() {
@SubscribeEvent
public static void generateResources(AddPackFindersEvent event) {
if (event.getPackType() == ResourceType.CLIENT_RESOURCES) {
PackResourceMetadata packResourceMetadata = new PackResourceMetadata(new LiteralText("pfm-runtime-resources"), SharedConstants.getGameVersion().getPackVersion(PackType.RESOURCE));
PackResourceMetadata packResourceMetadata = new PackResourceMetadata(new LiteralText("Runtime Generated Assets for PFM"), SharedConstants.getGameVersion().getPackVersion(PackType.RESOURCE));
event.addRepositorySource((profileAdder, factory) -> profileAdder.accept(factory.create("pfm-asset-resources", new LiteralText("PFM Assets"), true,
() -> new PathPackRPWrapper(Suppliers.memoize(() -> {
PFMRuntimeResources.prepareAndRunAssetGen(false); return PFMRuntimeResources.ASSETS_PACK;}), packResourceMetadata)
, packResourceMetadata, ResourcePackProfile.InsertionPosition.BOTTOM, ResourcePackSource.PACK_SOURCE_NONE, true)));
, packResourceMetadata, ResourcePackProfile.InsertionPosition.BOTTOM, ResourcePackSource.PACK_SOURCE_NONE, false)));
} else if (event.getPackType() == ResourceType.SERVER_DATA) {
PackResourceMetadata packResourceMetadata = new PackResourceMetadata(new LiteralText("pfm-runtime-data"), SharedConstants.getGameVersion().getPackVersion(PackType.DATA));
PackResourceMetadata packResourceMetadata = new PackResourceMetadata(new LiteralText("Runtime Generated Data for PFM"), SharedConstants.getGameVersion().getPackVersion(PackType.DATA));
event.addRepositorySource((profileAdder, factory) -> profileAdder.accept(factory.create("pfm-data-resources", new LiteralText("PFM Data"), true,
() -> new PathPackRPWrapper(Suppliers.memoize(() -> {
PFMRuntimeResources.prepareAndRunDataGen(false); return PFMRuntimeResources.DATA_PACK;}), packResourceMetadata)
, packResourceMetadata, ResourcePackProfile.InsertionPosition.BOTTOM, ResourcePackSource.PACK_SOURCE_NONE, true)));
, packResourceMetadata, ResourcePackProfile.InsertionPosition.BOTTOM, ResourcePackSource.PACK_SOURCE_NONE, false)));
}
}
}

0 comments on commit 363aa69

Please sign in to comment.