LapisSea

HOW TO ROTATE THE DAM PLAYER!!

Jun 4th, 2016
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.32 KB | None | 0 0
  1. package com.example.examplemod;
  2.  
  3. import org.lwjgl.opengl.GL11;
  4.  
  5. import net.minecraftforge.client.event.RenderPlayerEvent;
  6. import net.minecraftforge.common.MinecraftForge;
  7. import net.minecraftforge.fml.common.Mod;
  8. import net.minecraftforge.fml.common.Mod.EventHandler;
  9. import net.minecraftforge.fml.common.event.FMLInitializationEvent;
  10. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  11. import net.minecraftforge.fml.relauncher.Side;
  12.  
  13. @Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION)
  14. public class ExampleMod{
  15.     public static final String MODID = "examplemod";
  16.     public static final String VERSION = "1.0";
  17.    
  18.     @EventHandler
  19.     public void init(FMLInitializationEvent event){
  20.         /*
  21.         Register the event class only if side is client. You would usually do this in your client proxy but for
  22.         simplicity I am doing it here. Also the event class should not be the main again this is only for simplicity.
  23.         */
  24.         if(event.getSide()==Side.CLIENT)MinecraftForge.EVENT_BUS.register(this);
  25.     }
  26.    
  27.     @SubscribeEvent
  28.     public void rednerPlayerPre(RenderPlayerEvent.Pre event){
  29.         //Puch matrix aka save transformation so you can load/pop it later so the rest of the world is not affected by the player rotation.
  30.         GL11.glPushMatrix();
  31.        
  32.         //here is calculated the rotation yaw of the player body. you'll probably need this if your rotation is dependent on player rotation (what is in 90% of the cases true)
  33.         float baseRotation=(event.getEntityPlayer().renderYawOffset-event.getEntityPlayer().prevRenderYawOffset)*event.getPartialRenderTick()+event.getEntityPlayer().prevRenderYawOffset;
  34.         GL11.glRotatef(-baseRotation, 0, 1, 0);
  35.        
  36.         //here do your rotating
  37.         double time=event.getEntityPlayer().getEntityWorld().getTotalWorldTime();
  38.         GL11.glRotatef((float)time, 1, 0, 0);
  39.         GL11.glRotatef((float)time*2, 0, 1, 0);
  40.         GL11.glRotatef((float)time/2, 0, 0, 1);
  41.        
  42.         //if you did the player body yaw rotating than you'll need to rotate back. If you do not understand this you should read up on matrix transformations
  43.         GL11.glRotatef(baseRotation, 0, 1, 0);
  44.        
  45.     }
  46.     @SubscribeEvent
  47.     public void rednerPlayerPost(RenderPlayerEvent.Post event){
  48.         //here the player already rendered so no need for any transformations here, we just need to pop/load the initial matrix to protect the rest of the rendering
  49.         GL11.glPopMatrix();
  50.     }
  51. }
Add Comment
Please, Sign In to add comment