Jump to content

Recommended Posts

Posted

Hello all, I have been scouring the internet for information in making a glowing overlay for a block, and I am hoping that turning here will provide some help.

 

Specifically, I have been trying to make a block with a glowing overlay (over a smaller region of the block). How would I create an overlay for a block, and how would I make that overlay glow? I would especially love some help with making blockstate and model json files (all the previous examples I have found are using Forge Blockstates, which I know are depreciated in 1.15.x, so I am hoping to find a better, more supported method).

Posted

Hi

There are a few examples of different ways to generate block models in this tutorial project:

https://github.com/TheGreyGhost/MinecraftByExample

see mbe03, mbe04, mbe05.

 

But it mostly comes down to what you mean by "glow".  For example - the lamp block glows.  Do you mean some sort of animated "halo"?  Do you have a "concept" art that shows what effect you're trying to achieve, or something else in minecraft that is similar?

 

-TGG

 

 

  • Like 1
Posted

Thank you for the response TGG! To be more specific and as an example, say I have a custom flower and a flower_glow.png, which is a subspace of the original flower texture. I would like to use that flower_glow as a glowing overlay so that only that portion of the flower glows (so not like glowstone, but like spider eyes).

 

I will look through that GitHub link now and post back if I found anything of interest.

Posted

You can use a TESR if you want, but a block model should do the same.

Parts like spider eyes don’t “glow”; they are just drawn without considering the lighting.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted

Ah, ok.

I think you have two choices then:

TileEntityRenderer (mbe21 in that github link), or

(possibly) a multilayer block (similar to the mbe05 lantern) - you may also need a custom BlockModel to render the glowing layer at full brightness regardless of the daylight and blocklight nearby

 

I would suggest TileEntityRenderer if you only have a few of these blocks in the world at once(the rendering is easier to customise, and you can animate easily as well), or if you have many different types of flower that the block must store (say 50 or more)

If you have a lot of these blocks in the world, or you want them to be shaded like normal blocks ("ambient occlusion") then the multilayer block is probably better, but will probably be trickier to get right.

 

-TGG

Posted

I thought that fullbright or no-shade is possible with block json models, let me see...try this:

https://github.com/Choonster-Minecraft-Mods/TestMod3/blob/eb320948208a91fe4d21f364cb6973b335f367df/src/main/resources/assets/testmod3/models/block/fullbright.json#L10

 

Though that might not actually be sufficient.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I am going to try looking into using a multilayer block first because I am a bit worried about many of the block. I think I saw a mod implement something similar to that Draco18s--I'll look more into that link and post an update with progress.

Posted (edited)

Thank you TGG for the link--adding the layered textures was very easy while following it! However, my update for a glowing layer isn't great.

 

I tried modifying just the json model file as you suggested Draco18s, but I haven't had any luck there. The "shade" command is associated with whether shadows are rendered and don't effect lighting as far as I am aware. I also tried messing around with the tint index, but that hasn't been much help.

 

I most recently tried making a custom BlockState class in attempt to change the getLightValue method, but that attempt was pretty last ditch. I registered the custom BlockState with the default state, but I couldn't change the final stateContainer variable, which is why I think the plants failed to render (at least the game didn't completely crash).

 

I am a bit lost on how I would make a custom BlockModel, but perhaps the answer lies there. Does anybody know any resources that can help with me adding one? Alternatively, I have been trying to find an alternative to the getPackedLightmapCoords method in Block that existed in previous Forge versions. I am not sure if there is a way to do something similar to that, but if anybody has any ideas that would be wonderful. This link mentioned a technique similar to this but with Forge 1.8.x.

 

A mod called "The Midnight" implements something similar to what I am going for, with a glowing overflow for some flowers. For example, there is a bogshroom_glow.png file, however I am not sure how this file is implemented. There is what seems to be an unused blockstate file refrencing it, as well as a (as far as I can tell) unused "glowing" parameter in the MidnightPlantBlock.java file. 

 

If anybody has tried or has thoughts on any of these ideas I would greatly appreciate the help. Thank you everybody!

Edited by FrozenFarmer64
Updating the web link
Posted (edited)

That png is referenced in this model:

https://github.com/Cryptic-Mushroom/The-Midnight/search?q=bogweed_glow&unscoped_q=bogweed_glow

Which is unused.

 

The glowing parameter refers to whether or not it emits light:

https://github.com/Cryptic-Mushroom/The-Midnight/blob/1.15.2/src/main/java/com/mushroom/midnight/common/block/MidnightPlantBlock.java#L39

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Did you find anywhere where the glowing parameter is actually utilized, however? Perhaps I missed something, but I haven't found anywhere where the glowing parameter is used, beyond it being set in the constructor. 

Posted
19 minutes ago, FrozenFarmer64 said:

Did you find anywhere where the glowing parameter is actually utilized, however? Perhaps I missed something, but I haven't found anywhere where the glowing parameter is used, beyond it being set in the constructor. 

...yes...the line I directly linked to...

image.png.748afa8ed76ac6470b88f41774978616.png

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Ah, my apologies, that is not exactly what I meant--I wasn't very clear with what I said.

 

Yes, glowing is being used there to determine the light value. But, correct me if I am wrong, but that is just the ambient glow for the block (i.e. glowstone or torch). Lower in that class, there is a commented out method which is referencing the specific render layer. This seems to at one point have been the code that created the "glowing overlay" for the plants (which still exist, even though this method is commented out). I don't know how they are still doing this, however, after commenting out that method, and I haven't been able to find any other reference to the "glowing" variable, or any other code that references the lightmap coordinates (which I think is what I need to find). I hope that clears up what I meant.

 

