Skip to content

Comments

BME-170 Groundcover transparency fix#93

Open
maddie-j wants to merge 13 commits intoLordFokas:mc-1.18.2-v0.8.0-overhaulfrom
maddie-j:BME-170-fix-foliage-transparency
Open

BME-170 Groundcover transparency fix#93
maddie-j wants to merge 13 commits intoLordFokas:mc-1.18.2-v0.8.0-overhaulfrom
maddie-j:BME-170-fix-foliage-transparency

Conversation

@maddie-j
Copy link
Contributor

@maddie-j maddie-j commented Jan 6, 2026

Doing some fixes following the change in colour sourcing to texture files, mainly revolving around how that change interacts with transparency + non-solid blocks like flowers.

A before and after from the standard testing area. Note that the "before" is from the current main branch, which is now several changes ahead from where I started my changes:

2026-01-03_22 40 11 2026-01-06_17 28 57

There are still some things surrounding the transparency and shadows that I want to heavily refactor to fix, as outlined in the Discord, especially to help with the dire performance cost of collection over oceans. But this was enough of an improvement that I wanted to get this out before it stayed unpushed on my local for another year...

Note: There are a few bugfix commits it looks like I cherry picked over from the original 1.18.2 branch back before I left things off. They need to be fixed anyways, and I'm not changing the history of this branch to break them off into their own PRs! Will leave a comment to point them out as necessary.

if (processedBlock.totalColor <= 0) {
continue;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This inequality was causing issues when the alpha value caused the signed int that represented the colour to have a negative sign. Will explain more further down where the appropriate fix is.

Comment on lines 147 to 159
// Fallback 1: get block tint
if(color == 0) {
color = blockColors.getColor(state, level, blockPos, 0);
}

// Fallback 2: get block map color
if(color <= 0) {
MaterialColor mapColor = state.getMapColor(level, blockPos);
if(mapColor != MaterialColor.NONE) {
color = mapColor.col;
// Fallback 2: get block map color
// These magic numbers are dependent on blockColors.getColor's return value specifically
if(color == 0 || color == -1) {
MaterialColor mapColor = state.getMapColor(level, blockPos);
if(mapColor != MaterialColor.NONE) {
color = mapColor.col;
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the colour is stored in an int, and ints in Java are always signed, a colour with an alpha value that turned the int representation negative would accidentally get caught up in this conditional.

As -1 is a "magic number" being returned from getMapColor to show "not found", can check for it explicitly (plus a complete transparency that gets represented as 0) so valid values that happen to have a negative representation when presented as an int aren't accidentally caught in the crossfire.

This is also why "Fallback 2" is being explicitly moved inside the same if block as "Fallback 1". It uses the magic numbers returned by "Fallback 1", so should only apply in that instance. Any values that don't fall into the "Fallback 1" condition are treated as valid.

* These blocks don't return accurate colours using the other methods,
* so unfortunately need to set a colour manually
*/
protected static int handleSpecialCases(BlockState state) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this special cases logic now we're getting values from textures instead of MapColors!

g += (255 * pixel[2] * alpha);
b += (255 * pixel[1] * alpha);
total++;
total += alpha;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change required so the numbers don't get thrown off later when alpha != 1

TransparencyState.isAtLeastAsTransparentAs(
blockComposition.getTransparencyState(),
TransparencyState.SEMI_TRANSPARENT
TransparencyState.SLIGHTLY_TRANSPARENT
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a namechange of this enum value, since SEMI_TRANSPARENT has grown to be way more opaque since originally defined and I need to differentiate it from the new, middle HALF_TRANSPARENT enum value with an opacity set to exactly 0.5.

Comment on lines 72 to +74
if (BlazeMapConfig.CLIENT.clientFeatures.displayCoords.get()) {
Vec3 pos = Helpers.getPlayer().position();
String coords = String.format("[ %d | %d | %d ]", (int) pos.x, (int) pos.y, (int) pos.z);
BlockPos pos = Helpers.getPlayer().blockPosition();
String coords = String.format("[ %d | %d | %d ]", pos.getX(), pos.getY(), pos.getZ());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is the change that fixes the coordinates from being half a block off. Brought over from the v0.5 branch.

Comment on lines 341 to 346
if(key == GLFW.GLFW_KEY_F && Screen.hasControlDown() && search.isVisible() && !search.isFocused()) {
this.setFocused(search);
search.setFocus(true);
return true;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is the change that allows ctrl + F to focus the search bar. This was brought over from the v0.5 branch.

Considering there isn't a search bar right now in the v0.8 branch, this currently does nothing. But I'd already picked it across, and it doesn't break anything AFAICT, so assuming Me From The Past was making sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realised I've got a merge conflict here. Given the reimplementation is quite different and seems to be incomplete, will just remove this change for now and will have to put in a ticket to reimplement later


add(PROBLEM, ModIDs.OPTIFINE);
add(PROBLEM, ModIDs.CHUNKPREGEN);
add(PROBLEM, ModIDs.FANCY_MENU);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final unrelated commit. Picked across from the v0.5 branch.

We'd confirmed that ChunkPregen was no longer an issue, but that Fancy Menu was. So out with the old, in with the new!

private static final Set<TagKey<Block>> quiteTransparentBlockTags = initialiseTransparentBlockSet(true);
// TODO: See if I need to make these threadsafe datastructures
private static final SortedSet<TransparencyMapping> transparentBlockTypes = initialiseTransparentBlocks();
private static final SortedSet<TransparencyMapping> transparentFluidTypes = initialiseTransparentFluids();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely refactored how transparency mappings are stored to make it a lot better. Now, you give a block identifier, you give its TransparencyState, and you give a priority, and those values are used to let you query how transparent a block is.

It's probably more useful to read these changes "side-by-side" in the GitHub editor because there's just not much of the original code for the mappings left.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants