mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-14 04:00:30 +00:00
Fall back to the given side if the internal one isn't provided
See #1061, closes #1064. Nobody ever seems to implement this correctly (though it's better than 1.12, at least we've not seen any crashes), and this isn't a fight I care enough about fighting any more.
This commit is contained in:
parent
2a92794da3
commit
79b1872cab
@ -45,7 +45,7 @@ public class GenericPeripheralProvider
|
|||||||
|
|
||||||
for( Capability<?> capability : capabilities )
|
for( Capability<?> capability : capabilities )
|
||||||
{
|
{
|
||||||
LazyOptional<?> wrapper = tile.getCapability( capability );
|
LazyOptional<?> wrapper = CapabilityUtil.getCapability( tile, capability, side );
|
||||||
wrapper.ifPresent( contents -> {
|
wrapper.ifPresent( contents -> {
|
||||||
List<NamedMethod<PeripheralMethod>> capabilityMethods = PeripheralMethod.GENERATOR.getMethods( contents.getClass() );
|
List<NamedMethod<PeripheralMethod>> capabilityMethods = PeripheralMethod.GENERATOR.getMethods( contents.getClass() );
|
||||||
if( capabilityMethods.isEmpty() ) return;
|
if( capabilityMethods.isEmpty() ) return;
|
||||||
|
@ -5,9 +5,13 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.shared.util;
|
package dan200.computercraft.shared.util;
|
||||||
|
|
||||||
|
import net.minecraft.util.Direction;
|
||||||
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
|
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
import net.minecraftforge.common.util.LazyOptional;
|
||||||
import net.minecraftforge.common.util.NonNullConsumer;
|
import net.minecraftforge.common.util.NonNullConsumer;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public final class CapabilityUtil
|
public final class CapabilityUtil
|
||||||
@ -57,4 +61,21 @@ public final class CapabilityUtil
|
|||||||
{
|
{
|
||||||
return !p.isPresent() ? null : p.orElseThrow( NullPointerException::new );
|
return !p.isPresent() ? null : p.orElseThrow( NullPointerException::new );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a capability, preferring the internal/null side but falling back to a given side if a mod doesn't support
|
||||||
|
* the internal one.
|
||||||
|
*
|
||||||
|
* @param provider The capability provider to get the capability from.
|
||||||
|
* @param capability The capability to get.
|
||||||
|
* @param side The side we'll fall back to.
|
||||||
|
* @param <T> The type of the underlying capability.
|
||||||
|
* @return The extracted capability, if present.
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public static <T> LazyOptional<T> getCapability( ICapabilityProvider provider, Capability<T> capability, Direction side )
|
||||||
|
{
|
||||||
|
LazyOptional<T> cap = provider.getCapability( capability );
|
||||||
|
return cap.isPresent() ? cap : provider.getCapability( capability, side );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user