@Override
@OnlyIn(Dist.CLIENT)
public int getPackedLightmapCoords(BlockState state, ILightReader source, BlockPos pos) {
    if (!this.glowing) return super.getPackedLightmapCoords(state, source, pos);
    if (MinecraftForgeClient.getRenderLayer() == BlockRenderLayer.CUTOUT) {
        return source.getCombinedLight(pos, 0);
    } else {
        return source.getCombinedLight(pos, 14);
    }
}

 

Posted

Render layer is no longer handled by the block class, which is why it was removed and commented.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

That would be this stuff

https://github.com/Cryptic-Mushroom/The-Midnight/blob/4bef239506abd6a401af55a95c6f52bdbfe589c8/src/main/java/com/mushroom/midnight/client/render/block/BlockRenderLayer.java#L11

Client side only which there should be an FML lifecycle event you can call it from (that mod uses FMLCommonSetupEvent).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Oh yes, that makes sense, but is there a method similar to getPackedLightmapCoords in the render layer? If that is the case, then I would only have to register/pass in a custom render layer and modify the lightmap coordinates method to always register the translucent layer with full brightness. All I have been able to find, however, is the RenderType class, but I don't know exactly what render layer file different types are referencing/what those different RenderTypes are actually doing. The only real reference to lightmaps I have tracked down is in the RenderType.Builder class, but even with that variable I have not been able to track it back to a place where the lightmap coordinates are chosen. 

Posted

Howdy

 

Look in BlockModelRenderer renderModelFlat, renderQuadsFlat

IForgeVertexBuilder::applyBakedLighting

The rendering of quads is a bit unusual; there is logic that takes the maximum of the world lighting and the "baked quad" lighting.  If you generate your own quads in a custom BakedModel (see the mbe examples) you should be able to bake maximum light into some quads and use the world lighting for other quads

 

-TGG

  • Like 1
Posted

Ah ha! It worked! Thank you everybody for the incredible help! Here is a fairly detailed solution to the problem for anybody's reference:

 

1) Make your block tex multi-layered. TheGreyGhost has an excellent tutorial of this under mbe05 of Minecraft By Example. Be sure to register one layer as a RenderType.getCutout() and one as a RenderType.getTranslucent(), and to adjust the .json file accordingly.

 

/* In charge of client initialization */
private void onClientSetup(final FMLClientSetupEvent event) {
	...
	// Render type registry for glowing blocks
    RenderTypeLookup.setRenderLayer(MinenauticaBlocks.WRITHING_WEED, Minenautica::getDoubleLayer);
    ...
}
    
// Double layer render lookup
public static boolean getDoubleLayer(RenderType layerToCheck) {
	return layerToCheck == RenderType.getCutout() || layerToCheck == RenderType.getTranslucent();
}

 

2) Create and register a custom IBakedModel. We need to register a custom IBakedModel because we will need to manually update the light value of the quads on the translucent layer of the model. Again, Minecraft By Example has an excellent tutorial of this under mbe04. I would use the CamouflageBakedModel as reference, as we will be using the standard model of the block, just with a modification to the quads.

 

3) Alter the getQuads method. We will be altering this method to check which render layer we are currently on, and then altering the quads on the translucent layer. We are most interested with the vertexData of BakedQuad, which holds the following data, again from Minecraft By Example:

 

//    vertexData[i + 0] = Float.floatToRawIntBits(positionIn.getX());
//    vertexData[i + 1] = Float.floatToRawIntBits(positionIn.getY());
//    vertexData[i + 2] = Float.floatToRawIntBits(positionIn.getZ());
//    vertexData[i + 3] = shadeColor;
//    vertexData[i + 4] = Float.floatToRawIntBits(textureU));
//    vertexData[i + 5] = Float.floatToRawIntBits(textureV));
//    vertexData[i + 6] = baked lighting (blocklight + skylight)
//    vertexData[i + 7] = normal;

 

There are four groups of these eight pieces of data, and we are concerned which changing the 7th element in each of these groups that correspond with the baked lighting value. It is critical to note that to account for both the block light and sky light, the value of baked lighting is a 32-bit integer, where the upper 16 bits contain the sky lighting * 16 and the lower 16 bits contain the block lighting * 16. So, for example, the brightest baked lighting value would be 2^16 * 15 * 16 + 15 * 16 = 15728880. We will run through each BakedQuad in the model and set the baked lighting values to this new baked lighting value. For a more detailed explanation, here is a good link.

 

@Override
@Nonnull
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand,
		@Nonnull IModelData extraData) {
	List<BakedQuad> quads = this.model.getQuads(state, side, rand);
	if(MinecraftForgeClient.getRenderLayer() == RenderType.getTranslucent()) {
		for(int i = 0; i < quads.size(); i++) {
			BakedQuad quad = quads.get(i);
			int[] vertexData = quad.getVertexData();
			for(int j = 0; j < 4; j++) {
				vertexData[8 * j + 6] = getLightValue(15, 15);
			}
			quads.set(i, new BakedQuad(vertexData, quad.getTintIndex(), quad.getFace(), quad.func_187508_a(), quad.shouldApplyDiffuseLighting()));
		}
	}
	return quads;
}
	
/*
 * Return the light value for a given sky lighting and block lighting
 * A 32-bit integer, with the upper bits skyLighting*16 and the lower bits blockLighting*16
 */
private static final int UPPER_HALF = 65536; // 2^16
private static int getLightValue(int skyLighting, int blockLighting) {
	return UPPER_HALF * skyLighting * 16 + blockLighting * 16;
}

 

And that is it! There are few steps, but in the end we are just registering a translucent layer, and then adjusting the quads of that layer. Thank you everybody for the help, and I am posting pictures of the results below (for more pictures you can visit the mod's website at Minenautica).

 

Light Image: https://ibb.co/djRYL32
Dark Image: https://ibb.co/dQ7TctP

  • Thanks 1

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.