Initial 1.13.2 update. Major thing to note is that Dimensions have been completely revamped.

DimensionType is not unique per Dimension. See DimensionManager for more details.
Vanilla now has a chunk loading system, so Forge's will need to be deprecated/adapted.
This commit is contained in:
LexManos committed 2019-02-14 15:08:53 -08:00
1 parent 9a1688599a
commit ca72710937
361 files changed
+3166 -3547

No files matched your search

@@ -0,0 +1,175 @@
/*
* 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.Iterator;
import java.util.List;
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.IRegistry;
/**
* 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<V> implements IRegistry<V>
{
private static final Logger LOGGER = LogManager.getLogger();
private static final Marker REGISTRY = MarkerManager.getMarker("REGISTRY");
private final IntIdentityHashBiMap<V> ids = new IntIdentityHashBiMap<>(256);
private final BiMap<ResourceLocation, V> map = HashBiMap.create();
private final Set<ResourceLocation> keys = Collections.unmodifiableSet(map.keySet());
private List<V> values = new ArrayList<>();
private final ResourceLocation name;
private int nextId = 0;
public ClearableRegistry(ResourceLocation name)
{
this.name = name;
}
@Override
@Nullable
public ResourceLocation getKey(V value)
{
return map.inverse().get(value);
}
@Override
public V get(ResourceLocation key)
{
throw new UnsupportedOperationException("No default value");
}
@Override
public ResourceLocation func_212609_b()
{
throw new UnsupportedOperationException("No default key");
}
@Override
@Nullable
public int getId(V value)
{
return ids.getId(value);
}
@Override
@Nullable
public V get(int id)
{
return ids.get(id);
}
@Override
public Iterator<V> iterator()
{
return ids.iterator();
}
@Override
@Nullable
public V func_212608_b(ResourceLocation key)
{
return map.get(key);
}
@Override
public void register(int id, ResourceLocation key, V value)
{
Validate.isTrue(id >= 0, "Invalid ID, can not be < 0");
Validate.notNull(key);
Validate.notNull(value);
V old = map.get(key);
if (old != null)
{
LOGGER.debug(REGISTRY, "{}: Adding suplicate key '{}' to registry. Old: {} New: {}", name, key, old, value);
values.remove(old);
}
map.put(key, value);
ids.put(value, id);
values.add(value);
if (nextId <= id)
nextId = id + 1;
}
@Override
public void put(ResourceLocation key, V value)
{
register(nextId, key, value);
}
@Override
public Set<ResourceLocation> getKeys()
{
return keys;
}
@Override
public boolean isEmpty()
{
return map.isEmpty();
}
@Override
@Nullable
public V getRandom(Random random)
{
return values.isEmpty() ? null : values.get(random.nextInt(values.size()));
}
@Override
public boolean func_212607_c(ResourceLocation key)
{
return map.containsKey(key);
}
public void clear()
{
LOGGER.debug(REGISTRY, "{}: Clearing registry", name);
map.clear();
values.clear();
ids.clear();
nextId = 0;
}
public int getNextId()
{
return nextId;
}
}
@@ -30,6 +30,7 @@ import net.minecraft.potion.PotionType;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.SoundEvent;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.ModDimension;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.registry.VillagerRegistry;
import net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession;
@@ -52,8 +53,9 @@ public class ForgeRegistries
public static final IForgeRegistry<PotionType> POTION_TYPES = RegistryManager.ACTIVE.getRegistry(PotionType.class);
public static final IForgeRegistry<Enchantment> ENCHANTMENTS = RegistryManager.ACTIVE.getRegistry(Enchantment.class);
public static final IForgeRegistry<VillagerProfession> VILLAGER_PROFESSIONS = RegistryManager.ACTIVE.getRegistry(VillagerProfession.class);
public static final IForgeRegistry<EntityType<?>> ENTITIES = (IForgeRegistry)RegistryManager.ACTIVE.getRegistry(EntityType.class);
public static final IForgeRegistry<TileEntityType<?>> TILE_ENTITIES = (IForgeRegistry)RegistryManager.ACTIVE.getRegistry(TileEntityType.class);
public static final IForgeRegistry<EntityType<?>> ENTITIES = RegistryManager.ACTIVE.getRegistry(EntityType.class);
public static final IForgeRegistry<TileEntityType<?>> TILE_ENTITIES = RegistryManager.ACTIVE.getRegistry(TileEntityType.class);
public static final IForgeRegistry<ModDimension> MOD_DIMENSIONS = RegistryManager.ACTIVE.getRegistry(ModDimension.class);
/**
* This function is just to make sure static inializers in other classes have run and setup their registries before we query them.
*/
@@ -28,6 +28,8 @@ import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import net.minecraftforge.fml.loading.AdvancedLogMessageAdapter;
@@ -272,6 +274,12 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
Validate.notNull(this.defaultValue, "Missing default of ForgeRegistry: " + this.defaultKey + " Type: " + this.superType);
}
@Nullable
public ResourceLocation getDefaultKey()
{
return this.defaultKey;
}
ForgeRegistry<V> copy(RegistryManager stage)
{
return new ForgeRegistry<>(stage, name, builder);
@@ -358,7 +366,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
return idToUse;
}
private V getRaw(ResourceLocation key)
public V getRaw(ResourceLocation key)
{
V ret = this.names.get(key);
key = this.aliases.get(key);
@@ -39,6 +39,7 @@ import net.minecraft.util.registry.RegistryNamespaced;
import net.minecraft.util.registry.RegistryNamespacedDefaultedByKey;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.ModDimension;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.RegistryEvent.MissingMappings;
import net.minecraftforge.fml.LifecycleEventProvider;
@@ -84,15 +85,16 @@ public class GameData
public static final ResourceLocation ENTITIES = new ResourceLocation("minecraft:entities");
public static final ResourceLocation TILEENTITIES = new ResourceLocation("minecraft:tileentities");
public static final ResourceLocation PROFESSIONS = new ResourceLocation("minecraft:villagerprofessions");
public static final ResourceLocation MODDIMENSIONS = new ResourceLocation("forge:moddimensions");
private static final int MAX_REGISTRY_SIZE = Integer.MAX_VALUE >> 5;
private static final int MAX_BLOCK_ID = 4095;
private static final int MIN_ITEM_ID = MAX_BLOCK_ID + 1;
private static final int MAX_ITEM_ID = 31999;
private static final int MAX_POTION_ID = 255; // SPacketEntityEffect sends bytes, we can only use 255
private static final int MAX_BIOME_ID = 255; // Maximum number in a byte in the chunk
private static final int MAX_SOUND_ID = Integer.MAX_VALUE >> 5; // Varint (SPacketSoundEffect)
private static final int MAX_POTIONTYPE_ID = Integer.MAX_VALUE >> 5; // Int (SPacketEffect)
private static final int MAX_POTIONTYPE_ID = MAX_REGISTRY_SIZE; // Int (SPacketEffect)
private static final int MAX_ENCHANTMENT_ID = Short.MAX_VALUE - 1; // Short - serialized as a short in ItemStack NBTs.
private static final int MAX_ENTITY_ID = Integer.MAX_VALUE >> 5; // Varint (SPacketSpawnMob)
private static final int MAX_ENTITY_ID = MAX_REGISTRY_SIZE; // Varint (SPacketSpawnMob)
private static final int MAX_TILE_ENTITY_ID = Integer.MAX_VALUE; //Doesnt seem to be serialized anywhere, so no max.
private static final int MAX_PROFESSION_ID = 1024; //TODO: Is this serialized anywhere anymore?
@@ -118,7 +120,7 @@ public class GameData
return;
hasInit = true;
makeRegistry(BLOCKS, Block.class, MAX_BLOCK_ID, new ResourceLocation("air")).addCallback(BlockCallbacks.INSTANCE).create();
makeRegistry(ITEMS, Item.class, MIN_ITEM_ID, MAX_ITEM_ID).addCallback(ItemCallbacks.INSTANCE).create();
makeRegistry(ITEMS, Item.class, MAX_ITEM_ID).addCallback(ItemCallbacks.INSTANCE).create();
makeRegistry(POTIONS, Potion.class, MAX_POTION_ID).create();
makeRegistry(BIOMES, Biome.class, MAX_BIOME_ID).create();
makeRegistry(SOUNDEVENTS, SoundEvent.class, MAX_SOUND_ID).create();
@@ -128,12 +130,9 @@ public class GameData
// TODO do we need the callback and the static field anymore?
makeRegistry(ENTITIES, EntityType.class, MAX_ENTITY_ID).create();
makeRegistry(TILEENTITIES, TileEntityType.class, MAX_TILE_ENTITY_ID).disableSaving().create();
makeRegistry(MODDIMENSIONS, ModDimension.class, MAX_REGISTRY_SIZE).disableSaving().create();
}
private static <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).addCallback(new NamespacedWrapper.Factory<T>());
}
private static <T extends IForgeRegistryEntry<T>> RegistryBuilder<T> makeRegistry(ResourceLocation name, Class<T> type, int max)
{
return new RegistryBuilder<T>().setName(name).setType(type).setMaxID(max).addCallback(new NamespacedWrapper.Factory<T>());
@@ -143,22 +142,22 @@ public class GameData
return new RegistryBuilder<T>().setName(name).setType(type).setMaxID(max).addCallback(new NamespacedDefaultedWrapper.Factory<T>()).setDefaultKey(_default);
}
public static <V extends IForgeRegistryEntry<V>> RegistryNamespacedDefaultedByKey<ResourceLocation, V> getWrapperDefaulted(Class<V> cls)
public static <V extends IForgeRegistryEntry<V>> RegistryNamespacedDefaultedByKey<V> getWrapperDefaulted(Class<V> cls)
{
IForgeRegistry<V> reg = RegistryManager.ACTIVE.getRegistry(cls);
Validate.notNull(reg, "Attempted to get vanilla wrapper for unknown registry: " + cls.toString());
@SuppressWarnings("unchecked")
RegistryNamespacedDefaultedByKey<ResourceLocation, V> ret = reg.getSlaveMap(NamespacedDefaultedWrapper.Factory.ID, NamespacedDefaultedWrapper.class);
RegistryNamespacedDefaultedByKey<V> ret = reg.getSlaveMap(NamespacedDefaultedWrapper.Factory.ID, NamespacedDefaultedWrapper.class);
Validate.notNull(ret, "Attempted to get vanilla wrapper for registry created incorrectly: " + cls.toString());
return ret;
}
public static <V extends IForgeRegistryEntry<V>> RegistryNamespaced<ResourceLocation, V> getWrapper(Class<V> cls)
public static <V extends IForgeRegistryEntry<V>> RegistryNamespaced<V> getWrapper(Class<V> cls)
{
IForgeRegistry<V> reg = RegistryManager.ACTIVE.getRegistry(cls);
Validate.notNull(reg, "Attempted to get vanilla wrapper for unknown registry: " + cls.toString());
@SuppressWarnings("unchecked")
RegistryNamespaced<ResourceLocation, V> ret = reg.getSlaveMap(NamespacedWrapper.Factory.ID, NamespacedWrapper.class);
RegistryNamespaced<V> ret = reg.getSlaveMap(NamespacedWrapper.Factory.ID, NamespacedWrapper.class);
Validate.notNull(ret, "Attempted to get vanilla wrapper for registry created incorrectly: " + cls.toString());
return ret;
}
@@ -382,7 +381,7 @@ public class GameData
@Override
public Block createDummy(ResourceLocation key)
{
Block ret = new BlockDummyAir(Block.Builder.create(Material.AIR));
Block ret = new BlockDummyAir(Block.Properties.create(Material.AIR));
GameData.forceRegistryName(ret, key);
return ret;
}
@@ -404,9 +403,9 @@ public class GameData
private static class BlockDummyAir extends BlockAir //A named class so DummyBlockReplacementTest can detect if its a dummy
{
private BlockDummyAir(Block.Builder builder)
private BlockDummyAir(Block.Properties properties)
{
super(builder);
super(properties);
}
@Override
@@ -47,6 +47,7 @@ public interface IForgeRegistry<V extends IForgeRegistryEntry<V>> extends Iterab
@Nullable V getValue(ResourceLocation key);
@Nullable ResourceLocation getKey(V value);
@Nullable ResourceLocation getDefaultKey();
@Nonnull Set<ResourceLocation> getKeys();
@Nonnull Collection<V> getValues();
@@ -33,7 +33,7 @@ import net.minecraft.util.registry.RegistryNamespacedDefaultedByKey;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
class NamespacedDefaultedWrapper<V extends IForgeRegistryEntry<V>> extends RegistryNamespacedDefaultedByKey<ResourceLocation, V> implements ILockableRegistry
class NamespacedDefaultedWrapper<V extends IForgeRegistryEntry<V>> extends RegistryNamespacedDefaultedByKey<V> implements ILockableRegistry
{
private static final Logger LOGGER = LogManager.getLogger();
private boolean locked = false;
@@ -66,18 +66,19 @@ class NamespacedDefaultedWrapper<V extends IForgeRegistryEntry<V>> extends Regis
register(-1, key, value);
}
// Reading Functions
@Override
public void validateKey()
@Nullable
public V func_212608_b(@Nullable ResourceLocation name)
{
this.delegate.validateKey();
return this.delegate.getRaw(name); //get without default
}
// Reading Functions
@Override
@Nullable
public V get(@Nullable ResourceLocation name)
{
return this.delegate.getValue(name);
return this.delegate.getValue(name); //getOrDefault
}
@Override
@@ -88,7 +89,7 @@ class NamespacedDefaultedWrapper<V extends IForgeRegistryEntry<V>> extends Regis
}
@Override
public boolean containsKey(ResourceLocation key)
public boolean func_212607_c(ResourceLocation key)
{
return this.delegate.containsKey(key);
}
@@ -126,6 +127,12 @@ class NamespacedDefaultedWrapper<V extends IForgeRegistryEntry<V>> extends Regis
return values.stream().skip(random.nextInt(values.size())).findFirst().orElse(null);
}
@Override
public ResourceLocation func_212609_b()
{
return this.delegate.getDefaultKey();
}
//internal
@Override
public void lock(){ this.locked = true; }
@@ -33,7 +33,7 @@ import net.minecraft.util.registry.RegistryNamespaced;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
class NamespacedWrapper<V extends IForgeRegistryEntry<V>> extends RegistryNamespaced<ResourceLocation, V> implements ILockableRegistry
class NamespacedWrapper<V extends IForgeRegistryEntry<V>> extends RegistryNamespaced<V> implements ILockableRegistry
{
private static final Logger LOGGER = LogManager.getLogger();
private boolean locked = false;
@@ -70,9 +70,9 @@ class NamespacedWrapper<V extends IForgeRegistryEntry<V>> extends RegistryNamesp
// Reading Functions
@Override
@Nullable
public V get(@Nullable ResourceLocation name)
public V func_212608_b(@Nullable ResourceLocation name)
{
return this.delegate.getValue(name);
return this.delegate.getRaw(name); //get without default
}
@Override
@@ -83,7 +83,7 @@ class NamespacedWrapper<V extends IForgeRegistryEntry<V>> extends RegistryNamesp
}
@Override
public boolean containsKey(ResourceLocation key)
public boolean func_212607_c(ResourceLocation key)
{
return this.delegate.containsKey(key);
}