CheckedRegistry#add -> #register

This commit is contained in:
dfsek
2021-07-05 19:22:21 -07:00
parent d4a784ddb5
commit 9221a4f1ae
6 changed files with 8 additions and 9 deletions
@@ -13,7 +13,6 @@ import com.dfsek.terra.api.event.EventListener;
import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent; import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent;
import com.dfsek.terra.api.injection.annotations.Inject; import com.dfsek.terra.api.injection.annotations.Inject;
import com.dfsek.terra.api.registry.CheckedRegistry; import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.registry.OpenRegistry;
import com.dfsek.terra.api.registry.exception.DuplicateEntryException; import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
import com.dfsek.terra.api.structure.LootTable; import com.dfsek.terra.api.structure.LootTable;
import com.dfsek.terra.api.structure.Structure; import com.dfsek.terra.api.structure.Structure;
@@ -41,7 +40,7 @@ public class TerraScriptAddon extends TerraAddon implements EventListener {
try { try {
StructureScript structureScript = new StructureScript(entry.getValue(), main, structureRegistry, lootRegistry, event.getPack().getRegistryFactory().create()); StructureScript structureScript = new StructureScript(entry.getValue(), main, structureRegistry, lootRegistry, event.getPack().getRegistryFactory().create());
try { try {
structureRegistry.add(structureScript.getId(), structureScript); structureRegistry.register(structureScript.getId(), structureScript);
} catch(DuplicateEntryException e) { } catch(DuplicateEntryException e) {
throw new LoadException("Duplicate structure: ", e); throw new LoadException("Duplicate structure: ", e);
} }
@@ -10,7 +10,7 @@ public interface CheckedRegistry<T> extends Registry<T> {
* @param value Value to register. * @param value Value to register.
* @throws DuplicateEntryException If an entry with the same identifier is already present. * @throws DuplicateEntryException If an entry with the same identifier is already present.
*/ */
void add(String identifier, T value) throws DuplicateEntryException; void register(String identifier, T value) throws DuplicateEntryException;
/** /**
* Add a value to the registry, without checking presence beforehand. * Add a value to the registry, without checking presence beforehand.
@@ -19,7 +19,7 @@ public interface CheckedRegistry<T> extends Registry<T> {
* *
* @param identifier Identifier to assign value. * @param identifier Identifier to assign value.
* @param value Value to register. * @param value Value to register.
* @deprecated Use of {@link #add(String, Object)} is encouraged. * @deprecated Use of {@link #register(String, Object)} is encouraged.
*/ */
@Deprecated @Deprecated
void addUnchecked(String identifier, T value); void addUnchecked(String identifier, T value);
@@ -251,7 +251,7 @@ public class ConfigPackImpl implements ConfigPack {
for(ConfigType<?, ?> configType : configTypeRegistry.entries()) { for(ConfigType<?, ?> configType : configTypeRegistry.entries()) {
for(AbstractableTemplate config : abstractConfigLoader.loadConfigs(configs.getOrDefault(configType, Collections.emptyList()), () -> configType.getTemplate(this, main))) { for(AbstractableTemplate config : abstractConfigLoader.loadConfigs(configs.getOrDefault(configType, Collections.emptyList()), () -> configType.getTemplate(this, main))) {
try { try {
((CheckedRegistry) getRegistry(configType.getTypeClass())).add(config.getID(), ((ConfigFactory) configType.getFactory()).build(config, main)); ((CheckedRegistry) getRegistry(configType.getTypeClass())).register(config.getID(), ((ConfigFactory) configType.getFactory()).build(config, main));
} catch(DuplicateEntryException e) { } catch(DuplicateEntryException e) {
throw new LoadException("Duplicate registry entry: ", e); throw new LoadException("Duplicate registry entry: ", e);
} }
@@ -25,7 +25,7 @@ public class CheckedRegistryImpl<T> implements CheckedRegistry<T> {
} }
@Override @Override
public void add(String identifier, T value) throws DuplicateEntryException { public void register(String identifier, T value) throws DuplicateEntryException {
registry.registerChecked(identifier, value); registry.registerChecked(identifier, value);
} }
@@ -24,7 +24,7 @@ public class TerraListener implements EventListener {
for(TreeType value : TreeType.values()) { for(TreeType value : TreeType.values()) {
try { try {
String id = BukkitAdapter.TREE_TRANSFORMER.translate(value); String id = BukkitAdapter.TREE_TRANSFORMER.translate(value);
event.getPack().getRegistry(Tree.class).add(id, new BukkitTree(value, main)); event.getPack().getRegistry(Tree.class).register(id, new BukkitTree(value, main));
event.getPack().getRegistry(Tree.class).get(id); // Platform trees should never be marked "dead" event.getPack().getRegistry(Tree.class).get(id); // Platform trees should never be marked "dead"
} catch(DuplicateEntryException ignore) { // If another com.dfsek.terra.addon has already registered trees, do nothing. } catch(DuplicateEntryException ignore) { // If another com.dfsek.terra.addon has already registered trees, do nothing.
} }
@@ -359,7 +359,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
BuiltinRegistries.CONFIGURED_FEATURE.getEntries().forEach(entry -> { BuiltinRegistries.CONFIGURED_FEATURE.getEntries().forEach(entry -> {
if(!template.getExcludedRegistryFeatures().contains(entry.getKey().getValue())) { if(!template.getExcludedRegistryFeatures().contains(entry.getKey().getValue())) {
try { try {
event.getPack().getRegistry(Tree.class).add(entry.getKey().getValue().toString(), (Tree) entry.getValue()); event.getPack().getRegistry(Tree.class).register(entry.getKey().getValue().toString(), (Tree) entry.getValue());
debugLogger.info("Injected ConfiguredFeature " + entry.getKey().getValue() + " as Tree."); debugLogger.info("Injected ConfiguredFeature " + entry.getKey().getValue() + " as Tree.");
} catch(DuplicateEntryException ignored) { } catch(DuplicateEntryException ignored) {
} }
@@ -401,7 +401,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
private void injectTree(CheckedRegistry<Tree> registry, String id, ConfiguredFeature<?, ?> tree) { private void injectTree(CheckedRegistry<Tree> registry, String id, ConfiguredFeature<?, ?> tree) {
try { try {
registry.add(id, (Tree) tree); registry.register(id, (Tree) tree);
} catch(DuplicateEntryException ignore) { } catch(DuplicateEntryException ignore) {
} }
} }