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



×
×
  • Create New...

Important Information

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