Skip to content

Commit

Permalink
replace addMerged[Synced]Config with addFeatureConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
deirn committed Oct 22, 2023
1 parent 531a9f8 commit da76311
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 59 deletions.
47 changes: 24 additions & 23 deletions src/api/java/mcp/mobius/waila/api/IRegistrar.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,10 @@ default void addConfig(ResourceLocation key, int defaultValue) {

/**
* Registers a namespaced config key to be accessed within data providers.
* When the server has waila installed, the server will send its value and it will be merged with client value.
* <p>
* These translation keys will be used on the plugin config screen:<ul>
* <li>{@code config.waila.plugin_[namespace].[path]} for the config name.</li>
* <li>{@code config.waila.plugin_[namespace].[path]_desc} for the config description.
* This one is optional and can be left missing.</li></ul>
* <p>
* Config options can also be grouped with the same prefix on its path followed by a period [{@code .}],
* e.g. {@code my_plugin:group.option1} and {@code my_plugin:group.option2}.<br>
* Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name
* for it to be visible in the config screen.
*
* @param key the namespaced key
* @param defaultValue the default value
*/
void addMergedConfig(ResourceLocation key, boolean defaultValue);

/**
* Registers a namespaced config key to be accessed within data providers.
* When the server has waila installed, the server will send its value and it will be merged with client value.
* The main purpose of this method is for toggling feature that enabled by default.
* This method allows server to disable the option remotely for all connected clients,
* the clients can then toggle the option for their own side only if it is enabled on the server.
* <p>
* These translation keys will be used on the plugin config screen:<ul>
* <li>{@code config.waila.plugin_[namespace].[path]} for the config name.</li>
Expand All @@ -187,11 +171,10 @@ default void addConfig(ResourceLocation key, int defaultValue) {
* Then, add a translation for {@code config.waila.plugin_[namespace].[group]} with the group name
* for it to be visible in the config screen.
*
* @param key the namespaced key
* @param defaultValue the default value
* @param clientOnlyValue the value that will be used when the server connected doesn't have waila installed
* @param key the namespaced key to be used with {@link IPluginConfig#getBoolean(ResourceLocation)}
* @param clientOnly whether the feature available on client-only, e.g. not using {@linkplain IDataProvider server data}
*/
void addMergedSyncedConfig(ResourceLocation key, boolean defaultValue, boolean clientOnlyValue);
void addFeatureConfig(ResourceLocation key, boolean clientOnly);

/**
* Registers a namespaced config key to be accessed within data providers.
Expand Down Expand Up @@ -606,4 +589,22 @@ default <T, E extends Entity> void addEntityData(IServerDataProvider<E> provider
addEntityData((IDataProvider<? extends Entity>) provider, clazz);
}

/**
* @deprecated use {@link #addFeatureConfig(ResourceLocation, boolean)}
*/
@Deprecated(forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "1.22")
default void addMergedConfig(ResourceLocation key, boolean defaultValue) {
addFeatureConfig(key, true);
}

/**
* @deprecated use {@link #addFeatureConfig(ResourceLocation, boolean)}
*/
@Deprecated(forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "1.22")
default void addMergedSyncedConfig(ResourceLocation key, boolean defaultValue, boolean clientOnlyValue) {
addFeatureConfig(key, false);
}

}
9 changes: 2 additions & 7 deletions src/main/java/mcp/mobius/waila/registry/Registrar.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,8 @@ public void addConfig(ResourceLocation key, Path path) {
}

@Override
public void addMergedConfig(ResourceLocation key, boolean defaultValue) {
addConfig(key, defaultValue, defaultValue, false, true, ConfigEntry.BOOLEAN);
}

