This repository was archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathStaticCape.java
More file actions
80 lines (66 loc) · 2.43 KB
/
StaticCape.java
File metadata and controls
80 lines (66 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* DeveloperCapes by Jadar
* License: MIT License
* (https://raw.github.com/jadar/DeveloperCapes/master/LICENSE)
* version 4.0.0.x
*/
package com.jadarstudios.developercapes.cape;
import com.jadarstudios.developercapes.DevCapes;
import com.jadarstudios.developercapes.HDImageBuffer;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.client.renderer.ThreadDownloadImageData;
import net.minecraft.util.ResourceLocation;
import java.lang.reflect.Field;
import java.net.URL;
/**
* Default Cape implementation
*
* @author jadar
*/
public class StaticCape extends AbstractCape {
public StaticCape(String name, URL url) {
this.setName(name);
this.setURL(url);
}
public StaticCape(String name) {
this(name, null);
}
@Override
public void loadTexture(AbstractClientPlayer player) {
ResourceLocation location = this.getLocation();
//mmdanggg2: using reflection to modify the private locationCape, hacky but it works.
try {
Field playerInfoF = AbstractClientPlayer.class.getDeclaredField("playerInfo");
playerInfoF.setAccessible(true);
NetworkPlayerInfo nci = (NetworkPlayerInfo) playerInfoF.get(player);
Field locationCapeF = NetworkPlayerInfo.class.getDeclaredField("locationCape");
locationCapeF.setAccessible(true);
locationCapeF.set(nci, location);
playerInfoF.setAccessible(false);
locationCapeF.setAccessible(false);
} catch (Exception e) {
e.printStackTrace();
DevCapes.getInstance().logger.error("Setting cape ResourceLocation failed!");
}
Minecraft.getMinecraft().renderEngine.loadTexture(location, this.getTexture());
}
@Override
public boolean isTextureLoaded(AbstractClientPlayer player) {
ResourceLocation cape = player.getLocationCape();
return cape != null;
}
public void setURL(URL url) {
if (url == null) {
this.texture = null;
return;
}
this.texture = new ThreadDownloadImageData(null, url.toString(), null, new HDImageBuffer());
}
public void setName(String name) {
this.name = name;
this.location = new ResourceLocation("DevCapes/" + name);
}
}