Skip to content

Commit

Permalink
Merge branch 'architectury-1.17.1' into architectury-1.18.1
Browse files Browse the repository at this point in the history
  • Loading branch information
UnlikePaladin committed Nov 10, 2023
2 parents c38d133 + 9af1919 commit bce47cf
Show file tree
Hide file tree
Showing 29 changed files with 635 additions and 387 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import com.unlikepaladin.pfm.config.PaladinFurnitureModConfig;
import com.unlikepaladin.pfm.runtime.PFMRuntimeResources;
import com.unlikepaladin.pfm.utilities.Version;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.fabricmc.api.EnvType;
Expand All @@ -31,6 +32,7 @@
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
Expand All @@ -46,10 +48,9 @@ public class PaladinFurnitureModUpdateChecker {
public PaladinFurnitureModUpdateChecker() {
}

@ExpectPlatform
public static File getUpdateFile() {
PaladinFurnitureMod.GENERAL_LOGGER.error("[Paladin's Furniture Update Check] Unable to get local update file!");
return null;
Path path = PFMRuntimeResources.getPFMDirectory().resolve("pfmUpdateInfo.json");
return path.toFile();
}

@ExpectPlatform
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.unlikepaladin.pfm.blocks.models;

import com.unlikepaladin.pfm.PaladinFurnitureMod;
import com.unlikepaladin.pfm.blocks.DyeableFurnitureBlock;
import com.unlikepaladin.pfm.data.materials.*;
import com.unlikepaladin.pfm.runtime.PFMDataGenerator;
import com.unlikepaladin.pfm.runtime.PFMRuntimeResources;
import com.unlikepaladin.pfm.runtime.PFMDataGen;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.data.client.model.Texture;
Expand Down Expand Up @@ -173,7 +174,7 @@ else if(idExists(getLogId(block, "_bottom"), ResourceType.CLIENT_RESOURCES, IdLo
}
else {
if (!Registry.BLOCK.getId(block).getNamespace().equals("quark")) {
PFMDataGen.LOGGER.warn("Couldn't find texture for, {}", block);
PaladinFurnitureMod.GENERAL_LOGGER.warn("Couldn't find texture for, {}", block);
}
id = Texture.getSubId(block, postfix);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.function.Predicate;
import java.util.function.Supplier;

public class PathPackRPWrapper implements ResourcePack {
public class PathPackRPWrapper implements ResourcePack {
private final Supplier<ResourcePack> delegate;
private final PackResourceMetadata packResourceMetadata;

Expand All @@ -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,7 +6,8 @@
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.PFMDataGen;
import com.unlikepaladin.pfm.runtime.PFMAssetGenerator;
import com.unlikepaladin.pfm.runtime.PFMDataGenerator;
import com.unlikepaladin.pfm.runtime.PFMRuntimeResources;
import com.unlikepaladin.pfm.utilities.PFMFileUtil;
import net.fabricmc.api.EnvType;
Expand Down Expand Up @@ -61,12 +62,18 @@ 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.getResourceDirectory().toFile());
PFMDataGen.frozen = false;
PFMRuntimeResources.prepareAsyncResourceGen(true);
PFMFileUtil.deleteDir(PFMRuntimeResources.getAssetPackDirectory().toFile());
PFMAssetGenerator.FROZEN = false;
PFMRuntimeResources.prepareAsyncAssetGen(true);
PFMRuntimeResources.runAsyncResourceGen();
MinecraftClient.getInstance().reloadResourcesConcurrently();
}));
this.addEntry(new ButtonEntry(Side.SERVER, new TranslatableText("pfm.option.regenData"), new TranslatableText("pfm.config.regen"), new TranslatableText("pfm.option.regenData.tooltip"), button -> {
PFMFileUtil.deleteDir(PFMRuntimeResources.getDataPackDirectory().toFile());
PFMDataGenerator.FROZEN = false;
PFMRuntimeResources.prepareAsyncDataGen(true);
PFMRuntimeResources.runAsyncResourceGen();
}));
}

public void save() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.unlikepaladin.pfm.runtime;

import com.google.common.base.Stopwatch;
import com.mojang.bridge.game.PackType;
import com.unlikepaladin.pfm.PaladinFurnitureMod;
import com.unlikepaladin.pfm.runtime.assets.PFMBlockstateModelProvider;
import com.unlikepaladin.pfm.runtime.assets.PFMLangProvider;
import com.unlikepaladin.pfm.runtime.data.PFMMCMetaProvider;
import com.unlikepaladin.pfm.utilities.PFMFileUtil;
import net.minecraft.data.DataCache;
import net.minecraft.resource.ResourcePack;
import net.minecraft.resource.ResourceType;
import org.apache.logging.log4j.LogManager;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class PFMAssetGenerator extends PFMGenerator {
public static boolean FROZEN = false;
public PFMAssetGenerator(Path output, boolean logOrDebug) {
super(output, logOrDebug, LogManager.getLogger("PFM-Asset-Generation"));
}

public void run() throws IOException {
if (!FROZEN) {
log("Packs:");
for (ResourcePack pack : PFMRuntimeResources.RESOURCE_PACK_LIST) {
log("\tPack {}", pack.getName());
for (String namespace : pack.getNamespaces(ResourceType.CLIENT_RESOURCES)) {
log("\t\tNamespace {}", namespace);
}
}
this.setRunning(true);
FROZEN = true;

Path modListPath = output.resolve("modsList");
Path hashPath = output.resolve("dataHash");
if (!modListPath.toFile().isFile()) {
Files.deleteIfExists(modListPath);
Files.createFile(modListPath);
}
if (!hashPath.toFile().isFile()) {
Files.deleteIfExists(hashPath);
Files.createFile(hashPath);
}
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())) {
getLogger().info("Starting PFM Asset Generation");
PFMFileUtil.deleteDir(output.toFile());
PFMRuntimeResources.createDirIfNeeded(output);
DataCache dataCache = new DataCache(this.output, "cache");
dataCache.ignore(this.output.resolve("version.json"));
Stopwatch stopwatch = Stopwatch.createStarted();
Stopwatch stopwatch2 = Stopwatch.createUnstarted();

log("Starting provider: {}", "PFM Asset MC Meta");
stopwatch2.start();
new PFMMCMetaProvider(this).run(PackType.RESOURCE, "PFM-Assets");
stopwatch2.stop();
log("{} finished after {} ms", "PFM Asset MC Meta", stopwatch2.elapsed(TimeUnit.MILLISECONDS));

log("Starting provider: {}", "PFM Blockstates and Models");
stopwatch2.start();
new PFMBlockstateModelProvider(this).run(dataCache);
stopwatch2.stop();
log("{} finished after {} ms", "PFM Blockstates and Models", stopwatch2.elapsed(TimeUnit.MILLISECONDS));
stopwatch2.reset();

log("Starting provider: {}", "PFM Lang");
stopwatch2.start();
new PFMLangProvider(this).run();
stopwatch2.stop();
log("{} finished after {} ms", "PFM Lang", stopwatch2.elapsed(TimeUnit.MILLISECONDS));
stopwatch2.reset();

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(), 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.setRunning(false);
} else {
log("Data Hash and Mod list matched, skipping generation");
}
}
}
}
186 changes: 0 additions & 186 deletions common/src/main/java/com/unlikepaladin/pfm/runtime/PFMDataGen.java

This file was deleted.

Loading

0 comments on commit bce47cf

Please sign in to comment.