1+ /*
2+ * This file is part of Baritone.
3+ *
4+ * Baritone is free software: you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser General Public License as published by
6+ * the Free Software Foundation, either version 3 of the License, or
7+ * (at your option) any later version.
8+ *
9+ * Baritone is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ * GNU Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public License
15+ * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
16+ */
17+
18+ package baritone .launch ;
19+
20+ import net .fabricmc .loader .api .FabricLoader ;
21+ import org .objectweb .asm .tree .ClassNode ;
22+ import org .spongepowered .asm .mixin .extensibility .IMixinConfigPlugin ;
23+ import org .spongepowered .asm .mixin .extensibility .IMixinInfo ;
24+
25+ import java .util .List ;
26+ import java .util .Set ;
27+
28+ public class FabricMixinPlugin implements IMixinConfigPlugin {
29+ private static final String mixinPackage = "baritone.launch.mixins" ;
30+
31+ private static boolean loaded ;
32+
33+ private static boolean isBaritonePresent ;
34+
35+ @ Override
36+ public void onLoad (String mixinPackage ) {
37+ if (loaded ) return ;
38+
39+ isBaritonePresent = FabricLoader .getInstance ().isModLoaded ("baritone" );
40+
41+ loaded = true ;
42+ }
43+
44+ @ Override
45+ public String getRefMapperConfig () {
46+ return null ;
47+ }
48+
49+ @ Override
50+ public boolean shouldApplyMixin (String targetClassName , String mixinClassName ) {
51+ if (!mixinClassName .startsWith (mixinPackage )) {
52+ throw new RuntimeException ("Mixin " + mixinClassName + " is not in the mixin package" );
53+ } else {
54+ return !isBaritonePresent ;
55+ }
56+ }
57+
58+ @ Override
59+ public void acceptTargets (Set <String > myTargets , Set <String > otherTargets ) {}
60+
61+ @ Override
62+ public List <String > getMixins () {
63+ return null ;
64+ }
65+
66+ @ Override
67+ public void preApply (String targetClassName , ClassNode targetClass , String mixinClassName , IMixinInfo mixinInfo ) {}
68+
69+ @ Override
70+ public void postApply (String targetClassName , ClassNode targetClass , String mixinClassName , IMixinInfo mixinInfo ) {}
71+ }
0 commit comments