Changed version of the origin one
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
package org.auraclient.auracloaks;
|
||||
|
||||
import at.dhyan.open_imaging.GifDecoder;
|
||||
import org.auraclient.auracloaks.event.KeyInputHandler;
|
||||
import org.auraclient.auracloaks.utils.AnimatedCapeData;
|
||||
import org.auraclient.auracloaks.utils.IdentifierUtils;
|
||||
import org.auraclient.auracloaks.utils.RandomUtils;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
/*
|
||||
* Massive thank you to IIpho3nix for making this mod, i (leo) have modified it to fit Aura Client
|
||||
*/
|
||||
|
||||
public class AuraCloaks implements ModInitializer {
|
||||
public static final String MOD_ID = "auracloaks";
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||
private static final File capesFolder = new File(MinecraftClient.getInstance().runDirectory, "Capes");
|
||||
public static final List<String> list = new ArrayList<>();
|
||||
private static final List<AnimatedCapeData> anicape = new ArrayList<>();
|
||||
private static int capeindex = 0;
|
||||
private static long mili = System.currentTimeMillis();
|
||||
private static String lastCache = "NotCached";
|
||||
public static Identifier capeCacheIdentifier = null;
|
||||
public static String cape = "";
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
list.clear();
|
||||
list.add("");
|
||||
if (capesFolder.mkdir()) {
|
||||
LOGGER.info("New Cape Folder Created");
|
||||
downloadCloakTextures();
|
||||
} else {
|
||||
LOGGER.info("Cape Folder Already Exists");
|
||||
}
|
||||
loadCloakTextures();
|
||||
|
||||
KeyInputHandler.register();
|
||||
}
|
||||
|
||||
public void downloadCloakTextures() {
|
||||
// Todo: Download the cloak textures and put them in the Capes folder
|
||||
}
|
||||
|
||||
private static void loadCloakTextures() {
|
||||
if (capesFolder.isDirectory()) {
|
||||
for (final File fileEntry : Objects.requireNonNull(capesFolder.listFiles())) {
|
||||
if (
|
||||
fileEntry.getName().endsWith(".png") || fileEntry.getName().endsWith(".gif")
|
||||
) {
|
||||
list.add(fileEntry.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void tick() {
|
||||
if (!lastCache.equals(cape)) {
|
||||
if (!cape.isEmpty()) {
|
||||
if (cape.endsWith(".gif")) {
|
||||
try {
|
||||
anicape.clear();
|
||||
Identifier frameIdentifier;
|
||||
File file = new File(capesFolder, cape);
|
||||
final FileInputStream data = new FileInputStream(file);
|
||||
final GifDecoder.GifImage gif = GifDecoder.read(data);
|
||||
final int frameCount = gif.getFrameCount();
|
||||
for (int i = 0; i < frameCount; i++) {
|
||||
final BufferedImage img = gif.getFrame(i);
|
||||
final int delay = gif.getDelay(i);
|
||||
frameIdentifier = Identifier.of(MOD_ID, "capes_" + RandomUtils.randomStringLowercase(10));
|
||||
IdentifierUtils.registerBufferedImageTexture(frameIdentifier, img);
|
||||
anicape.add(new AnimatedCapeData(frameIdentifier, delay));
|
||||
}
|
||||
capeindex = 0;
|
||||
capeCacheIdentifier = anicape.get(0).getId();
|
||||
lastCache = cape;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
BufferedImage img = null;
|
||||
File file = new File(capesFolder, cape);
|
||||
try {
|
||||
img = ImageIO.read(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
capeCacheIdentifier = Identifier.of(MOD_ID, "capes_" + cape.toLowerCase(Locale.ROOT).replace(' ', '_').replaceAll("[^a-z0-9/._-]", ""));
|
||||
IdentifierUtils.registerBufferedImageTexture(capeCacheIdentifier, img);
|
||||
lastCache = cape;
|
||||
}
|
||||
} else {
|
||||
capeCacheIdentifier = null;
|
||||
lastCache = cape;
|
||||
}
|
||||
} else {
|
||||
if (cape.endsWith(".gif")) {
|
||||
if (capeindex > (anicape.size() - 1)) {
|
||||
capeindex = 0;
|
||||
}
|
||||
if (System.currentTimeMillis() > mili + anicape.get(capeindex).getDelay()) {
|
||||
mili = System.currentTimeMillis();
|
||||
capeCacheIdentifier = anicape.get(capeindex).getId();
|
||||
capeindex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.auraclient.auracloaks.event;
|
||||
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
import org.auraclient.auracloaks.AuraCloaks;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
public class KeyInputHandler {
|
||||
public static final String KEY_CATEGORY_CAPES = "key.category.auracloaks";
|
||||
public static final String KEY_CHANGE_CAPE = "key.auracloaks.change_cape";
|
||||
|
||||
public static KeyBinding changeCapeKey;
|
||||
|
||||
public static void register() {
|
||||
changeCapeKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
|
||||
KEY_CHANGE_CAPE, InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_N, KEY_CATEGORY_CAPES
|
||||
));
|
||||
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
if (changeCapeKey.wasPressed()) {
|
||||
if (AuraCloaks.list.indexOf(AuraCloaks.cape) + 1 == AuraCloaks.list.size()) {
|
||||
AuraCloaks.cape = AuraCloaks.list.get(0);
|
||||
AuraCloaks.capeCacheIdentifier = null;
|
||||
}else{
|
||||
AuraCloaks.cape = AuraCloaks.list.get(AuraCloaks.list.indexOf(AuraCloaks.cape) + 1);
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.auraclient.auracloaks.mixin;
|
||||
|
||||
import org.auraclient.auracloaks.AuraCloaks;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.client.util.SkinTextures;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(AbstractClientPlayerEntity.class)
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class AbstractClientPlayerEntityMixin {
|
||||
@Inject(at = @At("RETURN"), method = "getSkinTextures", cancellable = true)
|
||||
private void getSkinTextures(CallbackInfoReturnable<SkinTextures> cir) {
|
||||
if (((AbstractClientPlayerEntity) (Object) this) instanceof ClientPlayerEntity && AuraCloaks.capeCacheIdentifier != null) {
|
||||
SkinTextures textures = cir.getReturnValue();
|
||||
cir.setReturnValue(new SkinTextures(
|
||||
textures.texture(),
|
||||
textures.textureUrl(),
|
||||
AuraCloaks.capeCacheIdentifier,
|
||||
textures.elytraTexture(),
|
||||
textures.model(),
|
||||
textures.secure()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.auraclient.auracloaks.mixin;
|
||||
|
||||
import org.auraclient.auracloaks.AuraCloaks;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(MinecraftClient.class)
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class MinecraftClientMixin {
|
||||
@Inject(at = @At("HEAD"), method = "tick")
|
||||
private void tick(CallbackInfo ci) {
|
||||
AuraCloaks.tick();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.auraclient.auracloaks.utils;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class AnimatedCapeData {
|
||||
private final Identifier id;
|
||||
private final int delay;
|
||||
|
||||
public AnimatedCapeData(Identifier id, int delay) {
|
||||
this.id = id;
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
public Identifier getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getDelay() {
|
||||
return delay;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.auraclient.auracloaks.utils;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.texture.NativeImage;
|
||||
import net.minecraft.client.texture.NativeImageBackedTexture;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.lwjgl.BufferUtils;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class IdentifierUtils {
|
||||
public static void registerBufferedImageTexture(Identifier i, BufferedImage bi) {
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageIO.write(bi, "png", baos);
|
||||
byte[] bytes = baos.toByteArray();
|
||||
ByteBuffer bb = BufferUtils.createByteBuffer(bytes.length).put(bytes);
|
||||
bb.flip();
|
||||
NativeImageBackedTexture nibt = new NativeImageBackedTexture(NativeImage.read(bb));
|
||||
MinecraftClient.getInstance().getTextureManager().registerTexture(i, nibt);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.auraclient.auracloaks.utils;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class RandomUtils {
|
||||
private static String random(final int length, final char[] chars) {
|
||||
final StringBuilder stringBuilder = new StringBuilder();
|
||||
for (int i = 0; i < length; i++)
|
||||
stringBuilder.append(chars[new Random().nextInt(chars.length)]);
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
private static String random(final int length, final String chars) {
|
||||
return random(length, chars.toCharArray());
|
||||
}
|
||||
|
||||
public static String randomString(final int length) {
|
||||
return random(length, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
|
||||
}
|
||||
|
||||
public static String randomStringLowercase(final int length) {
|
||||
return random(length, "0123456789abcdefghijklmnopqrstuvwxyz");
|
||||
}
|
||||
|
||||
public static int randBetween(int min, int max) {
|
||||
Random r = new Random();
|
||||
return r.nextInt(max - min) + min;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user