Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
Load cosmetics on player world join, close #63
Browse files Browse the repository at this point in the history
  • Loading branch information
doctor4t committed Feb 7, 2021
1 parent 598f027 commit 7e05f2e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Illuminations - Changelog:

### Illuminations 1.4.5 - 1.16.5
- Illuminations cosmetics will now be reloaded upon a player joining a world, no longer needing to restart the game in order to see changes

### Illuminations 1.4.4 - 1.16.5
- Fixed an issue that caused fireflies not to spawn if time is set to something greater than 24000
- Updated to Vanguard 1.0.5
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ loader_version=0.11.1
fabric_version=0.30.0+1.16

# Mod Properties
mod_version = 1.4.4
mod_version = 1.4.5
maven_group = io.github.ladysnake
archives_base_name = illuminations

Expand All @@ -24,7 +24,7 @@ vanguard_version=1.0.+
owners = Ladysnake
license_header = CC-BY-NC-SA+4.0
curseforge_id = 292908
curseforge_versions = 1.16.4
curseforge_versions = 1.16.5
cf_requirements = fabric-api
release_type = release
changelog_url = https://github.com/Ladysnake/Illuminations/blob/main/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class IlluminationsClient implements ClientModInitializer {
public static final int EYES_VANISHING_DISTANCE = 5;

// illuminations cosmetics
private static final String COSMETICS_URL = "https://illuminations.glitch.me/data";
private static final String COSMETICS_URL = "https://illuminations.uuid.gg/data";
private static final Gson COSMETICS_GSON = new GsonBuilder().create();
static final Type COSMETIC_SELECT_TYPE = new TypeToken<Map<UUID, PlayerCosmeticData>>(){}.getType();
public static Map<UUID, PlayerCosmeticData> PLAYER_COSMETICS = Collections.emptyMap();
Expand Down Expand Up @@ -115,26 +115,7 @@ public void onInitializeClient() {
Config.load();

// get illuminations player cosmetics
CompletableFuture.supplyAsync(() -> {
try (Reader reader = new InputStreamReader(new URL(COSMETICS_URL).openStream())) {
Map<UUID, PlayerCosmeticData> playerData = COSMETICS_GSON.fromJson(reader, COSMETIC_SELECT_TYPE);
return playerData;
} catch (MalformedURLException e) {
logger.log(Level.ERROR, "Could not get player cosmetics because of malformed URL: " + e.getMessage());
} catch (IOException e) {
logger.log(Level.ERROR, "Could not get player cosmetics because of I/O Error: " + e.getMessage());
}

return null;
}).thenAcceptAsync(playerData -> {
if (playerData != null) {
PLAYER_COSMETICS = playerData;
logger.log(Level.INFO, "Player cosmetics retrieved");
} else {
PLAYER_COSMETICS = Collections.emptyMap();
logger.log(Level.WARN, "Player cosmetics could not be retrieved, cosmetics will be ignored");
}
}, MinecraftClient.getInstance());
loadPlayerCosmetics();

// particles
FIREFLY = Registry.register(Registry.PARTICLE_TYPE, "illuminations:firefly", FabricParticleTypes.simple(true));
Expand Down Expand Up @@ -217,4 +198,28 @@ public void onInitializeClient() {
.put("mooncult_crown", new OverheadData(new CrownEntityModel(), "mooncult_crown"))
.build();
}

public static void loadPlayerCosmetics() {
// get illuminations player cosmetics
CompletableFuture.supplyAsync(() -> {
try (Reader reader = new InputStreamReader(new URL(COSMETICS_URL).openStream())) {
Map<UUID, PlayerCosmeticData> playerData = COSMETICS_GSON.fromJson(reader, COSMETIC_SELECT_TYPE);
return playerData;
} catch (MalformedURLException e) {
logger.log(Level.ERROR, "Could not get player cosmetics because of malformed URL: " + e.getMessage());
} catch (IOException e) {
logger.log(Level.ERROR, "Could not get player cosmetics because of I/O Error: " + e.getMessage());
}

return null;
}).thenAcceptAsync(playerData -> {
if (playerData != null) {
PLAYER_COSMETICS = playerData;
logger.log(Level.INFO, "Player cosmetics retrieved");
} else {
PLAYER_COSMETICS = Collections.emptyMap();
logger.log(Level.WARN, "Player cosmetics could not be retrieved, cosmetics will be ignored");
}
}, MinecraftClient.getInstance());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.collect.ImmutableSet;
import ladysnake.illuminations.client.IlluminationsClient;
import ladysnake.illuminations.client.data.IlluminationData;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.profiler.Profiler;
Expand Down Expand Up @@ -50,4 +51,9 @@ public void randomBlockDisplayTick(int xCenter, int yCenter, int zCenter, int ra
}
}

@Inject(method = "addPlayer", at = @At(value = "RETURN"))
public void addPlayer(int id, AbstractClientPlayerEntity player, CallbackInfo ci) {
IlluminationsClient.loadPlayerCosmetics();
}

}

0 comments on commit 7e05f2e

Please sign in to comment.