Skip to content

Commit

Permalink
Remove Modlist in Fixes + Patch Capacitor Fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Jul 13, 2024
1 parent 32b3723 commit 7dd9033
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 156 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//version: 1720106721
//version: 1720840170
/*
* DO NOT CHANGE THIS FILE!
* Also, you may replace this file at any time if there is an update available.
Expand Down Expand Up @@ -1252,7 +1252,7 @@ if (cfApiKey.isPresent() || deploymentDebug.toBoolean()) {
def fileId = artifact.getCurseFileId()
def fileName = artifact.getArtifact().getSingleFile().name
println("Uploaded File ${fileName}, With File ID: ${fileId}")
summary = summary + "\n- File: ${fileName} | File ID: ${fileId}"
summary = summary + "\n - File: ${fileName} | File ID: ${fileId}"
}
println(summary)
def stepSummary = providers.environmentVariable("GITHUB_STEP_SUMMARY")
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/com/nomiceu/nomilabs/LabsValues.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.nomiceu.nomilabs;

import com.nomiceu.nomilabs.util.LabsVersionUtil;

@SuppressWarnings("unused")
public class LabsValues {

Expand Down Expand Up @@ -42,9 +40,5 @@ public class LabsValues {
public static final String FTB_UTILS_MODID = "ftbutilities";
public static final String TOP_ADDONS_MODID = "topaddons";
public static final String PACK_MODE_MODID = "packmode";

/* AE2 Stuff Compat */
public static final String AE2_STUFF_MODID = "ae2stuff";
public static final LabsVersionUtil.LabsVersion AE2_STUFF_UNOFFICIAL_SEPARATOR = LabsVersionUtil
.getVersionFromString("0.8");
}
19 changes: 6 additions & 13 deletions src/main/java/com/nomiceu/nomilabs/remap/datafixer/DataFix.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.nomiceu.nomilabs.remap.datafixer;

import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;

