Skip to content

Commit

Permalink
fix MTE data fixer registry conflicts (GregTechCEu#2515)
Browse files Browse the repository at this point in the history
  • Loading branch information
TechLord22 authored Jul 14, 2024
1 parent 7799009 commit fa281c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
11 changes: 4 additions & 7 deletions src/main/java/gregtech/datafix/GTDataFixers.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import gregtech.api.GTValues;
import gregtech.api.GregTechAPI;
import gregtech.api.metatileentity.registry.MTERegistry;
import gregtech.datafix.migration.impl.MigrateMTEBlockTE;
import gregtech.datafix.migration.impl.MigrateMTEItems;
import gregtech.datafix.migration.lib.MTERegistriesMigrator;
import gregtech.datafix.walker.WalkItemStackLike;

import net.minecraft.util.ResourceLocation;
import net.minecraft.util.datafix.FixTypes;
import net.minecraft.util.datafix.IDataWalker;
import net.minecraftforge.common.util.CompoundDataFixer;
Expand All @@ -19,6 +17,8 @@
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;

import java.util.stream.IntStream;

public final class GTDataFixers {

public static final Logger LOGGER = LogManager.getLogger("GregTech DataFixers");
Expand Down Expand Up @@ -63,13 +63,10 @@ private static void registerFixes(@NotNull GTDataVersion version, @NotNull ModFi
}

/**
* Migrate all MTEs to the new blocks automatically
* Migrate GT's own MTEs to the new blocks automatically
*/
private static void migrateMTERegistries() {
MTERegistriesMigrator migrator = GregTechAPI.MIGRATIONS.registriesMigrator();
MTERegistry registry = GregTechAPI.mteManager.getRegistry(GTValues.MODID);
for (ResourceLocation key : registry.getKeys()) {
migrator.migrate(key.getNamespace(), (short) registry.getIdByObjectName(key));
}
migrator.migrate(GTValues.MODID, IntStream.range(0, 2000));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.stream.IntStream;

/**
* Performs migration to an independent MTE registry.
* <p>
Expand Down Expand Up @@ -48,16 +50,30 @@ public void migrate(int preMeta, int postMeta) {
}

/**
* Register a data fix entry for the multiple MTE registry transition.
* Register a single data fix entry for the multiple MTE registry transition.
* <p>
* Callers will probably prefer {@link #migrate(String, IntStream)}.
*
* @param modid the registry's modid
* @param meta the metadata value to migrate
*/
@ApiStatus.Internal
public void migrate(@NotNull String modid, short meta) {
metaModidMap.put(meta, modid);
}

/**
* Register data fix entries for the multiple MTE registry transition.
* <p>
* Register the range of values allocated to the modid using {@link IntStream#range(int, int)} or
* {@link IntStream#builder()}.
*
* @param modid the registry's modid
* @param metaValues the metadata values to migrate
*/
public void migrate(@NotNull String modid, @NotNull IntStream metaValues) {
metaValues.forEach(i -> metaModidMap.put((short) i, modid));
}

@Override
public @Nullable ResourceLocation fixMTEid(@NotNull ResourceLocation original) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.function.Supplier;
import java.util.stream.IntStream;

@Optional.Interface(modid = Mods.Names.GROOVY_SCRIPT,
iface = "com.cleanroommc.groovyscript.api.GroovyPlugin",
Expand Down Expand Up @@ -100,7 +101,8 @@ public static void afterScriptLoad(ScriptRunEvent.Post event) {
@SubscribeEvent
public static void onMTERegistries(MTEManager.MTERegistryEvent event) {
// automatically create a registry for groovyscript to store its MTEs
GregTechAPI.mteManager.createRegistry(GroovyScriptModule.getPackId());
GregTechAPI.mteManager.createRegistry(getPackId());
GregTechAPI.MIGRATIONS.registriesMigrator().migrate(getPackId(), IntStream.rangeClosed(32000, Short.MAX_VALUE));
}

public static boolean isCurrentlyRunning() {
Expand Down

0 comments on commit fa281c8

Please sign in to comment.