Skip to content

Commit

Permalink
this mod conflict with essential
Browse files Browse the repository at this point in the history
  • Loading branch information
JieningYu committed Dec 30, 2022
1 parent cf188ce commit d61a9e8
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 28 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ indent_style = tab
ij_continuation_indent_size = 8
ij_java_class_count_to_use_import_on_demand = 99
ij_java_names_count_to_use_import_on_demand = 99
ij_java_imports_layout = $*,|,java.**,|,javax.**,|,org.**,|,com.**,|,*
9 changes: 8 additions & 1 deletion src/main/java/com/dm/earth/cabricality/Cabricality.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import java.util.Arrays;

import com.dm.earth.cabricality.util.func.CabfBlur;
import com.dm.earth.cabricality.util.mod.CabfModConflict;
import com.dm.earth.cabricality.util.PushUtil;

import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.quiltmc.loader.api.ModContainer;
import org.quiltmc.loader.api.entrypoint.PreLaunchEntrypoint;
import org.quiltmc.loader.api.minecraft.ClientOnly;
import org.quiltmc.qsl.base.api.entrypoint.ModInitializer;
import org.quiltmc.qsl.item.group.api.QuiltItemGroup;
Expand Down Expand Up @@ -38,7 +40,7 @@
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

public class Cabricality implements ModInitializer {
public class Cabricality implements ModInitializer, PreLaunchEntrypoint {
public static final String NAME = "Cabricality";
public static final String ID = "cabricality";
public static final Logger LOGGER = LoggerFactory.getLogger(ID);
Expand Down Expand Up @@ -122,4 +124,9 @@ public void onInitialize(ModContainer mod) {
private static void initClientAssets() {
RRPCallback.AFTER_VANILLA.register(list -> list.add(CLIENT_RESOURCES));
}

@Override
public void onPreLaunch(ModContainer mod) {
CabfModConflict.checkAndExit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import com.dm.earth.cabricality.Cabricality;

import com.dm.earth.cabricality.util.mod.ModDeps;
import com.dm.earth.cabricality.util.mod.CabfModDeps;

import org.jetbrains.annotations.Nullable;
import org.quiltmc.loader.api.QuiltLoader;
Expand Down Expand Up @@ -35,25 +35,25 @@
@SuppressWarnings("all")
public class MissingModScreen extends Screen {
@Nullable
private final ArrayList<ModDeps> missingMods;
private final ArrayList<CabfModDeps> missingMods;
@Nullable
private final Screen parent;
private final boolean renderBackgroundTexture;

public MissingModScreen(@Nullable ArrayList<ModDeps> missingMods) {
public MissingModScreen(@Nullable ArrayList<CabfModDeps> missingMods) {
this(missingMods, null, MinecraftClient.getInstance().world == null);
}

public MissingModScreen(@Nullable ArrayList<ModDeps> missingMods, @Nullable Screen parent) {
public MissingModScreen(@Nullable ArrayList<CabfModDeps> missingMods, @Nullable Screen parent) {
this(missingMods, parent, MinecraftClient.getInstance().world == null);
}

public MissingModScreen(@Nullable ArrayList<ModDeps> missingMods, boolean renderBackgroundTexture) {
public MissingModScreen(@Nullable ArrayList<CabfModDeps> missingMods, boolean renderBackgroundTexture) {
this(missingMods, null, renderBackgroundTexture);
}

public MissingModScreen(
@Nullable ArrayList<ModDeps> missingMods,
@Nullable ArrayList<CabfModDeps> missingMods,
@Nullable Screen parent, boolean renderBackgroundTexture
) {
super(Cabricality.genTranslatableText("screen", "missing_mod", "title" + (missingMods.size() == 1 ? "" : "_plural")));
Expand Down Expand Up @@ -163,7 +163,7 @@ private void scale(MatrixStack matrixStack, float scale) {
matrixStack.scale(scale, scale, scale);
}

private void modDownloadButton(ModDeps mod, Text text, int y) {
private void modDownloadButton(CabfModDeps mod, Text text, int y) {
this.addDrawableChild(
new PlainTextButtonWidget(
this.width / 2 - this.textRenderer.getWidth(text) / 2, y,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import com.dm.earth.cabricality.Cabricality;
import com.dm.earth.cabricality.client.screen.MissingModScreen;
import com.dm.earth.cabricality.util.mod.ModDeps;
import com.dm.earth.cabricality.util.mod.CabfModDeps;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
Expand All @@ -24,10 +24,10 @@
public abstract class MinecraftClientMixin {
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;setScreen(Lnet/minecraft/client/gui/screen/Screen;)V"))
private void checkMods(MinecraftClient client, Screen screen) {
if (!ModDeps.isAllLoaded())
if (!CabfModDeps.isAllLoaded())
// If not full loaded, set screen to MissingModScreen
client.setScreen(
new MissingModScreen(ModDeps.getAllMissing(), ModDeps.isLoaded(true, false) ? screen : null)
new MissingModScreen(CabfModDeps.getAllMissing(), CabfModDeps.isLoaded(true, false) ? screen : null)
);
else client.setScreen(screen);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.dm.earth.cabricality.Cabricality;
import com.dm.earth.cabricality.client.screen.MissingModScreen;
import com.dm.earth.cabricality.util.mod.ModDeps;
import com.dm.earth.cabricality.util.mod.CabfModDeps;

import com.mojang.blaze3d.systems.RenderSystem;

Expand Down Expand Up @@ -32,13 +32,13 @@ protected TitleScreenMixin(Text title) {
// Redirects the title screen to the missing mod screen if mods are missing
@Inject(method = "init", at = @At("TAIL"))
private void init(CallbackInfo ci) {
if (!ModDeps.isAllLoaded()) {
if (!CabfModDeps.isAllLoaded()) {
Text warning = (
ModDeps.getAllMissing().size() == 1
CabfModDeps.getAllMissing().size() == 1
? Cabricality.genTranslatableText("screen", "title_screen", "warning_missing_mod")
: new TranslatableText(
Cabricality.genTranslationKey("screen", "title_screen", "warning_missing_mod_plural"),
ModDeps.getAllMissing().size())
CabfModDeps.getAllMissing().size())
)
.formatted(Formatting.RED);
this.addDrawableChild(
Expand All @@ -47,7 +47,7 @@ private void init(CallbackInfo ci) {
this.textRenderer.getWidth(warning), 10, warning,
buttonWidget -> {
if (this.client != null)
this.client.setScreen(new MissingModScreen(ModDeps.getAllMissing(), this.client.currentScreen));
this.client.setScreen(new MissingModScreen(CabfModDeps.getAllMissing(), this.client.currentScreen));
}, this.textRenderer
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import org.quiltmc.loader.api.ModContainer;
import org.quiltmc.qsl.base.api.entrypoint.server.DedicatedServerModInitializer;

import com.dm.earth.cabricality.util.mod.ModDeps;
import com.dm.earth.cabricality.util.mod.CabfModDeps;

public class CabricalityServer implements DedicatedServerModInitializer {
@Override
public void onInitializeServer(ModContainer mod) {
if (ModDeps.isLoaded(true, true))
throw new RuntimeException(ModDeps.asString(true, true) + " is missing for " + Cabricality.NAME + "!");
else if (ModDeps.isLoaded(false, true))
CabfLogger.logWarn("Recommended mods " + ModDeps.asString(false, true) + " is missing for " + Cabricality.NAME + "!");
if (CabfModDeps.isLoaded(true, true))
throw new RuntimeException(CabfModDeps.asString(true, true) + " is missing for " + Cabricality.NAME + "!");
else if (CabfModDeps.isLoaded(false, true))
CabfLogger.logWarn("Recommended mods " + CabfModDeps.asString(false, true) + " is missing for " + Cabricality.NAME + "!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.dm.earth.cabricality.util.mod;

import java.util.stream.Stream;
import org.quiltmc.loader.api.QuiltLoader;

public enum CabfModConflict {
ESSENTIAL("essential-loader");

final String modId;

CabfModConflict(String modId) {
this.modId = modId;
}

public String getModId() {
return modId;
}

public boolean isLoaded() {
return QuiltLoader.isModLoaded(modId);
}

public static boolean isAnyLoaded() {
return Stream.of(values()).anyMatch(CabfModConflict::isLoaded);
}

public static void checkAndExit() {
if (isAnyLoaded()) {
System.exit(6);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Util;

public enum ModDeps {
public enum CabfModDeps {
FTB_LIBRARY("ftblibrary", new TranslatableText("mod.ftblibrary.name"),
"https://www.curseforge.com/minecraft/mc-mods/ftb-library-fabric/download/4210934/file",
false, false), // ftb-library-fabric-1802.3.9-build.167.jar
Expand All @@ -37,7 +37,7 @@ public enum ModDeps {
private final boolean required;
private final boolean isClient;

ModDeps(String id, Text name, String url, boolean required, boolean isClient) {
CabfModDeps(String id, Text name, String url, boolean required, boolean isClient) {
this.modId = id;
this.name = name;
this.required = required;
Expand Down Expand Up @@ -97,20 +97,20 @@ public boolean matchesSide(boolean isServer) {
return !isServer || !isClient;
}

public static Stream<ModDeps> stream() {
public static Stream<CabfModDeps> stream() {
return Arrays.stream(values());
}

private static ArrayList<ModDeps> arrayList(Stream<ModDeps> stream) {
private static ArrayList<CabfModDeps> arrayList(Stream<CabfModDeps> stream) {
return stream.collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
}

public static ArrayList<ModDeps> getMissing(boolean required, boolean isServer) {
public static ArrayList<CabfModDeps> getMissing(boolean required, boolean isServer) {
return arrayList(stream().filter(dep -> (dep.isRequired() || !required)
&& dep.matchesSide(isServer) && !dep.isLoaded()));
}

public static ArrayList<ModDeps> getAllMissing() {
public static ArrayList<CabfModDeps> getAllMissing() {
return arrayList(stream().filter(dep -> !dep.isLoaded()));
}

Expand Down

0 comments on commit d61a9e8

Please sign in to comment.