Expand All @@ -17,28 +16,24 @@ public abstract class DataFix<T> {
public final String description;
public final boolean needsMode;
public final Function<Integer, Boolean> validVersion;
public final Function<Map<String, String>, Boolean> validModList;
public final Function<T, Boolean> validEntry;
public final Consumer<T> transform;

public DataFix(String name, String description, boolean needsMode, Function<Integer, Boolean> validVersion,
Function<Map<String, String>, Boolean> validModList, Function<T, Boolean> validEntry,
Consumer<T> transform) {
Function<T, Boolean> validEntry, Consumer<T> transform) {
this.name = name;
this.description = description;
this.needsMode = needsMode;
this.validVersion = validVersion;
this.validModList = validModList;
this.validEntry = validEntry;
this.transform = transform;
}

public static class ItemFix extends DataFix<ItemStackLike> {

public ItemFix(String name, String description, boolean needsMode, Function<Integer, Boolean> validVersion,
Function<Map<String, String>, Boolean> validModList, Function<ItemStackLike, Boolean> validEntry,
Consumer<ItemStackLike> transform) {
super(name, description, needsMode, validVersion, validModList, validEntry, transform);
Function<ItemStackLike, Boolean> validEntry, Consumer<ItemStackLike> transform) {
super(name, description, needsMode, validVersion, validEntry, transform);
}
}

Expand All @@ -49,11 +44,10 @@ public static class BlockFix extends DataFix<BlockStateLike> {
public final Function<BlockStateLike, Boolean> secondaryValidEntry;

public BlockFix(String name, String description, boolean needsMode, Function<Integer, Boolean> validVersion,
Function<Map<String, String>, Boolean> validModList, boolean teNeeded,
Function<BlockStateLike, Boolean> validEntry,
boolean teNeeded, Function<BlockStateLike, Boolean> validEntry,
@Nullable Function<BlockStateLike, Boolean> secondaryValidEntry,
Consumer<BlockStateLike> blockTransform) {
super(name, description, needsMode, validVersion, validModList, validEntry, blockTransform);
super(name, description, needsMode, validVersion, validEntry, blockTransform);
this.secondaryValidEntry = secondaryValidEntry;
this.teNeeded = teNeeded;
}
Expand All @@ -63,9 +57,8 @@ public static class TileEntityFix extends DataFix<NBTTagCompound> {

public TileEntityFix(String name, String description, boolean needsMode,
Function<Integer, Boolean> validVersion,
Function<Map<String, String>, Boolean> validModList,
Function<NBTTagCompound, Boolean> validEntry, Consumer<NBTTagCompound> transform) {
super(name, description, needsMode, validVersion, validModList, validEntry, transform);
super(name, description, needsMode, validVersion, validEntry, transform);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
Expand Down Expand Up @@ -57,16 +56,16 @@ public class DataFixerHandler {
public static LabsWorldFixData worldSavedData = null;
public static boolean checked = false;

/* Fixes that should be applied */
public static Map<IFixType, List<DataFix<?>>> neededFixes;

/* Fixes that should be logged */
public static Map<IFixType, List<DataFix<?>>> neededNewFixes;

/* Whether Mode is needed for New Fixes */
public static boolean modeNeeded = false;

private static Map<String, String> mods;
/* Whether fix is available */
private static boolean fixAvailable = false;

private static String savedLabsVersion;

/* Must be split up so that idToBlockMap is the old one (so we can use not registered resource locations) */
private static NBTTagList oldBlockRegistry;
Expand Down Expand Up @@ -95,36 +94,27 @@ public static void preInit() {
public static void onWorldLoad(SaveHandler save) {
checked = false;
modeNeeded = false;
neededFixes = null;
neededNewFixes = null;
NomiLabs.LOGGER.info("Checking Data Fixers...");
savedLabsVersion = null;
fixAvailable = true;

// Clear Block Helper Maps, the ids can be different for each save
idToBlockMap = null;
blockToIdMap = null;
oldBlockRegistry = null;
NomiLabs.LOGGER.info("Checking Data Fixers...");

getInfoFromSave(save);
if (mods.isEmpty()) return;

LabsFixes.init();
neededFixes = new Object2ObjectOpenHashMap<>();
for (var fixType : LabsFixes.fixes.keySet()) {
for (var fix : LabsFixes.fixes.get(fixType)) {
if (fix.validModList.apply(mods)) {
if (!neededFixes.containsKey(fixType)) neededFixes.put(fixType, new ObjectArrayList<>());
neededFixes.get(fixType).add(fix);
}
}
}

var mapFile = save.getMapFileFromName(LabsFixes.DATA_NAME);

if (mapFile.exists()) {
DataFixerHandler.worldSavedData = LabsWorldFixData.load(mapFile);

// Shortcut: If saved version == Current Version, Exit
if (DataFixerHandler.worldSavedData.savedVersion == LabsFixes.CURRENT) {
if (DataFixerHandler.worldSavedData.savedFixVersion == LabsFixes.CURRENT) {
DataFixerHandler.worldSavedData = null;
NomiLabs.LOGGER.info("This world's data version is up to date.");
return;
Expand Down Expand Up @@ -168,8 +158,6 @@ public static void onWorldLoad(SaveHandler save) {
}

private static void getInfoFromSave(SaveHandler save) {
mods = new HashMap<>();

File levelDat = new File(save.getWorldDirectory(), "level.dat");

// If level.dat file does not exist, return.
Expand All @@ -179,20 +167,23 @@ private static void getInfoFromSave(SaveHandler save) {
if (!levelDat.exists())
return;

NBTTagList modList;
try {
NBTTagCompound nbt = CompressedStreamTools.readCompressed(new FileInputStream(levelDat));
if (!nbt.hasKey("FML", Constants.NBT.TAG_COMPOUND)) return;
NBTTagCompound fml = nbt.getCompoundTag("FML");

if (fml.hasKey("ModList", Constants.NBT.TAG_LIST)) {
modList = fml.getTagList("ModList", Constants.NBT.TAG_COMPOUND);
NBTTagList modList = fml.getTagList("ModList", Constants.NBT.TAG_COMPOUND);
for (var mod : modList) {
if (!(mod instanceof NBTTagCompound compound)) continue;
if (!compound.hasKey("ModId", Constants.NBT.TAG_STRING) ||
!compound.hasKey("ModVersion", Constants.NBT.TAG_STRING))
continue;
mods.put(compound.getString("ModId"), compound.getString("ModVersion"));
if (!LabsValues.LABS_MODID.equals(compound.getString("ModId")))
continue;

savedLabsVersion = compound.getString("ModVersion");
break;
}
}

Expand All @@ -212,24 +203,21 @@ private static void getInfoFromSave(SaveHandler save) {
private static void determineNeededFixesAndLog() {
neededNewFixes = new Object2ObjectOpenHashMap<>();

if (mods.isEmpty()) return;

// If Nomi Labs Version is same as current version, exit.
// This normally means it is a new world.
// Sometimes the level.dat file is created first, but usually this runs after it is created.
// If the level.dat file is created first, its mod list is equal to the current one.
if (mods.containsKey(LabsValues.LABS_MODID) && mods.get(LabsValues.LABS_MODID).equals(LabsValues.LABS_VERSION))
if (LabsValues.LABS_VERSION.equals(savedLabsVersion))
return;

DataFixerHandler.worldSavedData.processModList(mods);
DataFixerHandler.worldSavedData.processSavedLabsVersion(savedLabsVersion);

NomiLabs.LOGGER.info("NEEDED DATA FIXES: ----------------------------------------");
for (var fixType : LabsFixes.fixes.keySet()) {
NomiLabs.LOGGER.info("SECTION: {} -------------------------------------------", fixType);
var fixes = LabsFixes.fixes.get(fixType);
for (var fix : fixes) {
if (fix.validVersion.apply(DataFixerHandler.worldSavedData.savedVersion) &&
fix.validModList.apply(mods)) {
if (fix.validVersion.apply(DataFixerHandler.worldSavedData.savedFixVersion)) {
neededNewFixes.computeIfAbsent(fixType, (key) -> new ObjectArrayList<>()).add(fix);
if (fix.needsMode) modeNeeded = true;
NomiLabs.LOGGER.info("- {}: {}", fix.name, fix.description);
Expand Down Expand Up @@ -313,13 +301,16 @@ public static boolean hasNoNewFixes() {
}

public static boolean fixNotAvailable() {
return neededFixes == null || neededFixes.isEmpty();
return !fixAvailable;
}

public static void close() {
worldSavedData = null;
checked = false;
neededFixes = null;
fixAvailable = false;
neededNewFixes = null;
idToBlockMap = null;
blockToIdMap = null;
oldBlockRegistry = null;
}
}
Loading

0 comments on commit 7dd9033

Please sign in to comment.