diff --git a/.gitignore b/.gitignore index d4d609e94..23b017603 100644 --- a/.gitignore +++ b/.gitignore @@ -15,8 +15,8 @@ build.sh # donator -src/main/java/me/zeroeightsix/kami/module/modules/sdashb/capes/ -src/main/java/me/zeroeightsix/kami/mixin/client/MixinAbstractClientPlayer.java +#src/main/java/me/zeroeightsix/kami/module/modules/sdashb/capes/ +#src/main/java/me/zeroeightsix/kami/mixin/client/MixinAbstractClientPlayer.java # sdashb @@ -34,6 +34,7 @@ src/main/java/net/minecraft/ src/main/java/org/lwjgl # Google + src/main/java/com/google # private diff --git a/src/main/java/me/zeroeightsix/kami/mixin/client/MixinAbstractClientPlayer.java b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinAbstractClientPlayer.java new file mode 100644 index 000000000..1f1b5ce2f --- /dev/null +++ b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinAbstractClientPlayer.java @@ -0,0 +1,30 @@ +package me.zeroeightsix.kami.mixin.client; + +import com.mojang.authlib.GameProfile; +import me.zeroeightsix.kami.module.ModuleManager; +import me.zeroeightsix.kami.module.modules.sdashb.capes.LayerCape; +import me.zeroeightsix.kami.module.modules.sdashb.render.CapeGUI; +import me.zeroeightsix.kami.util.Wrapper; +import net.minecraft.client.entity.AbstractClientPlayer; +import net.minecraft.client.renderer.entity.RenderPlayer; +import net.minecraft.world.World; +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; + +//i love crystallinqq <3 + +@Mixin(AbstractClientPlayer.class) +public class MixinAbstractClientPlayer { + + @Inject(method = "", at = @At(value = "RETURN")) + public void AbstractClientPlayer(World worldIn, GameProfile playerProfile, CallbackInfo callbackInfo) { + for (RenderPlayer renderPlayer : Wrapper.getMinecraft().getRenderManager().getSkinMap().values()) { + //if (ModuleManager.getModuleByName("Cape").isEnabled()) { + LayerCape cape = new LayerCape(renderPlayer); + renderPlayer.addLayer(cape); + //} + } + } +} \ No newline at end of file diff --git a/src/main/java/me/zeroeightsix/kami/mixin/client/MixinMinecraft.java b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinMinecraft.java index 0933e2c9d..132f7752d 100644 --- a/src/main/java/me/zeroeightsix/kami/mixin/client/MixinMinecraft.java +++ b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinMinecraft.java @@ -2,6 +2,7 @@ package me.zeroeightsix.kami.mixin.client; import me.zeroeightsix.kami.KamiMod; import me.zeroeightsix.kami.event.events.GuiScreenEvent; +import me.zeroeightsix.kami.module.modules.sdashb.capes.Capes; import me.zeroeightsix.kami.util.Wrapper; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.SoundHandler; @@ -108,7 +109,7 @@ public class MixinMinecraft { @Inject(method = "init", at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;ingameGUI:Lnet/minecraft/client/gui/GuiIngame;", shift = At.Shift.AFTER)) public void startCapes(CallbackInfo ci) { System.out.println("Loaded capes"); - // new Capes(); // TODO: Fix capes. + new Capes(); // TODO: Fix capes. } private void save() { diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/sdashb/capes/Capes.java b/src/main/java/me/zeroeightsix/kami/module/modules/sdashb/capes/Capes.java new file mode 100644 index 000000000..664c37348 --- /dev/null +++ b/src/main/java/me/zeroeightsix/kami/module/modules/sdashb/capes/Capes.java @@ -0,0 +1,108 @@ +package me.zeroeightsix.kami.module.modules.sdashb.capes; + +import com.google.gson.Gson; +import me.zeroeightsix.kami.KamiMod; +import me.zeroeightsix.kami.module.Module; +import me.zeroeightsix.kami.module.ModuleManager; +import me.zeroeightsix.kami.module.modules.sdashb.render.CapeGUI; +import me.zeroeightsix.kami.util.Wrapper; +import net.minecraft.client.entity.AbstractClientPlayer; +import net.minecraft.client.renderer.IImageBuffer; +import net.minecraft.client.renderer.ThreadDownloadImageData; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.util.ResourceLocation; + +import javax.net.ssl.HttpsURLConnection; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.InputStreamReader; +import java.net.URL; + +//i love crystallinqq <3 + +/*** + * @author crystalling + */ +public class Capes { + + private static Capes INSTANCE; + private CapeUser[] capeUser; + + public Capes() { + INSTANCE = this; + if (ModuleManager.isModuleEnabled("Cape")) { + try { + HttpsURLConnection connection = (HttpsURLConnection) new URL("https://raw.githubusercontent.com/S-B99/KAMI/features-master/assets/capes.json").openConnection(); + + connection.connect(); + this.capeUser = new Gson().fromJson(new InputStreamReader(connection.getInputStream()), CapeUser[].class); + connection.disconnect(); + } catch (Exception e) { + KamiMod.log.error("Failed to load capes"); + e.printStackTrace(); + } + + if (capeUser != null) { + for (CapeUser user : capeUser) { + bindTexture(user.url, "capes/kami/" + formatUUID(user.uuid)); + } + } + } + } + + public static ResourceLocation getCapeResource(AbstractClientPlayer player) { + for(CapeUser user : INSTANCE.capeUser) { + if(player.getUniqueID().toString().equalsIgnoreCase(user.uuid)) { + return new ResourceLocation("capes/kami/" + formatUUID(user.uuid)); + } + } + + return null; + } + + private void bindTexture(String url, String resource) { + IImageBuffer iib = new IImageBuffer() { + @Override + public BufferedImage parseUserSkin(BufferedImage image) { + return parseCape(image); + } + + @Override + public void skinAvailable() {} + }; + + ResourceLocation rl = new ResourceLocation(resource); + TextureManager textureManager = Wrapper.getMinecraft().getTextureManager(); + textureManager.getTexture(rl); + ThreadDownloadImageData textureCape = new ThreadDownloadImageData(null, url, null, iib); + textureManager.loadTexture(rl, textureCape); + + } + + private BufferedImage parseCape(BufferedImage img) { + int imageWidth = 64; + int imageHeight = 32; + + int srcWidth = img.getWidth(); + int srcHeight = img.getHeight(); + while (imageWidth < srcWidth || imageHeight < srcHeight) { + imageWidth *= 2; + imageHeight *= 2; + } + BufferedImage imgNew = new BufferedImage(imageWidth, imageHeight, 2); + Graphics g = imgNew.getGraphics(); + g.drawImage(img, 0, 0, null); + g.dispose(); + + return imgNew; + } + + private static String formatUUID(String uuid) { + return uuid.replaceAll("-", ""); + } + + private class CapeUser { + public String uuid; + public String url; + } +} diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/sdashb/capes/LayerCape.java b/src/main/java/me/zeroeightsix/kami/module/modules/sdashb/capes/LayerCape.java new file mode 100644 index 000000000..2a591d72f --- /dev/null +++ b/src/main/java/me/zeroeightsix/kami/module/modules/sdashb/capes/LayerCape.java @@ -0,0 +1,69 @@ +package me.zeroeightsix.kami.module.modules.sdashb.capes; + +import net.minecraft.client.entity.AbstractClientPlayer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.entity.RenderPlayer; +import net.minecraft.client.renderer.entity.layers.LayerRenderer; +import net.minecraft.entity.player.EnumPlayerModelParts; +import net.minecraft.init.Items; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.MathHelper; + +public class LayerCape implements LayerRenderer { + + private final RenderPlayer playerRenderer; + + public LayerCape(RenderPlayer playerRenderer) { + this.playerRenderer = playerRenderer; + } + + @Override + public void doRenderLayer(AbstractClientPlayer player, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale) { + ResourceLocation rl = Capes.getCapeResource(player); + + ItemStack itemstack = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST); + if (!player.hasPlayerInfo() || player.isInvisible() || !player.isWearing(EnumPlayerModelParts.CAPE) || itemstack.getItem() == Items.ELYTRA || rl == null) return; + + float f9 = 0.14f; + float f10 = 0.0f; + if (player.isSneaking()) { + f9 = 0.1f; + f10 = 0.09f; + } + GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); + this.playerRenderer.bindTexture(rl); + GlStateManager.pushMatrix(); + GlStateManager.translate(0.0f, f10, f9); + double d0 = player.prevChasingPosX + (player.chasingPosX - player.prevChasingPosX) * new Float(partialTicks).doubleValue() - (player.prevPosX + (player.posX - player.prevPosX) * new Float(partialTicks).doubleValue()); + double d1 = player.prevChasingPosY + (player.chasingPosY - player.prevChasingPosY) * new Float(partialTicks).doubleValue() - (player.prevPosY + (player.posY - player.prevPosY) * new Float(partialTicks).doubleValue()); + double d2 = player.prevChasingPosZ + (player.chasingPosZ - player.prevChasingPosZ) * new Float(partialTicks).doubleValue() - (player.prevPosZ + (player.posZ - player.prevPosZ) * new Float(partialTicks).doubleValue()); + float f = player.prevRenderYawOffset + (player.renderYawOffset - player.prevRenderYawOffset) * partialTicks; + double d3 = new Float(MathHelper.sin(f * 0.01745329f)).doubleValue(); + double d4 = new Float(-MathHelper.cos(f * 0.01745329f)).doubleValue(); + float f1 = new Double(d1).floatValue() * 10.0f; + f1 = MathHelper.clamp(f1, 3.0f, 32.0f); + float f2 = new Double(d0 * d3 + d2 * d4).floatValue() * 100.0f; + float f3 = new Double(d0 * d4 - d2 * d3).floatValue() * 100.0f; + if (f2 < 0.0f) { + f2 = 0.0f; + } + float f4 = player.prevCameraYaw + (player.cameraYaw - player.prevCameraYaw) * partialTicks; + f1 += MathHelper.sin((player.prevDistanceWalkedModified + (player.distanceWalkedModified - player.prevDistanceWalkedModified) * partialTicks) * 6.0f) * 32.0f * f4; + if (player.isSneaking()) { + f1 += 20.0f; + } + GlStateManager.rotate(5.0f + f2 / 2.0f + f1, 1.0f, 0.0f, 0.0f); + GlStateManager.rotate(f3 / 2.0f, 0.0f, 0.0f, 1.0f); + GlStateManager.rotate(-f3 / 2.0f, 0.0f, 1.0f, 0.0f); + GlStateManager.rotate(180.0f, 0.0f, 1.0f, 0.0f); + this.playerRenderer.getMainModel().renderCape(0.0625f); + GlStateManager.popMatrix(); + } + + @Override + public boolean shouldCombineTextures() { + return false; + } +} \ No newline at end of file