Jump to content

[1.18.2] Make block temporarily invisible


Recommended Posts

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?

Posted (edited)

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
Posted

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

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

Posted (edited)

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

×   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

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • 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  
  • Topics

×
×
  • Create New...

Important Information

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