/// <summary> /// Method that calculates the key conflicts based on the GameState's Game.KeyBindings property. /// Returns an enumerable of all DeviceKeys with a conflict, and whether they are only modifier conflicts (warning). /// Forge shows modifier conflicts in red and soft in orange on the in-game keys menu. /// </summary> private Dictionary <DeviceKeys, bool> CalculateConflicts(GameState_Minecraft state) { Dictionary <DeviceKeys, bool> keys = new Dictionary <DeviceKeys, bool>(); foreach (var bind in state.Game.KeyBindings) // For every key binding // This code is based on the code from Minecraft in "GuiKeyBindingList.java" in the "drawEntry" method. // It may not be the most efficient way of computing conflicts but I'm struggling to entirely follow // the logic in the Minecraft code, so I've decided to replicate it to prevent conflicts { bool hasConflict = false; bool isOnlyModifierConflict = true; foreach (var otherBind in state.Game.KeyBindings) // Check against every other key binding { if (bind != null && otherBind != null) { if (bind != otherBind && otherBind.ConflictsWith(bind)) { hasConflict = true; isOnlyModifierConflict &= otherBind.ModifierConflictsWith(bind); } } } // End replicated section if (hasConflict) { foreach (var affectedKey in bind.AffectedKeys) // For each key that is affected by this keybind { keys[affectedKey] = keys.ContainsKey(affectedKey) // Check if this key is already flagged as a conflict ? keys[affectedKey] && isOnlyModifierConflict // If so, ensure it shows full conflicts over modifier conflicts : isOnlyModifierConflict; // Else if not already flagged, simply set it. } } } return(keys); }
public override EffectLayer Render(IGameState gamestate) { // Ensure the gamestate is for Minecraft, and store a casted reference to it if (!(gamestate is GameState_Minecraft)) { return(new EffectLayer()); } GameState_Minecraft state = gamestate as GameState_Minecraft; // Choose the main healthbar's color depending on whether the player is withered/poisoned/regen/normal. Color barColor = Properties.NormalHealthColor; // Default normal color if (Properties.EnableWitherHealthColor && state.Player.PlayerEffects.HasWither) // Wither takes priority over others { barColor = Properties.WitherHealthColor; } else if (Properties.EnablePoisonHealthColor && state.Player.PlayerEffects.HasPoison) // Poison 2nd priority { barColor = Properties.PoisonHealthColor; } else if (Properties.EnableRegenerationHealthColor && state.Player.PlayerEffects.HasRegeneration) // Regen 3rd priority { barColor = Properties.RegenerationHealthColor; } // Render the main healthbar, with the color decided above. EffectLayer layer = new EffectLayer() .PercentEffect(barColor, Properties.BackgroundColor, Properties.Sequence, state.Player.Health, state.Player.HealthMax, Settings.PercentEffectType.Progressive); // If absorption is enabled, overlay the absorption display on the top of the original healthbar if (Properties.EnableAbsorptionHealthColor) { layer.PercentEffect(Properties.AbsorptionHealthColor, Properties.BackgroundColor, Properties.Sequence, state.Player.Absorption, state.Player.AbsorptionMax, Properties.GradualProgress ? Settings.PercentEffectType.Progressive_Gradual : Settings.PercentEffectType.Progressive); } return(layer); }