Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions common/src/main/java/net/darkhax/tipsmod/api/TipsAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.contents.TranslatableContents;
import net.minecraft.resources.ResourceLocation;

import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -45,7 +46,17 @@ public static void registerTipScreen(Class<? extends Screen> screenClass) {

public static boolean canRenderOnScreen(Screen screen) {

return SCREENS.stream().anyMatch(clazz -> clazz.isInstance(screen));
return canRenderOnScreen(screen.getClass());
}

public static boolean canRenderOnScreen(Class<?> clazz) {

return SCREENS.contains(clazz) && !TipsModCommon.CONFIG.ignoredScreens.contains(clazz.getCanonicalName());
}

public static Collection<Class<?>> getTipsScreens() {

return Collections.unmodifiableSet(SCREENS);
}

@Nullable
Expand Down
3 changes: 3 additions & 0 deletions common/src/main/java/net/darkhax/tipsmod/impl/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public class Config {
@Expose
public Component defaultTitle = TipsAPI.DEFAULT_TITLE;

@Expose
public List<String> ignoredScreens = new ArrayList<>();

public static Config load() {

File configFile = Services.PLATFORM.getConfigPath().resolve("tips.json").toFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import net.darkhax.bookshelf.api.serialization.Serializers;
import com.mojang.serialization.JsonOps;
import net.darkhax.tipsmod.api.TipsAPI;
import net.darkhax.tipsmod.api.resources.ITip;
import net.darkhax.tipsmod.api.resources.ITipSerializer;
Expand Down Expand Up @@ -78,6 +79,8 @@ protected void apply(Map<ResourceLocation, JsonElement> map, ResourceManager res
}
});
Collections.shuffle(this.randomAccess);
Constants.LOG.debug("Loaded {} tips. Took {}ms.", this.loadedTips.size(), (double) (System.nanoTime() - startTime) / 1000000d);
Constants.LOG.info("Loaded {} tips. Took {}ms.", this.loadedTips.size(), (double) (System.nanoTime() - startTime) / 1000000d);
Constants.LOG.info("The following screens have been registered to the tips mod.");
TipsAPI.getTipsScreens().forEach(screen -> Constants.LOG.info("Screen: '{}' Enabled: '{}'", screen.getCanonicalName(), TipsAPI.canRenderOnScreen(screen)));
}
}