Skip to content

Commit db400bf

Browse files
committed
Allow to set a mod side and to disable them.
1 parent f5e9e93 commit db400bf

File tree

5 files changed

+38
-5
lines changed

5 files changed

+38
-5
lines changed

loader/src/main/java/com/fox2code/foxloader/client/gui/GuiModMenuContainer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ protected void drawSlot(Minecraft mc, int index, float x, float y, int iconHeigh
127127
float color = this.selected == index ? 1F : 0.5F;
128128
RenderSystem.color(color, color, color, 1F);
129129
RenderSystem.enableBlend();
130+
if ((modDisplayFlags & LoadingPlugin.DISPLAY_FLAG_DISABLED) != 0) {
131+
this.drawCustomIcon(iconPosX, iconPosY, 3);
132+
iconPosX -= 20;
133+
}
130134
if ((modDisplayFlags & LoadingPlugin.DISPLAY_FLAG_LIBRARY) != 0) {
131135
this.drawCustomIcon(iconPosX, iconPosY, 2);
132136
iconPosX -= 20;

loader/src/main/java/com/fox2code/foxloader/loader/LoadingPlugin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public abstract class LoadingPlugin {
3838
public static final int DISPLAY_FLAG_LIBRARY = 0x01;
3939
public static final int DISPLAY_FLAG_GAME_CONTENT = 0x02;
4040
public static final int DISPLAY_FLAG_MIXIN = 0x04;
41+
public static final int DISPLAY_FLAG_DISABLED = 0x08;
4142
private final String id;
4243
JavaModInfo javaModInfo;
4344

loader/src/main/java/com/fox2code/foxloader/loader/ModContainer.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@
4040
import java.util.logging.Logger;
4141

4242
public final class ModContainer {
43-
4443
private static final FastThreadLocal<ModContainer> activeModContainer = new FastThreadLocal<>();
44+
// Don't allow some display flags to be set directly by loading plugins
45+
private static final int DISPLAY_FLAGS_PRIVILEGED = (LoadingPlugin.DISPLAY_FLAG_DISABLED);
4546
// tmp is used to make getModContainer work in constructor.
4647
static ModContainer tmp;
4748
private final LoadingPlugin loadingPlugin;
@@ -50,6 +51,7 @@ public final class ModContainer {
5051
private final org.slf4j.Logger slf4jLogger;
5152
private final String modId;
5253
private int modDisplayFlags;
54+
private boolean modDisabled;
5355
private Object configObject;
5456
Mod mod;
5557

@@ -59,7 +61,7 @@ public final class ModContainer {
5961
this.logger = Logger.getLogger(modInfo.name);
6062
this.slf4jLogger = org.slf4j.LoggerFactory.getLogger(modInfo.name);
6163
this.modId = modInfo.id;
62-
this.modDisplayFlags = this.loadingPlugin.getModDisplayFlags(this);
64+
this.modDisplayFlags = this.loadingPlugin.getModDisplayFlags(this) & ~DISPLAY_FLAGS_PRIVILEGED;
6365
}
6466

6567
private ModContainer markActive() {
@@ -135,7 +137,9 @@ void setConfigObject(@Nullable Object configObject) {
135137
}
136138

137139
void preLoadContainer() throws Exception {
138-
this.loadingPlugin.preLoadModContainer(this);
140+
if (!this.isModDisabled()) {
141+
this.loadingPlugin.preLoadModContainer(this);
142+
}
139143
}
140144

141145
public void onReceiveDataFromClient(@NotNull NetworkManager connection, byte @NotNull [] data) {
@@ -176,6 +180,9 @@ Mod initializeMod() throws Exception {
176180
if (this == ModLoaderInit.FOX_LOADER_CONTAINER) {
177181
return this.mod = new ModLoader();
178182
}
183+
if (this.isModDisabled()) {
184+
return null;
185+
}
179186
Mod newMod;
180187
try {
181188
tmp = this;
@@ -202,7 +209,16 @@ void markAddMixin() {
202209
}
203210

204211
private AbstractUpdater makeModContainerUpdater() {
205-
return this.loadingPlugin.makeModContainerUpdater(this);
212+
return this.isModDisabled() ? null : this.loadingPlugin.makeModContainerUpdater(this);
213+
}
214+
215+
public boolean isModDisabled() {
216+
return this.modDisabled;
217+
}
218+
219+
void markModDisabled() {
220+
this.modDisabled = true;
221+
this.modDisplayFlags |= LoadingPlugin.DISPLAY_FLAG_DISABLED;
206222
}
207223

208224
static void initializeUpdateManager() {

loader/src/main/java/com/fox2code/foxloader/loader/ModLoaderInit.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,19 @@ private EarlyModRegistryInfo(LoadingPlugin loadingPlugin, ModInfo modInfo, boole
524524
private void register(HashSet<String> loadedBundles) {
525525
loadDependencyBundlesForMod(loadedBundles, this.modInfo);
526526
FoxLauncher.getFoxClassLoader().addFileToClassLoader(this.modInfo);
527-
modContainers.put(this.modInfo.id, new ModContainer(this.loadingPlugin, this.modInfo));
527+
ModContainer modContainer = new ModContainer(this.loadingPlugin, this.modInfo);
528+
modContainers.put(this.modInfo.id, modContainer);
529+
if ("client".equals(this.modInfo.environment)) {
530+
if (!FoxLauncher.isClient()) {
531+
modContainer.markModDisabled();
532+
}
533+
} else if ("server".equals(this.modInfo.environment)) {
534+
if (!FoxLauncher.isServer()) {
535+
modContainer.markModDisabled();
536+
}
537+
} else if (!"any".equals(this.modInfo.environment)) {
538+
modContainer.markModDisabled();
539+
}
528540
}
529541
}
530542

171 Bytes
Loading

0 commit comments

Comments
 (0)