Jump to content

Recommended Posts

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)

Posted

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

Posted

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

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

Posted
@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 )

Posted

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

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



×
×
  • Create New...

Important Information

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