Update to 1.18.2

Co-authored-by: sciwhiz12 <[email protected]>
Co-authored-by: Marc Hermans <[email protected]>
Co-authored-by: LexManos <[email protected]>
Co-authored-by: Curle <[email protected]>
Signed-off-by: SizableShrimp <[email protected]>
This commit is contained in:
authored and LexManos committed 2022-03-01 14:16:46 -08:00
1 parent 34291c1fb2
commit 425eff39ff
234 files changed
+2175 -3226

No files matched your search

@@ -392,6 +392,12 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
}
}
if (this.builder.getVanillaHolder() != null)
{
var ref = this.builder.getVanillaHolder().apply(value);
ref.bind(rkey, value);
}
if (this.add != null)
this.add.onAdd(this, this.stage, idToUse, value, oldEntry);
@@ -1140,5 +1146,10 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
LOGGER.debug(REGISTRIES,"There were {} missing mappings that have been ignored", ignored);
}
RegistryBuilder<V> getBuilder()
{
return this.builder;
}
private record OverrideOwner<V>(String owner, ResourceKey<V> key){};
}
@@ -35,7 +35,6 @@ import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.stats.StatType;
import net.minecraft.tags.StaticTags;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.core.DefaultedRegistry;
import net.minecraft.core.Registry;
@@ -50,7 +49,6 @@ import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.StructureFeature;
import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacerType;
import net.minecraft.world.level.levelgen.feature.treedecorators.TreeDecoratorType;
import net.minecraftforge.common.ForgeTagHandler;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.loot.GlobalLootModifierSerializer;
import net.minecraftforge.common.util.LogMessageAdapter;
@@ -120,15 +118,15 @@ public class GameData
hasInit = true;
// Game objects
makeRegistry(BLOCKS, Block.class, "air").addCallback(BlockCallbacks.INSTANCE).legacyName("blocks").create();
makeRegistry(FLUIDS, Fluid.class, "empty").create();
makeRegistry(ITEMS, Item.class, "air").addCallback(ItemCallbacks.INSTANCE).legacyName("items").create();
makeRegistry(BLOCKS, Block.class, "air").addCallback(BlockCallbacks.INSTANCE).legacyName("blocks").vanillaHolder(Block::builtInRegistryHolder).create();
makeRegistry(FLUIDS, Fluid.class, "empty").vanillaHolder(Fluid::builtInRegistryHolder).create();
makeRegistry(ITEMS, Item.class, "air").addCallback(ItemCallbacks.INSTANCE).legacyName("items").vanillaHolder(Item::builtInRegistryHolder).create();
makeRegistry(MOB_EFFECTS, MobEffect.class).legacyName("potions").tagFolder("mob_effects").create();
//makeRegistry(BIOMES, Biome.class).legacyName("biomes").create();
makeRegistry(SOUND_EVENTS, SoundEvent.class).legacyName("soundevents").create();
makeRegistry(POTIONS, Potion.class, "empty").legacyName("potiontypes").tagFolder("potions").create();
makeRegistry(ENCHANTMENTS, Enchantment.class).legacyName("enchantments").tagFolder("enchantments").create();
makeRegistry(ENTITY_TYPES, c(EntityType.class), "pig").legacyName("entities").create();
makeRegistry(ENTITY_TYPES, c(EntityType.class), "pig").legacyName("entities").vanillaHolder(EntityType::builtInRegistryHolder).create();
makeRegistry(BLOCK_ENTITY_TYPES, c(BlockEntityType.class)).disableSaving().legacyName("blockentities").tagFolder("block_entity_types").create();
makeRegistry(PARTICLE_TYPES, c(ParticleType.class)).disableSaving().create();
makeRegistry(CONTAINER_TYPES, c(MenuType.class)).disableSaving().create();
@@ -257,10 +255,18 @@ public class GameData
LOGGER.debug(REGISTRIES, "Vanilla freeze snapshot created");
}
public static void unfreezeData()
{
LOGGER.debug(REGISTRIES, "Unfreezing vanilla registries");
Registry.REGISTRY.stream().filter(r -> r instanceof MappedRegistry).forEach(r -> ((MappedRegistry<?>)r).unfreeze());
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void freezeData()
{
LOGGER.debug(REGISTRIES, "Freezing registries");
Registry.REGISTRY.stream().filter(r -> r instanceof MappedRegistry).forEach(r -> ((MappedRegistry<?>)r).freeze());
for (Map.Entry<ResourceLocation, ForgeRegistry<? extends IForgeRegistryEntry<?>>> r : RegistryManager.ACTIVE.registries.entrySet())
{
final Class<? extends IForgeRegistryEntry> clazz = RegistryManager.ACTIVE.getSuperType(r.getKey());
@@ -372,22 +378,6 @@ public class GameData
}, executor);
}
public static void setCustomTagTypesFromRegistries()
{
Set<ResourceLocation> customTagTypes = new HashSet<>();
for (Map.Entry<ResourceLocation, ForgeRegistry<? extends IForgeRegistryEntry<?>>> entry : RegistryManager.ACTIVE.registries.entrySet())
{
ResourceLocation registryName = entry.getKey();
if (entry.getValue().getTagFolder() != null && StaticTags.get(registryName) == null)
{
LOGGER.debug(REGISTRIES, "Registering custom tag type for: {}", registryName);
customTagTypes.add(registryName);
StaticTags.create(ResourceKey.createRegistryKey(registryName), "tags/" + entry.getValue().getTagFolder());
}
}
ForgeTagHandler.setCustomTagTypes(customTagTypes);
}
//Lets us clear the map so we can rebuild it.
private static class ClearableObjectIntIdentityMap<I> extends IdMapper<I>
{
@@ -5,16 +5,16 @@
package net.minecraftforge.registries;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.Random;
import java.util.Set;
import java.util.function.Function;
import javax.annotation.Nullable;
import net.minecraft.core.Holder;
import org.apache.commons.lang3.Validate;
import net.minecraft.resources.ResourceKey;
@@ -31,14 +31,14 @@ class NamespacedDefaultedWrapper<T extends IForgeRegistryEntry<T>> extends Defau
private boolean locked = false;
private ForgeRegistry<T> delegate;
private NamespacedDefaultedWrapper(ForgeRegistry<T> owner)
private NamespacedDefaultedWrapper(ForgeRegistry<T> owner, Function<T, Holder.Reference<T>> holderLookup)
{
super("empty", owner.getRegistryKey(), Lifecycle.experimental());
super("empty", owner.getRegistryKey(), Lifecycle.experimental(), holderLookup);
this.delegate = owner;
}
@Override
public <V extends T> V registerMapping(int id, ResourceKey<T> key, V value, Lifecycle lifecycle)
public Holder<T> registerMapping(final int id, final ResourceKey<T> key, final T value, final Lifecycle lifecycle)
{
if (locked)
throw new IllegalStateException("Can not register to a locked registry. Modder should use Forge Register methods.");
@@ -51,21 +51,22 @@ class NamespacedDefaultedWrapper<T extends IForgeRegistryEntry<T>> extends Defau
if (realId != id && id != -1)
LOGGER.warn("Registered object did not get ID it asked for. Name: {} Type: {} Expected: {} Got: {}", key, value.getRegistryType().getName(), id, realId);
return value;
return super.registerMapping(realId, key, value, lifecycle);
}
@Override
public <V extends T> V register(ResourceKey<T> key, V value, Lifecycle lifecycle)
public Holder<T> register(final ResourceKey<T> p_205891_, final T p_205892_, final Lifecycle p_205893_)
{
return registerMapping(-1, key, value, lifecycle);
return registerMapping(-1, p_205891_, p_205892_, p_205893_);
}
@Override
public <V extends T> V registerOrOverride(OptionalInt id, ResourceKey<T> key, V value, Lifecycle lifecycle) {
public Holder<T> registerOrOverride(final OptionalInt id, final ResourceKey<T> p_205885_, final T p_205886_, final Lifecycle p_205887_)
{
int wanted = -1;
if (id.isPresent() && byId(id.getAsInt()) != null)
wanted = id.getAsInt();
return registerMapping(wanted, key, value, lifecycle);
return registerMapping(wanted, p_205885_, p_205886_, p_205887_);
}
// Reading Functions
@@ -144,13 +145,7 @@ class NamespacedDefaultedWrapper<T extends IForgeRegistryEntry<T>> extends Defau
return this.delegate.getEntries();
}
@Override
@Nullable
public T getRandom(Random random)
{
Collection<T> values = this.delegate.getValues();
return values.stream().skip(random.nextInt(values.size())).findFirst().orElse(this.delegate.getDefault());
}
//TODO-PATCHING: Figure out if getRandom needs to be overriden.
@Override
public ResourceLocation getDefaultKey()
@@ -162,13 +157,16 @@ class NamespacedDefaultedWrapper<T extends IForgeRegistryEntry<T>> extends Defau
@Override
public void lock(){ this.locked = true; }
//@Override public void unfreeze() {}
public static class Factory<V extends IForgeRegistryEntry<V>> implements IForgeRegistry.CreateCallback<V>
{
public static final ResourceLocation ID = new ResourceLocation("forge", "registry_defaulted_wrapper");
@Override
public void onCreate(IForgeRegistryInternal<V> owner, RegistryManager stage)
{
owner.setSlaveMap(ID, new NamespacedDefaultedWrapper<V>((ForgeRegistry<V>)owner));
ForgeRegistry<V> fowner = (ForgeRegistry<V>)owner;
owner.setSlaveMap(ID, new NamespacedDefaultedWrapper<V>(fowner, fowner.getBuilder().getVanillaHolder()));
}
}
}
@@ -5,15 +5,15 @@
package net.minecraftforge.registries;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.Random;
import java.util.Set;
import java.util.function.Function;
import javax.annotation.Nullable;
import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.MappedRegistry;
@@ -29,14 +29,14 @@ class NamespacedWrapper<T extends IForgeRegistryEntry<T>> extends MappedRegistry
private boolean locked = false;
private ForgeRegistry<T> delegate;
public NamespacedWrapper(ForgeRegistry<T> owner)
public NamespacedWrapper(ForgeRegistry<T> owner, Function<T, Holder.Reference<T>> holderLookup)
{
super(owner.getRegistryKey(), Lifecycle.experimental());
super(owner.getRegistryKey(), Lifecycle.experimental(), holderLookup);
this.delegate = owner;
}
@Override
public <V extends T> V registerMapping(int id, ResourceKey<T> key, V value, Lifecycle lifecycle)
public Holder<T> registerMapping(int id, ResourceKey<T> key, T value, Lifecycle lifecycle)
{
if (locked)
throw new IllegalStateException("Can not register to a locked registry. Modder should use Forge Register methods.");
@@ -49,17 +49,17 @@ class NamespacedWrapper<T extends IForgeRegistryEntry<T>> extends MappedRegistry
int realId = this.delegate.add(id, value);
if (realId != id && id != -1)
LOGGER.warn("Registered object did not get ID it asked for. Name: {} Type: {} Expected: {} Got: {}", key, value.getRegistryType().getName(), id, realId);
return value;
return super.registerMapping(realId, key, value, lifecycle);
}
@Override
public <R extends T> R register(ResourceKey<T> key, R value, Lifecycle lifecycle)
public Holder<T> register(ResourceKey<T> key, T value, Lifecycle lifecycle)
{
return registerMapping(-1, key, value, lifecycle);
}
@Override
public <V extends T> V registerOrOverride(OptionalInt id, ResourceKey<T> key, V value, Lifecycle lifecycle) {
public Holder<T> registerOrOverride(OptionalInt id, ResourceKey<T> key, T value, Lifecycle lifecycle) {
int wanted = -1;
if (id.isPresent() && byId(id.getAsInt()) != null)
wanted = id.getAsInt();
@@ -142,13 +142,7 @@ class NamespacedWrapper<T extends IForgeRegistryEntry<T>> extends MappedRegistry
return this.delegate.getEntries();
}
@Override
@Nullable
public T getRandom(Random random)
{
Collection<T> values = this.delegate.getValues();
return values.stream().skip(random.nextInt(values.size())).findFirst().orElse(null);
}
// TODO-PATCHING: Figure out if getRandom needs to be overriden.
/*
@Override
@@ -162,13 +156,16 @@ class NamespacedWrapper<T extends IForgeRegistryEntry<T>> extends MappedRegistry
@Override
public void lock(){ this.locked = true; }
//@Override public void unfreeze() {}
public static class Factory<V extends IForgeRegistryEntry<V>> implements IForgeRegistry.CreateCallback<V>
{
public static final ResourceLocation ID = new ResourceLocation("forge", "registry_defaulted_wrapper");
@Override
public void onCreate(IForgeRegistryInternal<V> owner, RegistryManager stage)
{
owner.setSlaveMap(ID, new NamespacedWrapper<V>((ForgeRegistry<V>)owner));
ForgeRegistry<V> fowner = (ForgeRegistry<V>)owner;
owner.setSlaveMap(ID, new NamespacedWrapper<V>(fowner, fowner.getBuilder().getVanillaHolder()));
}
}
}
@@ -8,9 +8,11 @@ package net.minecraftforge.registries;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import com.google.common.collect.Lists;
import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.registries.IForgeRegistry.*;
@@ -30,6 +32,7 @@ public class RegistryBuilder<T extends IForgeRegistryEntry<T>>
private List<CreateCallback<T>> createCallback = Lists.newArrayList();
private List<ValidateCallback<T>> validateCallback = Lists.newArrayList();
private List<BakeCallback<T>> bakeCallback = Lists.newArrayList();
private Function<T, Holder.Reference<T>> vanillaHolder;
private boolean saveToDisc = true;
private boolean sync = true;
private boolean allowOverrides = true;
@@ -218,6 +221,12 @@ public class RegistryBuilder<T extends IForgeRegistryEntry<T>>
return this;
}
RegistryBuilder<T> vanillaHolder(Function<T, Holder.Reference<T>> func)
{
this.vanillaHolder = func;
return this;
}
public IForgeRegistry<T> create()
{
if (hasWrapper)
@@ -368,4 +377,9 @@ public class RegistryBuilder<T extends IForgeRegistryEntry<T>>
{
return legacyNames;
}
Function<T, Holder.Reference<T>> getVanillaHolder()
{
return this.vanillaHolder;
}
}