-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathCapesRegistry.java
More file actions
317 lines (282 loc) · 15.8 KB
/
Copy pathCapesRegistry.java
File metadata and controls
317 lines (282 loc) · 15.8 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
package gregtech.api.util;
import gregtech.api.GregTechAPI;
import gregtech.client.renderer.texture.Textures;
import gregtech.core.network.packets.PacketNotifyCapeChange;
import net.minecraft.advancements.Advancement;
import net.minecraft.advancements.AdvancementManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Tuple;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import net.minecraftforge.fml.common.Optional;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import crafttweaker.annotations.ZenRegister;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import java.io.File;
import java.io.IOException;
import java.util.*;
@ZenClass("mods.gregtech.util.CapesRegistry")
@ZenRegister
public class CapesRegistry {
private static final Map<UUID, List<ResourceLocation>> UNLOCKED_CAPES = new HashMap<>();
private static final Map<UUID, ResourceLocation> WORN_CAPES = new HashMap<>();
private static final Map<Advancement, ResourceLocation> CAPE_ADVANCEMENTS = new HashMap<>();
private static final Set<ResourceLocation> FREE_CAPES = new HashSet<>();
public static void registerDevCapes() {
unlockCape(UUID.fromString("a24a9108-23d2-43fc-8db7-43f809d017db"), Textures.GREGTECH_CAPE_TEXTURE); // ALongStringOfNumbers
unlockCape(UUID.fromString("77e2129d-8f68-4025-9394-df946f1f3aee"), Textures.GREGTECH_CAPE_TEXTURE); // Brachy84
unlockCape(UUID.fromString("c1377a67-4585-46b6-b70e-dfaa419f1e71"), Textures.GREGTECH_CAPE_TEXTURE); // BraggestSage833
unlockCape(UUID.fromString("aaf70ec1-ac70-494f-9966-ea5933712750"), Textures.GREGTECH_CAPE_TEXTURE); // Bruberu
unlockCape(UUID.fromString("77c0be85-2619-4ab7-96e8-627b45682e04"), Textures.GREGTECH_CAPE_TEXTURE); // Exaxxion4096
unlockCape(UUID.fromString("88374b6a-4710-46cd-bb04-a1580905a918"), Textures.GREGTECH_CAPE_TEXTURE); // Ghzdude
unlockCape(UUID.fromString("5d7073e3-882f-4c4a-94b3-0e5ba1c11e02"), Textures.GREGTECH_CAPE_TEXTURE); // htmlcsjs
unlockCape(UUID.fromString("30628e4c-f7ac-427f-8ca7-aab2c0572be8"), Textures.GREGTECH_CAPE_TEXTURE); // TheLastKumquat
unlockCape(UUID.fromString("44f38ff8-aad7-49c3-acb3-d92317af9078"), Textures.GREGTECH_CAPE_TEXTURE); // LAGIdiot
// todo Mikerooni (when he gets a new account)
unlockCape(UUID.fromString("4a57640e-c1b1-4413-a6ab-e9a8b60ec167"), Textures.GREGTECH_CAPE_TEXTURE); // PrototypeTrousers
unlockCape(UUID.fromString("12892f29-9eef-47ed-b8fb-df3e0e90db0c"), Textures.GREGTECH_CAPE_TEXTURE); // Quarri6343
unlockCape(UUID.fromString("1184eb79-5831-4f7d-b8f4-3a46fccf7a1d"), Textures.GREGTECH_CAPE_TEXTURE); // screret
unlockCape(UUID.fromString("a82fb558-64f9-4dd6-a87d-84040e84bb43"), Textures.GREGTECH_CAPE_TEXTURE); // serenibyss
unlockCape(UUID.fromString("fbd96f69-60f9-481c-b71e-4b190cd5fc72"), Textures.GREGTECH_CAPE_TEXTURE); // Anne-Marie
unlockCape(UUID.fromString("5c2933b3-5340-4356-81e7-783c53bd7845"), Textures.GREGTECH_CAPE_TEXTURE); // Tech22
unlockCape(UUID.fromString("e6e784af-bd04-46ad-8141-47b8b9102cb9"), Textures.GREGTECH_CAPE_TEXTURE); // Tictim
unlockCape(UUID.fromString("2fa297a6-7803-4629-8360-7059155cf43e"), Textures.GREGTECH_CAPE_TEXTURE); // KilaBash
unlockCape(UUID.fromString("56bd41d0-06ef-4ed7-ab48-926ce45651f9"), Textures.GREGTECH_CAPE_TEXTURE); // Zalgo239
unlockCape(UUID.fromString("2c69579f-a7fa-46ad-814e-9837e01215c1"), Textures.GREGTECH_CAPE_TEXTURE); // Z_orbatron
unlockCape(UUID.fromString("3dbb689e-edcf-41b9-9c09-6ae4ebb6ca5b"), Textures.GREGTECH_CAPE_TEXTURE); // M_W_K
// GT:CEu Modern devs
unlockCape(UUID.fromString("274846e6-1d07-4e59-8dea-f4f73e76f9fb"), Textures.GREGTECH_CAPE_TEXTURE); // DilithiumThoride
unlockCape(UUID.fromString("c43b3c3d-7da6-4c2b-b335-703fce2ed795"), Textures.GREGTECH_CAPE_TEXTURE); // Ghostipedia
unlockCape(UUID.fromString("fe4bafe8-8ea9-494a-b4e9-29397cea89fc"), Textures.GREGTECH_CAPE_TEXTURE); // Gustavo
unlockCape(UUID.fromString("c18c1d7f-3174-42c6-81dc-3c7ff9f720c3"), Textures.GREGTECH_CAPE_TEXTURE); // jurrejelle
unlockCape(UUID.fromString("29f1e04c-58d8-4a3b-9eff-f85be7825256"), Textures.GREGTECH_CAPE_TEXTURE); // kross000
unlockCape(UUID.fromString("5cb66945-2ca4-498d-8c9a-29a676769363"), Textures.GREGTECH_CAPE_TEXTURE); // omergunr100
unlockCape(UUID.fromString("f76fc8b3-ac6b-44b9-9023-76edaf3d5909"), Textures.GREGTECH_CAPE_TEXTURE); // spicierspace153
unlockCape(UUID.fromString("24ab5496-0c9d-45d7-bfa6-c57760263be6"), Textures.GREGTECH_CAPE_TEXTURE); // TarLaboratories
unlockCape(UUID.fromString("60057953-6a71-4f11-9e72-bb0c81fa0085"), Textures.GREGTECH_CAPE_TEXTURE); // ursamina
unlockCape(UUID.fromString("3a27782d-6864-4814-a9fe-7c6931f29a8a"), Textures.GREGTECH_CAPE_TEXTURE); // YoungOnion
save();
}
public static ResourceLocation getPlayerCape(UUID uuid) {
return WORN_CAPES.get(uuid);
}
public static void save() {
NBTTagCompound comp = new NBTTagCompound();
NBTTagList unlockedCapesTag = new NBTTagList();
for (Map.Entry<UUID, List<ResourceLocation>> entry : UNLOCKED_CAPES.entrySet()) {
for (ResourceLocation cape : entry.getValue()) {
String capeLocation = cape.toString();
NBTTagCompound tag = new NBTTagCompound();
tag.setString("Cape", capeLocation);
tag.setUniqueId("UUID", entry.getKey());
unlockedCapesTag.appendTag(tag);
}
}
comp.setTag("UnlockedCapesValList", unlockedCapesTag);
NBTTagList wornCapesTag = new NBTTagList();
for (Map.Entry<UUID, ResourceLocation> entry : WORN_CAPES.entrySet()) {
if (entry.getValue() == null)
continue;
String capeLocation = entry.getValue().toString();
NBTTagCompound tag = new NBTTagCompound();
tag.setString("Cape", capeLocation);
tag.setUniqueId("UUID", entry.getKey());
wornCapesTag.appendTag(tag);
}
comp.setTag("WornCapesValList", wornCapesTag);
try {
CompressedStreamTools.safeWrite(comp, new File(FMLCommonHandler.instance().getMinecraftServerInstance()
.getWorld(0).getSaveHandler().getWorldDirectory(), "gregtech_cape.dat"));
} catch (IOException exception) {
GTLog.logger.error(exception);
}
}
public static void load() {
NBTTagCompound comp = null;
try {
comp = CompressedStreamTools.read(new File(FMLCommonHandler.instance().getMinecraftServerInstance()
.getWorld(0).getSaveHandler().getWorldDirectory(), "gregtech_cape.dat"));
} catch (IOException exception) {
GTLog.logger.error(exception);
}
clearMaps();
if (comp == null) {
registerDevCapes();
return;
}
NBTTagList unlockedCapesTag = comp.getTagList("UnlockedCapesValList", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < unlockedCapesTag.tagCount(); i++) {
NBTTagCompound tag = unlockedCapesTag.getCompoundTagAt(i);
String capeLocation = tag.getString("Cape");
if (capeLocation.isEmpty())
continue;
UUID uuid = tag.getUniqueId("UUID");
List<ResourceLocation> capes = UNLOCKED_CAPES.get(uuid);
if (capes == null) {
capes = new ArrayList<>();
}
capes.add(new ResourceLocation(capeLocation));
UNLOCKED_CAPES.put(uuid, capes);
}
NBTTagList wornCapesTag = comp.getTagList("WornCapesValList", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < wornCapesTag.tagCount(); i++) {
NBTTagCompound tag = wornCapesTag.getCompoundTagAt(i);
String capeLocation = tag.getString("Cape");
if (capeLocation.isEmpty())
continue;
UUID uuid = tag.getUniqueId("UUID");
WORN_CAPES.put(uuid, new ResourceLocation(capeLocation));
}
registerDevCapes();
}
public static void checkAdvancements(World world) {
registerCape(GTUtility.gregtechId("ultimate_voltage/74_wetware_mainframe"), Textures.GREGTECH_CAPE_TEXTURE,
world);
registerCape(GTUtility.gregtechId("steam/12_electronic_circuit"), Textures.RED_CAPE_TEXTURE, world);
registerCape(GTUtility.gregtechId("high_voltage/82_large_chemical_reactor"), Textures.YELLOW_CAPE_TEXTURE,
world);
registerCape(GTUtility.gregtechId("ludicrous_voltage/60_fusion"), Textures.GREEN_CAPE_TEXTURE, world);
for (Tuple<ResourceLocation, ResourceLocation> tuple : ctRegisterCapes) {
registerCape(tuple.getFirst(), tuple.getSecond(), world);
}
FREE_CAPES.addAll(ctFreeCapes);
FREE_CAPES.add(Textures.ACE_CAPE_TEXTURE);
FREE_CAPES.add(Textures.AGENDER_CAPE_TEXTURE);
FREE_CAPES.add(Textures.AROMANTIC_CAPE_TEXTURE);
FREE_CAPES.add(Textures.BI_CAPE_TEXTURE);
FREE_CAPES.add(Textures.GENDERFLUID_CAPE_TEXTURE);
FREE_CAPES.add(Textures.GENDERQUEER_CAPE_TEXTURE);
FREE_CAPES.add(Textures.INTERSEX_CAPE_TEXTURE);
FREE_CAPES.add(Textures.LESBIAN_CAPE_TEXTURE);
FREE_CAPES.add(Textures.NONBINARY_CAPE_TEXTURE);
FREE_CAPES.add(Textures.PAN_CAPE_TEXTURE);
FREE_CAPES.add(Textures.RAINBOW_CAPE_TEXTURE);
FREE_CAPES.add(Textures.TRANS_CAPE_TEXTURE);
}
/**
* Allows one to check what capes a specific player has unlocked through CapesRegistry.
*
* @param uuid The player data used to get what capes the player has through internal maps.
* @return A list of ResourceLocations containing the cape textures that the player has unlocked.
*/
public static List<ResourceLocation> getUnlockedCapes(UUID uuid) {
return UNLOCKED_CAPES.getOrDefault(uuid, Collections.emptyList());
}
/**
* Links an advancement with a cape, which allows a player to unlock it when they receive the advancement.
* This should only be called on world load, since advancements are only accessible then.
*
* @param advancement A ResourceLocation pointing to the advancement that is to be used for getting a cape.
* @param cape The ResourceLocation that points to the cape that can be unlocked through the advancement.
* @param world The world that may contain the advancement used for getting a cape.
*/
public static void registerCape(ResourceLocation advancement, ResourceLocation cape, World world) {
if (!world.isRemote) {
AdvancementManager advManager = ObfuscationReflectionHelper.getPrivateValue(World.class, world,
"field_191951_C");
Advancement advObject = advManager.getAdvancement(advancement);
if (advObject != null) {
CAPE_ADVANCEMENTS.put(advObject, cape);
}
}
}
/**
* Adds a cape that will always be unlocked for all players.
*
* @param cape A ResourceLocation pointing to the cape texture.
*/
public static void addFreeCape(ResourceLocation cape) {
FREE_CAPES.add(cape);
}
private static final List<Tuple<ResourceLocation, ResourceLocation>> ctRegisterCapes = new ArrayList<>();
private static final List<ResourceLocation> ctFreeCapes = new ArrayList<>();
@Optional.Method(modid = Mods.Names.CRAFT_TWEAKER)
@ZenMethod
public static void registerCape(String advancement, String cape) {
ctRegisterCapes.add(new Tuple<>(new ResourceLocation(advancement), new ResourceLocation(cape)));
}
@Optional.Method(modid = Mods.Names.CRAFT_TWEAKER)
@ZenMethod
public static void registerFreeCape(String cape) {
ctFreeCapes.add(new ResourceLocation(cape));
}
/**
* Automatically gives a cape to a player, which may be used for a reward for something other than an advancement
* DOES NOT SAVE AUTOMATICALLY; PLEASE CALL SAVE AFTER THIS FUNCTION IS USED IF THIS DATA IS MEANT TO PERSIST.
*
* @param uuid The UUID of the player to be given the cape.
* @param cape The ResourceLocation that holds the cape used here.
*/
public static void unlockCape(UUID uuid, ResourceLocation cape) {
List<ResourceLocation> capes = UNLOCKED_CAPES.get(uuid);
if (capes == null) {
capes = new ArrayList<>();
} else if (capes.contains(cape))
return;
capes.add(cape);
UNLOCKED_CAPES.put(uuid, capes);
}
public static void unlockCapeOnAdvancement(EntityPlayer player, Advancement advancement) {
if (CAPE_ADVANCEMENTS.containsKey(advancement)) {
unlockCape(player.getPersistentID(), CAPE_ADVANCEMENTS.get(advancement));
player.sendMessage(new TextComponentTranslation("gregtech.chat.cape"));
save();
}
}
public static void clearMaps() {
UNLOCKED_CAPES.clear();
WORN_CAPES.clear();
}
@SideOnly(Side.CLIENT)
public static void giveRawCape(UUID uuid, ResourceLocation cape) {
WORN_CAPES.put(uuid, cape);
}
public static void giveCape(UUID uuid, ResourceLocation cape) {
WORN_CAPES.put(uuid, cape);
GregTechAPI.networkHandler.sendToAll(new PacketNotifyCapeChange(uuid, cape));
save();
}
// For loading capes when the player logs in, so that it's synced to the clients.
public static void loadWornCapeOnLogin(EntityPlayer player) {
if (player instanceof EntityPlayerMP) {
UUID uuid = player.getPersistentID();
GregTechAPI.networkHandler.sendToAll(new PacketNotifyCapeChange(uuid, WORN_CAPES.get(uuid))); // sync to
// others
for (EntityPlayerMP otherPlayer : FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList()
.getPlayers()) { // sync to login
uuid = otherPlayer.getPersistentID();
GregTechAPI.networkHandler.sendTo(new PacketNotifyCapeChange(uuid, WORN_CAPES.get(uuid)),
(EntityPlayerMP) player);
}
}
}
// Runs on login, and looks for any advancements that give the player a cape that the player doesn't already have.
public static void detectNewCapes(EntityPlayer player) {
if (player instanceof EntityPlayerMP) {
for (Map.Entry<Advancement, ResourceLocation> capeEntry : CAPE_ADVANCEMENTS.entrySet()) {
if ((UNLOCKED_CAPES.get(player.getPersistentID()) == null ||
!UNLOCKED_CAPES.get(player.getPersistentID()).contains(capeEntry.getValue())) &&
((EntityPlayerMP) player).getAdvancements().getProgress(capeEntry.getKey()).isDone()) {
unlockCapeOnAdvancement(player, capeEntry.getKey());
}
}
if (UNLOCKED_CAPES.get(player.getPersistentID()) == null ||
!new HashSet<>(UNLOCKED_CAPES.get(player.getPersistentID())).containsAll(FREE_CAPES)) {
for (ResourceLocation cape : FREE_CAPES) {
unlockCape(player.getPersistentID(), cape);
}
save();
}
}
}
}