mirror of
https://github.com/Pridecraft-Studios/joy.git
synced 2025-08-02 22:15:58 -04:00
feature: Joy's splashes now load alongside vanilla's
This commit is contained in:
parent
9a5b7f068a
commit
dc18da2f30
@ -1,5 +1,6 @@
|
||||
package gay.pridecraft.joy;
|
||||
|
||||
import gay.pridecraft.joy.client.SplashUtil;
|
||||
import gay.pridecraft.joy.registry.JoyBlockEntityTypes;
|
||||
import gay.pridecraft.joy.registry.JoyBlocks;
|
||||
import gay.pridecraft.joy.registry.JoyEntities;
|
||||
@ -45,6 +46,8 @@ public class JoyClient implements ClientModInitializer {
|
||||
|
||||
JoyUtil.registerEnabledPack("menu", Text.of("Joy's Main Menu & HUD"));
|
||||
JoyUtil.registerEnabledPack("glint", Text.of("Joy's Enchantment Glint"));
|
||||
|
||||
SplashUtil.init();
|
||||
}
|
||||
|
||||
private static void registerBedBlockRenderLayers() {
|
||||
|
112
src/client/java/gay/pridecraft/joy/client/SplashUtil.java
Normal file
112
src/client/java/gay/pridecraft/joy/client/SplashUtil.java
Normal file
@ -0,0 +1,112 @@
|
||||
package gay.pridecraft.joy.client;
|
||||
|
||||
import com.mojang.logging.LogUtils;
|
||||
import gay.pridecraft.joy.JoyUtil;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* @author Ampflower
|
||||
* @since 1.0.0
|
||||
**/
|
||||
public final class SplashUtil {
|
||||
private static final Logger logger = LogUtils.getLogger();
|
||||
private static final Random random = new Random();
|
||||
private static final Identifier joySplashes = JoyUtil.id("texts/splashes.txt");
|
||||
private static final Map<Birthday, List<String>> birthdays = new HashMap<>();
|
||||
private static final List<String> contributors = makeContributors();
|
||||
|
||||
private static final byte
|
||||
JAN = 1,
|
||||
FEB = 2,
|
||||
MAR = 3,
|
||||
APR = 4,
|
||||
MAY = 5,
|
||||
JUN = 6,
|
||||
JUL = 7,
|
||||
AUG = 8,
|
||||
SEP = 9,
|
||||
OCT = 10,
|
||||
NOV = 11,
|
||||
DEC = 12;
|
||||
|
||||
public static void init() {
|
||||
putBirthday(MAR, 18, "TheClashFruit");
|
||||
putBirthday(SEP, 14, "Blurry");
|
||||
putBirthday(NOV, 8, "Fery");
|
||||
}
|
||||
|
||||
private static List<String> makeContributors() {
|
||||
final var metadata = JoyUtil.joyContainer.getMetadata();
|
||||
|
||||
final var authors = metadata.getAuthors()
|
||||
.stream()
|
||||
.map(person -> "Joy, made by " + person.getName() + "!");
|
||||
|
||||
final var contributors = metadata.getContributors()
|
||||
.stream()
|
||||
.map(person -> "Joy, aided by " + person.getName() + "!");
|
||||
|
||||
return Stream.concat(authors, contributors).toList();
|
||||
}
|
||||
|
||||
public static List<String> prepare(ResourceManager manager) {
|
||||
try (final var reader = manager.openAsReader(joySplashes)) {
|
||||
return Stream.concat(reader.lines(), contributors.stream()).toList();
|
||||
} catch (IOException ioe) {
|
||||
logger.warn("Could not read Joy splashes", ioe);
|
||||
}
|
||||
|
||||
return contributors;
|
||||
}
|
||||
|
||||
private static void putBirthday(int month, int day, String... name) {
|
||||
birthdays.put(new Birthday(month, day), List.of(name));
|
||||
}
|
||||
|
||||
public static List<String> getBirthdays() {
|
||||
return birthdays.get(Birthday.now());
|
||||
}
|
||||
|
||||
public static String getBirthday(double chance) {
|
||||
if (random.nextDouble() < chance) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final var list = getBirthdays();
|
||||
if (list == null || list.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return "Happy birthday, " + getRandom(list) + "!";
|
||||
}
|
||||
|
||||
private static <T> T getRandom(List<T> list) {
|
||||
return list.get(random.nextInt(list.size()));
|
||||
}
|
||||
|
||||
private record Birthday(byte month, byte day) {
|
||||
private Birthday(int month, int day) {
|
||||
this((byte) month, (byte) day);
|
||||
}
|
||||
|
||||
public static Birthday now() {
|
||||
final var now = LocalDate.now();
|
||||
return new Birthday(now.getMonthValue(), now.getDayOfMonth());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (month << 8) | day;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,52 +1,35 @@
|
||||
package gay.pridecraft.joy.mixin.client;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
|
||||
import gay.pridecraft.joy.Joy;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import gay.pridecraft.joy.client.SplashUtil;
|
||||
import net.minecraft.client.gui.screen.SplashTextRenderer;
|
||||
import net.minecraft.client.resource.SplashTextResourceSupplier;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.util.profiler.Profiler;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Month;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(SplashTextResourceSupplier.class)
|
||||
public class SplashTextResourceSupplierMixin {
|
||||
@ModifyReturnValue(method = "prepare(Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/util/profiler/Profiler;)Ljava/util/List;", at = @At("RETURN"))
|
||||
private List<String> onPrepare(List<String> original) {
|
||||
List<String> bdSplash = new ArrayList<>();
|
||||
@ModifyReturnValue(method = "prepare", at = @At("RETURN"))
|
||||
private List<String> onPrepare(List<String> original, @Local(argsOnly = true) ResourceManager resourceManager) {
|
||||
original.addAll(SplashUtil.prepare(resourceManager));
|
||||
|
||||
FabricLoader
|
||||
.getInstance()
|
||||
.getModContainer(Joy.MOD_ID)
|
||||
.ifPresent(modContainer ->
|
||||
modContainer
|
||||
.getMetadata()
|
||||
.getAuthors()
|
||||
.forEach(author ->
|
||||
original.add("Made by " + author.getName() + "!")
|
||||
)
|
||||
);
|
||||
return original;
|
||||
}
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
@Inject(method = "get", at = @At("HEAD"), cancellable = true)
|
||||
private void onGet(CallbackInfoReturnable<SplashTextRenderer> ci) {
|
||||
String birthday = SplashUtil.getBirthday(.5);
|
||||
|
||||
if (now.getMonth() == Month.MARCH && now.getDayOfMonth() == 18)
|
||||
bdSplash.add("Happy Birthday, TheClashFruit!");
|
||||
|
||||
if (now.getMonth() == Month.SEPTEMBER && now.getDayOfMonth() == 14)
|
||||
bdSplash.add("Happy Birthday, Blurry!");
|
||||
|
||||
if (now.getMonth() == Month.NOVEMBER && now.getDayOfMonth() == 8)
|
||||
bdSplash.add("Happy Birthday, Fery!");
|
||||
|
||||
return !bdSplash.isEmpty() ? bdSplash : original;
|
||||
if (birthday != null) {
|
||||
ci.setReturnValue(new SplashTextRenderer(birthday));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user