|
@@ -22,10 +22,14 @@ package me.shedaniel.architectury.registry.forge;
|
|
import com.google.common.base.Objects;
|
|
import com.google.common.base.Objects;
|
|
import com.google.common.collect.HashBasedTable;
|
|
import com.google.common.collect.HashBasedTable;
|
|
import com.google.common.collect.Table;
|
|
import com.google.common.collect.Table;
|
|
|
|
+import me.shedaniel.architectury.core.RegistryEntry;
|
|
import me.shedaniel.architectury.platform.forge.EventBuses;
|
|
import me.shedaniel.architectury.platform.forge.EventBuses;
|
|
import me.shedaniel.architectury.registry.Registries;
|
|
import me.shedaniel.architectury.registry.Registries;
|
|
import me.shedaniel.architectury.registry.Registry;
|
|
import me.shedaniel.architectury.registry.Registry;
|
|
import me.shedaniel.architectury.registry.RegistrySupplier;
|
|
import me.shedaniel.architectury.registry.RegistrySupplier;
|
|
|
|
+import me.shedaniel.architectury.registry.registries.RegistryBuilder;
|
|
|
|
+import me.shedaniel.architectury.registry.registries.RegistryOption;
|
|
|
|
+import me.shedaniel.architectury.registry.registries.StandardRegistryOption;
|
|
import net.minecraft.resources.ResourceKey;
|
|
import net.minecraft.resources.ResourceKey;
|
|
import net.minecraft.resources.ResourceLocation;
|
|
import net.minecraft.resources.ResourceLocation;
|
|
import net.minecraft.util.LazyLoadedValue;
|
|
import net.minecraft.util.LazyLoadedValue;
|
|
@@ -33,6 +37,7 @@ import net.minecraftforge.event.RegistryEvent;
|
|
import net.minecraftforge.eventbus.api.IEventBus;
|
|
import net.minecraftforge.eventbus.api.IEventBus;
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
import net.minecraftforge.fml.RegistryObject;
|
|
import net.minecraftforge.fml.RegistryObject;
|
|
|
|
+import net.minecraftforge.registries.ForgeRegistry;
|
|
import net.minecraftforge.registries.IForgeRegistry;
|
|
import net.minecraftforge.registries.IForgeRegistry;
|
|
import net.minecraftforge.registries.IForgeRegistryEntry;
|
|
import net.minecraftforge.registries.IForgeRegistryEntry;
|
|
import net.minecraftforge.registries.RegistryManager;
|
|
import net.minecraftforge.registries.RegistryManager;
|
|
@@ -76,7 +81,11 @@ public class RegistriesImpl {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public <T> Registry<T> get(ResourceKey<net.minecraft.core.Registry<T>> registryKey) {
|
|
public <T> Registry<T> get(ResourceKey<net.minecraft.core.Registry<T>> registryKey) {
|
|
- return new ForgeBackedRegistryImpl<>(registry, (IForgeRegistry) RegistryManager.ACTIVE.getRegistry(registryKey.location()));
|
|
|
|
|
|
+ return get(RegistryManager.ACTIVE.getRegistry(registryKey.location()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public <T> Registry<T> get(IForgeRegistry registry) {
|
|
|
|
+ return new ForgeBackedRegistryImpl<>(this.registry, registry);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -84,6 +93,13 @@ public class RegistriesImpl {
|
|
return new VanillaBackedRegistryImpl<>(registry);
|
|
return new VanillaBackedRegistryImpl<>(registry);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public <T extends RegistryEntry<T>> RegistryBuilder<T> builder(Class<T> type, ResourceLocation registryId) {
|
|
|
|
+ return new RegistryBuilderWrapper<>(this, new net.minecraftforge.registries.RegistryBuilder<>()
|
|
|
|
+ .setName(registryId)
|
|
|
|
+ .setType((Class) type));
|
|
|
|
+ }
|
|
|
|
+
|
|
public class EventListener {
|
|
public class EventListener {
|
|
@SubscribeEvent
|
|
@SubscribeEvent
|
|
public void handleEvent(RegistryEvent.Register event) {
|
|
public void handleEvent(RegistryEvent.Register event) {
|
|
@@ -101,6 +117,37 @@ public class RegistriesImpl {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static class RegistryBuilderWrapper<T extends RegistryEntry<T>> implements RegistryBuilder<T> {
|
|
|
|
+ @NotNull
|
|
|
|
+ private final RegistryProviderImpl provider;
|
|
|
|
+ @NotNull
|
|
|
|
+ private final net.minecraftforge.registries.RegistryBuilder<?> builder;
|
|
|
|
+ private boolean saveToDisk = false;
|
|
|
|
+ private boolean syncToClients = false;
|
|
|
|
+
|
|
|
|
+ public RegistryBuilderWrapper(@NotNull RegistryProviderImpl provider, @NotNull net.minecraftforge.registries.RegistryBuilder<?> builder) {
|
|
|
|
+ this.provider = provider;
|
|
|
|
+ this.builder = builder;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public @NotNull Registry<T> build() {
|
|
|
|
+ if (!syncToClients) builder.disableSync();
|
|
|
|
+ if (!saveToDisk) builder.disableSaving();
|
|
|
|
+ return provider.get(builder.create());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public @NotNull RegistryBuilder<T> option(@NotNull RegistryOption option) {
|
|
|
|
+ if (option == StandardRegistryOption.SAVE_TO_DISC) {
|
|
|
|
+ this.saveToDisk = true;
|
|
|
|
+ } else if (option == StandardRegistryOption.SYNC_TO_CLIENTS) {
|
|
|
|
+ this.syncToClients = true;
|
|
|
|
+ }
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public static class VanillaBackedRegistryImpl<T> implements Registry<T> {
|
|
public static class VanillaBackedRegistryImpl<T> implements Registry<T> {
|
|
private net.minecraft.core.Registry<T> delegate;
|
|
private net.minecraft.core.Registry<T> delegate;
|
|
|
|
|
|
@@ -164,6 +211,11 @@ public class RegistriesImpl {
|
|
return delegate.getKey(obj);
|
|
return delegate.getKey(obj);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public int getRawId(T obj) {
|
|
|
|
+ return delegate.getId(obj);
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Optional<ResourceKey<T>> getKey(T t) {
|
|
public Optional<ResourceKey<T>> getKey(T t) {
|
|
return delegate.getResourceKey(t);
|
|
return delegate.getResourceKey(t);
|
|
@@ -175,6 +227,11 @@ public class RegistriesImpl {
|
|
return delegate.get(id);
|
|
return delegate.get(id);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public T byRawId(int rawId) {
|
|
|
|
+ return delegate.byId(rawId);
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public boolean contains(ResourceLocation resourceLocation) {
|
|
public boolean contains(ResourceLocation resourceLocation) {
|
|
return delegate.keySet().contains(resourceLocation);
|
|
return delegate.keySet().contains(resourceLocation);
|
|
@@ -310,6 +367,11 @@ public class RegistriesImpl {
|
|
return delegate.getKey(obj);
|
|
return delegate.getKey(obj);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public int getRawId(T obj) {
|
|
|
|
+ return ((ForgeRegistry<T>) delegate).getID(obj);
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Optional<ResourceKey<T>> getKey(T t) {
|
|
public Optional<ResourceKey<T>> getKey(T t) {
|
|
return Optional.ofNullable(getId(t)).map(id -> ResourceKey.create(key(), id));
|
|
return Optional.ofNullable(getId(t)).map(id -> ResourceKey.create(key(), id));
|
|
@@ -321,6 +383,11 @@ public class RegistriesImpl {
|
|
return delegate.getValue(id);
|
|
return delegate.getValue(id);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public T byRawId(int rawId) {
|
|
|
|
+ return ((ForgeRegistry<T>) delegate).getValue(rawId);
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public boolean contains(ResourceLocation resourceLocation) {
|
|
public boolean contains(ResourceLocation resourceLocation) {
|
|
return delegate.containsKey(resourceLocation);
|
|
return delegate.containsKey(resourceLocation);
|