add RotationManager (closes #6)
This commit is contained in:
parent
ea82cb3362
commit
56a6e8eafb
2 changed files with 51 additions and 0 deletions
|
@ -3,6 +3,7 @@ package com.baseband.client.module.client;
|
|||
import com.baseband.client.configuration.Configuration;
|
||||
import com.baseband.client.configuration.annotation.Config;
|
||||
import com.baseband.client.configuration.annotation.KeyBound;
|
||||
import com.baseband.client.util.interact.RotationManager;
|
||||
import com.baseband.client.util.interact.ServerDataManager;
|
||||
import com.baseband.client.util.misc.Description;
|
||||
import com.baseband.client.event.events.PacketEvent;
|
||||
|
@ -16,7 +17,9 @@ import net.minecraft.entity.EntityLivingBase;
|
|||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.SPacketPlayerPosLook;
|
||||
import net.minecraft.network.play.server.SPacketTimeUpdate;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
@com.baseband.client.module.category.Client
|
||||
public class Client extends Feature {
|
||||
|
@ -94,6 +97,12 @@ public class Client extends Feature {
|
|||
@Override
|
||||
public void onTick() {
|
||||
ServerDataManager.onTick();
|
||||
RotationManager.onTick();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRender(RenderWorldLastEvent event) {
|
||||
RotationManager.onTick();
|
||||
}
|
||||
|
||||
public void onPlayerDestroy(PlayerDestroyEvent event) {
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package com.baseband.client.util.interact;
|
||||
|
||||
import static com.baseband.client.BaseBand.mc;
|
||||
|
||||
public class RotationManager {
|
||||
|
||||
private static float sourceYaw, sourcePitch;
|
||||
public static float destYaw, destPitch;
|
||||
private static int timeMs;
|
||||
private static boolean active = false;
|
||||
private static long startTime = 0;
|
||||
|
||||
public static void run(float destYaw, float destPitch, int timeMs) {
|
||||
sourceYaw = mc.player.rotationYaw;
|
||||
sourcePitch = mc.player.rotationPitch;
|
||||
RotationManager.destYaw = destYaw;
|
||||
RotationManager.destPitch = destPitch;
|
||||
RotationManager.timeMs = timeMs;
|
||||
active = true;
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
private static float getDest(float source, float dest) {
|
||||
float diff = dest - source;
|
||||
if(Math.abs(diff) > 90)
|
||||
diff = -diff % 90;
|
||||
return source + diff * (System.currentTimeMillis() - startTime) / timeMs;
|
||||
}
|
||||
|
||||
public static void onTick() {
|
||||
if(!active) return;
|
||||
|
||||
if((mc.player.rotationYaw = getDest(sourceYaw, destYaw)) == destYaw &&
|
||||
(mc.player.rotationPitch = getDest(sourcePitch, destPitch)) == destPitch)
|
||||
active = false;
|
||||
}
|
||||
|
||||
public static boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue