HitSounds module

HitSounds: Minecraft 26.3 cheat module, full source for every implementation (1 client: Combatant).

1 implementationMISC

Clients with this module

Full module source: 1 implementation

Every implementation below is the complete module file, verbatim. Expand a client to read its code.

CombatantMISCsrc/main/java/combatant/client/features/module/modules/misc/HitSounds.javaJava · 177 lines · 6.3 KB
Settingshitsounds_sourceshitsounds_volumehitsounds_players_soundhitsounds_groups_enabledhitsounds_friend_soundhitsounds_enemy_soundhitsounds_staff_soundhitsounds_entities_soundhitsounds_entities_override_ignoredhitsounds_entities_ignored_sound
HitSounds.javaJava · Minecraft 26.2 · 177 lines · 6.3 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Combatant Client distribution.
3
 * Copyright (c) 2026 pivosos2007.
4
 *
5
 * Licensed under the GNU General Public License v3.0.
6
 */
7
8
package combatant.client.features.module.modules.misc;
9
10
import net.minecraft.world.entity.Entity;
11
import net.minecraft.world.entity.player.Player;
12
import combatant.client.config.DisableSettingI18n;
13
import combatant.client.config.values.BooleanMapValue;
14
import combatant.client.config.values.BooleanValue;
15
import combatant.client.config.values.EnumValue;
16
import combatant.client.config.values.NumberValue;
17
import combatant.client.features.module.Module;
18
import combatant.client.features.module.ModuleCategory;
19
import combatant.client.features.module.ModuleInfo;
20
import combatant.client.features.relations.CategoryRules;
21
import combatant.client.features.relations.CategoryType;
22
import combatant.client.features.relations.EntityFilters;
23
import combatant.client.util.sound.SoundAsset;
24
import combatant.client.util.sound.SoundCatalog;
25
import combatant.client.util.sound.SoundKey;
26
import combatant.client.util.sound.SoundOptions;
27
28
//todo Description
29
@ModuleInfo(
30
        id = "hitsounds",
31
        displayName = "HitSounds",
32
        category = ModuleCategory.MISC
33
)
34
public class HitSounds extends Module {
35
36
    private static final String SETTING_SOURCES = "sources";
37
    private static final String SETTING_VOLUME = "volume";
38
    private static final String SETTING_DEFAULT_SOUND = "default_sound";
39
    private static final String SETTING_GROUP_OVERRIDES = "group_overrides";
40
    private static final String SETTING_FRIEND_SOUND = "friend_sound";
41
    private static final String SETTING_ENEMY_SOUND = "enemy_sound";
42
    private static final String SETTING_STAFF_SOUND = "staff_sound";
43
    private static final String SETTING_ENTITY_SOUND = "entity_sound";
44
    private static final String SETTING_OVERRIDE_IGNORED = "override_ignored";
45
    private static final String SETTING_IGNORED_ENTITY_SOUND = "ignored_entity_sound";
46
47
    private final BooleanMapValue sources = group(
48
            "hitsounds_sources",
49
            SETTING_SOURCES,
50
            new java.util.LinkedHashMap<>() {{
51
                put("players", true);
52
                put("entities", true);
53
            }}
54
    );
55
    private final NumberValue<Float> volumeValue =
56
            num("hitsounds_volume", SETTING_VOLUME, 1.0f, 0.0f, 1.0f);
57
    @DisableSettingI18n(name = false, options = true)
58
    private final EnumValue<SoundType> playersSound = enumSetting(
59
            "hitsounds_players_sound",
60
            SETTING_DEFAULT_SOUND,
61
            SoundType.BELL,
62
            SoundType.values()
63
    );
64
    private final BooleanValue groupsEnabled =
65
            bool("hitsounds_groups_enabled", SETTING_GROUP_OVERRIDES, true);
66
    @DisableSettingI18n(name = false, options = true)
67
    private final EnumValue<SoundType> friendSound = enumSetting(
68
            "hitsounds_friend_sound",
69
            SETTING_FRIEND_SOUND,
70
            SoundType.BUBBLE,
71
            SoundType.values()
72
    );
73
    @DisableSettingI18n(name = false, options = true)
74
    private final EnumValue<SoundType> enemySound = enumSetting(
75
            "hitsounds_enemy_sound",
76
            SETTING_ENEMY_SOUND,
77
            SoundType.CRITICAL,
78
            SoundType.values()
79
    );
80
    @DisableSettingI18n(name = false, options = true)
81
    private final EnumValue<SoundType> staffSound = enumSetting(
82
            "hitsounds_staff_sound",
83
            SETTING_STAFF_SOUND,
84
            SoundType.CRIME,
85
            SoundType.values()
86
    );
87
88
    @DisableSettingI18n(name = false, options = true)
89
    private final EnumValue<SoundType> entitiesSound = enumSetting(
90
            "hitsounds_entities_sound",
91
            SETTING_ENTITY_SOUND,
92
            SoundType.BONK,
93
            SoundType.values()
94
    );
95
    private final BooleanValue entitiesOverrideIgnored =
96
            bool("hitsounds_entities_override_ignored", SETTING_OVERRIDE_IGNORED, false);
97
    @DisableSettingI18n(name = false, options = true)
98
    private final EnumValue<SoundType> entitiesIgnoredSound = enumSetting(
99
            "hitsounds_entities_ignored_sound",
100
            SETTING_IGNORED_ENTITY_SOUND,
101
            SoundType.BUBBLE,
102
            SoundType.values()
103
    );
104
105
    public void handleHit(Entity target) {
106
        if (!isEnabled() || target == null) return;
107
108
        if (target instanceof Player p) {
109
            if (!sources.get("players")) return;
110
            playForPlayer(p);
111
        } else {
112
            if (!sources.get("entities")) return;
113
            playForEntity(target);
114
        }
115
    }
116
117
118
    private void playForPlayer(Player p) {
119
        if (!groupsEnabled.get()) {
120
            playSoundKey(playersSound.get());
121
            return;
122
        }
123
124
        CategoryType type = CategoryRules.determine(p.getGameProfile().name());
125
        switch (type) {
126
            case FRIEND -> playSoundKey(friendSound.get());
127
            case BEDWARS_SELF -> playSoundKey(friendSound.get());
128
            case ENEMY -> playSoundKey(enemySound.get());
129
            case BEDWARS_ENEMY -> playSoundKey(enemySound.get());
130
            case STAFF -> playSoundKey(staffSound.get());
131
            default -> playSoundKey(playersSound.get());
132
        }
133
    }
134
135
    private void playForEntity(Entity e) {
136
        if (entitiesOverrideIgnored.get()) {
137
            var id = net.minecraft.core.registries.BuiltInRegistries.ENTITY_TYPE.getKey(e.getType());
138
            if (id != null && EntityFilters.get().isIgnoredEntity(id.toString())) {
139
                playSoundKey(entitiesIgnoredSound.get());
140
                return;
141
            }
142
        }
143
        playSoundKey(entitiesSound.get());
144
    }
145
146
    private void playSoundKey(SoundType key) {
147
        if (key == null) return;
148
        double vol = Math.min(1.0, volumeValue.get());
149
        key.play(SoundOptions.gain(vol));
150
    }
151
152
    @SoundCatalog(namespace = "combatant", root = "sounds/hitsounds", idPrefix = "hitsounds")
153
    private enum SoundType implements EnumValue.IdProvider, SoundKey {
154
        @SoundAsset("bell.wav")
155
        BELL("bell"),
156
        @SoundAsset("bonk.wav")
157
        BONK("bonk"),
158
        @SoundAsset("bubble.wav")
159
        BUBBLE("bubble"),
160
        @SoundAsset("crime.wav")
161
        CRIME("crime"),
162
        @SoundAsset("critical.wav")
163
        CRITICAL("critical");
164
165
        private final String id;
166
167
        SoundType(String id) {
168
            this.id = id;
169
        }
170
171
        @Override
172
        public String id() {
173
            return id;
174
        }
175
    }
176
}
177