mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 03:49:14 +00:00
Forge 1.19.3
Created a CreativeModeTabEvent to register creative mode tabs and populate entries per tab Moved datapack registries to DataPackRegistryEvent.NewRegistry event instead of tying them to ForgeRegistry Made it easier for mods to datagen datapack builtin entries with DatapackBuiltinEntriesProvider Provided access to lookupProvider for datagen Updated dependencies to match versions used by vanilla and update JarJar to 0.3.18 Added a test mod for the new CreativeModeTabEvent Throws better error message for Forge registries in tag datagen Deleted ForgeRegistryTagsProvider Updated ClientChatReceivedEvent and ServerChatEvent for Mojang changes Added patches for both sign related methods in ModelLayers Changed RegisterShadersEvent to use ResourceProvider Migrated old Mojang math types to JOML Co-authored-by: Marc Hermans <[email protected]> Co-authored-by: LexManos <[email protected]> Co-authored-by: sciwhiz12 <[email protected]> Co-authored-by: coehlrich <[email protected]>
This commit is contained in:
1 parent
617ecb7ad3
commit
8255d7aed3
726 files changed
+7615
-6653
No files matched your search
@@ -5,135 +5,42 @@
|
||||
|
||||
package net.minecraftforge.registries;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.mojang.serialization.DataResult;
|
||||
import net.minecraft.core.DefaultedRegistry;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.Registry;
|
||||
|
||||
import net.minecraft.util.RandomSource;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.core.DefaultedRegistry;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class NamespacedDefaultedWrapper<T> extends DefaultedRegistry<T> implements ILockableRegistry, IHolderHelperHolder<T>
|
||||
class NamespacedDefaultedWrapper<T> extends NamespacedWrapper<T> implements DefaultedRegistry<T>
|
||||
{
|
||||
private final ForgeRegistry<T> delegate;
|
||||
private final NamespacedHolderHelper<T> holders;
|
||||
private final ResourceLocation defaultKey;
|
||||
private Holder.Reference<T> defaultHolder;
|
||||
|
||||
private boolean locked = false;
|
||||
private Lifecycle elementsLifecycle = Lifecycle.experimental();
|
||||
|
||||
private NamespacedDefaultedWrapper(ForgeRegistry<T> owner, Function<T, Holder.Reference<T>> holderLookup)
|
||||
{
|
||||
super("empty", owner.getRegistryKey(), Lifecycle.experimental(), holderLookup);
|
||||
this.delegate = owner;
|
||||
this.holders = new NamespacedHolderHelper<>(owner, this, this.delegate.getDefaultKey(), holderLookup);
|
||||
}
|
||||
|
||||
@Override
|
||||
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.");
|
||||
|
||||
Validate.notNull(value);
|
||||
markKnown();
|
||||
this.elementsLifecycle = this.elementsLifecycle.add(lifecycle);
|
||||
|
||||
T oldValue = this.delegate.getRaw(key.location());
|
||||
|
||||
int realId = this.delegate.add(id, key.location(), value);
|
||||
|
||||
return this.holders.onAdded(RegistryManager.ACTIVE, realId, key, value, oldValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Holder<T> register(final ResourceKey<T> p_205891_, final T p_205892_, final Lifecycle p_205893_)
|
||||
{
|
||||
return registerMapping(-1, p_205891_, p_205892_, p_205893_);
|
||||
}
|
||||
|
||||
@Override
|
||||
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, p_205885_, p_205886_, p_205887_);
|
||||
NamespacedDefaultedWrapper(ForgeRegistry<T> fowner, Function<T, Holder.Reference<T>> intrusiveHolderCallback, RegistryManager stage) {
|
||||
super(fowner, intrusiveHolderCallback, stage);
|
||||
this.delegate = fowner;
|
||||
this.defaultKey = fowner.getDefaultKey();
|
||||
}
|
||||
|
||||
// Reading Functions
|
||||
@Override
|
||||
public Optional<T> getOptional(@Nullable ResourceLocation name)
|
||||
{
|
||||
return Optional.ofNullable( this.delegate.getRaw(name)); //get without default
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public T get(@Nullable ResourceLocation name)
|
||||
{
|
||||
return this.delegate.getValue(name); //getOrDefault
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public T get(@Nullable ResourceKey<T> name)
|
||||
public Optional<Holder.Reference<T>> getRandom(RandomSource rand)
|
||||
{
|
||||
return name == null ? null : this.delegate.getRaw(name.location()); //get without default
|
||||
}
|
||||
if (this.defaultHolder != null)
|
||||
return super.getRandom(rand).or(() -> Optional.of(this.defaultHolder));
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ResourceLocation getKey(T value)
|
||||
{
|
||||
return this.delegate.getKey(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ResourceKey<T>> getResourceKey(T p_122755_)
|
||||
{
|
||||
return this.delegate.getResourceKey(p_122755_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(ResourceLocation key)
|
||||
{
|
||||
return this.delegate.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(ResourceKey<T> key)
|
||||
{
|
||||
return this.delegate.getRegistryName().equals(key.registry()) && containsKey(key.location());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId(@Nullable T value)
|
||||
{
|
||||
return this.delegate.getID(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public T byId(int id)
|
||||
{
|
||||
return this.delegate.getValue(id);
|
||||
return super.getRandom(rand);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -142,81 +49,18 @@ class NamespacedDefaultedWrapper<T> extends DefaultedRegistry<T> implements ILoc
|
||||
return this.delegate.getDefaultKey();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Lifecycle lifecycle(T value)
|
||||
Holder.Reference<T> onAdded(RegistryManager stage, int id, ResourceKey<T> key, T newValue, T oldValue)
|
||||
{
|
||||
return Lifecycle.stable();
|
||||
Holder.Reference<T> newHolder = super.onAdded(stage, id, key, newValue, oldValue);
|
||||
|
||||
if (newHolder != null && this.defaultKey != null && this.defaultKey.equals(key.location()))
|
||||
this.defaultHolder = newHolder;
|
||||
|
||||
return newHolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lifecycle elementsLifecycle()
|
||||
{
|
||||
return this.elementsLifecycle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator()
|
||||
{
|
||||
return this.delegate.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ResourceLocation> keySet()
|
||||
{
|
||||
return this.delegate.getKeys();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ResourceKey<T>> registryKeySet()
|
||||
{
|
||||
return this.delegate.getResourceKeys();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Map.Entry<ResourceKey<T>, T>> entrySet()
|
||||
{
|
||||
return this.delegate.getEntries();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return this.delegate.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return this.delegate.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespacedHolderHelper<T> getHolderHelper()
|
||||
{
|
||||
return this.holders;
|
||||
}
|
||||
|
||||
@Override public Optional<Holder<T>> getHolder(int id) { return this.holders.getHolder(id); }
|
||||
@Override public Optional<Holder<T>> getHolder(ResourceKey<T> key) { return this.holders.getHolder(key); }
|
||||
@Override public DataResult<Holder<T>> getOrCreateHolder(ResourceKey<T> key) { return this.holders.getOrCreateHolder(key); }
|
||||
@Override public Holder<T> getOrCreateHolderOrThrow(ResourceKey<T> key) { return this.holders.getOrCreateHolderOrThrow(key); }
|
||||
@Override public Optional<Holder<T>> getRandom(RandomSource rand) { return this.holders.getRandom(rand); }
|
||||
@Override public Stream<Holder.Reference<T>> holders() { return this.holders.holders(); }
|
||||
@Override public boolean isKnownTagName(TagKey<T> name) { return this.holders.isKnownTagName(name); }
|
||||
@Override public Stream<Pair<TagKey<T>, HolderSet.Named<T>>> getTags() { return this.holders.getTags(); }
|
||||
@Override public HolderSet.Named<T> getOrCreateTag(TagKey<T> name) { return this.holders.getOrCreateTag(name); }
|
||||
@Override public Stream<TagKey<T>> getTagNames() { return this.holders.getTagNames(); }
|
||||
@Override public Registry<T> freeze() { return this.holders.freeze(); }
|
||||
@Override public Holder.Reference<T> createIntrusiveHolder(T value) { return this.holders.createIntrusiveHolder(value); }
|
||||
@Override public Optional<HolderSet.Named<T>> getTag(TagKey<T> name) { return this.holders.getTag(name); }
|
||||
@Override public void bindTags(Map<TagKey<T>, List<Holder<T>>> newTags) { this.holders.bindTags(newTags); }
|
||||
@Override public void resetTags() { this.holders.resetTags(); }
|
||||
@Deprecated @Override public void unfreeze() { this.holders.unfreeze(); }
|
||||
|
||||
/** @deprecated Forge: For internal use only. Use the Register events when registering values. */
|
||||
@Deprecated @Override public void lock(){ this.locked = true; }
|
||||
|
||||
|
||||
public static class Factory<V> implements IForgeRegistry.CreateCallback<V>, IForgeRegistry.AddCallback<V>
|
||||
{
|
||||
public static final ResourceLocation ID = new ResourceLocation("forge", "registry_defaulted_wrapper");
|
||||
@@ -224,15 +68,15 @@ class NamespacedDefaultedWrapper<T> extends DefaultedRegistry<T> implements ILoc
|
||||
@Override
|
||||
public void onCreate(IForgeRegistryInternal<V> owner, RegistryManager stage)
|
||||
{
|
||||
ForgeRegistry<V> fowner = (ForgeRegistry<V>)owner;
|
||||
owner.setSlaveMap(ID, new NamespacedDefaultedWrapper<V>(fowner, fowner.getBuilder().getVanillaHolder()));
|
||||
ForgeRegistry<V> fowner = (ForgeRegistry<V>) owner;
|
||||
owner.setSlaveMap(ID, new NamespacedDefaultedWrapper<V>(fowner, fowner.getBuilder().getIntrusiveHolderCallback(), stage));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void onAdd(IForgeRegistryInternal<V> owner, RegistryManager stage, int id, ResourceKey<V> key, V value, V oldValue)
|
||||
{
|
||||
owner.getSlaveMap(ID, NamespacedDefaultedWrapper.class).holders.onAdded(stage, id, key, value, oldValue);
|
||||
owner.getSlaveMap(ID, NamespacedDefaultedWrapper.class).onAdded(stage, id, key, value, oldValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user