Expose raw id from registries

This commit is contained in:
shedaniel
2021-01-25 12:26:38 +08:00
parent 9deb0f8be4
commit c13620fc9c
4 changed files with 38 additions and 3 deletions

View File

@@ -43,7 +43,6 @@ public interface ClientLifecycleEvent {
Event<ClientWorldState> CLIENT_WORLD_LOAD = EventFactory.createLoop();
Event<ClientState> CLIENT_SETUP = EventFactory.createLoop();
@Deprecated
@Environment(EnvType.CLIENT)
interface ClientState extends LifecycleEvent.InstanceState<Minecraft> {}

View File

@@ -49,11 +49,16 @@ public interface Registry<T> extends Iterable<T> {
@Nullable
ResourceLocation getId(T obj);
int getRawId(T obj);
Optional<ResourceKey<T>> getKey(T obj);
@Nullable
T get(ResourceLocation id);
@Nullable
T byRawId(int rawId);
boolean contains(ResourceLocation id);
boolean containsValue(T obj);

View File

@@ -165,6 +165,11 @@ public class RegistriesImpl {
return delegate.getKey(obj);
}
@Override
public int getRawId(T obj) {
return delegate.getId(obj);
}
@Override
public Optional<ResourceKey<T>> getKey(T obj) {
return delegate.getResourceKey(obj);
@@ -175,6 +180,11 @@ public class RegistriesImpl {
return delegate.get(id);
}
@Override
public T byRawId(int rawId) {
return delegate.byId(rawId);
}
@Override
public boolean contains(ResourceLocation id) {
return delegate.containsKey(id);

View File

@@ -37,6 +37,7 @@ import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.ForgeRegistry;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.IForgeRegistryEntry;
import net.minecraftforge.registries.RegistryManager;
@@ -82,7 +83,7 @@ public class RegistriesImpl {
public <T> Registry<T> get(ResourceKey<net.minecraft.core.Registry<T>> registryKey) {
return get(RegistryManager.ACTIVE.getRegistry(registryKey.location()));
}
public <T> Registry<T> get(IForgeRegistry registry) {
return new ForgeBackedRegistryImpl<>(this.registry, registry);
}
@@ -162,7 +163,7 @@ public class RegistriesImpl {
public @NotNull ResourceLocation getRegistryId() {
return delegate.key().location();
}
@Override
public @NotNull ResourceLocation getId() {
return id;
@@ -210,6 +211,11 @@ public class RegistriesImpl {
return delegate.getKey(obj);
}
@Override
public int getRawId(T obj) {
return delegate.getId(obj);
}
@Override
public Optional<ResourceKey<T>> getKey(T t) {
return delegate.getResourceKey(t);
@@ -221,6 +227,11 @@ public class RegistriesImpl {
return delegate.get(id);
}
@Override
public T byRawId(int rawId) {
return delegate.byId(rawId);
}
@Override
public boolean contains(ResourceLocation resourceLocation) {
return delegate.containsKey(resourceLocation);
@@ -356,6 +367,11 @@ public class RegistriesImpl {
return delegate.getKey(obj);
}
@Override
public int getRawId(T obj) {
return ((ForgeRegistry<T>) delegate).getID(obj);
}
@Override
public Optional<ResourceKey<T>> getKey(T t) {
return Optional.ofNullable(getId(t)).map(id -> ResourceKey.create(key(), id));
@@ -367,6 +383,11 @@ public class RegistriesImpl {
return delegate.getValue(id);
}
@Override
public T byRawId(int rawId) {
return ((ForgeRegistry<T>) delegate).getValue(rawId);
}
@Override
public boolean contains(ResourceLocation resourceLocation) {
return delegate.containsKey(resourceLocation);