Setup and import of 1.16 YEET

This commit is contained in:
cpw committed 2020-06-25 17:55:38 -04:00
1 parent 56397043bb
commit 6d15febdb3
931 files changed
+18847 -9127

No files matched your search

@@ -1,206 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2019.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.registries;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
import javax.annotation.Nullable;
import org.apache.commons.lang3.Validate;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import net.minecraft.util.IntIdentityHashBiMap;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.MutableRegistry;
/**
* A IRegistry implementation that allows for removing of objects. This is a internal helper
* class used by Forge for managing things that reset during Server initialization.
*/
public class ClearableRegistry<T> extends MutableRegistry<T>
{
private static final Logger LOGGER = LogManager.getLogger();
private static final Marker REGISTRY = MarkerManager.getMarker("REGISTRY");
private final IntIdentityHashBiMap<T> ids = new IntIdentityHashBiMap<>(256);
private final BiMap<ResourceLocation, T> map = HashBiMap.create();
private final Set<ResourceLocation> keys = Collections.unmodifiableSet(map.keySet());
private List<T> values = new ArrayList<>();
private Map<ResourceLocation, Set<T>> known = new HashMap<>();
private final ResourceLocation name;
private final boolean isDelegated;
private int nextId = 0;
public ClearableRegistry(ResourceLocation name) { this(name, null); }
public ClearableRegistry(ResourceLocation name, Class<T> superType)
{
this.name = name;
this.isDelegated = superType != null && ForgeRegistryEntry.class.isAssignableFrom(superType); //TODO: Make this IDelegatedRegistryEntry?
}
@Override
@Nullable
public ResourceLocation getKey(T value)
{
return map.inverse().get(value);
}
@Override
@Nullable
public int getId(T value)
{
return ids.getId(value);
}
@Override
@Nullable
public T getByValue(int id)
{
return ids.getByValue(id);
}
@Override
public Iterator<T> iterator()
{
return ids.iterator();
}
@Override
@Nullable
public T getOrDefault(ResourceLocation key)
{
return map.get(key);
}
@Override
public <V extends T> V register(int id, ResourceLocation key, V value)
{
Validate.isTrue(id >= 0, "Invalid ID, can not be < 0");
Validate.notNull(key);
Validate.notNull(value);
T old = map.get(key);
if (old != null)
{
LOGGER.debug(REGISTRY, "{}: Adding duplicate key '{}' to registry. Old: {} New: {}", name, key, old, value);
values.remove(old);
if (isDelegated)
{
Set<T> others = known.computeIfAbsent(key, k -> new HashSet<>());
others.add(old);
others.forEach(e -> getDelegate(e).changeReference(value));
}
}
map.put(key, value);
ids.put(value, id);
values.add(value);
if (nextId <= id)
nextId = id + 1;
if (isDelegated)
getDelegate(value).setName(key);
return value;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private RegistryDelegate<T> getDelegate(T thing)
{
if (isDelegated)
return (RegistryDelegate<T>)((ForgeRegistryEntry)thing).delegate;
else
throw new IllegalStateException("Tried to get existing delegate from registry that is not delegated.");
}
@Override
public <V extends T> V register(ResourceLocation key, V value)
{
return register(nextId, key, value);
}
@Override
public Set<ResourceLocation> keySet()
{
return keys;
}
@Override
public boolean isEmpty()
{
return map.isEmpty();
}
@Override
@Nullable
public T getRandom(Random random)
{
return values.isEmpty() ? null : values.get(random.nextInt(values.size()));
}
@Override
public boolean containsKey(ResourceLocation key)
{
return map.containsKey(key);
}
public void clear()
{
LOGGER.debug(REGISTRY, "{}: Clearing registry", name);
if (isDelegated)
{
known.values().forEach(s -> {
s.forEach(e -> getDelegate(e).changeReference(e));
s.clear();
});
known.clear();
}
map.clear();
values.clear();
ids.clear();
nextId = 0;
}
public int getNextId()
{
return nextId;
}
@Override
public Optional<T> getValue(ResourceLocation key)
{
return Optional.ofNullable(map.get(key));
}
}
@@ -41,9 +41,7 @@ import net.minecraft.stats.StatType;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.SoundEvent;
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.blockplacer.BlockPlacerType;
import net.minecraft.world.gen.blockstateprovider.BlockStateProviderType;
import net.minecraft.world.gen.carver.WorldCarver;
@@ -52,7 +50,6 @@ import net.minecraft.world.gen.foliageplacer.FoliagePlacerType;
import net.minecraft.world.gen.placement.Placement;
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder;
import net.minecraft.world.gen.treedecorator.TreeDecoratorType;
import net.minecraftforge.common.ModDimension;
import net.minecraftforge.common.loot.GlobalLootModifierSerializer;
import net.minecraftforge.fml.common.registry.GameRegistry;
@@ -95,8 +92,8 @@ public class ForgeRegistries
public static final IForgeRegistry<SurfaceBuilder<?>> SURFACE_BUILDERS = RegistryManager.ACTIVE.getRegistry(SurfaceBuilder.class);
public static final IForgeRegistry<Feature<?>> FEATURES = RegistryManager.ACTIVE.getRegistry(Feature.class);
public static final IForgeRegistry<Placement<?>> DECORATORS = RegistryManager.ACTIVE.getRegistry(Placement.class);
public static final IForgeRegistry<BiomeProviderType<?, ?>> BIOME_PROVIDER_TYPES = RegistryManager.ACTIVE.getRegistry(BiomeProviderType.class);
public static final IForgeRegistry<ChunkGeneratorType<?, ?>> CHUNK_GENERATOR_TYPES = RegistryManager.ACTIVE.getRegistry(ChunkGeneratorType.class);
// public static final IForgeRegistry<BiomeProviderType<?, ?>> BIOME_PROVIDER_TYPES = RegistryManager.ACTIVE.getRegistry(BiomeProviderType.class);
// public static final IForgeRegistry<ChunkGeneratorType<?, ?>> CHUNK_GENERATOR_TYPES = RegistryManager.ACTIVE.getRegistry(ChunkGeneratorType.class);
public static final IForgeRegistry<ChunkStatus> CHUNK_STATUS = RegistryManager.ACTIVE.getRegistry(ChunkStatus.class);
public static final IForgeRegistry<BlockStateProviderType<?>> BLOCK_STATE_PROVIDER_TYPES = RegistryManager.ACTIVE.getRegistry(BlockStateProviderType.class);
public static final IForgeRegistry<BlockPlacerType<?>> BLOCK_PLACER_TYPES = RegistryManager.ACTIVE.getRegistry(BlockPlacerType.class);
@@ -104,7 +101,7 @@ public class ForgeRegistries
public static final IForgeRegistry<TreeDecoratorType<?>> TREE_DECORATOR_TYPES = RegistryManager.ACTIVE.getRegistry(TreeDecoratorType.class);
// Custom forge registries
public static final IForgeRegistry<ModDimension> MOD_DIMENSIONS = RegistryManager.ACTIVE.getRegistry(ModDimension.class);
//public static final IForgeRegistry<ModDimension> MOD_DIMENSIONS = RegistryManager.ACTIVE.getRegistry(ModDimension.class); //TODO Dimensions..
public static final IForgeRegistry<DataSerializerEntry> DATA_SERIALIZERS = RegistryManager.ACTIVE.getRegistry(DataSerializerEntry.class);
public static final IForgeRegistry<GlobalLootModifierSerializer<?>> LOOT_MODIFIER_SERIALIZERS = RegistryManager.ACTIVE.getRegistry(GlobalLootModifierSerializer.class);
@@ -53,9 +53,7 @@ import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.SimpleRegistry;
import net.minecraft.village.PointOfInterestType;
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.blockplacer.BlockPlacerType;
import net.minecraft.world.gen.blockstateprovider.BlockStateProviderType;
import net.minecraft.world.gen.carver.WorldCarver;
@@ -66,7 +64,6 @@ import net.minecraft.world.gen.placement.Placement;
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder;
import net.minecraft.world.gen.treedecorator.TreeDecoratorType;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.ModDimension;
import net.minecraftforge.common.loot.GlobalLootModifierSerializer;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.RegistryEvent.MissingMappings;
@@ -109,7 +106,7 @@ public class GameData
// Vanilla registries
// Names used here match those in net.minecraft.util.Registry
// Game objects
public static final ResourceLocation BLOCKS = new ResourceLocation("block");
public static final ResourceLocation FLUIDS = new ResourceLocation("fluid");
@@ -126,7 +123,7 @@ public class GameData
public static final ResourceLocation PAINTING_TYPES = new ResourceLocation("motive"); // sic
public static final ResourceLocation RECIPE_SERIALIZERS = new ResourceLocation("recipe_serializer");
public static final ResourceLocation STAT_TYPES = new ResourceLocation("stat_type");
// Villages
public static final ResourceLocation PROFESSIONS = new ResourceLocation("villager_profession");
public static final ResourceLocation POI_TYPES = new ResourceLocation("point_of_interest_type");
@@ -158,7 +155,7 @@ 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 STRUCTURE_FEATURES = new ResourceLocation("minecraft:structure_feature");
private static final ResourceLocation STRUCTURES = new ResourceLocation("minecraft:structures");
private static boolean hasInit = false;
@@ -180,7 +177,7 @@ public class GameData
if (hasInit)
return;
hasInit = true;
// Game objects
makeRegistry(BLOCKS, Block.class, new ResourceLocation("air")).addCallback(BlockCallbacks.INSTANCE).legacyName("blocks").create();
makeRegistry(FLUIDS, Fluid.class, new ResourceLocation("empty")).create();
@@ -197,7 +194,7 @@ public class GameData
makeRegistry(PAINTING_TYPES, PaintingType.class, new ResourceLocation("kebab")).create();
makeRegistry(RECIPE_SERIALIZERS, IRecipeSerializer.class).disableSaving().create();
makeRegistry(STAT_TYPES, StatType.class).create();
// Villagers
makeRegistry(PROFESSIONS, VillagerProfession.class, new ResourceLocation("none")).create();
makeRegistry(POI_TYPES, PointOfInterestType.class, new ResourceLocation("unemployed")).disableSync().create();
@@ -211,8 +208,8 @@ public class GameData
makeRegistry(SURFACE_BUILDERS, SurfaceBuilder.class).disableSaving().disableSync().create();
makeRegistry(FEATURES, Feature.class).addCallback(FeatureCallbacks.INSTANCE).disableSaving().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();
// makeRegistry(BIOME_PROVIDER_TYPES, BiomeProviderType.class).disableSaving().disableSync().create();
// makeRegistry(CHUNK_GENERATOR_TYPES, ChunkGeneratorType.class).disableSaving().disableSync().create();
makeRegistry(CHUNK_STATUS, ChunkStatus.class, new ResourceLocation("empty")).disableSaving().disableSync().create();
makeRegistry(BLOCK_STATE_PROVIDER_TYPES, BlockStateProviderType.class).disableSaving().disableSync().create();
makeRegistry(BLOCK_PLACER_TYPES, BlockPlacerType.class).disableSaving().disableSync().create();
@@ -220,7 +217,7 @@ public class GameData
makeRegistry(TREE_DECORATOR_TYPES, TreeDecoratorType.class).disableSaving().disableSync().create();
// Custom forge registries
makeRegistry(MODDIMENSIONS, ModDimension.class ).disableSaving().create();
//makeRegistry(MODDIMENSIONS, ModDimension.class ).disableSaving().create(); //TODO Dimensions
makeRegistry(SERIALIZERS, DataSerializerEntry.class, 256 /*vanilla space*/, MAX_VARINT).disableSaving().disableOverrides().addCallback(SerializerCallbacks.INSTANCE).create();
makeRegistry(LOOT_MODIFIER_SERIALIZERS, GlobalLootModifierSerializer.class).disableSaving().disableSync().create();
}
@@ -275,13 +272,15 @@ 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()
{
@@ -629,41 +628,43 @@ public class GameData
owner.setSlaveMap(SERIALIZER_TO_ENTRY, new IdentityHashMap<>());
}
}
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)
{
/*TODO, Structures arent Features anymore.
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(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(STRUCTURE_FEATURES, new ClearableRegistry<>(owner.getRegistryName()));
owner.setSlaveMap(STRUCTURES, HashBiMap.create());
}
}
@@ -715,7 +716,7 @@ public class GameData
RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.validateContent(name));
RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.dump(name));
RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.resetDelegates());
// Update legacy names
snapshot = snapshot.entrySet().stream()
.sorted(Map.Entry.comparingByKey()) // FIXME Registries need dependency ordering, this makes sure blocks are done before items (for ItemCallbacks) but it's lazy as hell
@@ -29,11 +29,14 @@ import javax.annotation.Nullable;
import org.apache.commons.lang3.Validate;
import net.minecraft.util.RegistryKey;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.DefaultedRegistry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.mojang.serialization.Lifecycle;
class NamespacedDefaultedWrapper<T extends IForgeRegistryEntry<T>> extends DefaultedRegistry<T> implements ILockableRegistry
{
private static final Logger LOGGER = LogManager.getLogger();
@@ -42,19 +45,19 @@ class NamespacedDefaultedWrapper<T extends IForgeRegistryEntry<T>> extends Defau
private NamespacedDefaultedWrapper(ForgeRegistry<T> owner)
{
super(owner.getRegistryName().toString());
super("empty", RegistryKey.<T>func_240904_a_(owner.getRegistryName()), Lifecycle.experimental());
this.delegate = owner;
}
@Override
public <V extends T> V register(int id, ResourceLocation key, V value)
public <V extends T> V register(int id, RegistryKey<T> key, V value)
{
if (locked)
throw new IllegalStateException("Can not register to a locked registry. Modder should use Forge Register methods.");
Validate.notNull(value);
if (value.getRegistryName() == null)
value.setRegistryName(key);
value.setRegistryName(key.func_240901_a_());
int realId = this.delegate.add(id, value);
if (realId != id && id != -1)
@@ -64,7 +67,7 @@ class NamespacedDefaultedWrapper<T extends IForgeRegistryEntry<T>> extends Defau
}
@Override
public <V extends T> V register(ResourceLocation key, V value)
public <V extends T> V register(RegistryKey<T> key, V value)
{
return register(-1, key, value);
}
@@ -109,6 +112,12 @@ class NamespacedDefaultedWrapper<T extends IForgeRegistryEntry<T>> extends Defau
return this.delegate.getValue(id);
}
@Override
public boolean func_230518_b_(int id)
{
return this.getByValue(id) != null;
}
@Override
public Iterator<T> iterator()
{
@@ -135,12 +144,6 @@ class NamespacedDefaultedWrapper<T extends IForgeRegistryEntry<T>> extends Defau
return this.delegate.getDefaultKey();
}
@Override
public boolean isEmpty()
{
return this.delegate.isEmpty();
}
//internal
@Override
public void lock(){ this.locked = true; }
@@ -25,12 +25,16 @@ import java.util.Optional;
import java.util.Random;
import java.util.Set;
import javax.annotation.Nullable;
import net.minecraft.util.RegistryKey;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.SimpleRegistry;
import org.apache.commons.lang3.Validate;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.mojang.serialization.Lifecycle;
class NamespacedWrapper<T extends IForgeRegistryEntry<T>> extends SimpleRegistry<T> implements ILockableRegistry
{
private static final Logger LOGGER = LogManager.getLogger();
@@ -39,11 +43,12 @@ class NamespacedWrapper<T extends IForgeRegistryEntry<T>> extends SimpleRegistry
public NamespacedWrapper(ForgeRegistry<T> owner)
{
super(RegistryKey.func_240904_a_(owner.getRegistryName()), Lifecycle.experimental());
this.delegate = owner;
}
@Override
public <V extends T> V register(int id, ResourceLocation key, V value)
public <V extends T> V register(int id, RegistryKey<T> key, V value)
{
if (locked)
throw new IllegalStateException("Can not register to a locked registry. Modder should use Forge Register methods.");
@@ -51,7 +56,7 @@ class NamespacedWrapper<T extends IForgeRegistryEntry<T>> extends SimpleRegistry
Validate.notNull(value);
if (value.getRegistryName() == null)
value.setRegistryName(key);
value.setRegistryName(key.func_240901_a_());
int realId = this.delegate.add(id, value);
if (realId != id && id != -1)
@@ -60,7 +65,7 @@ class NamespacedWrapper<T extends IForgeRegistryEntry<T>> extends SimpleRegistry
}
@Override
public <R extends T> R register(ResourceLocation key, R value)
public <R extends T> R register(RegistryKey<T> key, R value)
{
return register(-1, key, value);
}
@@ -125,11 +130,13 @@ class NamespacedWrapper<T extends IForgeRegistryEntry<T>> extends SimpleRegistry
return values.stream().skip(random.nextInt(values.size())).findFirst().orElse(null);
}
/*
@Override
public boolean isEmpty()
{
return this.delegate.isEmpty();
}
*/
//internal
@Override