Skip to content

Commit

Permalink
enable mod configuration screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheaterpaul committed Aug 11, 2024
1 parent 457bcad commit 6e3f164
Show file tree
Hide file tree
Showing 24 changed files with 557 additions and 196 deletions.
14 changes: 13 additions & 1 deletion src/lib/java/de/teamlapen/lib/lib/util/UtilLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.locale.Language;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -693,6 +693,18 @@ public static boolean isValidResourceLocation(@NotNull String loc) {
return ResourceLocation.tryParse(loc) != null;
}

public static boolean checkRegistryObjectExistence(ResourceKey<? extends Registry<?>> key, Object obj) {
if (obj instanceof String string) {
ResourceLocation id = ResourceLocation.tryParse(string);
if (id != null) {
if (ServerLifecycleHooks.getCurrentServer() != null) {
return ServerLifecycleHooks.getCurrentServer().registryAccess().registryOrThrow(key).containsKey(id);
}
}
}
return false;
}

/**
* Replace an entity with a new one. Removes the old ones, adds the new one to the same world. Fires the respective Forge event
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public static void onConfigChanged(@NotNull ModConfigEvent event) {
* @return true if the order is valid
*/
public static boolean testActions(Object string) {
if (string == null) return false;
try {
GSON.fromJson((String) string, ACTION_TOKEN);
} catch (JsonSyntaxException | ClassCastException | IllegalArgumentException e) {
Expand All @@ -103,6 +104,7 @@ public static boolean testActions(Object string) {
* @return true if the order is valid
*/
public static boolean testTasks(Object string) {
if (string == null) return false;
try {
GSON.fromJson((String) string, MINION_TASK_TOKEN);
} catch (JsonSyntaxException | ClassCastException | IllegalArgumentException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import de.teamlapen.vampirism.api.VampirismAPI;
import de.teamlapen.vampirism.api.client.VIngameOverlays;
import de.teamlapen.vampirism.blocks.LogBlock;
import de.teamlapen.vampirism.client.config.ModFilter;
import de.teamlapen.vampirism.client.core.*;
import de.teamlapen.vampirism.client.gui.ScreenEventHandler;
import de.teamlapen.vampirism.client.gui.overlay.*;
Expand All @@ -25,6 +26,8 @@
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import net.neoforged.neoforge.client.gui.ConfigurationScreen;
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.AddReloadListenerEvent;
import net.neoforged.neoforge.event.level.LevelEvent;
Expand Down Expand Up @@ -57,6 +60,8 @@ public VampirismModClient(IEventBus modEventBus, ModContainer modContainer) {
this.renderHandler = new RenderHandler(Minecraft.getInstance());
this.modEventBus.register(this);

this.modContainer.registerExtensionPoint(IConfigScreenFactory.class, (container, parent) -> new ConfigurationScreen(container, parent, new ModFilter()));

NeoForge.EVENT_BUS.addListener(this::onAddReloadListenerEvent);
NeoForge.EVENT_BUS.addListener(this::onDataMapsUpdated);
NeoForge.EVENT_BUS.register(this.overlay);
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/de/teamlapen/vampirism/client/config/ModFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package de.teamlapen.vampirism.client.config;

import net.neoforged.neoforge.client.gui.ConfigurationScreen.ConfigurationSectionScreen.Context;
import net.neoforged.neoforge.client.gui.ConfigurationScreen.ConfigurationSectionScreen.Element;
import net.neoforged.neoforge.client.gui.ConfigurationScreen.ConfigurationSectionScreen.Filter;
import org.jetbrains.annotations.Nullable;

import javax.annotation.ParametersAreNonnullByDefault;

@ParametersAreNonnullByDefault
public class ModFilter implements Filter {

@Override
public @Nullable Element filterEntry(Context context, String key, Element original) {
return switch (key) {
case "integrationsNotifier", "optifineBloodvisionWarning", "actionOrder", "minionTaskOrder", "infoAboutGuideAPI", "oldVampireBiomeGen" -> null;
default -> original;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,29 @@ public class ActionCooldownOverlay implements LayeredDraw.Layer {

@Override
public void render(@NotNull GuiGraphics graphics, DeltaTracker partialTicks) {
if (this.mc.player != null) {
if (this.mc.player != null && VampirismConfig.CLIENT.enableHudActionCooldownRendering.get()) {
VampirismAPI.factionPlayerHandler(this.mc.player).getCurrentFactionPlayer().ifPresent(factionPlayer -> {
IActionHandler<?> actionHandler = factionPlayer.getActionHandler();

int y = this.mc.getWindow().getGuiScaledHeight() - 27;
int x = this.mc.getWindow().getGuiScaledWidth() - 12 - 16;

if (!VampirismConfig.CLIENT.disableHudActionCooldownRendering.get()) {
//noinspection rawtypes
for (IAction action : factionPlayer.getActionHandler().getUnlockedActions()) {
if (!(action.showHudCooldown(this.mc.player))) continue;
// noinspection unchecked
if (!actionHandler.isActionOnCooldown(action)) continue;
ResourceLocation id = RegUtil.id(action);
ResourceLocation loc = id.withPath("textures/actions/" + id.getPath() + ".png");
//noinspection unchecked
int perc = (int) ((1 + actionHandler.getPercentageForAction(action)) * 16);
//render gray transparent background for remaining cooldown
graphics.fillGradient(x, y + perc, x + 16, y + 16, 0x44888888/*Color.GRAY - 0xBB000000 */, 0x44888888/*Color.GRAY - 0xBB000000 */);
//render action icon transparent
graphics.setColor(1, 1, 1, 0.5f);
graphics.blit(loc, x, y, 0, 0, 0, 16, 16, 16, 16);
graphics.setColor(1, 1, 1, 1);
x -= 17;
}
//noinspection rawtypes
for (IAction action : factionPlayer.getActionHandler().getUnlockedActions()) {
if (!(action.showHudCooldown(this.mc.player))) continue;
// noinspection unchecked
if (!actionHandler.isActionOnCooldown(action)) continue;
ResourceLocation id = RegUtil.id(action);
ResourceLocation loc = id.withPath("textures/actions/" + id.getPath() + ".png");
//noinspection unchecked
int perc = (int) ((1 + actionHandler.getPercentageForAction(action)) * 16);
//render gray transparent background for remaining cooldown
graphics.fillGradient(x, y + perc, x + 16, y + 16, 0x44888888/*Color.GRAY - 0xBB000000 */, 0x44888888/*Color.GRAY - 0xBB000000 */);
//render action icon transparent
graphics.setColor(1, 1, 1, 0.5f);
graphics.blit(loc, x, y, 0, 0, 0, 16, 16, 16, 16);
graphics.setColor(1, 1, 1, 1);
x -= 17;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,30 @@ public class ActionDurationOverlay implements LayeredDraw.Layer {

@Override
public void render(@NotNull GuiGraphics graphics, @NotNull DeltaTracker partialTicks) {
if (this.mc.player != null) {
if (this.mc.player != null && VampirismConfig.CLIENT.enableHudActionDurationRendering.get()) {
VampirismAPI.factionPlayerHandler(this.mc.player).getCurrentFactionPlayer().ifPresent(factionPlayer -> {
IActionHandler<?> actionHandler = factionPlayer.getActionHandler();

int x = 12;
int y = this.mc.getWindow().getGuiScaledHeight() - 27;

if (!VampirismConfig.CLIENT.disableHudActionDurationRendering.get()) {
//noinspection rawtypes
for (IAction action : factionPlayer.getActionHandler().getUnlockedActions()) {
if (!(action instanceof ILastingAction)) continue;
if (!(((ILastingAction<?>) action).showHudDuration(this.mc.player))) continue;
//noinspection unchecked,rawtypes
if (!actionHandler.isActionActive(((ILastingAction) action))) continue;
ResourceLocation id = RegUtil.id(action);
ResourceLocation loc = id.withPath("textures/actions/" + id.getPath() + ".png");
//noinspection unchecked
int perc = (int) ((1 - actionHandler.getPercentageForAction(action)) * 16);
//render gray transparent background for remaining duration
graphics.fillGradient(x, y + perc, x + 16, y + 16, 0x44888888/*Color.GRAY - 0xBB000000 */, 0x44888888/*Color.GRAY - 0xBB000000 */);
//render action icon transparent
graphics.setColor(1, 1, 1, 0.5f);
graphics.blit(loc, x, y, 0, 0, 0, 16, 16, 16, 16);
graphics.setColor(1, 1, 1, 1f);
x += 17;
}
//noinspection rawtypes
for (IAction action : factionPlayer.getActionHandler().getUnlockedActions()) {
if (!(action instanceof ILastingAction)) continue;
if (!(((ILastingAction<?>) action).showHudDuration(this.mc.player))) continue;
//noinspection unchecked,rawtypes
if (!actionHandler.isActionActive(((ILastingAction) action))) continue;
ResourceLocation id = RegUtil.id(action);
ResourceLocation loc = id.withPath("textures/actions/" + id.getPath() + ".png");
//noinspection unchecked
int perc = (int) ((1 - actionHandler.getPercentageForAction(action)) * 16);
//render gray transparent background for remaining duration
graphics.fillGradient(x, y + perc, x + 16, y + 16, 0x44888888/*Color.GRAY - 0xBB000000 */, 0x44888888/*Color.GRAY - 0xBB000000 */);
//render action icon transparent
graphics.setColor(1, 1, 1, 0.5f);
graphics.blit(loc, x, y, 0, 0, 0, 16, 16, 16, 16);
graphics.setColor(1, 1, 1, 1f);
x += 17;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import de.teamlapen.vampirism.api.entity.player.actions.IActionHandler;
import de.teamlapen.vampirism.api.entity.player.vampire.IVampirePlayer;
import de.teamlapen.vampirism.api.util.VResourceLocation;
import de.teamlapen.vampirism.config.VampirismConfig;
import de.teamlapen.vampirism.entity.player.vampire.VampirePlayer;
import de.teamlapen.vampirism.entity.player.vampire.actions.VampireActions;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
Expand All @@ -17,9 +17,11 @@ public class BatOverlay extends TextureOverlay {

@Override
public void render(@NotNull GuiGraphics graphics, @NotNull DeltaTracker deltaTracker) {
IActionHandler<IVampirePlayer> actionHandler = VampirePlayer.get(Minecraft.getInstance().player).getActionHandler();
if (actionHandler.isActionActive(VampireActions.BAT.get())) {
renderTextureOverlay(graphics, BAT_TEXTURE, 1.0F);
if (this.mc.player != null && VampirismConfig.CLIENT.enableHudBatOverlayRendering.get()) {
IActionHandler<IVampirePlayer> actionHandler = VampirePlayer.get(this.mc.player).getActionHandler();
if (actionHandler.isActionActive(VampireActions.BAT.get())) {
renderTextureOverlay(graphics, BAT_TEXTURE, 1.0F);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.teamlapen.vampirism.client.gui.overlay;

import de.teamlapen.vampirism.REFERENCE;
import de.teamlapen.vampirism.api.entity.player.vampire.IBloodStats;
import de.teamlapen.vampirism.api.util.VResourceLocation;
import de.teamlapen.vampirism.entity.player.vampire.VampirePlayer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.blaze3d.systems.RenderSystem;
import de.teamlapen.lib.util.Color;
import de.teamlapen.vampirism.api.util.VResourceLocation;
import de.teamlapen.vampirism.config.VampirismConfig;
import de.teamlapen.vampirism.mixin.client.accessor.BossHealthOverlayAccessor;
import de.teamlapen.vampirism.mixin.client.accessor.BossOverlayGuiAccessor;
import de.teamlapen.vampirism.network.ClientboundUpdateMultiBossEventPacket;
Expand Down Expand Up @@ -49,6 +50,9 @@ public void read(@NotNull ClientboundUpdateMultiBossEventPacket packet) {

@Override
public void render(GuiGraphics graphics, DeltaTracker partialTicks) {
if (!VampirismConfig.CLIENT.enableVillageRaidOverlayRendering.get()) {
return;
}
int i = Minecraft.getInstance().getWindow().getGuiScaledWidth();
int j = 12 + ((BossOverlayGuiAccessor) this.client.gui.getBossOverlay()).getMapBossInfos().size() * (10 + this.client.font.lineHeight);
for (MultiBossEvent value : bossInfoMap.values()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package de.teamlapen.vampirism.client.gui.overlay;

import de.teamlapen.vampirism.api.util.VResourceLocation;
import de.teamlapen.vampirism.config.VampirismConfig;
import de.teamlapen.vampirism.entity.player.IVampirismPlayer;
import de.teamlapen.vampirism.entity.player.hunter.HunterPlayerSpecialAttribute;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
Expand All @@ -15,12 +15,14 @@ public class DisguiseOverlay extends TextureOverlay {

@Override
public void render(@NotNull GuiGraphics graphics, @NotNull DeltaTracker deltaTracker) {
HunterPlayerSpecialAttribute huntSpecial = ((IVampirismPlayer) Minecraft.getInstance().player).getVampAtts().getHuntSpecial();
if (huntSpecial.isDisguised()) {
graphics.pose().pushPose();
scaleBy(huntSpecial.getDisguiseProgress(), 1/4f, 2F, 1.0F, graphics);
renderTextureOverlay(graphics, DISGUISE_TEXTURE, 1.0F);
graphics.pose().popPose();
if (this.mc.player != null && VampirismConfig.CLIENT.enableDisguiseOverlayRendering.get()) {
HunterPlayerSpecialAttribute huntSpecial = ((IVampirismPlayer) this.mc.player).getVampAtts().getHuntSpecial();
if (huntSpecial.isDisguised()) {
graphics.pose().pushPose();
scaleBy(huntSpecial.getDisguiseProgress(), 1 / 4f, 2F, 1.0F, graphics);
renderTextureOverlay(graphics, DISGUISE_TEXTURE, 1.0F);
graphics.pose().popPose();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class FactionLevelOverlay implements LayeredDraw.Layer {

@Override
public void render(@NotNull GuiGraphics graphics, @NotNull DeltaTracker partialTicks) {
if (this.mc.player != null && this.mc.player.isAlive() && this.mc.player.jumpableVehicle() == null && !this.mc.options.hideGui) {
if (this.mc.player != null && this.mc.player.isAlive() && this.mc.player.jumpableVehicle() == null && !this.mc.options.hideGui && VampirismConfig.CLIENT.enableFactionLevelOverlayRendering.get()) {
FactionPlayerHandler handler = FactionPlayerHandler.get(this.mc.player);
IPlayableFaction<?> faction = handler.getCurrentFaction();
if (this.mc.gameMode != null && this.mc.gameMode.hasExperience() && faction != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.teamlapen.vampirism.client.gui.overlay;

import de.teamlapen.vampirism.api.util.VResourceLocation;
import de.teamlapen.vampirism.config.VampirismConfig;
import de.teamlapen.vampirism.entity.player.IVampirismPlayer;
import de.teamlapen.vampirism.entity.player.hunter.HunterPlayerSpecialAttribute;
import net.minecraft.client.DeltaTracker;
Expand All @@ -15,12 +16,14 @@ public class NearbyVampireOverlay extends TextureOverlay {

@Override
public void render(@NotNull GuiGraphics graphics, @NotNull DeltaTracker deltaTracker) {
HunterPlayerSpecialAttribute huntSpecial = ((IVampirismPlayer) Minecraft.getInstance().player).getVampAtts().getHuntSpecial();
if (huntSpecial.isVampireNearby()) {
graphics.pose().pushPose();
scaleBy(huntSpecial.getVampireNearbyProgress(), 1/4f, 2F, 1.0F, graphics);
renderTextureOverlay(graphics, AWARENESS_TEXTURE, 1.0F);
graphics.pose().popPose();
if (this.mc.player != null && VampirismConfig.CLIENT.enableNearbyVampireOverlayRendering.get()) {
HunterPlayerSpecialAttribute huntSpecial = ((IVampirismPlayer) Minecraft.getInstance().player).getVampAtts().getHuntSpecial();
if (huntSpecial.isVampireNearby()) {
graphics.pose().pushPose();
scaleBy(huntSpecial.getVampireNearbyProgress(), 1 / 4f, 2F, 1.0F, graphics);
renderTextureOverlay(graphics, AWARENESS_TEXTURE, 1.0F);
graphics.pose().popPose();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.teamlapen.vampirism.client.gui.overlay;

import de.teamlapen.vampirism.api.util.VResourceLocation;
import de.teamlapen.vampirism.config.VampirismConfig;
import de.teamlapen.vampirism.entity.player.vampire.VampirePlayer;
import de.teamlapen.vampirism.entity.player.vampire.actions.VampireActions;
import net.minecraft.client.DeltaTracker;
Expand All @@ -15,8 +16,10 @@ public class RageOverlay extends TextureOverlay {

@Override
public void render(@NotNull GuiGraphics graphics, @NotNull DeltaTracker deltaTracker) {
if (VampirePlayer.get(Minecraft.getInstance().player).getActionHandler().isActionActive(VampireActions.VAMPIRE_RAGE.get())) {
renderTextureOverlay(graphics, RAGE_TEXTURE, 1.0F);
if (this.mc.player != null && VampirismConfig.CLIENT.enableRageOverlayRendering.get()) {
if (VampirePlayer.get(Minecraft.getInstance().player).getActionHandler().isActionActive(VampireActions.VAMPIRE_RAGE.get())) {
renderTextureOverlay(graphics, RAGE_TEXTURE, 1.0F);
}
}
}
}
Loading

3 comments on commit 6e3f164

@maxanier
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reordering the configuration, does break existing configs, right?
I would prefer to guarantee users and pack creators some stability.
If for instance somebody changed the gui level indicator in some pack to add compatibility with another pack mod, this config would be ignored when upgrading to this version.

Of course it is always annoying if there is such a change, so ideally we can avoid it. If required, maybe it can be postponed until a major version update, or if not, at least some sort of warning could be issued.

@maxanier
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side-note: When trying to check if the villageTotemWeight still works when moved to server config, I was not able to find any totem in a village. Neither before nor with this commit.

@maxanier
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the config GUI is convenient :)

Please sign in to comment.