remove most references to ConfigPack from API

This commit is contained in:
dfsek
2022-08-21 01:02:10 -07:00
parent 997d2204c7
commit ec8564df2f
33 changed files with 32 additions and 520 deletions

View File

@@ -133,11 +133,7 @@ public class RegistryArgument<T, R> extends CommandArgument<T, R> {
try {
result = registry.get(RegistryKey.parse(input));
} catch(IllegalArgumentException e) {
try {
result = registry.getByID(input);
} catch(IllegalArgumentException e1) {
return ArgumentParseResult.failure(e1);
}
return ArgumentParseResult.failure(e);
}
return result

View File

@@ -1,25 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the common/api directory.
*/
package com.dfsek.terra.api.event.events;
/**
* An event with functionality directly linked to a {@link ConfigPack}.
* <p>
* PackEvents are only invoked when the pack specifies the addon in its
* {@code addon} key (or when the listener is global).
*/
@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
public interface PackEvent extends Event {
/**
* Get the {@link ConfigPack} associated with this event.
*
* @return ConfigPack associated with the event.
*/
ConfigPack getPack();
}

View File

@@ -1,48 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the common/api directory.
*/
package com.dfsek.terra.api.event.events.config;
import com.dfsek.tectonic.api.config.Configuration;
import java.util.function.BiConsumer;
import com.dfsek.terra.api.event.events.FailThroughEvent;
import com.dfsek.terra.api.event.events.PackEvent;
/**
* Fired when a pack is searched for {@link Configuration}s.
* <p>
* Addons should listen to this event if they wish to add
* another configuration format.
*/
public class ConfigurationDiscoveryEvent implements PackEvent, FailThroughEvent {
private final ConfigPack pack;
private final Loader loader;
private final BiConsumer<String, Configuration> consumer;
public ConfigurationDiscoveryEvent(ConfigPack pack, Loader loader, BiConsumer<String, Configuration> consumer) {
this.pack = pack;
this.loader = loader;
this.consumer = consumer;
}
public void register(String identifier, Configuration config) {
consumer.accept(identifier, config);
}
@Override
public ConfigPack getPack() {
return pack;
}
public Loader getLoader() {
return loader;
}
}

View File

@@ -1,78 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the common/api directory.
*/
package com.dfsek.terra.api.event.events.config;
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
import com.dfsek.tectonic.impl.abstraction.AbstractConfiguration;
import java.util.function.Consumer;
import com.dfsek.terra.api.event.events.FailThroughEvent;
import com.dfsek.terra.api.event.events.PackEvent;
import com.dfsek.terra.api.util.reflection.ReflectionUtil;
/**
* Fired when each individual configuration is loaded.
* <p>
* Addons should listen to this event if they wish to add
* config values to existing {@link ConfigType}s.
*/
public class ConfigurationLoadEvent implements PackEvent, FailThroughEvent {
private final ConfigPack pack;
private final AbstractConfiguration configuration;
private final Consumer<ConfigTemplate> loader;
private final ConfigType<?, ?> type;
private final Object loaded;
public ConfigurationLoadEvent(ConfigPack pack, AbstractConfiguration configuration, Consumer<ConfigTemplate> loader,
ConfigType<?, ?> type, Object loaded) {
this.pack = pack;
this.configuration = configuration;
this.loader = loader;
this.type = type;
this.loaded = loaded;
}
public <T extends ConfigTemplate> T load(T template) {
loader.accept(template);
return template;
}
public boolean is(Class<?> clazz) {
return clazz.isAssignableFrom(type.getTypeKey().getRawType());
}
@Override
public ConfigPack getPack() {
return pack;
}
public AbstractConfiguration getConfiguration() {
return configuration;
}
public ConfigType<?, ?> getType() {
return type;
}
@SuppressWarnings("unchecked")
public <T> T getLoadedObject(Class<T> clazz) {
if(!clazz.isAssignableFrom(type.getTypeKey().getRawType()))
throw new ClassCastException(
"Cannot assign object from loader of type " + ReflectionUtil.typeToString(type.getTypeKey().getType()) + " to class " +
clazz.getCanonicalName());
return (T) loaded;
}
@SuppressWarnings("unchecked")
public <T> T getLoadedObject() {
return (T) loaded;
}
}

View File

@@ -1,47 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the common/api directory.
*/
package com.dfsek.terra.api.event.events.config.pack;
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
import com.dfsek.tectonic.api.exception.ConfigException;
import com.dfsek.terra.api.event.events.FailThroughEvent;
import com.dfsek.terra.api.event.events.PackEvent;
/**
* An event related to the loading process of config packs.
*/
public abstract class ConfigPackLoadEvent implements PackEvent, FailThroughEvent {
private final ConfigPack pack;
private final ExceptionalConsumer<ConfigTemplate> configLoader;
public ConfigPackLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configLoader) {
this.pack = pack;
this.configLoader = configLoader;
}
/**
* Load a custom {@link ConfigTemplate} using the pack manifest.
*
* @param template Template to register.
*/
public <T extends ConfigTemplate> T loadTemplate(T template) throws ConfigException {
configLoader.accept(template);
return template;
}
@Override
public ConfigPack getPack() {
return pack;
}
public interface ExceptionalConsumer<T extends ConfigTemplate> {
void accept(T value) throws ConfigException;
}
}

