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.

[1.18.2] Make block temporarily invisible

Featured Replies

Posted

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?

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

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.

 

  • 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).

3 hours ago, Sireous said:

I was asking if something like level.setBlockInvisible(position) is possible

nope.

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

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.