Jump to content

[] function to get the top highes solid block in a chunk


perromercenary00

Recommended Posts

WELL it is but 


            BlockPos top = warudo.getHeightmapPos(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, startingpos);

gives back the pos from the highes solid block on the starting pos 

but i need the highest block inside the current chunck 

hihges-Block.png

the other way around would be to make some code to get the side of the world you are currently in coze that [-0] minuz zero block fucks ups the numbers 
then calculate where the chunk min xz and max XZ to iterate all over those blocks getting the max z to see what is the highest 

thanks for your attention 

 


 

Link to comment
Share on other sites

this is getting harder than it must be 

i end doing the side of the world thing to make the get min max block from chunk thing to iterate trough all the blocks xz from the chunk to get whats the highest one whit 

bpos = warudo.getHeightmapPos(Heightmap.Type.WORLD_SURFACE  , new BlockPos(x, bmin.getY(), z));

and no mater what i use as Heightmap it includes wood blocks soo it marks as higher block the top of trees and also wood pre existent structure's as  the higher block 
i remeber having the same problem in 1.8 but dont remember how i solved 
an as i loss that code i just have some pieces from things i write in the forum soo i dont have that solution 

 

 

	    // ########## ########## ########## ##########
    // en que cuadrante del plano cartesiano se encuentra el blocke
    public static String get_cuadrante(Vector3d vector) {
        return get_cuadrante(vector.x, vector.y, vector.z);
    }
	    public static String get_cuadrante(BlockPos pos) {
        return get_cuadrante(pos.getX(), pos.getY(), pos.getZ());
    }
	    public static String get_cuadrante(double x, double y, double z) {
	        // nortwest - 0 -
        // norteast + 0 -
        // southwest - 0 +
        // southeast + 0 +
	        if (x < 0.0D) {
            if (z < 0.0D) {
                return "nortwest";
            } else {
                return "southwest";
            }
        } else {
            if (z < 0.0D) {
                return "norteast";
            } else {
                return "southeast";
            }
        }
    }
	    // ########## ########## ########## ##########
	 
	    // ########## ########## ########## ##########
    public static Set<BlockPos> chunk_minmax(World warudo, BlockPos pos) {
	        Set<BlockPos> blocklist = new HashSet<BlockPos>();
	        // BlockPos pos = new BlockPos(le.getX(), le.getY(), le.getZ());
	        int chunkminX = (int) (pos.getX() / 16) * 16;
        int chunkminZ = (int) (pos.getZ() / 16) * 16;
	        int chunkmaxX = chunkminX + 15;
        int chunkmaxZ = chunkminZ + 15;
	        switch (util.get_cuadrante(pos)) {
	        default:
            chunkmaxX = chunkminX + 15;
            chunkmaxZ = chunkminZ + 15;
            break;
	        case "southwest":
            chunkminX -= 1;
            chunkmaxX = chunkminX - 15;
            break;
	        case "nortwest":
            chunkminX -= 1;
            chunkmaxX = chunkminX - 15;
            chunkminZ -= 1;
            chunkmaxZ = chunkminZ - 15;
            break;
	        case "norteast":
            chunkminZ -= 1;
            chunkmaxZ = chunkminZ - 15;
            break;
        }
	        System.out.println("chunkminX = " + chunkminX + " chunkminZ = " + chunkminZ + " " + util.get_cuadrante(pos));
	        BlockState dirt = Blocks.DIRT.defaultBlockState();
	        // southeast
        BlockPos chunmin = new BlockPos(chunkminX, pos.getY(), chunkminZ);
        BlockPos chunmax = new BlockPos(chunkmaxX, pos.getY(), chunkmaxZ);
	        blocklist.add(chunmin);
        blocklist.add(chunmax);
	        return blocklist;
    }
	    // ########## ########## ########## ##########
    public static BlockPos highest_block_inside_chunck(World warudo, BlockPos pos) {
        // System.out.println(" highest_block_inside_chunck ");
	        // chunk_minmax(World warudo, BlockPos pos)
        Set<BlockPos> blocklist = new HashSet<BlockPos>();
	        ArrayList<BlockPos> minmax = new ArrayList<BlockPos>(); // Creating A New ArrayList...
        minmax.addAll(chunk_minmax(warudo, pos));
	        BlockPos bmin = minmax.get(0);
        BlockPos bmax = minmax.get(1);
        BlockPos bpos;
	        // System.out.println(" bmin = " + bmin );
        // System.out.println(" bmax = " + bmax );
	        int xmin = bmin.getX();
        int xmax = bmax.getX();
        int tmp = 0;
	        if (xmin > xmax) {
            tmp = xmin;
            xmin = xmax;
            xmax = tmp;
        }
	        int zmin = bmin.getZ();
        int zmaz = bmax.getZ();
	        if (zmin > zmaz) {
            tmp = zmin;
            zmin = zmaz;
            zmaz = tmp;
        }
	        BlockPos zpos = new BlockPos(0, -100, 0);
	        for (int x = xmin; x < xmax; x++) {
	            for (int z = zmin; z < zmaz; z++) {
	                //MOTION_BLOCKING_NO_LEAVES
                bpos = warudo.getHeightmapPos(Heightmap.Type.WORLD_SURFACE  ,
                        new BlockPos(x, bmin.getY(), z));
	                if (bpos.getY() > zpos.getY()) {
	                    System.out.println("x =" + x + " y =" + bpos.getY() + " z =" + z);
                    zpos = bpos;
                }
            }
        }
	        return zpos;
    }
	    // ########## ########## ########## ##########
	

