Re-introduce patch for injecting registry mappings during world loading.

And re-introduce registry freezing to ONLY the Register events.
Filter ObjectHolders by registry type and fire between every Register event.
This commit is contained in:
LexManos 2019-01-16 12:28:13 -08:00
parent cd21f7b927
commit 3b029ba031
10 changed files with 93 additions and 44 deletions

View File

@ -74,4 +74,4 @@
+ public int getPendingSaveCount() {
+ return this.field_75828_a.size();
+ }
}
}

View File

@ -0,0 +1,27 @@
--- a/net/minecraft/world/storage/SaveFormatOld.java
+++ b/net/minecraft/world/storage/SaveFormatOld.java
@@ -86,13 +86,23 @@
@Nullable
public static WorldInfo func_186353_a(File p_186353_0_, DataFixer p_186353_1_) {
+ return getWorldData(p_186353_0_, p_186353_1_, null);
+ }
+
+ @Nullable
+ public static WorldInfo getWorldData(File p_186353_0_, DataFixer p_186353_1_, @Nullable SaveHandler saveHandler) {
try {
NBTTagCompound nbttagcompound = CompressedStreamTools.func_74796_a(new FileInputStream(p_186353_0_));
NBTTagCompound nbttagcompound1 = nbttagcompound.func_74775_l("Data");
NBTTagCompound nbttagcompound2 = nbttagcompound1.func_150297_b("Player", 10) ? nbttagcompound1.func_74775_l("Player") : null;
nbttagcompound1.func_82580_o("Player");
int i = nbttagcompound1.func_150297_b("DataVersion", 99) ? nbttagcompound1.func_74762_e("DataVersion") : -1;
- return new WorldInfo(NBTUtil.func_210822_a(p_186353_1_, DataFixTypes.LEVEL, nbttagcompound1, i), p_186353_1_, i, nbttagcompound2);
+ WorldInfo ret = new WorldInfo(NBTUtil.func_210822_a(p_186353_1_, DataFixTypes.LEVEL, nbttagcompound1, i), p_186353_1_, i, nbttagcompound2);
+ if (saveHandler != null)
+ net.minecraftforge.fml.WorldPersistenceHooks.handleWorldDataLoad(saveHandler, ret, nbttagcompound);
+ return ret;
+ } catch (net.minecraftforge.fml.StartupQuery.AbortedException e) {
+ throw e;
} catch (Exception exception) {
field_151479_b.error("Exception reading {}", p_186353_0_, exception);
return null;

View File

@ -1,5 +1,22 @@
--- a/net/minecraft/world/storage/SaveHandler.java
+++ b/net/minecraft/world/storage/SaveHandler.java
@@ -96,14 +96,14 @@
public WorldInfo func_75757_d() {
File file1 = new File(this.field_75770_b, "level.dat");
if (file1.exists()) {
- WorldInfo worldinfo = SaveFormatOld.func_186353_a(file1, this.field_186341_a);
+ WorldInfo worldinfo = SaveFormatOld.getWorldData(file1, this.field_186341_a, this);
if (worldinfo != null) {
return worldinfo;
}
}
file1 = new File(this.field_75770_b, "level.dat_old");
- return file1.exists() ? SaveFormatOld.func_186353_a(file1, this.field_186341_a) : null;
+ return file1.exists() ? SaveFormatOld.getWorldData(file1, this.field_186341_a, this) : null;
}
public void func_75755_a(WorldInfo p_75755_1_, @Nullable NBTTagCompound p_75755_2_) {
@@ -150,6 +150,7 @@
}

View File

@ -28,8 +28,6 @@ import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraftforge.fml.ModThreadContext;
import org.apache.commons.lang3.Validate;
@ -39,7 +37,6 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
@ -56,13 +53,6 @@ import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import net.minecraftforge.registries.IForgeRegistry.AddCallback;
import net.minecraftforge.registries.IForgeRegistry.ClearCallback;
import net.minecraftforge.registries.IForgeRegistry.CreateCallback;
import net.minecraftforge.registries.IForgeRegistry.DummyFactory;
import net.minecraftforge.registries.IForgeRegistry.MissingFactory;
import net.minecraftforge.registries.IForgeRegistry.ValidateCallback;
public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRegistryInternal<V>, IForgeRegistryModifiable<V>
{
public static Marker REGISTRIES = MarkerManager.getMarker("REGISTRIES");
@ -95,10 +85,12 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
private V defaultValue = null;
boolean isFrozen = false;
private final ResourceLocation name;
private final RegistryBuilder<V> builder;
ForgeRegistry(RegistryManager stage, RegistryBuilder<V> builder)
ForgeRegistry(RegistryManager stage, ResourceLocation name, RegistryBuilder<V> builder)
{
this.name = name;
this.builder = builder;
this.stage = stage;
this.superType = builder.getType();
@ -154,6 +146,12 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
};
}
@Override
public ResourceLocation getRegistryName()
{
return this.name;
}
@Override
public Class<V> getRegistrySuperType()
{
@ -273,7 +271,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
ForgeRegistry<V> copy(RegistryManager stage)
{
return new ForgeRegistry<>(stage, builder);
return new ForgeRegistry<>(stage, name, builder);
}
int add(int id, V value)

View File

@ -248,6 +248,7 @@ public class GameData
// the id mapping has reverted, fire remap events for those that care about id changes
//Loader.instance().fireRemapEvent(ImmutableMap.of(), true);
ObjectHolderRegistry.applyObjectHolders();
// the id mapping has reverted, ensure we sync up the object holders
LOGGER.debug("Frozen state restored.");
}
@ -786,35 +787,25 @@ public class GameData
{
List<ResourceLocation> keys = Lists.newArrayList(RegistryManager.ACTIVE.registries.keySet());
Collections.sort(keys, (o1, o2) -> o1.toString().compareToIgnoreCase(o2.toString()));
/*
RegistryManager.ACTIVE.registries.forEach((name, reg) -> {
if (filter.test(name))
((ForgeRegistry<?>)reg).unfreeze();
});
*/
if (filter.test(BLOCKS))
{
MinecraftForge.EVENT_BUS.post(RegistryManager.ACTIVE.getRegistry(BLOCKS).getRegisterEvent(BLOCKS));
}
if (filter.test(ITEMS))
{
MinecraftForge.EVENT_BUS.post(RegistryManager.ACTIVE.getRegistry(ITEMS).getRegisterEvent(ITEMS));
}
//Move Blocks to first, and Items to second.
keys.remove(BLOCKS);
keys.remove(ITEMS);
keys.add(0, BLOCKS);
keys.add(1, ITEMS);
for (ResourceLocation rl : keys)
{
if (!filter.test(rl)) continue;
if (rl == BLOCKS || rl == ITEMS) continue;
MinecraftForge.EVENT_BUS.post(RegistryManager.ACTIVE.getRegistry(rl).getRegisterEvent(rl));
ForgeRegistry<?> reg = RegistryManager.ACTIVE.getRegistry(rl);
reg.unfreeze();
MinecraftForge.EVENT_BUS.post(reg.getRegisterEvent(rl));
reg.freeze();
LOGGER.info("{} Applying holder lookups", rl.toString());
ObjectHolderRegistry.applyObjectHolders(key -> rl.equals(key));
LOGGER.info("{} Holder lookups applied", rl.toString());
}
/*
RegistryManager.ACTIVE.registries.forEach((name, reg) -> {
if (filter.test(name))
((ForgeRegistry<?>)reg).freeze();
});
*/
}
public static ResourceLocation checkPrefix(String name)

View File

@ -35,6 +35,7 @@ import javax.annotation.Nullable;
*/
public interface IForgeRegistry<V extends IForgeRegistryEntry<V>> extends Iterable<V>
{
ResourceLocation getRegistryName();
Class<V> getRegistrySuperType();
void register(V value);

View File

@ -24,6 +24,8 @@ import java.lang.reflect.Modifier;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Queue;
import java.util.function.Consumer;
import java.util.function.Predicate;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.ResourceLocationException;
@ -34,7 +36,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@SuppressWarnings("rawtypes")
public class ObjectHolderRef implements Runnable
public class ObjectHolderRef implements Consumer<Predicate<ResourceLocation>>
{
private static final Logger LOGGER = LogManager.getLogger();
private Field field;
@ -132,8 +134,11 @@ public class ObjectHolderRef implements Runnable
}
@Override
public void run()
public void accept(Predicate<ResourceLocation> filter)
{
if (registry == null || !filter.test(registry.getRegistryName()))
return;
Object thing;
if (isValid && registry.containsKey(injectedObject) && !registry.isDummied(injectedObject))
{

View File

@ -27,8 +27,11 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.forgespi.language.ModFileScanData;
@ -54,7 +57,7 @@ public class ObjectHolderRegistry
* and hashCode function to de-duplicate callers here.
* The default @ObjectHolder implementation uses the hashCode/equals for the field the annotation is on.
*/
public static void addHandler(Runnable ref)
public static void addHandler(Consumer<Predicate<ResourceLocation>> ref)
{
objectHolders.add(ref);
}
@ -68,7 +71,7 @@ public class ObjectHolderRegistry
*
* @return true if handler was matched and removed.
*/
public static boolean removeHandler(Runnable ref)
public static boolean removeHandler(Consumer<Predicate<ResourceLocation>> ref)
{
return objectHolders.remove(ref);
}
@ -78,7 +81,7 @@ public class ObjectHolderRegistry
//==============================================================
private static final Logger LOGGER = LogManager.getLogger();
private static final Set<Runnable> objectHolders = new HashSet<>();
private static final Set<Consumer<Predicate<ResourceLocation>>> objectHolders = new HashSet<>();
private static final Type OBJECT_HOLDER = Type.getType(ObjectHolder.class);
private static final Type MOD = Type.getType(Mod.class);
@ -174,8 +177,13 @@ public class ObjectHolderRegistry
public static void applyObjectHolders()
{
LOGGER.info("Applying holder lookups");
objectHolders.forEach(Runnable::run);
applyObjectHolders(key -> true);
LOGGER.info("Holder lookups applied");
}
public static void applyObjectHolders(Predicate<ResourceLocation> filter)
{
objectHolders.forEach(e -> e.accept(filter));
}
}

View File

@ -110,7 +110,7 @@ public class RegistryManager
foundType, superTypes.get(foundType), name, builder.getType(), builder.getType());
throw new IllegalArgumentException("Duplicate registry parent type found - you can only have one registry for a particular super type");
}
ForgeRegistry<V> reg = new ForgeRegistry<V>(this, builder);
ForgeRegistry<V> reg = new ForgeRegistry<V>(this, name, builder);
registries.put(name, reg);
superTypes.put(builder.getType(), name);
if (builder.getSaveToDisc())

View File

@ -70,6 +70,8 @@ net/minecraft/client/renderer/block/model/BakedQuad.<init>([IILnet/minecraft/uti
#net/minecraft/client/renderer/texture/TextureMap.<init>(Ljava/lang/String;Lnet/minecraft/client/renderer/texture/ITextureMapPopulator;Z)V=|p_i46100_1_,p_i46100_2_,skipFirst
#net/minecraft/client/renderer/texture/TextureMap.loadTexture(Lnet/minecraft/client/renderer/texture/Stitcher;Lnet/minecraft/client/resources/IResourceManager;Lnet/minecraft/util/ResourceLocation;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;Lnet/minecraftforge/fml/common/ProgressManager$ProgressBar;II)I=|stitcher,p_110571_1_,location,textureatlassprite,bar,j,k
net/minecraft/world/storage/SaveFormatOld.getWorldData(Ljava/io/File;Lcom/mojang/datafixers/DataFixer;Lnet/minecraft/world/storage/SaveHandler;)Lnet/minecraft/world/storage/WorldInfo;=|p_186353_0_,p_186353_1_,saveHandler
net/minecraft/world/storage/loot/LootPool.<init>([Lnet/minecraft/world/storage/loot/LootEntry;[Lnet/minecraft/world/storage/loot/conditions/LootCondition;Lnet/minecraft/world/storage/loot/RandomValueRange;Lnet/minecraft/world/storage/loot/RandomValueRange;Ljava/lang/String;)V=|p_i46643_1_,p_i46643_2_,p_i46643_3_,p_i46643_4_
net/minecraft/world/storage/loot/LootEntry.<init>(II[Lnet/minecraft/world/storage/loot/conditions/LootCondition;Ljava/lang/String;)V=|p_i46642_1_,p_i46642_2_,p_i46642_3_,entryName
net/minecraft/world/storage/loot/LootEntryItem.<init>(Lnet/minecraft/item/Item;II[Lnet/minecraft/world/storage/loot/functions/LootFunction;[Lnet/minecraft/world/storage/loot/conditions/LootCondition;Ljava/lang/String;)V=|p_i46644_1_,p_i46644_2_,p_i46644_3_,p_i46644_4_,p_i46644_5_,entryName