Skip to content

Commit 66eb277

Browse files
committed
perks
1 parent 24a31ec commit 66eb277

File tree

6 files changed

+236
-0
lines changed

6 files changed

+236
-0
lines changed

src/main/java/com/nxyi/addon/Addon.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public void onInitialize() {
7171
Commands.get().add(new ImageBookCommand());
7272
Commands.get().add(new ImageLoreCommand());
7373
Commands.get().add(new TrashCommand());
74+
Commands.get().add(new ReloadCapes());
7475

7576
// HUD
7677
Hud.get().register(HudExample.INFO);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.nxyi.addon.commands;
2+
3+
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
4+
import com.nxyi.addon.perk.Capes;
5+
import meteordevelopment.meteorclient.renderer.Fonts;
6+
import meteordevelopment.meteorclient.systems.Systems;
7+
import meteordevelopment.meteorclient.systems.commands.Command;
8+
import meteordevelopment.meteorclient.systems.friends.Friend;
9+
import meteordevelopment.meteorclient.systems.friends.Friends;
10+
import meteordevelopment.meteorclient.utils.network.MeteorExecutor;
11+
import net.minecraft.command.CommandSource;
12+
13+
import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
14+
15+
public class ReloadCapes extends Command {
16+
public ReloadCapes() {
17+
super("reloadCapes", "Reloads cape textures.");
18+
}
19+
20+
@Override
21+
public void build(LiteralArgumentBuilder<CommandSource> builder) {
22+
builder.executes(context -> {
23+
warning("Reloading capes...");
24+
25+
Capes.init();
26+
27+
return SINGLE_SUCCESS;
28+
});
29+
}
30+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.nxyi.addon.mixin;
2+
3+
import com.nxyi.addon.perk.Capes;
4+
import net.minecraft.client.network.AbstractClientPlayerEntity;
5+
import net.minecraft.entity.player.PlayerEntity;
6+
import net.minecraft.util.Identifier;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.injection.At;
9+
import org.spongepowered.asm.mixin.injection.Inject;
10+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
11+
12+
@Mixin(AbstractClientPlayerEntity.class)
13+
public class RenderCapes {
14+
@Inject(method = "getCapeTexture", at = @At("HEAD"), cancellable = true)
15+
private void onGetCapeTexture(CallbackInfoReturnable<Identifier> info) {
16+
Identifier id = Capes.get((PlayerEntity) (Object) this);
17+
if (id != null) info.setReturnValue(id);
18+
}
19+
}

src/main/java/com/nxyi/addon/modules/AntiSpawnpoint.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ private void onclick(PacketEvent.Send event){
4141

4242
if (fakeuse.get()){
4343
mc.player.networkHandler.sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND));
44+
mc.player.swingHand(Hand.MAIN_HAND);
4445
}
4546

4647
if (mc.world.getDimension().bedWorks() && mc.world.getBlockState(blockpos).getBlock() instanceof BedBlock) {
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
package com.nxyi.addon.perk;
2+
3+
import meteordevelopment.meteorclient.MeteorClient;
4+
import meteordevelopment.meteorclient.events.world.TickEvent;
5+
import meteordevelopment.meteorclient.utils.PreInit;
6+
import meteordevelopment.meteorclient.utils.misc.MeteorIdentifier;
7+
import meteordevelopment.meteorclient.utils.network.Http;
8+
import meteordevelopment.meteorclient.utils.network.MeteorExecutor;
9+
import meteordevelopment.orbit.EventHandler;
10+
import net.minecraft.client.texture.NativeImage;
11+
import net.minecraft.client.texture.NativeImageBackedTexture;
12+
import net.minecraft.entity.player.PlayerEntity;
13+
import net.minecraft.util.Identifier;
14+
15+
import java.io.IOException;
16+
import java.io.InputStream;
17+
import java.util.*;
18+
import java.util.stream.Stream;
19+
20+
import static meteordevelopment.meteorclient.MeteorClient.mc;
21+
22+
public class Capes {
23+
private static final String CAPE_OWNERS_URL = "https://raw.githubusercontent.com/Dark-Developments/Recauses/main/Perks/Capes/capeowners.txt";
24+
private static final String CAPES_URL = "https://raw.githubusercontent.com/Dark-Developments/Recauses/main/Perks/Capes/capes.txt";
25+
26+
private static final Map<UUID, String> OWNERS = new HashMap<>();
27+
private static final Map<String, String> URLS = new HashMap<>();
28+
private static final Map<String, Cape> TEXTURES = new HashMap<>();
29+
30+
private static final List<Cape> TO_REGISTER = new ArrayList<>();
31+
private static final List<Cape> TO_RETRY = new ArrayList<>();
32+
private static final List<Cape> TO_REMOVE = new ArrayList<>();
33+
34+
@PreInit(dependencies = MeteorExecutor.class)
35+
public static void init() {
36+
OWNERS.clear();
37+
URLS.clear();
38+
TEXTURES.clear();
39+
TO_REGISTER.clear();
40+
TO_RETRY.clear();
41+
TO_REMOVE.clear();
42+
43+
MeteorExecutor.execute(() -> {
44+
// Cape owners
45+
Stream<String> lines = Http.get(CAPE_OWNERS_URL).sendLines();
46+
if (lines != null) lines.forEach(s -> {
47+
String[] split = s.split(" ");
48+
49+
if (split.length >= 2) {
50+
OWNERS.put(UUID.fromString(split[0]), split[1]);
51+
if (!TEXTURES.containsKey(split[1])) TEXTURES.put(split[1], new Cape(split[1]));
52+
}
53+
});
54+
55+
// Capes
56+
lines = Http.get(CAPES_URL).sendLines();
57+
if (lines != null) lines.forEach(s -> {
58+
String[] split = s.split(" ");
59+
60+
if (split.length >= 2) {
61+
if (!URLS.containsKey(split[0])) URLS.put(split[0], split[1]);
62+
}
63+
});
64+
});
65+
66+
MeteorClient.EVENT_BUS.subscribe(Capes.class);
67+
}
68+
69+
@EventHandler
70+
private static void onTick(TickEvent.Post event) {
71+
synchronized (TO_REGISTER) {
72+
for (Cape cape : TO_REGISTER) cape.register();
73+
TO_REGISTER.clear();
74+
}
75+
76+
synchronized (TO_RETRY) {
77+
TO_RETRY.removeIf(Cape::tick);
78+
}
79+
80+
synchronized (TO_REMOVE) {
81+
for (Cape cape : TO_REMOVE) {
82+
URLS.remove(cape.name);
83+
TEXTURES.remove(cape.name);
84+
TO_REGISTER.remove(cape);
85+
TO_RETRY.remove(cape);
86+
}
87+
88+
TO_REMOVE.clear();
89+
}
90+
}
91+
92+
public static Identifier get(PlayerEntity player) {
93+
String capeName = OWNERS.get(player.getUuid());
94+
if (capeName != null) {
95+
Cape cape = TEXTURES.get(capeName);
96+
if (cape == null) return null;
97+
98+
if (cape.isDownloaded()) return cape;
99+
100+
cape.download();
101+
return null;
102+
}
103+
104+
return null;
105+
}
106+
107+
private static class Cape extends MeteorIdentifier {
108+
private static int COUNT = 0;
109+
110+
private final String name;
111+
112+
private boolean downloaded;
113+
private boolean downloading;
114+
115+
private NativeImage img;
116+
117+
private int retryTimer;
118+
119+
public Cape(String name) {
120+
super("capes/" + COUNT++);
121+
122+
this.name = name;
123+
}
124+
125+
public void download() {
126+
if (downloaded || downloading || retryTimer > 0) return;
127+
downloading = true;
128+
129+
MeteorExecutor.execute(() -> {
130+
try {
131+
String url = URLS.get(name);
132+
if (url == null) {
133+
synchronized (TO_RETRY) {
134+
TO_REMOVE.add(this);
135+
downloading = false;
136+
return;
137+
}
138+
}
139+
140+
InputStream in = Http.get(url).sendInputStream();
141+
if (in == null) {
142+
synchronized (TO_RETRY) {
143+
TO_RETRY.add(this);
144+
retryTimer = 10 * 20;
145+
downloading = false;
146+
return;
147+
}
148+
}
149+
150+
img = NativeImage.read(in);
151+
152+
synchronized (TO_REGISTER) {
153+
TO_REGISTER.add(this);
154+
}
155+
} catch (IOException e) {
156+
e.printStackTrace();
157+
}
158+
});
159+
}
160+
161+
public void register() {
162+
mc.getTextureManager().registerTexture(this, new NativeImageBackedTexture(img));
163+
img = null;
164+
165+
downloading = false;
166+
downloaded = true;
167+
}
168+
169+
public boolean tick() {
170+
if (retryTimer > 0) {
171+
retryTimer--;
172+
} else {
173+
download();
174+
return true;
175+
}
176+
177+
return false;
178+
}
179+
180+
public boolean isDownloaded() {
181+
return downloaded;
182+
}
183+
}
184+
}

src/main/resources/zewo2.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"ChatMixin",
77
"ClientLoginNetworkHandlerMixin",
88
"MultiplayerScreenMixin",
9+
"RenderCapes",
910
"SessionMixin",
1011
"Interface.INClientPlayerInteractionManagerMixin"
1112
],

0 commit comments

Comments
 (0)