Skip to content

Commit 42d1495

Browse files
committed
Modify Renderer / Cleanup Config Category code
1 parent 8f14c33 commit 42d1495

File tree

18 files changed

+412
-1302
lines changed

18 files changed

+412
-1302
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* Animatium
3+
* The all-you-could-want legacy animations mod for modern minecraft versions.
4+
* Brings back animations from the 1.7/1.8 era and more.
5+
* <p>
6+
* Copyright (C) 2024-2025 lowercasebtw
7+
* Copyright (C) 2024-2025 mixces
8+
* Copyright (C) 2024-2025 Contributors to the project retain their copyright
9+
* <p>
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
* <p>
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
* <p>
20+
* You should have received a copy of the GNU General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
* <p>
23+
* "MINECRAFT" LINKING EXCEPTION TO THE GPL
24+
*/
25+
26+
package org.visuals.legacy.animatium.config.category;
27+
28+
import dev.isxander.yacl3.api.Option;
29+
import dev.isxander.yacl3.api.OptionDescription;
30+
import dev.isxander.yacl3.api.controller.ControllerBuilder;
31+
import dev.isxander.yacl3.api.controller.EnumControllerBuilder;
32+
import dev.isxander.yacl3.api.controller.FloatSliderControllerBuilder;
33+
import dev.isxander.yacl3.api.controller.TickBoxControllerBuilder;
34+
import net.minecraft.network.chat.Component;
35+
import org.visuals.legacy.animatium.Animatium;
36+
37+
import java.lang.reflect.Field;
38+
import java.util.function.Function;
39+
40+
public abstract class Category {
41+
public static <T extends Category> Option<Boolean> booleanOption(String fieldName, T defaults, T current) {
42+
return option(fieldName, defaults, current, TickBoxControllerBuilder::create);
43+
}
44+
45+
public static <T extends Category, S extends Enum<S>> Option<S> enumOption(String fieldName, T defaults, T current, Class<S> enumClazz) {
46+
return option(fieldName, defaults, current, (opt) -> EnumControllerBuilder.create(opt).enumClass(enumClazz).formatValue(it -> Component.translatable(Animatium.MOD_ID + ".enum." + enumClazz.getSimpleName() + "." + it.name())));
47+
}
48+
49+
public static <T extends Category> Option<Float> floatSliderOption(String fieldName, T defaults, T current, float min, float max, float step) {
50+
return option(fieldName, defaults, current, (opt) -> FloatSliderControllerBuilder.create(opt).range(min, max).step(step));
51+
}
52+
53+
public static <T extends Category, S> Option<S> option(String fieldName, T defaults, T current, Function<Option<S>, ControllerBuilder<S>> controllerBuilder) {
54+
final Reference<S> reference = Reference.get(fieldName, defaults, current);
55+
final String id = Animatium.MOD_ID + "." + fieldName;
56+
return Option.<S>createBuilder()
57+
.name(Component.translatable(id))
58+
.description(OptionDescription.of(Component.translatable(id + ".description")))
59+
.binding(reference.defaultValue,
60+
() -> {
61+
try {
62+
return (S) reference.currentField.get(current);
63+
} catch (IllegalAccessException exception) {
64+
exception.printStackTrace();
65+
return reference.defaultValue;
66+
}
67+
},
68+
(newVal) -> {
69+
try {
70+
reference.currentField.set(current, newVal);
71+
} catch (IllegalAccessException exception) {
72+
exception.printStackTrace();
73+
}
74+
})
75+
.controller(controllerBuilder)
76+
.build();
77+
}
78+
79+
private static class Reference<S> {
80+
public Field defaultField;
81+
public Field currentField;
82+
public S defaultValue;
83+
84+
public static <T extends Category, S> Reference<S> get(String fieldName, T defaults, T current) {
85+
final Reference<S> reference = new Reference<>();
86+
87+
final Class<?> defaultsClazz = defaults.getClass();
88+
try {
89+
reference.defaultField = defaultsClazz.getField(fieldName);
90+
reference.defaultValue = (S) reference.defaultField.get(defaults);
91+
} catch (NoSuchFieldException | IllegalAccessException exception) {
92+
exception.printStackTrace();
93+
}
94+
95+
final Class<?> currentClazz = current.getClass();
96+
try {
97+
reference.currentField = currentClazz.getField(fieldName);
98+
} catch (NoSuchFieldException exception) {
99+
exception.printStackTrace();
100+
}
101+
102+
return reference;
103+
}
104+
}
105+
}

src/main/java/org/visuals/legacy/animatium/config/category/ExtrasConfigCategory.java

Lines changed: 39 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,11 @@
2626
package org.visuals.legacy.animatium.config.category;
2727

