|
| 1 | +package me.redth.vapev69; |
| 2 | + |
| 3 | +import me.redth.vapev69.config.VapeConfig; |
| 4 | +import net.minecraft.client.Minecraft; |
| 5 | +import net.minecraft.entity.player.EntityPlayer; |
| 6 | +import net.minecraft.item.ItemStack; |
| 7 | +import net.minecraft.item.ItemSword; |
| 8 | +import net.minecraft.util.Vec3; |
| 9 | +import net.minecraftforge.client.event.RenderPlayerEvent; |
| 10 | +import net.minecraftforge.common.MinecraftForge; |
| 11 | +import net.minecraftforge.fml.common.Mod; |
| 12 | +import net.minecraftforge.fml.common.event.FMLInitializationEvent; |
| 13 | +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; |
| 14 | +import net.minecraftforge.fml.common.gameevent.TickEvent; |
| 15 | + |
| 16 | +@Mod(modid = "@ID@", name = "@NAME@", version = "@VER@") |
| 17 | +public class VapeV69 { |
| 18 | + private static final Minecraft mc = Minecraft.getMinecraft(); |
| 19 | + public static VapeConfig config; |
| 20 | + public static boolean isInRenderTick; |
| 21 | + |
| 22 | + public static float prevRotationYawHead; |
| 23 | + public static float rotationYawHead; |
| 24 | + public static float prevRotationPitch; |
| 25 | + public static float rotationPitch; |
| 26 | + |
| 27 | + public static float prevRotationYawHeadVisual; |
| 28 | + public static float prevRotationPitchVisual; |
| 29 | + public static float rotationYawHeadVisual; |
| 30 | + public static float rotationPitchVisual; |
| 31 | + |
| 32 | + @Mod.EventHandler |
| 33 | + public void init(FMLInitializationEvent e) { |
| 34 | + MinecraftForge.EVENT_BUS.register(this); |
| 35 | + config = new VapeConfig(); |
| 36 | + } |
| 37 | + |
| 38 | + @SubscribeEvent |
| 39 | + public void playerPreRender(RenderPlayerEvent.Pre e) { |
| 40 | + if (!e.entityPlayer.equals(mc.thePlayer) || !config.enabled || !VapeConfig.spinning) return; |
| 41 | + |
| 42 | + prevRotationYawHead = mc.thePlayer.prevRotationYawHead; |
| 43 | + rotationYawHead = mc.thePlayer.rotationYawHead; |
| 44 | + prevRotationPitch = mc.thePlayer.prevRotationPitch; |
| 45 | + rotationPitch = mc.thePlayer.rotationPitch; |
| 46 | + |
| 47 | + mc.thePlayer.prevRotationYawHead = prevRotationYawHeadVisual; |
| 48 | + mc.thePlayer.prevRotationPitch = prevRotationPitchVisual; |
| 49 | + mc.thePlayer.rotationYawHead = rotationYawHeadVisual; |
| 50 | + mc.thePlayer.rotationPitch = rotationPitchVisual; |
| 51 | + } |
| 52 | + |
| 53 | + @SubscribeEvent |
| 54 | + public void onTick(TickEvent.ClientTickEvent e) { |
| 55 | + if (e.phase != TickEvent.Phase.END) return; |
| 56 | + if (mc.theWorld == null || mc.thePlayer == null) return; |
| 57 | + getDirection(); |
| 58 | + } |
| 59 | + |
| 60 | + public static void getDirection() { |
| 61 | + prevRotationYawHeadVisual = rotationYawHeadVisual; |
| 62 | + prevRotationPitchVisual = rotationPitchVisual; |
| 63 | + |
| 64 | + EntityPlayer nearestEntity = mc.theWorld.findNearestEntityWithinAABB(EntityPlayer.class, mc.thePlayer.getEntityBoundingBox().expand(5, 5, 5), mc.thePlayer); |
| 65 | + if (nearestEntity == null) { |
| 66 | + |
| 67 | + rotationYawHeadVisual = System.currentTimeMillis() % 360; |
| 68 | + rotationPitchVisual = (float) Math.sin(System.currentTimeMillis() % 360) * 90; |
| 69 | + |
| 70 | + } else { |
| 71 | + |
| 72 | + Vec3 difference = mc.thePlayer.getPositionEyes(1).subtract(nearestEntity.getPositionEyes(1)); |
| 73 | + |
| 74 | + double yaw = Math.toDegrees(Math.atan2(difference.zCoord, difference.xCoord)) + 90; |
| 75 | + yaw = (yaw + 360) % 360; |
| 76 | + |
| 77 | + double horizontalDistance = Math.sqrt(difference.xCoord * difference.xCoord + difference.zCoord * difference.zCoord); |
| 78 | + double pitch = Math.toDegrees(Math.atan2(difference.yCoord, horizontalDistance)); |
| 79 | + pitch = (pitch + 360) % 360; |
| 80 | + |
| 81 | + rotationYawHeadVisual = (float) yaw; |
| 82 | + rotationPitchVisual = (float) pitch; |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + @SubscribeEvent |
| 87 | + public void playerPostRender(RenderPlayerEvent.Post e) { |
| 88 | + if (!e.entityPlayer.equals(mc.thePlayer) || !config.enabled || !VapeConfig.spinning) return; |
| 89 | + mc.thePlayer.prevRotationYawHead = prevRotationYawHead; |
| 90 | + mc.thePlayer.rotationYawHead = rotationYawHead; |
| 91 | + mc.thePlayer.prevRotationPitch = prevRotationPitch; |
| 92 | + mc.thePlayer.rotationPitch = rotationPitch; |
| 93 | + } |
| 94 | + |
| 95 | + public static boolean isEnabledAndRendering() { |
| 96 | + return config.enabled && isInRenderTick; |
| 97 | + } |
| 98 | + |
| 99 | + public static boolean isSword(ItemStack item) { |
| 100 | + return VapeConfig.blockhit && item != null && item.getItem() instanceof ItemSword; |
| 101 | + } |
| 102 | + |
| 103 | + public static boolean hasSafeWalk() { |
| 104 | + return VapeConfig.safewalk; |
| 105 | + } |
| 106 | + |
| 107 | + |
| 108 | + @SubscribeEvent |
| 109 | + public void onRenderTick(TickEvent.RenderTickEvent event) { |
| 110 | + isInRenderTick = event.phase == TickEvent.Phase.START; |
| 111 | + } |
| 112 | + |
| 113 | +} |
0 commit comments