Skip to content

Commit

Permalink
Add Codecs to Registrar
Browse files Browse the repository at this point in the history
  • Loading branch information
Waterpicker committed May 22, 2024
1 parent 5e4933e commit 7f50bf0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package dev.architectury.registry.registries;

import com.mojang.serialization.Codec;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
Expand Down Expand Up @@ -77,6 +78,10 @@ default Holder<T> getHolder(ResourceLocation id) {
return getHolder(ResourceKey.create(key(), id));
}

Codec<T> codec();

Codec<Holder<T>> holderCodec();

/**
* Listens to when the registry entry is registered, and calls the given action.
* Evaluates immediately if the entry is already registered.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.common.base.Suppliers;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.mojang.serialization.Codec;
import dev.architectury.impl.RegistrySupplierImpl;
import dev.architectury.registry.registries.Registrar;
import dev.architectury.registry.registries.RegistrarBuilder;
Expand Down Expand Up @@ -289,6 +290,16 @@ public Holder<T> getHolder(ResourceKey<T> key) {
return delegate.getHolder(key).orElse(null);
}

@Override
public Codec<T> codec() {
return delegate.byNameCodec();
}

@Override
public Codec<Holder<T>> holderCodec() {
return delegate.holderByNameCodec();
}

@Override
public Iterator<T> iterator() {
return delegate.iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.common.base.Suppliers;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.mojang.serialization.Codec;
import dev.architectury.impl.RegistrySupplierImpl;
import dev.architectury.platform.hooks.EventBusesHooks;
import dev.architectury.registry.registries.Registrar;
Expand Down Expand Up @@ -397,6 +398,16 @@ public Holder<T> getHolder(ResourceKey<T> key) {
return delegate.getHolder(key).orElse(null);
}

@Override
public Codec<T> codec() {
return delegate.byNameCodec();
}

@Override
public Codec<Holder<T>> holderCodec() {
return delegate.holderByNameCodec();
}

@Override
public Iterator<T> iterator() {
return delegate.iterator();
Expand Down

0 comments on commit 7f50bf0

Please sign in to comment.