-
Notifications
You must be signed in to change notification settings - Fork 535
Implement dynamic block tinting support with BlockTintsFactory integration #5357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
marchermans
wants to merge
4
commits into
FabricMC:26.1.2
Choose a base branch
from
marchermans:feature/dynamic-block-tint-sources
base: 26.1.2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2f385cf
Implement dynamic block tinting support with BlockTintsFactory integr…
marchermans a63a928
Refactor tint configuration methods and update BlockTintsFactory access
marchermans 27157d8
Apply Spotless
marchermans d2e3602
Add dynamic color block support with BlockTintsFactory integration
marchermans File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...ing-v1/src/client/java/net/fabricmc/fabric/api/client/rendering/v1/BlockTintsFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package net.fabricmc.fabric.api.client.rendering.v1; | ||
|
|
||
| import it.unimi.dsi.fastutil.ints.IntList; | ||
|
|
||
| import net.minecraft.client.renderer.block.BlockAndTintGetter; | ||
| import net.minecraft.client.resources.model.geometry.BakedQuad; | ||
| import net.minecraft.core.BlockPos; | ||
| import net.minecraft.world.level.block.state.BlockState; | ||
|
|
||
| /** | ||
| * This factory takes over the collection of tint colors in a model renderer. | ||
| * <p> | ||
| * If this factory provides any tints in the tintValues collections of its {@link #collect(BlockState, BlockAndTintGetter, BlockPos, IntList)} | ||
| * method then the default vanilla behaviour of iterating the registered {@link net.minecraft.client.color.block.BlockTintSource block tint sources} | ||
| * is skipped. | ||
| * </p> | ||
| * <p> | ||
| * This factory is only invoked if no {@link net.minecraft.client.color.block.BlockTintSource tint source} has been registered for the {@link BlockState block state}. | ||
| * </p> | ||
| */ | ||
| @FunctionalInterface | ||
| public interface BlockTintsFactory | ||
| { | ||
| /** | ||
| * Invoked to collect the dynamic tint values for the given block state. | ||
| * <p> | ||
| * The tint applied to a given {@link net.minecraft.client.resources.model.geometry.BakedQuad quad} | ||
| * is then determined based on the index stored in {@link BakedQuad.MaterialInfo#tintIndex()} by looking | ||
| * them up in the tint values list after this collect method is called. | ||
| * </p> | ||
| * <p> | ||
| * The resulting tints might be cached for this state, level and position, while the | ||
| * given position and model are rendered, but may not be stored beyond that time window, | ||
| * especially not beyond any given frame being rendered. | ||
| * </p> | ||
| * <p> | ||
| * The given tint list is guaranteed to be empty. | ||
| * It is recommended to call the {@link IntList#size(int) size} method if you at the start of the method, ahead of time, how many | ||
| * tints your system will eventually register as this will pre-allocate enough memory to hold your ints. | ||
| * </p> | ||
| * | ||
| * @param state The state for which the tints are retrieved. | ||
| * @param level The level in which they are retrieved. | ||
| * @param pos The position inside the level for which they are retrieved. | ||
| * @param tintValues The target collection in which to store the tint values for the given index. | ||
| */ | ||
| void collect(BlockState state, BlockAndTintGetter level, BlockPos pos, IntList tintValues); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/ModelBlockRendererMixin.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package net.fabricmc.fabric.mixin.client.rendering; | ||
|
|
||
| import it.unimi.dsi.fastutil.ints.IntList; | ||
|
|
||
| import net.fabricmc.fabric.api.client.rendering.v1.BlockColorRegistry; | ||
| import net.fabricmc.fabric.api.client.rendering.v1.BlockTintsFactory; | ||
|
|
||
| import net.minecraft.client.color.block.BlockTintSource; | ||
| import net.minecraft.client.renderer.block.BlockAndTintGetter; | ||
| import net.minecraft.client.renderer.block.ModelBlockRenderer; | ||
|
|
||
| import net.minecraft.core.BlockPos; | ||
| import net.minecraft.world.level.block.state.BlockState; | ||
|
|
||
| import org.jspecify.annotations.Nullable; | ||
| import org.objectweb.asm.Opcodes; | ||
| import org.spongepowered.asm.mixin.Final; | ||
| import org.spongepowered.asm.mixin.Mixin; | ||
| import org.spongepowered.asm.mixin.Shadow; | ||
| import org.spongepowered.asm.mixin.injection.At; | ||
| import org.spongepowered.asm.mixin.injection.Inject; | ||
| import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Mixin(ModelBlockRenderer.class) | ||
| public abstract class ModelBlockRendererMixin | ||
| { | ||
|
|
||
| @Shadow | ||
| @Final | ||
| private IntList computedTintValues; | ||
| @Shadow | ||
| @Final | ||
| private List<@Nullable BlockTintSource> tintSources; | ||
|
|
||
| @Inject( | ||
| method = "computeTintColor(Lnet/minecraft/client/renderer/block/BlockAndTintGetter;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/BlockPos;I)I", | ||
| at = @At( | ||
| value = "FIELD", | ||
| target = "Lnet/minecraft/client/renderer/block/ModelBlockRenderer;tintSourcesInitialized:Z", | ||
| opcode = Opcodes.PUTFIELD, | ||
| shift = At.Shift.AFTER | ||
| ) | ||
|
|
||
| ) | ||
| private void injectFactoryTintCacheLoading( | ||
| final BlockAndTintGetter level, | ||
| final BlockState state, | ||
| final BlockPos pos, | ||
| final int tintIndex, | ||
| final CallbackInfoReturnable<Integer> cir) { | ||
| if (this.tintSources.isEmpty()) { | ||
| final BlockTintsFactory factory = BlockColorRegistry.getFactory(state); | ||
| if (factory != null) { | ||
| factory.collect(state, level, pos, this.computedTintValues); | ||
| } | ||
|
|
||
| if (!this.computedTintValues.isEmpty()) { | ||
| for (int i = 0; i < this.computedTintValues.size(); i++) { | ||
| this.tintSources.add(null); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.