View File

@@ -1,20 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the common/api directory.
*/
package com.dfsek.terra.api.event.events.config.pack;
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
/**
* Called when a config pack has finished loading.
*/
public class ConfigPackPostLoadEvent extends ConfigPackLoadEvent {
public ConfigPackPostLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> loader) {
super(pack, loader);
}
}

View File

@@ -1,20 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the common/api directory.
*/
package com.dfsek.terra.api.event.events.config.pack;
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
/**
* Called before a config pack's registries are filled.
*/
public class ConfigPackPreLoadEvent extends ConfigPackLoadEvent {
public ConfigPackPreLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configLoader) {
super(pack, configLoader);
}
}

View File

@@ -1,45 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the common/api directory.
*/
package com.dfsek.terra.api.event.events.config.type;
import com.dfsek.terra.api.event.events.FailThroughEvent;
import com.dfsek.terra.api.event.events.PackEvent;
import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.util.reflection.ReflectionUtil;
public abstract class ConfigTypeLoadEvent implements PackEvent, FailThroughEvent {
private final ConfigType<?, ?> type;
private final Registry<?> registry;
private final ConfigPack pack;
public ConfigTypeLoadEvent(ConfigType<?, ?> type, Registry<?> registry, ConfigPack pack) {
this.type = type;
this.registry = registry;
this.pack = pack;
}
public boolean is(Class<?> clazz) {
return clazz.isAssignableFrom(type.getTypeKey().getRawType());
}
@Override
public ConfigPack getPack() {
return pack;
}
@SuppressWarnings("unchecked")
public <T> Registry<T> getRegistry(Class<T> clazz) {
if(!clazz.isAssignableFrom(type.getTypeKey().getRawType()))
throw new ClassCastException(
"Cannot assign object from loader of type " + ReflectionUtil.typeToString(type.getTypeKey().getType()) + " to class " +
clazz.getCanonicalName());
return (Registry<T>) registry;
}
}

View File

@@ -1,17 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the common/api directory.
*/
package com.dfsek.terra.api.event.events.config.type;
import com.dfsek.terra.api.registry.Registry;
public class ConfigTypePostLoadEvent extends ConfigTypeLoadEvent {
public ConfigTypePostLoadEvent(ConfigType<?, ?> type, Registry<?> registry, ConfigPack pack) {
super(type, registry, pack);
}
}

View File

@@ -1,17 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the common/api directory.
*/
package com.dfsek.terra.api.event.events.config.type;
import com.dfsek.terra.api.registry.Registry;
public class ConfigTypePreLoadEvent extends ConfigTypeLoadEvent {
public ConfigTypePreLoadEvent(ConfigType<?, ?> type, Registry<?> registry, ConfigPack pack) {
super(type, registry, pack);
}
}

View File

