Reworked PipeUtils and GasUtils side access (#5529)

These two methods were ghost loading chunks causing issues. Rather than simply adding a is loaded check I reworked the flow to be more reusable and clearer in general. The extra code can be used in other places to improve the code base.
This commit is contained in:
Robert WC Seifert authored and Richard Freimer committed 2019-06-27 13:42:10 -04:00
1 parent f00fe44124
commit 5d17d706c0
4 files changed
+85 -44

No files matched your search

@@ -21,6 +21,22 @@ public final class CapabilityUtils {
return provider.getCapability(cap, side);
}
/**
* Runs an action on a capability if it exists
*
* @param provider - provider hosting the capability
* @param cap - capability type
* @param side - side to access
* @param action - handler for completing the action on the capability
* @param <T> - type to return
*/
public static <T> void runIfCap(ICapabilityProvider provider, Capability<T> cap, EnumFacing side, Consumer<T> action) {
final T capability = getCapability(provider, cap, side);
if (capability != null) {
action.accept(capability);
}
}
public static <T> OptionalCapability withCapability(ICapabilityProvider provider, Capability<T> cap, EnumFacing side, Consumer<T> consumer) {
return new OptionalCapability(provider).orElseWith(cap, side, consumer);
}