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:
committed 2022-12-08 01:45:22 -06:00
1 parent 617ecb7ad3
commit 8255d7aed3
726 files changed
+7615 -6653

No files matched your search

@@ -15,7 +15,10 @@ import java.util.stream.Stream;
import com.mojang.datafixers.util.Either;
import com.mojang.serialization.Codec;
import net.minecraft.Util;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.HolderOwner;
import net.minecraft.core.Registry;
import net.minecraft.resources.RegistryOps;
import net.minecraft.resources.ResourceKey;
@@ -31,12 +34,12 @@ import net.minecraftforge.common.ForgeMod;
* }
* </pre>
*/
public record AnyHolderSet<T>(Registry<T> registry) implements ICustomHolderSet<T>
public record AnyHolderSet<T>(HolderLookup.RegistryLookup<T> registryLookup) implements ICustomHolderSet<T>
{
public static <T> Codec<? extends ICustomHolderSet<T>> codec(ResourceKey<? extends Registry<T>> registryKey, Codec<Holder<T>> holderCodec, boolean forceList)
{
return RegistryOps.retrieveRegistry(registryKey)
.xmap(AnyHolderSet::new, AnyHolderSet::registry)
return RegistryOps.retrieveRegistryLookup(registryKey)
.xmap(AnyHolderSet::new, AnyHolderSet::registryLookup)
.codec();
}
@@ -45,7 +48,7 @@ public record AnyHolderSet<T>(Registry<T> registry) implements ICustomHolderSet<
{
return ForgeMod.ANY_HOLDER_SET.get();
}
@Override
public Iterator<Holder<T>> iterator()
{
@@ -55,13 +58,13 @@ public record AnyHolderSet<T>(Registry<T> registry) implements ICustomHolderSet<
@Override
public Stream<Holder<T>> stream()
{
return registry.holders().map(Function.identity());
return this.registryLookup.listElements().map(Function.identity());
}
@Override
public int size()
{
return this.registry.size();
return (int) this.stream().count();
}
@Override
@@ -73,30 +76,41 @@ public record AnyHolderSet<T>(Registry<T> registry) implements ICustomHolderSet<
@Override
public Optional<Holder<T>> getRandomElement(RandomSource random)
{
return this.registry.getRandom(random);
return Util.getRandomSafe(this.stream().toList(), random);
}
@Override
public Holder<T> get(int i)
{
return this.registry.getHolder(i).orElseThrow(() -> new NoSuchElementException("No element " + i + " in registry " + this.registry.key()));
List<Holder<T>> holders = this.stream().toList();
Holder<T> holder = i >= holders.size() ? null : holders.get(i);
if (holder == null)
throw new NoSuchElementException("No element " + i + " in registry " + this.registryLookup.key());
return holder;
}
@Override
public boolean contains(Holder<T> holder)
{
return holder.unwrapKey().map(this.registry::containsKey).orElse(false);
return holder.unwrapKey().map(key -> this.registryLookup.listElementIds().anyMatch(key::equals)).orElse(false);
}
@Override
public boolean isValidInRegistry(Registry<T> registry)
public boolean canSerializeIn(HolderOwner<T> holderOwner)
{
return this.registry == registry;
return this.registryLookup.canSerializeIn(holderOwner);
}
@Override
public Optional<TagKey<T>> unwrapKey()
{
return Optional.empty();
}
@Override
public String toString()
{
return "AnySet(" + this.registry.key() + ")";
return "AnySet(" + this.registryLookup.key() + ")";
}
}
@@ -12,6 +12,7 @@ import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;
import net.minecraft.core.HolderOwner;
import org.jetbrains.annotations.Nullable;
import com.mojang.datafixers.util.Either;
@@ -37,7 +38,7 @@ public abstract class CompositeHolderSet<T> implements ICustomHolderSet<T>
private Set<Holder<T>> set = null;
@Nullable
private List<Holder<T>> list = null;
public CompositeHolderSet(List<HolderSet<T>> components)
{
this.components = components;
@@ -46,17 +47,17 @@ public abstract class CompositeHolderSet<T> implements ICustomHolderSet<T>
holderset.addInvalidationListener(this::invalidate);
}
}
/**
* {@return immutable Set of Holders given this composite holderset's component holdersets}
*/
protected abstract Set<Holder<T>> createSet();
public List<HolderSet<T>> getComponents()
{
return this.components;
}
public Set<Holder<T>> getSet()
{
Set<Holder<T>> thisSet = this.set;
@@ -71,7 +72,7 @@ public abstract class CompositeHolderSet<T> implements ICustomHolderSet<T>
return thisSet;
}
}
public List<Holder<T>> getList()
{
List<Holder<T>> thisList = this.list;
@@ -86,13 +87,13 @@ public abstract class CompositeHolderSet<T> implements ICustomHolderSet<T>
return thisList;
}
}
@Override
public void addInvalidationListener(Runnable runnable)
{
this.owners.add(runnable);
}
private void invalidate()
{
this.set = null;
@@ -144,11 +145,11 @@ public abstract class CompositeHolderSet<T> implements ICustomHolderSet<T>
}
@Override
public boolean isValidInRegistry(Registry<T> registry)
public boolean canSerializeIn(HolderOwner<T> holderOwner)
{
for (HolderSet<T> component : this.components)
{
if (!component.isValidInRegistry(registry))
if (!component.canSerializeIn(holderOwner))
{
return false;
}
@@ -156,6 +157,12 @@ public abstract class CompositeHolderSet<T> implements ICustomHolderSet<T>
return true;
}
@Override
public Optional<TagKey<T>> unwrapKey()
{
return Optional.empty();
}
@Override
public Iterator<Holder<T>> iterator()
{
@@ -11,6 +11,9 @@ import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import net.minecraft.core.HolderGetter;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.HolderOwner;
import org.jetbrains.annotations.Nullable;
import com.mojang.datafixers.util.Either;
@@ -44,23 +47,23 @@ public class NotHolderSet<T> implements ICustomHolderSet<T>
public static <T> Codec<? extends ICustomHolderSet<T>> codec(ResourceKey<? extends Registry<T>> registryKey, Codec<Holder<T>> holderCodec, boolean forceList)
{
return RecordCodecBuilder.<NotHolderSet<T>>create(builder -> builder.group(
RegistryOps.retrieveRegistry(registryKey).forGetter(NotHolderSet::registry),
RegistryOps.retrieveRegistryLookup(registryKey).forGetter(NotHolderSet::registryLookup),
HolderSetCodec.create(registryKey, holderCodec, forceList).fieldOf("value").forGetter(NotHolderSet::value)
).apply(builder, NotHolderSet::new));
}
private final List<Runnable> owners = new ArrayList<>();
private final Registry<T> registry;
private final HolderLookup.RegistryLookup<T> registryLookup;
private final HolderSet<T> value;
@Nullable
private List<Holder<T>> list = null;
public Registry<T> registry() { return this.registry; }
public HolderLookup.RegistryLookup<T> registryLookup() { return this.registryLookup; }
public HolderSet<T> value() { return this.value; }
public NotHolderSet(Registry<T> registry, HolderSet<T> value)
public NotHolderSet(HolderLookup.RegistryLookup<T> registryLookup, HolderSet<T> value)
{
this.registry = registry;
this.registryLookup = registryLookup;
this.value = value;
this.value.addInvalidationListener(this::invalidate);
}
@@ -70,13 +73,13 @@ public class NotHolderSet<T> implements ICustomHolderSet<T>
{
return ForgeMod.NOT_HOLDER_SET.get();
}
@Override
public void addInvalidationListener(Runnable runnable)
{
this.owners.add(runnable);
}
@Override
public Iterator<Holder<T>> iterator()
{
@@ -124,9 +127,15 @@ public class NotHolderSet<T> implements ICustomHolderSet<T>
}
@Override
public boolean isValidInRegistry(Registry<T> registry)
public boolean canSerializeIn(HolderOwner<T> holderOwner)
{
return this.registry == registry;
return this.registryLookup.canSerializeIn(holderOwner);
}
@Override
public Optional<TagKey<T>> unwrapKey()
{
return Optional.empty();
}
@Override
@@ -134,13 +143,13 @@ public class NotHolderSet<T> implements ICustomHolderSet<T>
{
return "NotSet(" + this.value + ")";
}
private List<Holder<T>> getList()
{
List<Holder<T>> thisList = this.list;
if (thisList == null)
{
List<Holder<T>> list = this.registry.holders()
List<Holder<T>> list = this.registryLookup.listElements()
.filter(holder -> !this.value.contains(holder))
.map(holder -> (Holder<T>)holder)
.toList();
@@ -152,7 +161,7 @@ public class NotHolderSet<T> implements ICustomHolderSet<T>
return thisList;
}
}
private void invalidate()
{
this.list = null;
@@ -12,6 +12,7 @@ import java.util.stream.Collectors;
import com.mojang.serialization.Codec;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderOwner;
import net.minecraft.core.HolderSet;
import net.minecraft.core.Registry;
import net.minecraft.resources.HolderSetCodec;
@@ -40,7 +41,7 @@ public class OrHolderSet<T> extends CompositeHolderSet<T>
.fieldOf("values")
.codec();
}
public OrHolderSet(List<HolderSet<T>> values)
{
super(values);