Skip to content

Commit

Permalink
Implement a super-interface for ModifierModule for just a module with…
Browse files Browse the repository at this point in the history
… hooks

Will be useful in simplifying ModifierHookMap usages without requiring it be serializable. May have other usages in the future. Adding to 1.18 instead of 1.19 as it will make documenting this stuff easier
  • Loading branch information
KnightMiner committed Mar 10, 2024
1 parent 3e685d1 commit 50def7e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package slimeknights.tconstruct.library.modifiers.modules;

import slimeknights.tconstruct.library.modifiers.ModifierHook;

import java.util.List;

/** Interface to simplify building of modifier hook maps */
public interface ModifierHookProvider {
/** Gets the default list of hooks this module implements. */
List<ModifierHook<?>> getDefaultHooks();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,11 @@
import java.util.Collections;
import java.util.List;

/**
* Interface for a module in a composable modifier
*/
public interface ModifierModule extends IHaveLoader<ModifierModule> {
/** Interface for a module in a composable modifier. This is the serializable version of {@link ModifierHookProvider}. */
public interface ModifierModule extends IHaveLoader<ModifierModule>, ModifierHookProvider {
/** Loader instance to register new modules. Note that loaders should not use the key "hooks" else composable modifiers will not parse */
GenericLoaderRegistry<ModifierModule> LOADER = new GenericLoaderRegistry<>();

/**
* Gets the default list of hooks this module implements
*/
List<ModifierHook<?>> getDefaultHooks();

/**
* Gets the priority for this module.
* All modules are polled to choose the priority of the final modifier with the following criteria:
Expand Down Expand Up @@ -134,7 +127,10 @@ static ModifierHookMap createMap(List<ModuleWithHooks> modules) {
return builder.build();
}

/** Helper method to validate generics on the hooks when building a default hooks list. To use, make sure you set the generics instead of leaving it automatic. */
/**
* Helper method to validate generics on the hooks when building a default hooks list. To use, make sure you set the generics instead of leaving it automatic.
* TODO 1.19: move to {@link ModifierHookProvider}.
*/
@SafeVarargs
static <T> List<ModifierHook<?>> defaultHooks(ModifierHook<? super T> ... hooks) {
return List.of(hooks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.google.common.collect.LinkedHashMultimap;
import lombok.RequiredArgsConstructor;
import slimeknights.tconstruct.library.modifiers.ModifierHook;
import slimeknights.tconstruct.library.modifiers.modules.ModifierModule;
import slimeknights.tconstruct.library.modifiers.modules.ModifierHookProvider;

import javax.annotation.Nullable;
import java.util.Collection;
Expand Down Expand Up @@ -67,8 +67,8 @@ public Builder addHookChecked(Object object, ModifierHook<?> hook) {
return this;
}

/** Adds a modifier module to the builder, automatically adding all its hooks */
public Builder addModule(ModifierModule module) {
/** Adds a modifier module to the builder, automatically adding all its hooks. Use {@link #addHook(Object, ModifierHook)} to specify hooks. */
public Builder addModule(ModifierHookProvider module) {
for (ModifierHook<?> hook : module.getDefaultHooks()) {
addHookChecked(module, hook);
}
Expand Down

0 comments on commit 50def7e

Please sign in to comment.