Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I am making a client-side mod, that can rotate users head ( principe like aimbot, but I am creating a map ).

 

I use onPlayerTick to set rotation and pitch, but it's looks awfull, because it "has only 20 fps"

 

What's a faster way to make something?

 

(Minecraft 1.15.2)

  • Author

I am calculating the angle ( trigonometrically ) using coordinates of an entity. By the way, is it possible to do something like

"palyer.lookAtEntity(entity)"? That would be faster and less performance-heavy than using square root as I do

  • Author

Okaay, it looks better, but still not smooth enough, looks like it's around 25 updates per second, though my FPS-Meter shows I have 60/70 FPS

 

I used

public void onPlayerTick(TickEvent.RenderTickEvent event) {

    if (event.phase == TickEvent.Phase.START) {
      //...

I guess, either "onPlayerTick" is wrong... 😕

  • Author

in the method I am testing if player is available and then I call another procedure "aim", and in that I am setting the pitch and rotation

  • Author
public void onPlayerTick(TickEvent.RenderTickEvent event) {
    if (event.phase == TickEvent.Phase.START) {
        if (Minecraft.getInstance().player == null) return;
        PlayerEntity player = Minecraft.getInstance().player;
        execute ( player );
    }
}
public void execute() {
    //set rotation of player
}

Can't post more because I'm on phone right now.

  • Author
@SubscribeEvent
public void aim (TickEvent.RenderTickEvent event) {
	if (event.phase == TickEvent.Phase.START) {
		if ( Minecraft.getInstance().player == null ) return;
		PlayerEntity entity = (PlayerEntity) Minecraft.getInstance().player;
		IWorld world = (IWorld) entity.world;
		boolean aiming = PlaceModVariables.WorldVariables.get(world).aiming;
		if ( aiming ) {
			double d = PlaceModVariables.WorldVariables.get(world).aim_distance;
			{
				List<Entity> _entfound = world
						.getEntitiesWithinAABB(Entity.class,
								new AxisAlignedBB((entity.getPosX()) - (d / 2d), (entity.getPosY()) - (d / 2d), (entity.getPosZ()) - (d / 2d),
										(entity.getPosX()) + (d / 2d), (entity.getPosY()) + (d / 2d), (entity.getPosZ()) + (d / 2d)),
								null)
						.stream().sorted(new Object() {
							Comparator<Entity> compareDistOf(double _x, double _y, double _z) {
								return Comparator.comparing((Function<Entity, Double>) (_entcnd -> _entcnd.getDistanceSq(_x, _y, _z)));
							}
						}.compareDistOf((entity.getPosX()), (entity.getPosY()), (entity.getPosZ()))).collect(Collectors.toList());
				for (Entity entityiterator : _entfound) {
					if ((entityiterator != entity) && (entityiterator.getDisplayName().getString().equals( PlaceModVariables.WorldVariables.get(world).aim ) ) ) {
						double dX = (double) ((entity.getPosX()) - (entityiterator.getPosX()));
						double dY = (double) ((entity.getPosY() + entity.getHeight()) - (entityiterator.getPosY() + ((entityiterator.getHeight()) / 2 )));
						double dZ = (double) ((entity.getPosZ()) - (entityiterator.getPosZ()));
						float yaw = (float) (Math.toDegrees((Math.atan2(dZ, dX))) + 90);
						float pitch = (float) ( 263 - (Math.toDegrees((Math.atan2(Math.sqrt(dZ * dZ + dX * dX), dY) + Math.PI ))));
						entity.rotationYaw = yaw;
						entity.rotationPitch = pitch;
						break;
					}
				}
			}
		}
	}
}

This code was partially generated by MCreator ( it's a Scratch-like programm to make mods for minecraft )

  • Author

Thank you for your advice, but after going through it, did not have any idea, how to use it ( as mentioned earlier, I was never programming before and was always using MCreator )

   private void cursorPosCallback(long handle, double xpos, double ypos) {
      if (handle == Minecraft.getInstance().getMainWindow().getHandle()) {
         if (this.ignoreFirstMove) {
            this.mouseX = xpos;
            this.mouseY = ypos;
            this.ignoreFirstMove = false;
         }

         IGuiEventListener iguieventlistener = this.minecraft.currentScreen;
         if (iguieventlistener != null && this.minecraft.loadingGui == null) {
            double d0 = xpos * (double)this.minecraft.getMainWindow().getScaledWidth() / (double)this.minecraft.getMainWindow().getWidth();
            double d1 = ypos * (double)this.minecraft.getMainWindow().getScaledHeight() / (double)this.minecraft.getMainWindow().getHeight();
            Screen.wrapScreenError(() -> {
               iguieventlistener.mouseMoved(d0, d1);
            }, "mouseMoved event handler", iguieventlistener.getClass().getCanonicalName());
            if (this.activeButton != -1 && this.eventTime > 0.0D) {
               double d2 = (xpos - this.mouseX) * (double)this.minecraft.getMainWindow().getScaledWidth() / (double)this.minecraft.getMainWindow().getWidth();
               double d3 = (ypos - this.mouseY) * (double)this.minecraft.getMainWindow().getScaledHeight() / (double)this.minecraft.getMainWindow().getHeight();
               Screen.wrapScreenError(() -> {
                  if (net.minecraftforge.client.ForgeHooksClient.onGuiMouseDragPre(this.minecraft.currentScreen, d0, d1, this.activeButton, d2, d3)) return;
                  if (iguieventlistener.mouseDragged(d0, d1, this.activeButton, d2, d3)) return;
                  net.minecraftforge.client.ForgeHooksClient.onGuiMouseDragPost(this.minecraft.currentScreen, d0, d1, this.activeButton, d2, d3);
               }, "mouseDragged event handler", iguieventlistener.getClass().getCanonicalName());
            }
         }

         this.minecraft.getProfiler().startSection("mouse");
         if (this.isMouseGrabbed() && this.minecraft.isGameFocused()) {
            this.xVelocity += xpos - this.mouseX;
            this.yVelocity += ypos - this.mouseY;
         }

         this.updatePlayerLook();
         this.mouseX = xpos;
         this.mouseY = ypos;
         this.minecraft.getProfiler().endSection();
      }
   }

   public void updatePlayerLook() {
      double d0 = NativeUtil.getTime();
      double d1 = d0 - this.lastLookTime;
      this.lastLookTime = d0;
      if (this.isMouseGrabbed() && this.minecraft.isGameFocused()) {
         double d4 = this.minecraft.gameSettings.mouseSensitivity * (double)0.6F + (double)0.2F;
         double d5 = d4 * d4 * d4 * 8.0D;
         double d2;
         double d3;
         if (this.minecraft.gameSettings.smoothCamera) {
            double d6 = this.xSmoother.smooth(this.xVelocity * d5, d1 * d5);
            double d7 = this.ySmoother.smooth(this.yVelocity * d5, d1 * d5);
            d2 = d6;
            d3 = d7;
         } else {
            this.xSmoother.reset();
            this.ySmoother.reset();
            d2 = this.xVelocity * d5;
            d3 = this.yVelocity * d5;
         }

         this.xVelocity = 0.0D;
         this.yVelocity = 0.0D;
         int i = 1;
         if (this.minecraft.gameSettings.invertMouse) {
            i = -1;
         }

         this.minecraft.getTutorial().onMouseMove(d2, d3);
         if (this.minecraft.player != null) {
            this.minecraft.player.rotateTowards(d2, d3 * (double)i);
         }

      } else {
         this.xVelocity = 0.0D;
         this.yVelocity = 0.0D;
      }
   }

Only things to use in my opinion are "this.minecraft.getProfiler().startSection("mouse");" and "IGuiEventListener iguieventlistener = this.minecraft.currentScreen;", but I have no idea, how to use them as trigger for my function... 😵

  • Author

I know the very basics.. I guess it is still not enough.. But I am here to get help :)

I am sorry, but it won't help me, if you tell me, how bad I am

  • Author

Hmm, well, then 🤷‍♂️ I don't want to argue a lot, because, you're right.. Could you still please help me to find this out?

  • Author

Ow... RotateTowards...

I tried it out right now, and it looks smooth :) Now need to figure out, which arguments to pass 

Edited by Kemuri Senpai

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.