Jump to content

Recommended Posts

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!

Posted (edited)
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
Posted

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

×   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

    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
    • Maybe you need to create file in assets/<modid>/items/<itemname>.json with content like this:   { "model": { "type": "minecraft:model", "model": "modname:item/itemname" } }  
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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