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

My goal is to every tick scan for a "diamond block" for example in loaded chunks from client-side. I already did something like looping all surrounding blocks in a radius, and taking a block by 

world.getBlockState(new BlockPos(x, y, z)).getBlock() == Blocks.diamond_block

and my loop is like this:

int range = 100;
for (int xi = -range; xi < range; xi++) {
	for (int yi = -3; yi < 3; yi++) {
		for (int zi = -range; zi < range; zi++) {
			double x = Math.floor(xi + player.posX);
			double y = Math.floor(yi + player.posY);
			double z = Math.floor(zi + player.posZ);

			if (world.getBlockState(new BlockPos(x, y, z)).getBlock() == Blocks.diamond_block) {
				//do something
			}
		}
	}
}

It is working, BUT. It is lagging so much (i use it every tick, and i need to use it so often). My fps drops from 200 to 50. I need a faster way of doing this, please help!

what did you try to achieve, since this code is terrible you should not call it each tick

and btw you loop through round about 120k Blocks each tick

  • Author
4 minutes ago, Luis_ST said:

what did you try to achieve, since this code is terrible you should not call it each tick

and btw you loop through round about 120k Blocks each tick

Yea, I know, that's why it is lagging. I need it for my custom minimap. I want to show specific blocks on it, but I need to loop through all of them to find them. Also, blocks can be destroyed, so I need to scan them frequently. I was wondering if forge has some methods for finding blocks in rendered world

Edited by DimChig

 You don't need to update a minimap every 0.05 seconds. I'm pretty sure you are writing an x-ray.🙂

Anyway have a look at BlockPos.findClosestMatch() or one of the other static methods like betweenClosed().

Their main optimisation I guess is using MutableBlockPos instead of creating 120,000 new BlockPos() like you are.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

  • 2 weeks later...
  • Author
On 7/12/2022 at 11:52 PM, warjort said:

 You don't need to update a minimap every 0.05 seconds. I'm pretty sure you are writing an x-ray.🙂

Anyway have a look at BlockPos.findClosestMatch() or one of the other static methods like betweenClosed().

Their main optimisation I guess is using MutableBlockPos instead of creating 120,000 new BlockPos() like you are.

Okay, i solved it. So i just splitted my "scan zone" into small zones, and scan each zone every tick. So in 1-3 seconds it scans 60 small zones, and i have no lag. So after i find my block in "small scan zone" i add it to an array (and save new Date().getTime()) so than each tick i clear all my blocks from array that have time diffrence more that 3 seconds. And minimap reaction time is fine, around 3 seconds.

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.