Make STRUCTURE_FEATURE registry a slave map of the FEATURE registry
Also convert Feature.STRUCTURES to a slave map
This commit is contained in:
parent
3ef1d6919c
commit
55fe7c470f
5 changed files with 98 additions and 10 deletions
|
@ -1,6 +1,11 @@
|
|||
--- a/net/minecraft/util/registry/Registry.java
|
||||
+++ b/net/minecraft/util/registry/Registry.java
|
||||
@@ -66,71 +66,75 @@
|
||||
@@ -62,80 +62,83 @@
|
||||
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
+
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
@ -95,8 +100,14 @@
|
|||
+ @Deprecated public static final DefaultedRegistry<ChunkStatus> field_218360_A = forgeDefaulted("chunk_status", ChunkStatus.class, () -> {
|
||||
return ChunkStatus.field_223226_a_;
|
||||
});
|
||||
public static final Registry<Structure<?>> field_218361_B = func_222935_a("structure_feature", () -> {
|
||||
@@ -148,37 +152,37 @@
|
||||
- public static final Registry<Structure<?>> field_218361_B = func_222935_a("structure_feature", () -> {
|
||||
- return Structures.field_215143_a;
|
||||
- });
|
||||
+ @Deprecated public static final Registry<Structure<?>> field_218361_B = net.minecraftforge.registries.GameData.getStructureFeatures();
|
||||
public static final Registry<IStructurePieceType> field_218362_C = func_222935_a("structure_piece", () -> {
|
||||
return IStructurePieceType.field_214782_c;
|
||||
});
|
||||
@@ -148,37 +151,37 @@
|
||||
public static final Registry<IJigsawDeserializer> field_218365_F = func_222935_a("structure_pool_element", () -> {
|
||||
return IJigsawDeserializer.field_214931_e;
|
||||
});
|
||||
|
@ -143,7 +154,7 @@
|
|||
return Activity.field_221366_b;
|
||||
});
|
||||
|
||||
@@ -230,6 +234,14 @@
|
||||
@@ -230,6 +233,14 @@
|
||||
return ((MutableRegistry<T>)p_218343_0_).func_218382_a(p_218343_1_, new ResourceLocation(p_218343_2_), p_218343_3_);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,3 +9,13 @@
|
|||
public static final Structure<PillagerOutpostConfig> field_214536_b = func_214468_a("pillager_outpost", new PillagerOutpostStructure(PillagerOutpostConfig::func_214642_a));
|
||||
public static final Structure<MineshaftConfig> field_202329_g = func_214468_a("mineshaft", new MineshaftStructure(MineshaftConfig::func_214638_a));
|
||||
public static final Structure<NoFeatureConfig> field_202330_h = func_214468_a("woodland_mansion", new WoodlandMansionStructure(NoFeatureConfig::func_214639_a));
|
||||
@@ -137,7 +137,8 @@
|
||||
public static final Feature<NoFeatureConfig> field_214485_aM = func_214468_a("sweet_berry_bush", new ScatteredPlantFeature(NoFeatureConfig::func_214639_a, Blocks.field_222434_lW.func_176223_P().func_206870_a(SweetBerryBushBlock.field_220125_a, Integer.valueOf(3))));
|
||||
public static final Feature<FillLayerConfig> field_214486_aN = func_214468_a("fill_layer", new FillLayerFeature(FillLayerConfig::func_214635_a));
|
||||
public static final BonusChestFeature field_214487_aO = func_214468_a("bonus_chest", new BonusChestFeature(NoFeatureConfig::func_214639_a));
|
||||
- public static final BiMap<String, Structure<?>> field_202300_at = Util.func_200696_a(HashBiMap.create(), (p_205170_0_) -> {
|
||||
+ public static final BiMap<String, Structure<?>> field_202300_at = Util.func_200696_a(net.minecraftforge.registries.GameData.getStructureMap(), (p_205170_0_) -> {
|
||||
+ if (true) return; // Forge: This is now a slave map to the feature registry, leave this code here to reduce patch size
|
||||
p_205170_0_.put("Pillager_Outpost".toLowerCase(Locale.ROOT), field_214536_b);
|
||||
p_205170_0_.put("Mineshaft".toLowerCase(Locale.ROOT), field_202329_g);
|
||||
p_205170_0_.put("Mansion".toLowerCase(Locale.ROOT), field_202330_h);
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
--- a/net/minecraft/world/gen/feature/structure/Structures.java
|
||||
+++ b/net/minecraft/world/gen/feature/structure/Structures.java
|
||||
@@ -35,6 +35,7 @@
|
||||
public static final Structure<?> field_215157_o = func_215141_a("Village", Feature.field_214550_p);
|
||||
|
||||
private static Structure<?> func_215141_a(String p_215141_0_, Structure<?> p_215141_1_) {
|
||||
+ if (true) return p_215141_1_; // FORGE: Registry replaced with slave map
|
||||
return Registry.func_218325_a(Registry.field_218361_B, p_215141_0_.toLowerCase(Locale.ROOT), p_215141_1_);
|
||||
}
|
||||
|
|
@ -67,7 +67,7 @@ public class ClearableRegistry<T> extends MutableRegistry<T>
|
|||
public ClearableRegistry(ResourceLocation name, Class<T> superType)
|
||||
{
|
||||
this.name = name;
|
||||
this.isDelegated = ForgeRegistryEntry.class.isAssignableFrom(superType); //TODO: Make this IDelegatedRegistryEntry?
|
||||
this.isDelegated = superType != null && ForgeRegistryEntry.class.isAssignableFrom(superType); //TODO: Make this IDelegatedRegistryEntry?
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,10 +20,11 @@
|
|||
package net.minecraftforge.registries;
|
||||
|
||||
import com.google.common.collect.*;
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
import net.minecraft.block.AirBlock;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.ai.brain.memory.MemoryModuleType;
|
||||
|
@ -34,9 +35,9 @@ import net.minecraft.entity.item.PaintingType;
|
|||
import net.minecraft.entity.merchant.villager.VillagerProfession;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.network.datasync.IDataSerializer;
|
||||
import net.minecraft.particles.ParticleType;
|
||||
import net.minecraft.potion.Effect;
|
||||
|
@ -47,15 +48,17 @@ import net.minecraft.tileentity.TileEntityType;
|
|||
import net.minecraft.util.ObjectIntIdentityMap;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.registry.DefaultedRegistry;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.SimpleRegistry;
|
||||
import net.minecraft.village.PointOfInterestType;
|
||||
import net.minecraft.util.registry.DefaultedRegistry;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.provider.BiomeProviderType;
|
||||
import net.minecraft.world.chunk.ChunkStatus;
|
||||
import net.minecraft.world.gen.ChunkGeneratorType;
|
||||
import net.minecraft.world.gen.carver.WorldCarver;
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
import net.minecraft.world.gen.feature.structure.Structure;
|
||||
import net.minecraft.world.gen.placement.Placement;
|
||||
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
@ -69,11 +72,13 @@ import net.minecraftforge.fml.common.EnhancedRuntimeException;
|
|||
import net.minecraftforge.fml.common.thread.EffectiveSide;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLModIdMappingEvent;
|
||||
import net.minecraftforge.fml.loading.AdvancedLogMessageAdapter;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collection;
|
||||
import java.util.IdentityHashMap;
|
||||
|
@ -142,6 +147,8 @@ public class GameData
|
|||
private static final ResourceLocation BLOCK_TO_ITEM = new ResourceLocation("minecraft:blocktoitemmap");
|
||||
private static final ResourceLocation BLOCKSTATE_TO_ID = new ResourceLocation("minecraft:blockstatetoid");
|
||||
private static final ResourceLocation SERIALIZER_TO_ENTRY = new ResourceLocation("forge:serializer_to_entry");
|
||||
private static final ResourceLocation STRUCTURE_FEATURES = new ResourceLocation("minecraft:structure_feature");
|
||||
private static final ResourceLocation STRUCTURES = new ResourceLocation("minecraft:structures");
|
||||
|
||||
private static boolean hasInit = false;
|
||||
private static final boolean DISABLE_VANILLA_REGISTRIES = Boolean.parseBoolean(System.getProperty("forge.disableVanillaGameData", "false")); // Use for unit tests/debugging
|
||||
|
@ -191,7 +198,7 @@ public class GameData
|
|||
// Worldgen
|
||||
makeRegistry(WORLD_CARVERS, WorldCarver.class).disableSaving().disableSync().create();
|
||||
makeRegistry(SURFACE_BUILDERS, SurfaceBuilder.class).disableSaving().disableSync().create();
|
||||
makeRegistry(FEATURES, Feature.class).disableSaving().disableSync().create();
|
||||
makeRegistry(FEATURES, Feature.class).addCallback(FeatureCallbacks.INSTANCE).disableSaving().disableSync().create();
|
||||
makeRegistry(DECORATORS, Placement.class).disableSaving().disableSync().create();
|
||||
makeRegistry(BIOME_PROVIDER_TYPES, BiomeProviderType.class).disableSaving().disableSync().create();
|
||||
makeRegistry(CHUNK_GENERATOR_TYPES, ChunkGeneratorType.class).disableSaving().disableSync().create();
|
||||
|
@ -253,6 +260,18 @@ public class GameData
|
|||
return RegistryManager.ACTIVE.getRegistry(DataSerializerEntry.class).getSlaveMap(SERIALIZER_TO_ENTRY, Map.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Registry<Structure<?>> getStructureFeatures()
|
||||
{
|
||||
return (Registry<Structure<?>>) RegistryManager.ACTIVE.getRegistry(Feature.class).getSlaveMap(STRUCTURE_FEATURES, Registry.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static BiMap<String, Structure<?>> getStructureMap()
|
||||
{
|
||||
return (BiMap<String, Structure<?>>) RegistryManager.ACTIVE.getRegistry(Feature.class).getSlaveMap(STRUCTURES, BiMap.class);
|
||||
}
|
||||
|
||||
public static <K extends IForgeRegistryEntry<K>> K register_impl(K value)
|
||||
{
|
||||
Validate.notNull(value, "Attempted to register a null object");
|
||||
|
@ -595,6 +614,44 @@ public class GameData
|
|||
}
|
||||
}
|
||||
|
||||
private static class FeatureCallbacks implements IForgeRegistry.AddCallback<Feature<?>>, IForgeRegistry.ClearCallback<Feature<?>>, IForgeRegistry.CreateCallback<Feature<?>>
|
||||
{
|
||||
static final FeatureCallbacks INSTANCE = new FeatureCallbacks();
|
||||
|
||||
@Override
|
||||
public void onAdd(IForgeRegistryInternal<Feature<?>> owner, RegistryManager stage, int id, Feature<?> obj, Feature<?> oldObj)
|
||||
{
|
||||
if (obj instanceof Structure)
|
||||
{
|
||||
Structure<?> structure = (Structure<?>) obj;
|
||||
String key = structure.getStructureName().toLowerCase(Locale.ROOT);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Registry<Structure<?>> reg = owner.getSlaveMap(STRUCTURE_FEATURES, Registry.class);
|
||||
Registry.register(reg, key, structure);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
BiMap<String, Structure<?>> map = owner.getSlaveMap(STRUCTURES, BiMap.class);
|
||||
if (oldObj != null && oldObj instanceof Structure) map.remove(((Structure<?>)oldObj).getStructureName());
|
||||
map.put(key, structure);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClear(IForgeRegistryInternal<Feature<?>> owner, RegistryManager stage)
|
||||
{
|
||||
owner.getSlaveMap(STRUCTURE_FEATURES, ClearableRegistry.class).clear();
|
||||
owner.getSlaveMap(STRUCTURES, BiMap.class).clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(IForgeRegistryInternal<Feature<?>> owner, RegistryManager stage)
|
||||
{
|
||||
owner.setSlaveMap(STRUCTURE_FEATURES, new ClearableRegistry<>(owner.getRegistryName()));
|
||||
owner.setSlaveMap(STRUCTURES, HashBiMap.create());
|
||||
}
|
||||
}
|
||||
|
||||
private static <T extends IForgeRegistryEntry<T>> void loadRegistry(final ResourceLocation registryName, final RegistryManager from, final RegistryManager to, final Class<T> regType, boolean freeze)
|
||||
{
|
||||
ForgeRegistry<T> fromRegistry = from.getRegistry(registryName);
|
||||
|
|
Loading…
Reference in a new issue