2828
import dev.isxander.yacl3.api.ConfigCategory;
29-
import dev.isxander.yacl3.api.Option;
30-
import dev.isxander.yacl3.api.OptionDescription;
31-
import dev.isxander.yacl3.api.controller.TickBoxControllerBuilder;
32-
import net.minecraft.client.Minecraft;
33-
import net.minecraft.client.renderer.texture.OverlayTexture;
29+
import dev.isxander.yacl3.api.OptionGroup;
3430
import net.minecraft.network.chat.Component;
35-
import org.visuals.legacy.animatium.mixins.accessor.GameRendererAccessor;
3631
import org.visuals.legacy.animatium.util.compatibility.Mods;
3732

38-
public class ExtrasConfigCategory {
33+
public class ExtrasConfigCategory extends Category {
3934
public boolean minimalViewBobbing = false;
4035
public boolean showNameTagInThirdPerson = false;
4136
public boolean hideNameTagBackground = false;
@@ -55,186 +50,49 @@ public class ExtrasConfigCategory {
5550
public boolean disableFirstPersonParticles = false;
5651
public boolean dontClearChat = false;
5752
public boolean dontCloseChat = false;
53+
public float itemSwingSpeed = 0.0F;
54+
public float hasteSwingSpeed = 0.0F;
55+
public float miningFatigueSwingSpeed = 0.0F;
56+
public boolean ignoreHasteSpeed = false;
57+
public boolean ignoreMiningFatigueSpeed = false;
5858

5959
public static ConfigCategory setup(final ExtrasConfigCategory defaults, final ExtrasConfigCategory config) {
6060
final ConfigCategory.Builder category = ConfigCategory.createBuilder();
6161
category.name(Component.translatable("animatium.category.extras"));
62-
category.option(Option.<Boolean>createBuilder()
63-
.name(Component.translatable("animatium.minimalViewBobbing"))
64-
.description(OptionDescription.of(Component.translatable("animatium.minimalViewBobbing.description")))
65-
.binding(
66-
defaults.minimalViewBobbing,
67-
() -> config.minimalViewBobbing,
68-
(newVal) -> config.minimalViewBobbing = newVal)
69-
.controller(TickBoxControllerBuilder::create)
70-
.build());
71-
category.option(Option.<Boolean>createBuilder()
72-
.name(Component.translatable("animatium.showNameTagInThirdPerson"))
73-
.description(OptionDescription.of(Component.translatable("animatium.showNameTagInThirdPerson.description")))
74-
.binding(
75-
defaults.showNameTagInThirdPerson,
76-
() -> config.showNameTagInThirdPerson,
77-
(newVal) -> config.showNameTagInThirdPerson = newVal)
78-
.controller(TickBoxControllerBuilder::create)
79-
.build());
80-
category.option(Option.<Boolean>createBuilder()
81-
.name(Component.translatable("animatium.hideNameTagBackground"))
82-
.description(OptionDescription.of(Component.translatable("animatium.hideNameTagBackground.description")))
83-
.binding(
84-
defaults.hideNameTagBackground,
85-
() -> config.hideNameTagBackground,
86-
(newVal) -> config.hideNameTagBackground = newVal)
87-
.controller(TickBoxControllerBuilder::create)
88-
.build());
89-
category.option(Option.<Boolean>createBuilder()
90-
.name(Component.translatable("animatium.nameTagTextShadow"))
91-
.description(OptionDescription.of(Component.translatable("animatium.nameTagTextShadow.description")))
92-
.binding(
93-
defaults.nameTagTextShadow,
94-
() -> config.nameTagTextShadow,
95-
(newVal) -> config.nameTagTextShadow = newVal)
96-
.controller(TickBoxControllerBuilder::create)
97-
.build());
98-
category.option(Option.<Boolean>createBuilder()
99-
.name(Component.translatable("animatium.debugHudTextColor"))
100-
.description(OptionDescription.of(Component.translatable("animatium.debugHudTextColor.description")))
101-
.binding(
102-
defaults.debugHudTextColor,
103-
() -> config.debugHudTextColor,
104-
(newVal) -> config.debugHudTextColor = newVal)
105-
.controller(TickBoxControllerBuilder::create)
106-
.build());
107-
category.option(Option.<Boolean>createBuilder()
108-
.name(Component.translatable("animatium.persistentBlockOutline"))
109-
.description(OptionDescription.of(Component.translatable("animatium.persistentBlockOutline.description")))
110-
.binding(
111-
defaults.persistentBlockOutline,
112-
() -> config.persistentBlockOutline,
113-
(newVal) -> config.persistentBlockOutline = newVal)
114-
.controller(TickBoxControllerBuilder::create)
115-
.build());
116-
category.option(Option.<Boolean>createBuilder()
117-
.name(Component.translatable("animatium.offhandUsageSwinging"))
118-
.description(OptionDescription.of(Component.translatable("animatium.offhandUsageSwinging.description")))
119-
.binding(
120-
defaults.offhandUsageSwinging,
121-
() -> config.offhandUsageSwinging,
122-
(newVal) -> config.offhandUsageSwinging = newVal)
123-
.controller(TickBoxControllerBuilder::create)
124-
.build());
125-
category.option(Option.<Boolean>createBuilder()
126-
.name(Component.translatable("animatium.alwaysUsageSwing"))
127-
.description(OptionDescription.of(Component.translatable("animatium.alwaysUsageSwing.description")))
128-
.binding(
129-
defaults.alwaysUsageSwing,
130-
() -> config.alwaysUsageSwing,
131-
(newVal) -> config.alwaysUsageSwing = newVal)
132-
.controller(TickBoxControllerBuilder::create)
133-
.build());
134-
category.option(Option.<Boolean>createBuilder()
135-
.name(Component.translatable("animatium.alwaysSharpParticles"))
136-
.description(OptionDescription.of(Component.translatable("animatium.alwaysSharpParticles.description")))
137-
.binding(
138-
defaults.alwaysSharpParticles,
139-
() -> config.alwaysSharpParticles,
140-
(newVal) -> config.alwaysSharpParticles = newVal)
141-
.controller(TickBoxControllerBuilder::create)
142-
.build());
62+
category.option(booleanOption("minimalViewBobbing", defaults, config));
63+
category.option(booleanOption("showNameTagInThirdPerson", defaults, config));
64+
category.option(booleanOption("hideNameTagBackground", defaults, config));
65+
category.option(booleanOption("nameTagTextShadow", defaults, config));
66+
category.option(booleanOption("debugHudTextColor", defaults, config));
67+
category.option(booleanOption("persistentBlockOutline", defaults, config));
68+
category.option(booleanOption("offhandUsageSwinging", defaults, config));
69+
category.option(booleanOption("alwaysUsageSwing", defaults, config));
70+
category.option(booleanOption("alwaysSharpParticles", defaults, config));
14371
if (!Mods.HAS_SODIUM_EXTRAS) {
144-
category.option(Option.<Boolean>createBuilder()
145-
.name(Component.translatable("animatium.disableRecipeAndTutorialToasts"))
146-
.description(OptionDescription.of(Component.translatable("animatium.disableRecipeAndTutorialToasts.description")))
147-
.binding(
148-
defaults.disableRecipeAndTutorialToasts,
149-
() -> config.disableRecipeAndTutorialToasts,
150-
(newVal) -> config.disableRecipeAndTutorialToasts = newVal)
151-
.controller(TickBoxControllerBuilder::create)
152-
.build());
72+
category.option(booleanOption("disableRecipeAndTutorialToasts", defaults, config));
15373
}
154-
category.option(Option.<Boolean>createBuilder()
155-
.name(Component.translatable("animatium.showArmWhileInvisible"))
156-
.description(OptionDescription.of(Component.translatable("animatium.showArmWhileInvisible.description")))
157-
.binding(
158-
defaults.showArmWhileInvisible,
159-
() -> config.showArmWhileInvisible,
160-
(newVal) -> config.showArmWhileInvisible = newVal)
161-
.controller(TickBoxControllerBuilder::create)
162-
.build());
163-
category.option(Option.<Boolean>createBuilder()
164-
.name(Component.translatable("animatium.fakeMissPenaltySwing"))
165-
.description(OptionDescription.of(Component.translatable("animatium.fakeMissPenaltySwing.description")))
166-
.binding(
167-
defaults.fakeMissPenaltySwing,
168-
() -> config.fakeMissPenaltySwing,
169-
(newVal) -> config.fakeMissPenaltySwing = newVal)
170-
.controller(TickBoxControllerBuilder::create)
171-
.build());
172-
category.option(Option.<Boolean>createBuilder()
173-
.name(Component.translatable("animatium.dontMoveBlueVoid"))
174-
.description(OptionDescription.of(Component.translatable("animatium.dontMoveBlueVoid.description")))
175-
.binding(
176-
defaults.dontMoveBlueVoid,
177-
() -> config.dontMoveBlueVoid,
178-
(newVal) -> config.dontMoveBlueVoid = newVal)
179-
.controller(TickBoxControllerBuilder::create)
180-
.build());
181-
category.option(Option.<Boolean>createBuilder()
182-
.name(Component.translatable("animatium.disableEntityDeathTopple"))
183-
.description(OptionDescription.of(Component.translatable("animatium.disableEntityDeathTopple.description")))
184-
.binding(
185-
defaults.disableEntityDeathTopple,
186-
() -> config.disableEntityDeathTopple,
187-
(newVal) -> config.disableEntityDeathTopple = newVal)
188-
.controller(TickBoxControllerBuilder::create)
189-
.build());
190-
category.option(Option.<Boolean>createBuilder()
191-
.name(Component.translatable("animatium.deepRedHurtTint"))
192-
.description(OptionDescription.of(Component.translatable("animatium.deepRedHurtTint.description")))
193-
.binding(
194-
defaults.deepRedHurtTint,
195-
() -> config.deepRedHurtTint,
196-
(newVal) -> {
197-
config.deepRedHurtTint = newVal;
198-
((GameRendererAccessor) Minecraft.getInstance().gameRenderer).animatium$setOverlayTexture(new OverlayTexture());
199-
})
200-
.controller(TickBoxControllerBuilder::create)
201-
.build());
202-
category.option(Option.<Boolean>createBuilder()
203-
.name(Component.translatable("animatium.disableParticlePhysics"))
204-
.description(OptionDescription.of(Component.translatable("animatium.disableParticlePhysics.description")))
205-
.binding(
206-
defaults.disableParticlePhysics,
207-
() -> config.disableParticlePhysics,
208-
(newVal) -> config.disableParticlePhysics = newVal)
209-
.controller(TickBoxControllerBuilder::create)
210-
.build());
211-
category.option(Option.<Boolean>createBuilder()
212-
.name(Component.translatable("animatium.disableFirstPersonParticles"))
213-
.description(OptionDescription.of(Component.translatable("animatium.disableFirstPersonParticles.description")))
214-
.binding(
215-
defaults.disableFirstPersonParticles,
216-
() -> config.disableFirstPersonParticles,
217-
(newVal) -> config.disableFirstPersonParticles = newVal)
218-
.controller(TickBoxControllerBuilder::create)
219-
.build());
220-
category.option(Option.<Boolean>createBuilder()
221-
.name(Component.translatable("animatium.dontClearChat"))
222-
.description(OptionDescription.of(Component.translatable("animatium.dontClearChat.description")))
223-
.binding(
224-
defaults.dontClearChat,
225-
() -> config.dontClearChat,
226-
(newVal) -> config.dontClearChat = newVal)
227-
.controller(TickBoxControllerBuilder::create)
228-
.build());
229-
category.option(Option.<Boolean>createBuilder()
230-
.name(Component.translatable("animatium.dontCloseChat"))
231-
.description(OptionDescription.of(Component.translatable("animatium.dontCloseChat.description")))
232-
.binding(
233-
defaults.dontCloseChat,
234-
() -> config.dontCloseChat,
235-
(newVal) -> config.dontCloseChat = newVal)
236-
.controller(TickBoxControllerBuilder::create)
237-
.build());
74+
75+
category.option(booleanOption("showArmWhileInvisible", defaults, config));
76+
category.option(booleanOption("fakeMissPenaltySwing", defaults, config));
77+
category.option(booleanOption("dontMoveBlueVoid", defaults, config));
78+
category.option(booleanOption("disableEntityDeathTopple", defaults, config));
79+
category.option(booleanOption("deepRedHurtTint", defaults, config));
80+
category.option(booleanOption("disableParticlePhysics", defaults, config));
81+
category.option(booleanOption("disableFirstPersonParticles", defaults, config));
82+
category.option(booleanOption("dontClearChat", defaults, config));
83+
category.option(booleanOption("dontCloseChat", defaults, config));
84+
85+
{
86+
final OptionGroup.Builder itemSwingCategory = OptionGroup.createBuilder();
87+
itemSwingCategory.name(Component.translatable("animatium.category.extras.item_swing"));
88+
itemSwingCategory.option(floatSliderOption("itemSwingSpeed", defaults, config, -1.0F, 1.0F, 0.1F));
89+
itemSwingCategory.option(floatSliderOption("hasteSwingSpeed", defaults, config, -1.0F, 1.0F, 0.1F));
90+
itemSwingCategory.option(floatSliderOption("miningFatigueSwingSpeed", defaults, config, -1.0F, 1.0F, 0.1F));
91+
itemSwingCategory.option(booleanOption("ignoreHasteSpeed", defaults, config));
92+
itemSwingCategory.option(booleanOption("ignoreMiningFatigueSpeed", defaults, config));
93+
category.group(itemSwingCategory.build());
94+
}
95+
23896
return category.build();
23997
}
24098
}

0 commit comments

Comments
 (0)