chore: structure
This commit is contained in:
@@ -1,26 +1,10 @@
|
||||
package org.auraclient.auraclient;
|
||||
|
||||
import at.dhyan.open_imaging.GifDecoder;
|
||||
import org.auraclient.auraclient.event.KeyInputHandler;
|
||||
import org.auraclient.auraclient.utils.AnimatedCapeData;
|
||||
import org.auraclient.auraclient.utils.IdentifierUtils;
|
||||
import org.auraclient.auraclient.utils.RandomUtils;
|
||||
import org.auraclient.auraclient.cloaks.Cloaks;
|
||||
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
|
||||
*/
|
||||
@@ -28,98 +12,13 @@ import java.util.Objects;
|
||||
public class AuraClient implements ModInitializer {
|
||||
public static final String MOD_ID = "auraclient";
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Cloaks.initialize();
|
||||
}
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Cloaks.tick();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
package org.auraclient.auraclient.cloaks;
|
||||
|
||||
import at.dhyan.open_imaging.GifDecoder;
|
||||
|
||||
import org.auraclient.auraclient.AuraClient;
|
||||
import org.auraclient.auraclient.cloaks.utils.AnimatedCapeData;
|
||||
import org.auraclient.auraclient.cloaks.utils.IdentifierUtils;
|
||||
import org.auraclient.auraclient.cloaks.utils.RandomUtils;
|
||||
import org.auraclient.auraclient.event.KeyInputHandler;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
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;
|
||||
|
||||
public class Cloaks {
|
||||
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 = "";
|
||||
|
||||
public static void initialize() {
|
||||
list.clear();
|
||||
list.add("");
|
||||
if (capesFolder.mkdir()) {
|
||||
AuraClient.LOGGER.info("New Cape Folder Created");
|
||||
downloadCloakTextures();
|
||||
} else {
|
||||
AuraClient.LOGGER.info("Cape Folder Already Exists");
|
||||
}
|
||||
loadCloakTextures();
|
||||
|
||||
KeyInputHandler.register();
|
||||
}
|
||||
|
||||
public static 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(AuraClient.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(AuraClient.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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.auraclient.auraclient.utils;
|
||||
package org.auraclient.auraclient.cloaks.utils;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.auraclient.auraclient.utils;
|
||||
package org.auraclient.auraclient.cloaks.utils;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.texture.NativeImage;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.auraclient.auraclient.utils;
|
||||
package org.auraclient.auraclient.cloaks.utils;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.auraclient.auraclient.menus;
|
||||
|
||||
import org.auraclient.auraclient.AuraClient;
|
||||
import org.auraclient.auraclient.cloaks.Cloaks;
|
||||
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
@@ -13,11 +13,11 @@ public class CloakSelector extends Screen {
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
int y = ((this.height - (35 * (AuraClient.list.size()))) / 2);
|
||||
int y = ((this.height - (35 * (Cloaks.list.size()))) / 2);
|
||||
|
||||
for (String cloak : AuraClient.list) {
|
||||
for (String cloak : Cloaks.list) {
|
||||
addDrawableChild(ButtonWidget.builder(Text.literal(cloak), (__) -> {
|
||||
AuraClient.cape = cloak;
|
||||
Cloaks.cape = cloak;
|
||||
}).dimensions((this.width - 50) / 2, y, 50, 30).build());
|
||||
|
||||
y += 35;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.auraclient.auraclient.mixin;
|
||||
|
||||
import org.auraclient.auraclient.AuraClient;
|
||||
import org.auraclient.auraclient.cloaks.Cloaks;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||
@@ -16,12 +17,12 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
public class AbstractClientPlayerEntityMixin {
|
||||
@Inject(at = @At("RETURN"), method = "getSkinTextures", cancellable = true)
|
||||
private void getSkinTextures(CallbackInfoReturnable<SkinTextures> cir) {
|
||||
if (((AbstractClientPlayerEntity) (Object) this) instanceof ClientPlayerEntity && AuraClient.capeCacheIdentifier != null) {
|
||||
if (((AbstractClientPlayerEntity) (Object) this) instanceof ClientPlayerEntity && Cloaks.capeCacheIdentifier != null) {
|
||||
SkinTextures textures = cir.getReturnValue();
|
||||
cir.setReturnValue(new SkinTextures(
|
||||
textures.texture(),
|
||||
textures.textureUrl(),
|
||||
AuraClient.capeCacheIdentifier,
|
||||
Cloaks.capeCacheIdentifier,
|
||||
textures.elytraTexture(),
|
||||
textures.model(),
|
||||
textures.secure()
|
||||
|
||||
Reference in New Issue
Block a user