@Override
public void addMergedSyncedConfig(ResourceLocation key, boolean defaultValue, boolean clientOnlyValue) {
addConfig(key, defaultValue, clientOnlyValue, true, true, ConfigEntry.BOOLEAN);
public void addFeatureConfig(ResourceLocation key, boolean clientOnly) {
addConfig(key, true, clientOnly, !clientOnly, true, ConfigEntry.BOOLEAN);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ protected DataProvider(ResourceLocation id, Class<T> type, IData.Serializer<T> s
}

public void register(IRegistrar registrar, int priority) {
registrar.addMergedSyncedConfig(enabledBlockOption, true, false);
registrar.addMergedSyncedConfig(enabledEntityOption, true, false);
registrar.addFeatureConfig(enabledBlockOption, false);
registrar.addFeatureConfig(enabledEntityOption, false);
registerAdditions(registrar, priority);
registrar.addConfig(createConfigKey("blacklist"), blacklistConfig.getPath());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,93 +89,93 @@ public class WailaPluginVanilla implements IWailaPlugin {

@Override
public void register(IRegistrar registrar) {
registrar.addMergedConfig(Options.ITEM_ENTITY, true);
registrar.addFeatureConfig(Options.ITEM_ENTITY, true);
registrar.addIcon(ItemEntityProvider.INSTANCE, ItemEntity.class);
registrar.addComponent(ItemEntityProvider.INSTANCE, HEAD, ItemEntity.class, 950);
registrar.addComponent(ItemEntityProvider.INSTANCE, BODY, ItemEntity.class, 950);
registrar.addComponent(ItemEntityProvider.INSTANCE, TAIL, ItemEntity.class, 950);
registrar.addOverride(ItemEntityProvider.INSTANCE, ItemEntity.class);

registrar.addMergedSyncedConfig(Options.PET_OWNER, true, false);
registrar.addFeatureConfig(Options.PET_OWNER, false);
registrar.addConfig(Options.PET_HIDE_UNKNOWN_OWNER, false);
registrar.addComponent(PetOwnerProvider.INSTANCE, BODY, OwnableEntity.class);
registrar.addEntityData(PetOwnerProvider.INSTANCE, OwnableEntity.class);

registrar.addConfig(Options.ATTRIBUTE_BLOCK_POSITION, false);
registrar.addConfig(Options.ATTRIBUTE_BLOCK_STATE, false);
registrar.addConfig(Options.ATTRIBUTE_ENTITY_POSITION, false);
registrar.addMergedConfig(Options.ATTRIBUTE_HEALTH, true);
registrar.addMergedSyncedConfig(Options.ATTRIBUTE_ABSORPTION, true, false);
registrar.addMergedConfig(Options.ATTRIBUTE_ARMOR, true);
registrar.addFeatureConfig(Options.ATTRIBUTE_HEALTH, true);
registrar.addFeatureConfig(Options.ATTRIBUTE_ABSORPTION, false);
registrar.addFeatureConfig(Options.ATTRIBUTE_ARMOR, true);
registrar.addConfig(Options.ATTRIBUTE_COMPACT, false);
registrar.addConfig(Options.ATTRIBUTE_ICON_PER_LINE, 25);
registrar.addConfig(Options.ATTRIBUTE_LONG_HEALTH_MAX, 100);
registrar.addConfig(Options.ATTRIBUTE_LONG_ARMOR_MAX, 100);
registrar.addMergedConfig(Options.ATTRIBUTE_HORSE_JUMP_HEIGHT, true);
registrar.addMergedConfig(Options.ATTRIBUTE_HORSE_SPEED, true);
registrar.addMergedConfig(Options.ATTRIBUTE_PANDA_GENES, true);
registrar.addFeatureConfig(Options.ATTRIBUTE_HORSE_JUMP_HEIGHT, true);
registrar.addFeatureConfig(Options.ATTRIBUTE_HORSE_SPEED, true);
registrar.addFeatureConfig(Options.ATTRIBUTE_PANDA_GENES, true);
registrar.addComponent(BlockAttributesProvider.INSTANCE, BODY, Block.class, 950);
registrar.addComponent(EntityAttributesProvider.INSTANCE, HEAD, Entity.class, 950);
registrar.addComponent(EntityAttributesProvider.INSTANCE, BODY, Entity.class, 950);
registrar.addComponent(HorseProvider.INSTANCE, BODY, AbstractHorse.class);
registrar.addComponent(PandaProvider.INSTANCE, BODY, Panda.class);
registrar.addEntityData(EntityAttributesProvider.INSTANCE, Entity.class);

registrar.addMergedSyncedConfig(Options.JUKEBOX_RECORD, true, false);
registrar.addFeatureConfig(Options.JUKEBOX_RECORD, false);
registrar.addComponent(JukeboxProvider.INSTANCE, BODY, JukeboxBlockEntity.class);
registrar.addBlockData(JukeboxProvider.INSTANCE, JukeboxBlockEntity.class);

registrar.addMergedSyncedConfig(Options.TIMER_GROW, true, false);
registrar.addMergedSyncedConfig(Options.TIMER_BREED, true, false);
registrar.addFeatureConfig(Options.TIMER_GROW, false);
registrar.addFeatureConfig(Options.TIMER_BREED, false);
registrar.addComponent(MobTimerProvider.INSTANCE, BODY, AgeableMob.class);
registrar.addEntityData(MobTimerProvider.INSTANCE, AgeableMob.class);

registrar.addMergedConfig(Options.OVERRIDE_INVISIBLE_ENTITY, true);
registrar.addMergedConfig(Options.OVERRIDE_TRAPPED_CHEST, true);
registrar.addMergedConfig(Options.OVERRIDE_POWDER_SNOW, true);
registrar.addMergedConfig(Options.OVERRIDE_INFESTED, true);
registrar.addFeatureConfig(Options.OVERRIDE_INVISIBLE_ENTITY, true);
registrar.addFeatureConfig(Options.OVERRIDE_TRAPPED_CHEST, true);
registrar.addFeatureConfig(Options.OVERRIDE_POWDER_SNOW, true);
registrar.addFeatureConfig(Options.OVERRIDE_INFESTED, true);
registrar.addConfig(Options.OVERRIDE_VEHICLE, true);
registrar.addOverride(InvisibleEntityProvider.INSTANCE, LivingEntity.class);
registrar.addOverride(InfestedBlockProvider.INSTANCE, InfestedBlock.class);
registrar.addOverride(TrappedChestProvider.INSTANCE, TrappedChestBlock.class);
registrar.addOverride(PowderSnowProvider.INSTANCE, PowderSnowBlock.class);
registrar.addOverride(VehicleProvider.INSTANCE, Entity.class, 900);

registrar.addMergedConfig(Options.BREAKING_PROGRESS, true);
registrar.addFeatureConfig(Options.BREAKING_PROGRESS, true);
registrar.addConfig(Options.BREAKING_PROGRESS_COLOR, 0xAAFFFFFF, IntFormat.ARGB_HEX);
registrar.addConfig(Options.BREAKING_PROGRESS_BOTTOM_ONLY, false);
registrar.addEventListener(BreakProgressProvider.INSTANCE);

registrar.addMergedConfig(Options.SPAWNER_TYPE, true);
registrar.addFeatureConfig(Options.SPAWNER_TYPE, true);
registrar.addComponent(SpawnerProvider.INSTANCE, HEAD, SpawnerBlockEntity.class, 950);

registrar.addMergedConfig(Options.CROP_PROGRESS, true);
registrar.addFeatureConfig(Options.CROP_PROGRESS, true);
registrar.addIcon(PlantProvider.INSTANCE, CropBlock.class);
registrar.addComponent(PlantProvider.INSTANCE, BODY, CropBlock.class);
registrar.addComponent(PlantProvider.INSTANCE, BODY, StemBlock.class);
registrar.addComponent(PlantProvider.INSTANCE, BODY, CocoaBlock.class);
registrar.addComponent(PlantProvider.INSTANCE, BODY, NetherWartBlock.class);
registrar.addComponent(PlantProvider.INSTANCE, BODY, SweetBerryBushBlock.class);

registrar.addMergedConfig(Options.REDSTONE_LEVER, true);
registrar.addMergedConfig(Options.REDSTONE_REPEATER, true);
registrar.addMergedConfig(Options.REDSTONE_COMPARATOR, true);
registrar.addMergedConfig(Options.REDSTONE_LEVEL, true);
registrar.addFeatureConfig(Options.REDSTONE_LEVER, true);
registrar.addFeatureConfig(Options.REDSTONE_REPEATER, true);
registrar.addFeatureConfig(Options.REDSTONE_COMPARATOR, true);
registrar.addFeatureConfig(Options.REDSTONE_LEVEL, true);
registrar.addComponent(RedstoneProvider.INSTANCE, BODY, LeverBlock.class);
registrar.addComponent(RedstoneProvider.INSTANCE, BODY, RepeaterBlock.class);
registrar.addComponent(RedstoneProvider.INSTANCE, BODY, ComparatorBlock.class);
registrar.addComponent(RedstoneProvider.INSTANCE, BODY, RedStoneWireBlock.class);

registrar.addMergedConfig(Options.PLAYER_HEAD_NAME, true);
registrar.addFeatureConfig(Options.PLAYER_HEAD_NAME, true);
registrar.addIcon(PlayerHeadProvider.INSTANCE, SkullBlockEntity.class);
registrar.addComponent(PlayerHeadProvider.INSTANCE, BODY, SkullBlockEntity.class);

registrar.addMergedConfig(Options.LEVEL_COMPOSTER, true);
registrar.addMergedConfig(Options.LEVEL_HONEY, true);
registrar.addFeatureConfig(Options.LEVEL_COMPOSTER, true);
registrar.addFeatureConfig(Options.LEVEL_HONEY, true);
registrar.addComponent(ComposterProvider.INSTANCE, BODY, ComposterBlock.class);
registrar.addComponent(BeehiveProvider.INSTANCE, BODY, BeehiveBlock.class);

registrar.addMergedConfig(Options.NOTE_BLOCK_TYPE, true);
registrar.addFeatureConfig(Options.NOTE_BLOCK_TYPE, true);
registrar.addConfig(Options.NOTE_BLOCK_NOTE, NoteDisplayMode.SHARP);
registrar.addConfig(Options.NOTE_BLOCK_INT_VALUE, false);
registrar.addComponent(NoteBlockProvider.INSTANCE, BODY, NoteBlock.class);
Expand All @@ -191,7 +191,7 @@ public void register(IRegistrar registrar) {
registrar.addComponent(ItemFrameProvider.INSTANCE, BODY, ItemFrame.class);
registrar.addComponent(ItemFrameProvider.INSTANCE, TAIL, ItemFrame.class);

registrar.addMergedSyncedConfig(Options.BOOK_BOOKSHELF, true, false);
registrar.addFeatureConfig(Options.BOOK_BOOKSHELF, false);
registrar.addConfig(Options.BOOK_ENCHANTMENT_DISPLAY_MODE, EnchantmentDisplayMode.CYCLE);
registrar.addConfig(Options.BOOK_ENCHANTMENT_CYCLE_TIMING, 500);
registrar.addConfig(Options.BOOK_WRITTEN, true);
Expand Down

0 comments on commit da76311

Please sign in to comment.