im using that from a custome item right click 

 

    // ########## ########## ########## ##########
    public void releaseUsing(ItemStack itemstack, World warudo, LivingEntity le, int p_77615_4_) {

        String mensaje = "";

        if (!warudo.isClientSide) {
            BlockPos pos = new BlockPos(le.getX(), le.getY(), le.getZ());
            
            BlockState bglow = Blocks.GLOWSTONE.defaultBlockState();
            
            ArrayList<BlockPos> minmax = new ArrayList<BlockPos>(); // Creating A New ArrayList...
            minmax.addAll(util.chunk_minmax(warudo, pos));
            
            
            warudo.setBlock(minmax.get(0), bglow, 2);
            warudo.setBlock(minmax.get(1), bglow, 2);
            
            
            System.out.println(minmax.get(0));
            System.out.println(minmax.get(1));
            
            BlockPos hpos = util.highest_block_inside_chunck(warudo, pos);

            System.out.println(hpos);
            
            warudo.setBlock(hpos, bglow, 2);
            
            //warudo.setBlock(hpos, bglow, 2);

        }

    }

Link to comment
Share on other sites

You might want to look at MinecraftServer.setInitialSpawn()/PlayerRespawnLogic.getOverworldRespawnPos()

Its doesn't solve your problem directly, but you may be able to adapt some of the logic to what you need. e.g.

* Using the Heightmap.TYPES

* Using a mutable BlockPos for performance

* Determining which blocks/positions are valid player spawn points

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.

Link to comment
Share on other sites

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

    • They are heartless scammers, they ruined my life, by making me develop an interest in investing my hard-earned money. I deposited 67,000 USD which was later turned into 110,450 USD including my payout bonus, there was an impressive improvement in a few weeks, later I had an emergency and needed money to pay my insurance fee, I tried reaching out to them to collect the money I invested, they cut the live chats and got me harassed then I realized that I was being scammed. I just wanted my money back! I was advised by a friend to seek help from a recovery firm to assist me in recovering my invested funds, God was so kind I came across some great positive reviews about BETAFORT ONLINE on how they helped scammed victims like me to recover their lost cryptocurrency assets, I took no delay and got in touch with BETAFORT ONLINE, the Expert immediately looked into my case and after providing all the required information they need, and it took them less then a day to recover all my funds. And now I really feel obligated to recommend BETAFORT ONLINE and their team, their recovery strategies, and for working relentlessly to help me recover my funds. Feel free to reach out to BETAFORT ONLINE via google search and they will guide you on how to recover your invested funds, I advise everyone to be careful with these heartless cryptocurrency scammers.  
    • yeah I believe so, its been something deep with the modpack I'm guessing. ill fix each error it states if its saying to replace or download a mod but I'm not sure where to go from here. I have been spending days and have yet to find the issue    
    • It worked, thank you very much 😭
    • https://spark.lucko.me/0ZaR1OAi2F I use spark mod to do a scan and send it here to search for help and if someone know about this issue I dont know to much about, but one thing i see in the record of the minecraft launcher when i play says: can't keep up server overloaded and etc, etc.  I assign 6GB ram to minecraft from the 16 GB of my pc, and fps is not a problem...(no to much) its something about tic rate/second and i am in SINGLE PLAYER. The funny thing is, minecraft vanilla (No mods) works normaly. My mods list (130): https://imgur.com/a/kY3yQr1  Datapacks: https://imgur.com/CTDBe7D ResourcePacks: https://imgur.com/AztTOOw so plis, is someone help me T_T a work  a loot of time in downloading and trying to all mods work but i dont know what to do anymore. Last thing  I SPEAK SPANISH so... sorry if my english is a little scuff or ... werever... bad. Thanks :3
    • Whenever I try to create an world my game crashes. I´ve tried to figure it out myself but wasnt able to do it.   Here are the logs
  • Topics

×
×
  • Create New...

Important Information

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