Skip to content

Commit cd3a6d6

Browse files
authored
Merge pull request #60 from litetex-oss/dev
Release
2 parents 52e9b10 + c480f68 commit cd3a6d6

30 files changed

+857
-267
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# 2.0.0
2+
* New options
3+
* Control over animated textures
4+
* ON (default)
5+
* Frozen = only the first frame of the animation is displayed
6+
* OFF = Animated textures are ignored
7+
* Only load your cape (and ignore other players)
8+
* New debug options
9+
* block certain capes by provider
10+
* amount of Cape-Loader Threads (default: 2)
11+
* Now refreshes the capes of all players when the configuration is changed
12+
* Utilizes Fabric's Rendering API - if present - to prevent conflicts with other mods
13+
* Various minor improvements and optimizations
14+
115
# 1.2.0
216
* Updated to 1.21.6
317
* Reworked/Fixed preview rendering

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Improved/Reworked version of the ["Capes" mod](https://github.com/CaelTheColher/
1717
* Improved and easier cape provider integration
1818
* Allows ordering providers
1919
* Support for custom providers
20+
* More options to fine tune how capes are applied
2021
* Written only in Java (no Kotlin needed)
2122
* Various fixes and improvements
2223

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ dependencies {
8585
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
8686
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
8787
// Required when translations and icons should be loaded correctly
88-
modImplementation "net.fabricmc.fabric-api:fabric-api:0.126.1+1.21.6"
88+
modImplementation "net.fabricmc.fabric-api:fabric-api:0.127.1+1.21.6"
8989

9090
modCompileOnly "com.terraformersmc:modmenu:${project.modmenu_version}"
9191

9292
// Only needed during development
93-
// modLocalRuntime "com.terraformersmc:modmenu:${project.modmenu_version}"
94-
modLocalRuntime "net.fabricmc.fabric-api:fabric-api:0.126.1+1.21.6"
93+
modLocalRuntime "com.terraformersmc:modmenu:${project.modmenu_version}"
94+
modLocalRuntime "net.fabricmc.fabric-api:fabric-api:0.127.1+1.21.6"
9595
modLocalRuntime "me.djtheredstoner:DevAuth-fabric:1.2.1"
9696
// modLocalRuntime "maven.modrinth:no-chat-reports:Fabric-1.21.4-v2.11.0"
9797
}

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Done to increase the memory available to gradle.
22
org.gradle.jvmargs=-Xmx2G
33
# Fabric Properties
4-
yarn_mappings=1.21.6-rc1+build.1
4+
yarn_mappings=1.21.6+build.1
55
loader_version=0.16.14
66
# Mod Properties
7-
mod_version=1.2.1-SNAPSHOT
7+
mod_version=2.0.0-SNAPSHOT
88
maven_group=net.litetex.mcm
99
archives_base_name=cape-provider
1010
mod_name=Cape Provider
1111
mod_desc=Use capes from various providers
1212
mod_license_spdx_id=LGPL-2.1-or-later
1313
mod_license_url=https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
1414
# Additional
15-
modmenu_version=14.0.0-rc.2
15+
modmenu_version=15.0.0-beta.2

src/main/java/net/litetex/capes/Capes.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55
import java.util.Map;
66
import java.util.Objects;
77
import java.util.Optional;
8+
import java.util.Set;
89
import java.util.function.Consumer;
910
import java.util.function.Predicate;
11+
import java.util.stream.Collectors;
1012

1113
import net.litetex.capes.config.Config;
14+
import net.litetex.capes.handler.PlayerCapeHandlerManager;
15+
import net.litetex.capes.handler.TextureLoadThrottler;
1216
import net.litetex.capes.provider.CapeProvider;
1317
import net.litetex.capes.provider.MinecraftCapeProvider;
18+
import net.minecraft.client.MinecraftClient;
19+
import net.minecraft.client.network.ClientPlayNetworkHandler;
1420
import net.minecraft.util.Identifier;
1521

1622

@@ -42,6 +48,11 @@ public static void setInstance(final Capes instance)
4248

4349
private final boolean validateProfile;
4450
private final Duration loadThrottleSuppressDuration;
51+
private final Map<CapeProvider, Set<Integer>> blockedProviderCapeHashes;
52+
53+
private final PlayerCapeHandlerManager playerCapeHandlerManager;
54+
private final TextureLoadThrottler textureLoadThrottler;
55+
private boolean shouldRefresh;
4556

4657
public Capes(
4758
final Config config,
@@ -56,13 +67,50 @@ public Capes(
5667
this.loadThrottleSuppressDuration = Optional.ofNullable(this.config().getLoadThrottleSuppressSec())
5768
.map(Duration::ofSeconds)
5869
.orElse(Duration.ofMinutes(3));
70+
this.blockedProviderCapeHashes = Optional.ofNullable(this.config().getBlockedProviderCapeHashes())
71+
.map(map -> map.entrySet()
72+
.stream()
73+
.filter(e -> allProviders.containsKey(e.getKey()))
74+
.collect(Collectors.toMap(e -> allProviders.get(e.getKey()), Map.Entry::getValue)))
75+
.orElseGet(Map::of);
76+
77+
this.playerCapeHandlerManager = new PlayerCapeHandlerManager(this);
78+
this.textureLoadThrottler = new TextureLoadThrottler(this.playerCapeHandlerManager);
5979
}
6080

6181
public void saveConfig()
6282
{
6383
this.saveConfigFunc.accept(this.config);
6484
}
6585

86+
public void saveConfigAndMarkRefresh()
87+
{
88+
this.saveConfig();
89+
this.shouldRefresh = true;
90+
}
91+
92+
public void refreshIfMarked()
93+
{
94+
if(this.shouldRefresh)
95+
{
96+
this.refresh();
97+
this.shouldRefresh = false;
98+
}
99+
}
100+
101+
protected void refresh()
102+
{
103+
this.textureLoadThrottler.clearCache();
104+
this.playerCapeHandlerManager.clearCache();
105+
106+
final ClientPlayNetworkHandler networkHandler = MinecraftClient.getInstance().getNetworkHandler();
107+
if(networkHandler != null)
108+
{
109+
networkHandler.getPlayerList().forEach(e ->
110+
this.textureLoadThrottler.loadIfRequired(e.getProfile()));
111+
}
112+
}
113+
66114
public Config config()
67115
{
68116
return this.config;
@@ -97,4 +145,19 @@ public Duration loadThrottleSuppressDuration()
97145
{
98146
return this.loadThrottleSuppressDuration;
99147
}
148+
149+
public Map<CapeProvider, Set<Integer>> blockedProviderCapeHashes()
150+
{
151+
return this.blockedProviderCapeHashes;
152+
}
153+
154+
public TextureLoadThrottler textureLoadThrottler()
155+
{
156+
return this.textureLoadThrottler;
157+
}
158+
159+
public PlayerCapeHandlerManager playerCapeHandlerManager()
160+
{
161+
return this.playerCapeHandlerManager;
162+
}
100163
}

src/main/java/net/litetex/capes/CapesI18NKeys.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ public final class CapesI18NKeys
1414
public static final String MANAGE_PROVIDERS = PREFIX + "manage_providers";
1515

1616
public static final String OTHER = PREFIX + "other";
17+
public static final String ANIMATED_TEXTURES = PREFIX + "animated_textures";
1718
public static final String ELYTRA_TEXTURE = PREFIX + "elytra_texture";
19+
public static final String FROZEN = PREFIX + "frozen";
20+
public static final String ONLY_LOAD_YOUR_CAPE = PREFIX + "only_load_your_cape";
1821

1922
private static final String ANTI_FEATURE_PREFIX = PREFIX + "anti_feature.";
2023
public static final String ANTI_FEATURE_BAD_CONNECTION = ANTI_FEATURE_PREFIX + "bad_connection";
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package net.litetex.capes;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
import java.util.Set;
6+
import java.util.function.BooleanSupplier;
7+
8+
import org.objectweb.asm.tree.ClassNode;
9+
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
10+
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
11+
12+
import net.litetex.capes.fabric.FabricModDetector;
13+
14+
15+
public class CapesMixinPlugin implements IMixinConfigPlugin
16+
{
17+
private static final String MIXIN_PACKAGE = "net.litetex.capes.mixins.";
18+
19+
static final Map<String, BooleanSupplier> CONDITIONS = Map.of(
20+
MIXIN_PACKAGE + "SpecialGuiElementRendererRegisterGuiRendererMixin",
21+
() -> !FabricModDetector.isFabricRenderingApiPresent()
22+
);
23+
24+
@Override
25+
public boolean shouldApplyMixin(final String targetClassName, final String mixinClassName)
26+
{
27+
final BooleanSupplier supplier = CONDITIONS.get(targetClassName);
28+
return supplier == null || supplier.getAsBoolean();
29+
}
30+
31+
// region Boiler
32+
33+
@Override
34+
public void onLoad(final String mixinPackage)
35+
{
36+
}
37+
38+
@Override
39+
public String getRefMapperConfig()
40+
{
41+
return null;
42+
}
43+
44+
@Override
45+
public void acceptTargets(final Set<String> myTargets, final Set<String> otherTargets)
46+
{
47+
}
48+
49+
@Override
50+
public List<String> getMixins()
51+
{
52+
return null;
53+
}
54+
55+
@Override
56+
public void preApply(
57+
final String targetClassName,
58+
final ClassNode targetClass,
59+
final String mixinClassName,
60+
final IMixinInfo mixinInfo)
61+
{
62+
}
63+
64+
@Override
65+
public void postApply(
66+
final String targetClassName,
67+
final ClassNode targetClass,
68+
final String mixinClassName,
69+
final IMixinInfo mixinInfo)
70+
{
71+
}
72+
73+
// endregion
74+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package net.litetex.capes.config;
2+
3+
public enum AnimatedCapesHandling
4+
{
5+
ON,
6+
FROZEN,
7+
OFF
8+
}

src/main/java/net/litetex/capes/config/Config.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.Collection;
44
import java.util.LinkedHashSet;
55
import java.util.List;
6+
import java.util.Map;
67
import java.util.Objects;
78
import java.util.Set;
89

@@ -15,21 +16,29 @@ public class Config
1516
private String currentPreviewProviderId;
1617
// NOTE: Default/Minecraft is always active
1718
private Set<String> activeProviderIds;
19+
private boolean onlyLoadForSelf;
1820
private boolean enableElytraTexture;
21+
private AnimatedCapesHandling animatedCapesHandling = AnimatedCapesHandling.ON;
1922
private List<CustomProviderConfig> customProviders = List.of();
2023

2124
// Advanced/Debug options
2225
private Boolean validateProfile;
2326
private Integer loadThrottleSuppressSec;
27+
private Map<String, Set<Integer>> blockedProviderCapeHashes;
28+
private Integer loadThreads;
2429

2530
public void reset()
2631
{
2732
this.setCurrentPreviewProviderId(null);
2833
this.setActiveProviderIds(List.of(MinecraftCapesCapeProvider.ID, OptiFineCapeProvider.ID));
34+
this.setOnlyLoadForSelf(false);
2935
this.setEnableElytraTexture(true);
36+
this.setAnimatedCapesHandling(AnimatedCapesHandling.ON);
3037

3138
this.setValidateProfile(null);
3239
this.setLoadThrottleSuppressSec(null);
40+
this.setBlockedProviderCapeHashes(null);
41+
this.setLoadThreads(null);
3342
}
3443

3544
public static Config createDefault()
@@ -61,6 +70,16 @@ public void setActiveProviderIds(final Collection<String> activeProviderIds)
6170
this.activeProviderIds = new LinkedHashSet<>(Objects.requireNonNull(activeProviderIds));
6271
}
6372

73+
public boolean isOnlyLoadForSelf()
74+
{
75+
return this.onlyLoadForSelf;
76+
}
77+
78+
public void setOnlyLoadForSelf(final boolean onlyLoadForSelf)
79+
{
80+
this.onlyLoadForSelf = onlyLoadForSelf;
81+
}
82+
6483
public boolean isEnableElytraTexture()
6584
{
6685
return this.enableElytraTexture;
@@ -71,6 +90,16 @@ public void setEnableElytraTexture(final boolean enableElytraTexture)
7190
this.enableElytraTexture = enableElytraTexture;
7291
}
7392

93+
public AnimatedCapesHandling getAnimatedCapesHandling()
94+
{
95+
return this.animatedCapesHandling;
96+
}
97+
98+
public void setAnimatedCapesHandling(final AnimatedCapesHandling animatedCapesHandling)
99+
{
100+
this.animatedCapesHandling = animatedCapesHandling;
101+
}
102+
74103
public List<CustomProviderConfig> getCustomProviders()
75104
{
76105
return this.customProviders;
@@ -101,5 +130,25 @@ public void setLoadThrottleSuppressSec(final Integer loadThrottleSuppressSec)
101130
this.loadThrottleSuppressSec = loadThrottleSuppressSec;
102131
}
103132

133+
public Map<String, Set<Integer>> getBlockedProviderCapeHashes()
134+
{
135+
return this.blockedProviderCapeHashes;
136+
}
137+
138+
public void setBlockedProviderCapeHashes(final Map<String, Set<Integer>> blockedProviderCapeHashes)
139+
{
140+
this.blockedProviderCapeHashes = blockedProviderCapeHashes;
141+
}
142+
143+
public Integer getLoadThreads()
144+
{
145+
return this.loadThreads;
146+
}
147+
148+
public void setLoadThreads(final Integer loadThreads)
149+
{
150+
this.loadThreads = loadThreads;
151+
}
152+
104153
// endregion
105154
}

src/main/java/net/litetex/capes/fabric/FabricCapes.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public class FabricCapes implements ClientModInitializer
2727
@Override
2828
public void onInitializeClient()
2929
{
30+
FabricCapesCompatibilityInit.init();
31+
3032
final Config config = this.loadConfig();
3133
Capes.setInstance(new Capes(
3234
config,

0 commit comments

Comments
 (0)