|
| 1 | +/* |
| 2 | + * Minecraft Forge, Patchwork Project |
| 3 | + * Copyright (c) 2016-2020, 2019-2020 |
| 4 | + * |
| 5 | + * This library is free software; you can redistribute it and/or |
| 6 | + * modify it under the terms of the GNU Lesser General Public |
| 7 | + * License as published by the Free Software Foundation version 2.1 |
| 8 | + * of the License. |
| 9 | + * |
| 10 | + * This library is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + * Lesser General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Lesser General Public |
| 16 | + * License along with this library; if not, write to the Free Software |
| 17 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | + */ |
| 19 | + |
| 20 | +package com.patchworkmc.impl.capability; |
| 21 | + |
| 22 | +import javax.annotation.Nonnull; |
| 23 | +import javax.annotation.Nullable; |
| 24 | + |
| 25 | +import net.minecraftforge.common.capabilities.Capability; |
| 26 | +import net.minecraftforge.common.capabilities.CapabilityDispatcher; |
| 27 | +import net.minecraftforge.common.capabilities.CapabilityProvider; |
| 28 | +import net.minecraftforge.common.capabilities.ICapabilityProvider; |
| 29 | +import net.minecraftforge.common.util.LazyOptional; |
| 30 | + |
| 31 | +import net.minecraft.nbt.CompoundTag; |
| 32 | +import net.minecraft.util.math.Direction; |
| 33 | + |
| 34 | +/** |
| 35 | + * A holder for {@link CapabilityProvider}, since some classes cannot directly extend {@link CapabilityProvider}. |
| 36 | + */ |
| 37 | +public interface CapabilityProviderHolder extends ICapabilityProvider { |
| 38 | + @Nonnull |
| 39 | + CapabilityProvider<?> getCapabilityProvider(); |
| 40 | + |
| 41 | + default void gatherCapabilities() { |
| 42 | + getCapabilityProvider().gatherCapabilities(); |
| 43 | + } |
| 44 | + |
| 45 | + default void gatherCapabilities(@Nullable ICapabilityProvider parent) { |
| 46 | + getCapabilityProvider().gatherCapabilities(parent); |
| 47 | + } |
| 48 | + |
| 49 | + default CapabilityDispatcher getCapabilities() { |
| 50 | + return getCapabilityProvider().getCapabilities(); |
| 51 | + } |
| 52 | + |
| 53 | + default boolean areCapsCompatible(CapabilityProvider<?> other) { |
| 54 | + return getCapabilityProvider().areCapsCompatible((CapabilityProvider) other); |
| 55 | + } |
| 56 | + |
| 57 | + default boolean areCapsCompatible(CapabilityDispatcher other) { |
| 58 | + return getCapabilityProvider().areCapsCompatible(other); |
| 59 | + } |
| 60 | + |
| 61 | + @Nullable |
| 62 | + default CompoundTag serializeCaps() { |
| 63 | + return getCapabilityProvider().serializeCaps(); |
| 64 | + } |
| 65 | + |
| 66 | + default void deserializeCaps(CompoundTag tag) { |
| 67 | + getCapabilityProvider().deserializeCaps(tag); |
| 68 | + } |
| 69 | + |
| 70 | + default void invalidateCaps() { |
| 71 | + getCapabilityProvider().invalidateCaps(); |
| 72 | + } |
| 73 | + |
| 74 | + default void reviveCaps() { |
| 75 | + getCapabilityProvider().reviveCaps(); |
| 76 | + } |
| 77 | + |
| 78 | + @Nonnull |
| 79 | + default <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { |
| 80 | + return getCapabilityProvider().getCapability(cap, side); |
| 81 | + } |
| 82 | + |
| 83 | + @Nonnull |
| 84 | + default <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap) { |
| 85 | + return getCapabilityProvider().getCapability(cap); |
| 86 | + } |
| 87 | +} |
0 commit comments