@@ -1,39 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the common/api directory.
*/
package com.dfsek.terra.api.event.events.world.generation;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.api.event.events.PackEvent;
/**
* Called when an entity is spawned.
*/
public class EntitySpawnEvent implements PackEvent {
private final ConfigPack pack;
private final Entity entity;
public EntitySpawnEvent(ConfigPack pack, Entity entity) {
this.pack = pack;
this.entity = entity;
}
@Override
public ConfigPack getPack() {
return pack;
}
/**
* Get the entity that triggered the event.
*
* @return The entity.
*/
public Entity getEntity() {
return entity;
}
}

View File

@@ -1,80 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the common/api directory.
*/
package com.dfsek.terra.api.event.events.world.generation;
import org.jetbrains.annotations.NotNull;
import com.dfsek.terra.api.block.entity.Container;
import com.dfsek.terra.api.event.events.AbstractCancellable;
import com.dfsek.terra.api.event.events.PackEvent;
import com.dfsek.terra.api.structure.LootTable;
import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.util.vector.Vector3;
/**
* Called when loot is populated.
*/
public class LootPopulateEvent extends AbstractCancellable implements PackEvent {
private final Container container;
private final ConfigPack pack;
private final Structure structure;
private LootTable table;
public LootPopulateEvent(Container container, LootTable table, ConfigPack pack, Structure structure) {
this.container = container;
this.table = table;
this.pack = pack;
this.structure = structure;
}
@Override
public ConfigPack getPack() {
return pack;
}
public Vector3 getPosition() {
return container.getPosition();
}
/**
* Get the {@link Container} representing the inventory.
*
* @return Inventory recieving loot.
*/
public Container getContainer() {
return container;
}
/**
* Get the loot table to be populated.
*
* @return Loot table.
*/
public LootTable getTable() {
return table;
}
/**
* Set the loot table to be populated.
*
* @param table New loot table.
*/
public void setTable(@NotNull LootTable table) {
this.table = table;
}
/**
* Get the script used to generate the structure.
*
* @return Structure script.
*/
public Structure getStructure() {
return structure;
}
}

View File

@@ -13,6 +13,8 @@ import com.dfsek.terra.api.world.util.Interceptors;
import com.dfsek.terra.api.world.util.ReadInterceptor;
import com.dfsek.terra.api.world.util.WriteInterceptor;
import org.jetbrains.annotations.NotNull;
/**
* A {@link WritableWorld} implementation which delegates read/write operations to
@@ -71,18 +73,13 @@ public class BufferedWorld implements WritableWorld {
}
@Override
public ChunkGenerator getGenerator() {
return delegate.getGenerator();
public @NotNull ChunkGenerator generator() {
return delegate.generator();
}
@Override
public BiomeProvider getBiomeProvider() {
return delegate.getBiomeProvider();
}
@Override
public ConfigPack getPack() {
return delegate.getPack();
public @NotNull BiomeProvider biomeProvider() {
return delegate.biomeProvider();
}
@Override

View File

@@ -4,6 +4,9 @@ import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
import com.dfsek.terra.api.world.info.WorldProperties;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
/**
* Represents a world.
@@ -14,19 +17,16 @@ public interface World extends WorldProperties {
*
* @return Chunk generator.
*/
ChunkGenerator getGenerator();
@NotNull
@Contract(pure = true)
ChunkGenerator generator();
/**
* Get the {@link BiomeProvider} this world uses.
*
* @return Biome provider.
*/
BiomeProvider getBiomeProvider();
/**
* Get the {@link ConfigPack} this world uses.
*
* @return Config pack.
*/
ConfigPack getPack();
@NotNull
@Contract(pure = true)
BiomeProvider biomeProvider();
}

View File

@@ -1,15 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the common/api directory.
*/
package com.dfsek.terra.api.world.chunk.generation.util.provider;
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
public interface ChunkGeneratorProvider {
ChunkGenerator newInstance(ConfigPack pack);
}

View File

@@ -1,15 +0,0 @@
/*
* Copyright (c) 2020-2021 Polyhedral Development
*
* The Terra API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the common/api directory.
*/
package com.dfsek.terra.api.world.chunk.generation.util.provider;
import com.dfsek.terra.api.world.chunk.generation.stage.GenerationStage;
public interface GenerationStageProvider {
GenerationStage newInstance(ConfigPack pack);
}