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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Alright, here is the log file https://mclo.gs/5eCwafV
    • Please read the FAQ (https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/) and post log files as described there, using a site such as https://mclo.gs/ and post the link here.  
    • I tried updating the mods in my modpack which caused incompatibilities so i have tried to revert them back to their older versions i was using before. In the logs it doesnt show me any clear incompatibilities except for tfmg & entity texture features, but when i try to remove those it still doesn't work. I have tried removing the forge-client.toml file which was a suggestion i found on  a few other posts. This is the log file i get. [inline log removed] Any help would be appreciated. Thanks in advance
    • I don't use KubeJS, never even heard of it. But after doing what "Ugdhar" suggested earlier in this post with the "config/Mekanism/generator-storage.toml", I tried going into an individual save's serverconfig folder, and just deleting everything except the parcool folder (I have that mod installed.) Then, a bit of loading and temporary freezing later, seems to have worked. Even when quitting to menu and loading back in, or also when quitting to menu, exiting to desktop, and re-launching MC, choose a save and loading it.
    • [Mekanism] Broken tags in Mekanism recipes detected, please check server logs for details. You will be missing some recipes and machines may not accept expected inputs. Do you use KubeJS? It is some kind of bug with it and not fixed A workaround is setting "allowAsyncStreams" to false in the KubeJS common config file https://github.com/KubeJS-Mods/KubeJS/issues/1016   For the rest of your issues, keep deleting these files - now it is the jei-server.toml file If the file is not in config, check the worldsave serverconfig folder These files usually break after updating mods, game crashes or force closing the game    
  • Topics

×
×
  • Create New...

Important Information

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