mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-11 22:45:38 -04:00
Make minor changes to Technici4n's PR
This commit is contained in:
parent
bb7c8b8790
commit
741bd52c1e
3 changed files with 13 additions and 15 deletions
fabric-api-base/src/main/java/net/fabricmc/fabric/impl/base
fabric-registry-sync-v0/src/main/java/net/fabricmc/fabric/impl/registry/sync
|
@ -29,6 +29,7 @@ import net.minecraft.util.Identifier;
|
|||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.impl.base.toposort.NodeSorting;
|
||||
import net.fabricmc.fabric.impl.base.toposort.SortableNode;
|
||||
|
||||
class ArrayBackedEvent<T> extends Event<T> {
|
||||
private final Function<T[], T> invokerFactory;
|
||||
|
@ -118,8 +119,7 @@ class ArrayBackedEvent<T> extends Event<T> {
|
|||
synchronized (lock) {
|
||||
EventPhaseData<T> first = getOrCreatePhase(firstPhase, false);
|
||||
EventPhaseData<T> second = getOrCreatePhase(secondPhase, false);
|
||||
first.subsequentNodes.add(second);
|
||||
second.previousNodes.add(first);
|
||||
SortableNode.link(first, second);
|
||||
NodeSorting.sort(this.sortedPhases, "event phases", Comparator.comparing(data -> data.id));
|
||||
rebuildInvoker(handlers.length);
|
||||
}
|
||||
|
|
|
@ -28,4 +28,9 @@ public abstract class SortableNode<N extends SortableNode<N>> {
|
|||
* @return Description of this node, used to print the cycle warning.
|
||||
*/
|
||||
protected abstract String getDescription();
|
||||
|
||||
public static <N extends SortableNode<N>> void link(N first, N second) {
|
||||
first.subsequentNodes.add(second);
|
||||
second.previousNodes.add(first);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ public final class DynamicRegistriesImpl {
|
|||
nodes.put(vanillaEntry.key(), node);
|
||||
|
||||
if (previousVanillaNode != null) {
|
||||
link(previousVanillaNode, node);
|
||||
SortableNode.link(previousVanillaNode, node);
|
||||
}
|
||||
|
||||
previousVanillaNode = node;
|
||||
|
@ -97,7 +97,7 @@ public final class DynamicRegistriesImpl {
|
|||
throw new IllegalStateException("Registry " + settings.owner.key() + " has a dependency on " + before + ", which does not exist!");
|
||||
}
|
||||
|
||||
link(node, other);
|
||||
SortableNode.link(node, other);
|
||||
}
|
||||
|
||||
for (RegistryKey<? extends Registry<?>> after : settings.after) {
|
||||
|
@ -107,7 +107,7 @@ public final class DynamicRegistriesImpl {
|
|||
throw new IllegalStateException("Registry " + settings.owner.key() + " has a dependency on " + after + ", which does not exist!");
|
||||
}
|
||||
|
||||
link(other, node);
|
||||
SortableNode.link(other, node);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,18 +115,9 @@ public final class DynamicRegistriesImpl {
|
|||
List<RegistryNode> nodesToSort = new ArrayList<>(nodes.values());
|
||||
NodeSorting.sort(nodesToSort, "dynamic registries", RegistryNode.COMPARATOR);
|
||||
|
||||
for (RegistryNode node : nodesToSort) {
|
||||
System.out.println("Sorted node: " + node.entry.key());
|
||||
}
|
||||
|
||||
return nodesToSort.stream().map(node -> node.entry).collect(Collectors.toUnmodifiableList());
|
||||
}
|
||||
|
||||
private static void link(RegistryNode node1, RegistryNode node2) {
|
||||
node1.subsequentNodes.add(node2);
|
||||
node2.previousNodes.add(node1);
|
||||
}
|
||||
|
||||
public static <T> DynamicRegistries.Settings<T> register(RegistryKey<? extends Registry<T>> key, Codec<T> codec) {
|
||||
Objects.requireNonNull(key, "Registry key cannot be null");
|
||||
Objects.requireNonNull(codec, "Codec cannot be null");
|
||||
|
@ -199,7 +190,9 @@ public final class DynamicRegistriesImpl {
|
|||
private static final class RegistryNode extends SortableNode<RegistryNode> {
|
||||
private static final Comparator<RegistryNode> COMPARATOR = Comparator.<RegistryNode>comparingInt(node -> node.vanillaIndex)
|
||||
.thenComparing(node -> node.entry.key().getValue());
|
||||
private static final int MODDED_INDEX = 1000; // modded registries go after vanilla by default
|
||||
|
||||
// Modded registries go after vanilla by default.
|
||||
private static final int MODDED_INDEX = RegistryLoader.DYNAMIC_REGISTRIES.size();
|
||||
|
||||
private final RegistryLoader.Entry<?> entry;
|
||||
private final int vanillaIndex;
|
||||
|
|
Loading…
Add table
Reference in a new issue