mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-23 21:49:46 +00:00
In-progress Registry system enhancement.
Needs cpw to take a look at enabling removing/overriding in the registry stuff. But in theory it loads json recipes for mods now.
This commit is contained in:
1 parent
54d26cb4cc
commit
a8659a1613
37 files changed
+1476
-208
No files matched your search
@@ -57,6 +57,7 @@ import net.minecraft.world.storage.WorldInfo;
|
||||
import net.minecraftforge.client.model.animation.Animation;
|
||||
import net.minecraftforge.common.ForgeVersion;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.common.util.CompoundDataFixer;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventBus;
|
||||
import net.minecraftforge.fml.common.gameevent.InputEvent;
|
||||
|
||||
@@ -125,6 +125,9 @@ public final class FMLContainer extends DummyModContainer implements WorldAccess
|
||||
|
||||
for (Map.Entry<ResourceLocation, PersistentRegistryManager.GameDataSnapshot.Entry> e : dataSnapshot.entries.entrySet())
|
||||
{
|
||||
if (!e.getValue().saveToDisc) //Skip registries that don't need to persist, Currently Recipes.
|
||||
continue;
|
||||
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
registries.setTag(e.getKey().toString(), data);
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import java.util.Set;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||
import net.minecraftforge.common.config.ConfigManager;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.fml.common.LoaderState.ModState;
|
||||
import net.minecraftforge.fml.common.ModContainer.Disableable;
|
||||
import net.minecraftforge.fml.common.ProgressManager.ProgressBar;
|
||||
@@ -824,6 +825,7 @@ public class Loader
|
||||
public void initializeMods()
|
||||
{
|
||||
progressBar.step("Initializing mods Phase 2");
|
||||
CraftingHelper.loadRecipes();
|
||||
// Mod controller should be in the initialization state here
|
||||
modController.distributeStateMessage(LoaderState.INITIALIZATION);
|
||||
progressBar.step("Initializing mods Phase 3");
|
||||
|
||||
@@ -23,8 +23,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
import net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
@@ -35,7 +34,7 @@ import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Multimaps;
|
||||
import com.google.common.collect.SetMultimap;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
|
||||
public class ASMDataTable
|
||||
{
|
||||
|
||||
+13
-2
@@ -97,8 +97,13 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
|
||||
private final CreateCallback<I> createCallback;
|
||||
@Nullable
|
||||
private final SubstitutionCallback<I> substitutionCallback;
|
||||
/**
|
||||
* If true, this registry will persist in the save folder and be reloaded when the world is loaded.
|
||||
* This should only be true if the save format includes this registry entries in ID format.
|
||||
*/
|
||||
private final boolean saveToDisc;
|
||||
|
||||
FMLControlledNamespacedRegistry(@Nullable ResourceLocation defaultKey, int minIdValue, int maxIdValue, Class<I> type, BiMap<ResourceLocation, ? extends IForgeRegistry<?>> registries, @Nullable AddCallback<I> addCallback, @Nullable ClearCallback<I> clearCallback, @Nullable CreateCallback<I> createCallback, @Nullable SubstitutionCallback<I> substitutionCallback)
|
||||
FMLControlledNamespacedRegistry(@Nullable ResourceLocation defaultKey, int minIdValue, int maxIdValue, Class<I> type, BiMap<ResourceLocation, ? extends IForgeRegistry<?>> registries, @Nullable AddCallback<I> addCallback, @Nullable ClearCallback<I> clearCallback, @Nullable CreateCallback<I> createCallback, @Nullable SubstitutionCallback<I> substitutionCallback, boolean saveToDisc)
|
||||
{
|
||||
super(defaultKey);
|
||||
this.superType = type;
|
||||
@@ -115,6 +120,7 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
|
||||
{
|
||||
createCallback.onCreate(slaves, registries);
|
||||
}
|
||||
this.saveToDisc = saveToDisc;
|
||||
}
|
||||
|
||||
void validateContent(ResourceLocation registryName)
|
||||
@@ -684,7 +690,7 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
|
||||
|
||||
FMLControlledNamespacedRegistry<I> makeShallowCopy(BiMap<ResourceLocation, ? extends IForgeRegistry<?>> registries)
|
||||
{
|
||||
return new FMLControlledNamespacedRegistry<I>(optionalDefaultKey, minId, maxId, superType, registries, addCallback, clearCallback, createCallback, substitutionCallback);
|
||||
return new FMLControlledNamespacedRegistry<I>(optionalDefaultKey, minId, maxId, superType, registries, addCallback, clearCallback, createCallback, substitutionCallback, saveToDisc);
|
||||
}
|
||||
|
||||
void resetSubstitutionDelegates()
|
||||
@@ -935,4 +941,9 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
|
||||
return new RegistryEvent.Register<I>(location, this);
|
||||
}
|
||||
|
||||
public boolean shouldSaveToDisc()
|
||||
{
|
||||
return this.saveToDisc;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,7 +21,9 @@ package net.minecraftforge.fml.common.registry;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.init.Bootstrap;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.potion.PotionType;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
@@ -46,6 +48,7 @@ public class ForgeRegistries
|
||||
public static final IForgeRegistry<Enchantment> ENCHANTMENTS = GameRegistry.findRegistry(Enchantment.class);
|
||||
public static final IForgeRegistry<VillagerProfession> VILLAGER_PROFESSIONS = GameRegistry.findRegistry(VillagerProfession.class);
|
||||
public static final IForgeRegistry<EntityEntry> ENTITIES = GameRegistry.findRegistry(EntityEntry.class);
|
||||
public static final IForgeRegistry<IRecipe> RECIPES = GameRegistry.findRegistry(IRecipe.class);
|
||||
|
||||
|
||||
/**
|
||||
@@ -55,6 +58,7 @@ public class ForgeRegistries
|
||||
{
|
||||
GameData.getMain();
|
||||
VillagerRegistry.instance();
|
||||
Bootstrap.register();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.potion.PotionType;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -39,12 +40,13 @@ import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import net.minecraftforge.fml.relauncher.ReflectionHelper;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import static net.minecraftforge.fml.common.registry.PersistentRegistryManager.*;
|
||||
|
||||
public class GameData
|
||||
{
|
||||
private static final int MIN_BLOCK_ID = 0;
|
||||
@@ -63,6 +65,8 @@ public class GameData
|
||||
private static final int MAX_ENCHANTMENT_ID = Short.MAX_VALUE - 1; // Short - serialized as a short in ItemStack NBTs.
|
||||
private static final int MIN_ENTITY_ID = 0;
|
||||
private static final int MAX_ENTITY_ID = Integer.MAX_VALUE >> 5; // Varint (SPacketSpawnMob)
|
||||
private static final int MIN_RECIPE_ID = 0;
|
||||
private static final int MAX_RECIPE_ID = Integer.MAX_VALUE >> 5; // Varint CPacketRecipeInfo/SPacketRecipeBook
|
||||
|
||||
private static final ResourceLocation BLOCK_TO_ITEM = new ResourceLocation("minecraft:blocktoitemmap");
|
||||
private static final ResourceLocation BLOCKSTATE_TO_ID = new ResourceLocation("minecraft:blockstatetoid");
|
||||
@@ -73,15 +77,15 @@ public class GameData
|
||||
|
||||
public GameData()
|
||||
{
|
||||
iBlockRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.BLOCKS, Block.class, new ResourceLocation("minecraft:air"), MIN_BLOCK_ID, MAX_BLOCK_ID, true, BlockCallbacks.INSTANCE, BlockCallbacks.INSTANCE, BlockCallbacks.INSTANCE, BlockCallbacks.INSTANCE);
|
||||
iItemRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.ITEMS, Item.class, null, MIN_ITEM_ID, MAX_ITEM_ID, true, ItemCallbacks.INSTANCE, ItemCallbacks.INSTANCE, ItemCallbacks.INSTANCE, ItemCallbacks.INSTANCE);
|
||||
iPotionRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.POTIONS, Potion.class, null, MIN_POTION_ID, MAX_POTION_ID, false, PotionCallbacks.INSTANCE, PotionCallbacks.INSTANCE, PotionCallbacks.INSTANCE, null);
|
||||
iBiomeRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.BIOMES, Biome.class, null, MIN_BIOME_ID, MAX_BIOME_ID, false, BiomeCallbacks.INSTANCE, BiomeCallbacks.INSTANCE, BiomeCallbacks.INSTANCE, null);
|
||||
iSoundEventRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.SOUNDEVENTS, SoundEvent.class, null, MIN_SOUND_ID, MAX_SOUND_ID, false, null, null, null, null);
|
||||
ResourceLocation WATER = new ResourceLocation("water");
|
||||
iPotionTypeRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.POTIONTYPES, PotionType.class, WATER, MIN_POTIONTYPE_ID, MAX_POTIONTYPE_ID, false, null, null, null, null);
|
||||
iEnchantmentRegistry = PersistentRegistryManager.createRegistry(PersistentRegistryManager.ENCHANTMENTS, Enchantment.class, null, MIN_ENCHANTMENT_ID, MAX_ENCHANTMENT_ID, false, null, null, null, null);
|
||||
iEntityRegistry = (FMLControlledNamespacedRegistry<EntityEntry>)new RegistryBuilder<EntityEntry>().setName(PersistentRegistryManager.ENTITIES).setType(EntityEntry.class).setIDRange(MIN_ENTITY_ID, MAX_ENTITY_ID).addCallback(EntityCallbacks.INSTANCE).create();
|
||||
iBlockRegistry = (FMLControlledNamespacedRegistry<Block>) makeRegistry(BLOCKS, Block.class, MIN_BLOCK_ID, MAX_BLOCK_ID).addCallback(BlockCallbacks.INSTANCE).enableDelegates().setDefaultKey(new ResourceLocation("air")).create();
|
||||
iItemRegistry = (FMLControlledNamespacedRegistry<Item>) makeRegistry(ITEMS, Item.class, MIN_ITEM_ID, MAX_ITEM_ID).addCallback(ItemCallbacks.INSTANCE).enableDelegates().create();
|
||||
iPotionRegistry = (FMLControlledNamespacedRegistry<Potion>) makeRegistry(POTIONS, Potion.class, MIN_POTION_ID, MAX_POTION_ID).addCallback(PotionCallbacks.INSTANCE).create();
|
||||
iBiomeRegistry = (FMLControlledNamespacedRegistry<Biome>) makeRegistry(BIOMES, Biome.class, MIN_BIOME_ID, MAX_BIOME_ID).addCallback(BiomeCallbacks.INSTANCE).create();
|
||||
iSoundEventRegistry = (FMLControlledNamespacedRegistry<SoundEvent>) makeRegistry(SOUNDEVENTS, SoundEvent.class, MIN_SOUND_ID, MAX_SOUND_ID).create();
|
||||
iPotionTypeRegistry = (FMLControlledNamespacedRegistry<PotionType>) makeRegistry(POTIONTYPES, PotionType.class, MIN_POTIONTYPE_ID, MAX_POTIONTYPE_ID).setDefaultKey(new ResourceLocation("water")).create();
|
||||
iEnchantmentRegistry = (FMLControlledNamespacedRegistry<Enchantment>)makeRegistry(ENCHANTMENTS, Enchantment.class, MIN_ENCHANTMENT_ID, MAX_ENCHANTMENT_ID).create();
|
||||
iEntityRegistry = (FMLControlledNamespacedRegistry<EntityEntry>)makeRegistry(ENTITIES, EntityEntry.class, MIN_ENTITY_ID, MAX_ENTITY_ID).addCallback(EntityCallbacks.INSTANCE).create();
|
||||
iRecipeRegistry = (FMLControlledNamespacedRegistry<IRecipe>) makeRegistry(RECIPES, IRecipe.class, MIN_RECIPE_ID, MAX_RECIPE_ID).disableSaving().create();
|
||||
|
||||
try
|
||||
{
|
||||
@@ -95,6 +99,11 @@ public class GameData
|
||||
|
||||
iTileEntityRegistry = new LegacyNamespacedRegistry<Class<? extends TileEntity>>();
|
||||
}
|
||||
|
||||
private <T extends IForgeRegistryEntry<T>> RegistryBuilder<T> makeRegistry(ResourceLocation name, Class<T> type, int min, int max)
|
||||
{
|
||||
return new RegistryBuilder<T>().setName(name).setType(type).setIDRange(min, max);
|
||||
}
|
||||
// internal registry objects
|
||||
private final FMLControlledNamespacedRegistry<Block> iBlockRegistry;
|
||||
private final FMLControlledNamespacedRegistry<Item> iItemRegistry;
|
||||
@@ -110,6 +119,9 @@ public class GameData
|
||||
//don't follow the same patterns as the other ones.
|
||||
private final LegacyNamespacedRegistry<Class<? extends TileEntity>> iTileEntityRegistry;
|
||||
|
||||
//TODO: This is not a recipe that is serilized to disc by ID, so we need to skip over any saving/loading from disc
|
||||
private final FMLControlledNamespacedRegistry<IRecipe> iRecipeRegistry;
|
||||
|
||||
/** INTERNAL ONLY */
|
||||
@Deprecated
|
||||
public static FMLControlledNamespacedRegistry<Block> getBlockRegistry()
|
||||
@@ -154,17 +166,9 @@ public class GameData
|
||||
@Deprecated
|
||||
public static FMLControlledNamespacedRegistry<EntityEntry> getEntityRegistry() { return getMain().iEntityRegistry; }
|
||||
|
||||
/** INTERNAL ONLY */
|
||||
@Deprecated
|
||||
static Item findItem(String modId, String name)
|
||||
{
|
||||
return getMain().iItemRegistry.getObject(new ResourceLocation(modId, name));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
static Block findBlock(String modId, String name)
|
||||
{
|
||||
return getMain().iBlockRegistry.getObject(new ResourceLocation(modId, name));
|
||||
}
|
||||
public static FMLControlledNamespacedRegistry<IRecipe> getRecipeRegistry() { return getMain().iRecipeRegistry; }
|
||||
|
||||
protected static GameData getMain()
|
||||
{
|
||||
|
||||
@@ -62,7 +62,7 @@ public interface IForgeRegistryEntry<V>
|
||||
Class<V> getRegistryType();
|
||||
|
||||
// Default implementation, modders who make extra items SHOULD extend this instead of Object.
|
||||
// We have to do this until we get default implementations in Java 8.
|
||||
// So, all fields in interfaces are forced static, so even with Java8 people must still extend this.
|
||||
@SuppressWarnings({ "serial", "unchecked" })
|
||||
public static class Impl<T extends IForgeRegistryEntry<T>> implements IForgeRegistryEntry<T>
|
||||
{
|
||||
|
||||
+11
-16
@@ -90,6 +90,7 @@ public class PersistentRegistryManager
|
||||
ObjectHolderRegistry.INSTANCE.applyObjectHolders(); // inject any items
|
||||
for (ResourceLocation rl : registryKeys) {
|
||||
if (rl == BLOCKS || rl == ITEMS) continue;
|
||||
if (rl == RECIPES) continue; //For now disable, we should fire this event in ServerInit or something...
|
||||
fireRegistryEvent(PersistentRegistry.ACTIVE.registries, rl);
|
||||
}
|
||||
ObjectHolderRegistry.INSTANCE.applyObjectHolders(); // inject everything else
|
||||
@@ -129,7 +130,7 @@ public class PersistentRegistryManager
|
||||
return getRegistry(key, regType);
|
||||
}
|
||||
|
||||
private <T extends IForgeRegistryEntry<T>> FMLControlledNamespacedRegistry<T> createRegistry(ResourceLocation registryName, Class<T> type, ResourceLocation defaultObjectKey, int minId, int maxId, @Nullable IForgeRegistry.AddCallback<T> addCallback, @Nullable IForgeRegistry.ClearCallback<T> clearCallback, @Nullable IForgeRegistry.CreateCallback<T> createCallback, @Nullable IForgeRegistry.SubstitutionCallback<T> substitutionCallback)
|
||||
private <T extends IForgeRegistryEntry<T>> FMLControlledNamespacedRegistry<T> createRegistry(ResourceLocation registryName, Class<T> type, ResourceLocation defaultObjectKey, int minId, int maxId, @Nullable IForgeRegistry.AddCallback<T> addCallback, @Nullable IForgeRegistry.ClearCallback<T> clearCallback, @Nullable IForgeRegistry.CreateCallback<T> createCallback, @Nullable IForgeRegistry.SubstitutionCallback<T> substitutionCallback, boolean saveToDisc)
|
||||
{
|
||||
Set<Class<?>> parents = Sets.newHashSet();
|
||||
findSuperTypes(type, parents);
|
||||
@@ -140,7 +141,7 @@ public class PersistentRegistryManager
|
||||
FMLLog.severe("Found existing registry of type %1s named %2s, you cannot create a new registry (%3s) with type %4s, as %4s has a parent of that type", foundType, registrySuperTypes.get(foundType), registryName, type);
|
||||
throw new IllegalArgumentException("Duplicate registry parent type found - you can only have one registry for a particular super type");
|
||||
}
|
||||
FMLControlledNamespacedRegistry<T> fmlControlledNamespacedRegistry = new FMLControlledNamespacedRegistry<T>(defaultObjectKey, minId, maxId, type, registries, addCallback, clearCallback, createCallback, substitutionCallback);
|
||||
FMLControlledNamespacedRegistry<T> fmlControlledNamespacedRegistry = new FMLControlledNamespacedRegistry<T>(defaultObjectKey, minId, maxId, type, registries, addCallback, clearCallback, createCallback, substitutionCallback, saveToDisc);
|
||||
registries.put(registryName, fmlControlledNamespacedRegistry);
|
||||
registrySuperTypes.put(type, registryName);
|
||||
return getRegistry(registryName, type);
|
||||
@@ -192,30 +193,21 @@ public class PersistentRegistryManager
|
||||
public static final ResourceLocation POTIONTYPES = new ResourceLocation("minecraft:potiontypes");
|
||||
public static final ResourceLocation ENCHANTMENTS = new ResourceLocation("minecraft:enchantments");
|
||||
public static final ResourceLocation ENTITIES = new ResourceLocation("minecraft:entities");
|
||||
public static final ResourceLocation RECIPES = new ResourceLocation("minecraft:recipes");
|
||||
static final ResourceLocation SUBSTITUTION_ORIGINALS = new ResourceLocation("fml:suboriginals");
|
||||
|
||||
@Deprecated //Use RegistryBuilder TODO: Remove in 1.11
|
||||
public static <T extends IForgeRegistryEntry<T>> FMLControlledNamespacedRegistry<T> createRegistry(
|
||||
ResourceLocation registryName, Class<T> registryType, ResourceLocation optionalDefaultKey,
|
||||
int minId, int maxId, boolean hasDelegates,
|
||||
@Nullable IForgeRegistry.AddCallback<T> addCallback,
|
||||
@Nullable IForgeRegistry.ClearCallback<T> clearCallback,
|
||||
@Nullable IForgeRegistry.CreateCallback<T> createCallback)
|
||||
{
|
||||
return PersistentRegistry.ACTIVE.createRegistry(registryName, registryType, optionalDefaultKey, minId, maxId,
|
||||
getLegacyAdd(addCallback), getLegacyClear(clearCallback), getLegacyCreate(createCallback), null);
|
||||
}
|
||||
@Deprecated //Use RegistryBuilder TODO: Remove in 1.11 {Make package private so only builder can use it}
|
||||
public static <T extends IForgeRegistryEntry<T>> FMLControlledNamespacedRegistry<T> createRegistry(
|
||||
static <T extends IForgeRegistryEntry<T>> FMLControlledNamespacedRegistry<T> createRegistry(
|
||||
ResourceLocation registryName, Class<T> registryType, @Nullable ResourceLocation optionalDefaultKey,
|
||||
int minId, int maxId, boolean hasDelegates,
|
||||
@Nullable IForgeRegistry.AddCallback<T> addCallback,
|
||||
@Nullable IForgeRegistry.ClearCallback<T> clearCallback,
|
||||
@Nullable IForgeRegistry.CreateCallback<T> createCallback,
|
||||
@Nullable IForgeRegistry.SubstitutionCallback<T> substitutionCallback)
|
||||
@Nullable IForgeRegistry.SubstitutionCallback<T> substitutionCallback,
|
||||
boolean saveToDisc)
|
||||
{
|
||||
return PersistentRegistry.ACTIVE.createRegistry(registryName, registryType, optionalDefaultKey, minId, maxId,
|
||||
addCallback, clearCallback, createCallback, substitutionCallback);
|
||||
addCallback, clearCallback, createCallback, substitutionCallback, saveToDisc);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@@ -693,6 +685,7 @@ public class PersistentRegistryManager
|
||||
public final Map<ResourceLocation, ResourceLocation> aliases;
|
||||
public final Set<Integer> blocked;
|
||||
public final Set<ResourceLocation> dummied;
|
||||
public final boolean saveToDisc;
|
||||
|
||||
public Entry()
|
||||
{
|
||||
@@ -706,6 +699,7 @@ public class PersistentRegistryManager
|
||||
this.aliases = aliases;
|
||||
this.blocked = blocked;
|
||||
this.dummied = dummies;
|
||||
saveToDisc = false;
|
||||
}
|
||||
|
||||
public Entry(FMLControlledNamespacedRegistry<?> registry)
|
||||
@@ -721,6 +715,7 @@ public class PersistentRegistryManager
|
||||
registry.serializeAliases(this.aliases);
|
||||
registry.serializeBlockList(this.blocked);
|
||||
registry.serializeDummied(this.dummied);
|
||||
this.saveToDisc = registry.shouldSaveToDisc();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,10 +37,12 @@ public class RegistryBuilder<T extends IForgeRegistryEntry<T>>
|
||||
private ResourceLocation optionalDefaultKey;
|
||||
private int minId;
|
||||
private int maxId;
|
||||
private boolean hasDelegates = false;
|
||||
private List<AddCallback<T>> addCallback = Lists.newArrayList();
|
||||
private List<ClearCallback<T>> clearCallback = Lists.newArrayList();
|
||||
private List<CreateCallback<T>> createCallback = Lists.newArrayList();
|
||||
private List<SubstitutionCallback<T>> substitutionCallback = Lists.newArrayList();
|
||||
private boolean saveToDisc;
|
||||
|
||||
public RegistryBuilder<T> setName(ResourceLocation name)
|
||||
{
|
||||
@@ -105,11 +107,23 @@ public class RegistryBuilder<T extends IForgeRegistryEntry<T>>
|
||||
return this;
|
||||
}
|
||||
|
||||
public RegistryBuilder<T> enableDelegates()
|
||||
{
|
||||
this.hasDelegates = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RegistryBuilder<T> disableSaving()
|
||||
{
|
||||
this.saveToDisc = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public IForgeRegistry<T> create()
|
||||
{
|
||||
return PersistentRegistryManager.createRegistry(registryName, registryType, optionalDefaultKey, minId, maxId, false,
|
||||
getAdd(), getClear(), getCreate(), getSubstitution());
|
||||
return PersistentRegistryManager.createRegistry(registryName, registryType, optionalDefaultKey, minId, maxId, hasDelegates,
|
||||
getAdd(), getClear(), getCreate(), getSubstitution(), saveToDisc);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -38,6 +38,7 @@ import net.minecraft.world.gen.structure.StructureVillagePieces;
|
||||
import net.minecraft.world.gen.structure.StructureVillagePieces.PieceWeight;
|
||||
import net.minecraft.world.gen.structure.StructureVillagePieces.Village;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder;
|
||||
import net.minecraftforge.fml.common.registry.RegistryBuilder;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -138,7 +139,7 @@ public class VillagerRegistry
|
||||
}
|
||||
|
||||
private boolean hasInit = false;
|
||||
private FMLControlledNamespacedRegistry<VillagerProfession> professions = PersistentRegistryManager.createRegistry(PROFESSIONS, VillagerProfession.class, null, 0, 1024, true, null, null, null, null);
|
||||
private FMLControlledNamespacedRegistry<VillagerProfession> professions = (FMLControlledNamespacedRegistry<VillagerProfession>)new RegistryBuilder<VillagerProfession>().setName(PROFESSIONS).setType(VillagerProfession.class).setIDRange(0, 1024).enableDelegates().create();
|
||||
public IForgeRegistry<VillagerProfession> getRegistry() { return this.professions; }
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user