2022-07-31 20:41:56 +02:00
|
|
|
/*
|
2022-07-30 15:21:11 +02:00
|
|
|
* Copyright (C) 2022 FalsePattern
|
|
|
|
|
* All Rights Reserved
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice, this permission notice and the word "SNEED"
|
|
|
|
|
* shall be included in all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2022-04-17 17:26:30 +02:00
|
|
|
package com.falsepattern.lib.mixin;
|
|
|
|
|
|
2022-06-12 11:58:13 +02:00
|
|
|
import com.falsepattern.lib.StableAPI;
|
2022-07-31 20:41:56 +02:00
|
|
|
import lombok.val;
|
|
|
|
|
|
2022-04-17 17:26:30 +02:00
|
|
|
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
2022-07-31 20:41:56 +02:00
|
|
|
|
2022-04-17 17:26:30 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.function.Predicate;
|
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
2022-06-12 11:58:13 +02:00
|
|
|
@StableAPI(since = "0.8.0")
|
2022-04-17 17:26:30 +02:00
|
|
|
public interface IMixin {
|
|
|
|
|
|
|
|
|
|
String getMixin();
|
|
|
|
|
|
|
|
|
|
default boolean shouldLoad(List<ITargetedMod> loadedMods) {
|
|
|
|
|
val side = getSide();
|
2022-06-08 16:01:06 +02:00
|
|
|
return (side == Side.COMMON || side == Side.SERVER && FMLLaunchHandler.side().isServer() ||
|
|
|
|
|
side == Side.CLIENT && FMLLaunchHandler.side().isClient()) && getFilter().test(loadedMods);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Side getSide();
|
|
|
|
|
|
|
|
|
|
Predicate<List<ITargetedMod>> getFilter();
|
|
|
|
|
|
|
|
|
|
enum Side {
|
|
|
|
|
COMMON,
|
|
|
|
|
CLIENT,
|
|
|
|
|
SERVER
|
2022-04-17 17:26:30 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-17 20:30:32 +02:00
|
|
|
final class PredicateHelpers {
|
|
|
|
|
public static Predicate<List<ITargetedMod>> never() {
|
|
|
|
|
return (list) -> false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Predicate<List<ITargetedMod>> condition(Supplier<Boolean> condition) {
|
|
|
|
|
return (list) -> condition.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Predicate<List<ITargetedMod>> always() {
|
|
|
|
|
return (list) -> true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Predicate<List<ITargetedMod>> require(ITargetedMod mod) {
|
|
|
|
|
return (list) -> list.contains(mod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Predicate<List<ITargetedMod>> avoid(ITargetedMod mod) {
|
|
|
|
|
return (list) -> !list.contains(mod);
|
|
|
|
|
}
|
2022-04-17 17:26:30 +02:00
|
|
|
}
|
|
|
|
|
}
|