-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use custom color resolver if requested
- Implement BlockColorRegistry for fast look up - Refactor
- Loading branch information
1 parent
5c8bbfe
commit b56a22d
Showing
6 changed files
with
141 additions
and
47 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/main/java/net/vulkanmod/interfaces/color/BlockColorsExtended.java
This file contains 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,13 @@ | ||
package net.vulkanmod.interfaces.color; | ||
|
||
import net.minecraft.client.color.block.BlockColors; | ||
import net.vulkanmod.render.chunk.build.color.BlockColorRegistry; | ||
|
||
public interface BlockColorsExtended { | ||
|
||
static BlockColorsExtended from(BlockColors blockColors) { | ||
return (BlockColorsExtended) blockColors; | ||
} | ||
|
||
BlockColorRegistry getColorResolverMap(); | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/net/vulkanmod/mixin/render/color/BlockColorsM.java
This file contains 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,29 @@ | ||
package net.vulkanmod.mixin.render.color; | ||
|
||
import net.minecraft.client.color.block.BlockColor; | ||
import net.minecraft.client.color.block.BlockColors; | ||
import net.minecraft.world.level.block.Block; | ||
import net.vulkanmod.interfaces.color.BlockColorsExtended; | ||
import net.vulkanmod.render.chunk.build.color.BlockColorRegistry; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(BlockColors.class) | ||
public class BlockColorsM implements BlockColorsExtended { | ||
|
||
@Unique | ||
private BlockColorRegistry colorResolvers = new BlockColorRegistry(); | ||
|
||
@Inject(method = "register", at = @At("RETURN")) | ||
private void onRegister(BlockColor blockColor, Block[] blocks, CallbackInfo ci) { | ||
this.colorResolvers.register(blockColor, blocks); | ||
} | ||
|
||
@Override | ||
public BlockColorRegistry getColorResolverMap() { | ||
return this.colorResolvers; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/net/vulkanmod/render/chunk/build/color/BlockColorRegistry.java
This file contains 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,21 @@ | ||
package net.vulkanmod.render.chunk.build.color; | ||
|
||
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap; | ||
import net.minecraft.client.color.block.BlockColor; | ||
import net.minecraft.world.level.block.Block; | ||
|
||
public class BlockColorRegistry { | ||
|
||
private final Reference2ReferenceOpenHashMap<Block, BlockColor> map = new Reference2ReferenceOpenHashMap<>(); | ||
|
||
public void register(BlockColor blockColor, Block... blocks) { | ||
for (Block block : blocks) { | ||
this.map.put(block, blockColor); | ||
} | ||
} | ||
|
||
public BlockColor getBlockColor(Block block) { | ||
return this.map.get(block); | ||
} | ||
|
||
} |
This file contains 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 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 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