Jump to content

[1.18.2] Make block temporarily invisible


Sireous

Recommended Posts

Let's say I have those 2 variables:

ServerLevel level = source.getLevel();

BlockState block = level.getBlockState(levelPosition);

I want to make block near one I got (in any direction) temporarily invisible, perform some actions with block I have and then make invisible one visible again. How can I do this?

Link to comment
Share on other sites

Well, the scenario... It's quite complicated. You can view the whole source code here:

https://github.com/Dreadoom/RenderCube

I am interested in this piece of code:

// Min and max coordinates over each axes
int region_min_x = Math.min(position1.getX(), position2.getX());
int region_max_x = Math.max(position1.getX(), position2.getX());
int region_min_y = Math.min(position1.getY(), position2.getY());
int region_max_y = Math.max(position1.getY(), position2.getY());
int region_min_z = Math.min(position1.getZ(), position2.getZ());
int region_max_z = Math.max(position1.getZ(), position2.getZ());

// Loop over coordinates
for(int x = region_min_x; x <= region_max_x; x++){
	for(int y = region_min_y; y <= region_max_y; y++){
		for(int z = region_min_z; z <= region_max_z; z++){
			// Current block position
            BlockPos position = new BlockPos(x, y, z);

			// Process block
			boolean success = RenderCubeUtils.renderBlock( source, jsonWriter, position, new BlockPos(
                                        position.getX() - region_min_x,
                                        position.getY() - region_min_y,
                                        position.getZ() - region_min_z));

			// We finish with success only if RenderCubeUtils.RenderBlock(...) returned true
			if(!success){
				// Finish with failure
				return -1;
           	}
		}
	}
}

I want it to look something like this:

// Min and max coordinates over each axes
int region_min_x = Math.min(position1.getX(), position2.getX());
int region_max_x = Math.max(position1.getX(), position2.getX());
int region_min_y = Math.min(position1.getY(), position2.getY());
int region_max_y = Math.max(position1.getY(), position2.getY());
int region_min_z = Math.min(position1.getZ(), position2.getZ());
int region_max_z = Math.max(position1.getZ(), position2.getZ());

// Loop over coordinates
for(int x = region_min_x; x <= region_max_x; x++){
	for(int y = region_min_y; y <= region_max_y; y++){
		for(int z = region_min_z; z <= region_max_z; z++){
			// Current block position
            BlockPos position = new BlockPos(x, y, z);
                                                   
            if(x == region_min_x){
            	makeInvisible(position.mutable().setWithOffset(position, Direction.WEST)));
            }
            // Same for other 5 vars

			// Process block
			boolean success = RenderCubeUtils.renderBlock( source, jsonWriter, position, new BlockPos(
                                        position.getX() - region_min_x,
                                        position.getY() - region_min_y,
                                        position.getZ() - region_min_z));
                                                   
            if(x == region_min_x){
            	makeVisible(position.mutable().setWithOffset(position, Direction.WEST)));
            }
            // Same for other 5 vars

			// We finish with success only if RenderCubeUtils.RenderBlock(...) returned true
			if(!success){
				// Finish with failure
				return -1;
           	}
		}
	}
}

 

Edited by Sireous
Link to comment
Share on other sites

so instead of typing "i have a multiblock and want to temporarily remove the boring outer shell to show some fancy-shmancy animation" you decided to go with "here's a bunch of code, work it out"?

if the shell block are your blocks, you can set aside one block state for invisible mode (model with zero cubes).
if they are vanilla blocks, either memorize them and remove for a while, or, when the multiblock is formed, replace shell blocks with block entities that hold their data and emulate their look.

 

Link to comment
Share on other sites

  • 2 weeks later...

Well, I inserted bunch of code to just point out the place, where I want this to happen, because I my opinion task "make block at BlockPosition invisible" is quite scenario independent. I was asking if something like level.setBlockInvisible(position) is possible (level is instance of ServerLevel).

Link to comment
Share on other sites

The redstone lampa Block features an light on and light off set mechanic. in this process the texture is changed. Look for Blockstates.

To change between the texture of an invisible block to a visible block, just make the first blockstate textured and the second blockstate invisible texture (invisible texture is different from no texture!!!!).

If your game gets too heavy, looking for Entity Blocks might help.

Edited by DouglasRafael
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.