Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.examplemod;
- import org.lwjgl.opengl.GL11;
- import net.minecraftforge.client.event.RenderPlayerEvent;
- import net.minecraftforge.common.MinecraftForge;
- import net.minecraftforge.fml.common.Mod;
- import net.minecraftforge.fml.common.Mod.EventHandler;
- import net.minecraftforge.fml.common.event.FMLInitializationEvent;
- import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
- import net.minecraftforge.fml.relauncher.Side;
- @Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION)
- public class ExampleMod{
- public static final String MODID = "examplemod";
- public static final String VERSION = "1.0";
- @EventHandler
- public void init(FMLInitializationEvent event){
- /*
- Register the event class only if side is client. You would usually do this in your client proxy but for
- simplicity I am doing it here. Also the event class should not be the main again this is only for simplicity.
- */
- if(event.getSide()==Side.CLIENT)MinecraftForge.EVENT_BUS.register(this);
- }
- @SubscribeEvent
- public void rednerPlayerPre(RenderPlayerEvent.Pre event){
- //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.
- GL11.glPushMatrix();
- //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)
- float baseRotation=(event.getEntityPlayer().renderYawOffset-event.getEntityPlayer().prevRenderYawOffset)*event.getPartialRenderTick()+event.getEntityPlayer().prevRenderYawOffset;
- GL11.glRotatef(-baseRotation, 0, 1, 0);
- //here do your rotating
- double time=event.getEntityPlayer().getEntityWorld().getTotalWorldTime();
- GL11.glRotatef((float)time, 1, 0, 0);
- GL11.glRotatef((float)time*2, 0, 1, 0);
- GL11.glRotatef((float)time/2, 0, 0, 1);
- //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
- GL11.glRotatef(baseRotation, 0, 1, 0);
- }
- @SubscribeEvent
- public void rednerPlayerPost(RenderPlayerEvent.Post event){
- //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
- GL11.glPopMatrix();
- }
- }
Add Comment
Please, Sign In to add comment