Jump to content

Recommended Posts

Posted

Hello, i was working on my minecraft client trying to make an automatic entity facing module and it works perfectly fine. The only problem that is bothering me is that there are stutters in between the yaw updating of the player which I don't know the reason to. The code is from this youtube video:  Facing smoothly

 

Here is a clip of it ingame to understand my problem more easily: Facing Stuttery (My version)

 

It's a bit strange, since for the guy in the video its running smoothly.

 

Here's the code:

 

	@EventTarget
	public void update(EventUpdate e) {
		
		
		ticks1 += 1;
		
		for(Iterator<Object> entities = mc.theWorld.loadedEntityList.iterator(); entities.hasNext();) {
            Object theObject = entities.next();
            if(theObject instanceof EntityLivingBase) {
	                EntityLivingBase entityplayer = (EntityLivingBase) theObject;
	               
	            if(entityplayer.getName() == mc.thePlayer.getName()){
	                continue;
	            }
	            
	            if(entityplayer instanceof EntityPig) {
	            
	            	if(mc.thePlayer.getDistanceSqToEntity(entityplayer) <= 10F) {
	            		
	            		this.faceEntity(entityplayer);
	            	}
	            		
	            }
            
            }	
		}
		
		
	}
	
	public static float[] getRotationsNeeded(Entity entity)
    {
        if(entity == null)
            return null;
        double diffX = entity.posX - Minecraft.getMinecraft().thePlayer.posX;
        double diffY;
        if(entity instanceof EntityLivingBase)
        {
            EntityLivingBase entityLivingBase = (EntityLivingBase)entity;
            diffY =
                entityLivingBase.posY
                    + entityLivingBase.getEyeHeight()
                    * 0.9
                    - (Minecraft.getMinecraft().thePlayer.posY + Minecraft
                        .getMinecraft().thePlayer.getEyeHeight());
        }else
            diffY =
                (entity.boundingBox.minY + entity.boundingBox.maxY)
                    / 2.0D
                    - (Minecraft.getMinecraft().thePlayer.posY + Minecraft
                        .getMinecraft().thePlayer.getEyeHeight());
        double diffZ = entity.posZ - Minecraft.getMinecraft().thePlayer.posZ;
        double dist = MathHelper.sqrt_double(diffX * diffX + diffZ * diffZ);
        float yaw =
            (float)(Math.atan2(diffZ, diffX) * 180.0 / Math.PI) - 90.0F;
        float pitch = (float)-(Math.atan2(diffY, dist) * 180.0 / Math.PI);
        return new float[]{
            Minecraft.getMinecraft().thePlayer.prevCameraYaw
                + MathHelper.wrapAngleTo180_float(yaw
                    - Minecraft.getMinecraft().thePlayer.prevCameraYaw),
            Minecraft.getMinecraft().thePlayer.rotationPitch
                + MathHelper.wrapAngleTo180_float(pitch
                    - Minecraft.getMinecraft().thePlayer.rotationPitch)};
       
    }
   
    public static void faceEntity(EntityLivingBase entity)
      {
    	float[] rotations = getRotationsNeeded(entity);
        if (rotations != null)
        {
            Minecraft.getMinecraft().thePlayer.rotationYaw = rotations[0];
            Minecraft.getMinecraft().thePlayer.rotationPitch = rotations[1] + 1;
        }
    }

 

I would really appreciate it if someone would help me out with my problem!

The person that will help me gets a cookie ?

 

Best Regards,

Freakz :)

Posted

You aren't properly handling "partial ticks." Remember, ticks (game processing) are 20 times per second, but the rendering can be anywhere from 30 to 120 times a second.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
1 minute ago, Draco18s said:

You aren't properly handling "partial ticks." Remember, ticks (game processing) are 20 times per second, but the rendering can be anywhere from 30 to 120 times a second.

Thank you for your quick response, so the reason regarding to the stutter, is my update() method with the EventUpdate e that is calling my faceEntity only 20 times a second?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I was trying to find a mod that added something specific, and was unable to find it with what limited memory I had of seeing it. I don't know why there isn't an option to include words in overviews of mods. I could see it being in the sort tab near filters on the app in my opinion. It might help someone trying to find something specific, only based off something from the overview tab, but idk
    • Please read the FAQ and post logs as described there.   Also, do not just add a post onto someone else's thread with your issue, create a new one please.
    • I am creating a server with mods but when i try tostart it it say in the logs:   [29Jan2025 20:36:50.715] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file /server/libraries/net/minecraftforge/fmlcore/1.20.1-47.3.27/fmlcore-1.20.1-47.3.27.jar is missing mods.toml file 159[29Jan2025 20:36:50.717] [main/DEBUG] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Considering mod file candidate /server/libraries/net/minecraftforge/javafmllanguage/1.20.1-47.3.27/javafmllanguage-1.20.1-47.3.27.jar 160[29Jan2025 20:36:50.717] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file /server/libraries/net/minecraftforge/javafmllanguage/1.20.1-47.3.27/javafmllanguage-1.20.1-47.3.27.jar is missing mods.toml file 161[29Jan2025 20:36:50.718] [main/DEBUG] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Considering mod file candidate /server/libraries/net/minecraftforge/lowcodelanguage/1.20.1-47.3.27/lowcodelanguage-1.20.1-47.3.27.jar 162[29Jan2025 20:36:50.718] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file /server/libraries/net/minecraftforge/lowcodelanguage/1.20.1-47.3.27/lowcodelanguage-1.20.1-47.3.27.jar is missing mods.toml file 163[29Jan2025 20:36:50.719] [main/DEBUG] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Considering mod file candidate /server/libraries/net/minecraftforge/mclanguage/1.20.1-47.3.27/mclanguage-1.20.1-47.3.27.jar 164[29Jan2025 20:36:50.719] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file /server/libraries/net/minecraftforge/mclanguage/1.20.1-47.3.27/mclanguage-1.20.1-47.3.27.jar is missing mods.toml file
    • How do you configure the entity reach of a custom weapon? Asking for 1.21 Minecraft parchment
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.