-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete rewrite. Add support for short grass, fern, tall grass, large fern. Make jungle leaves with pods an optional resource. Can be added back using the "Podded Jungle Leaves" resource pack.
- Loading branch information
Showing
59 changed files
with
2,429 additions
and
351 deletions.
There are no files selected for viewing
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
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,16 @@ | ||
package com.ishikyoo.leavesly; | ||
|
||
import net.fabricmc.api.ModInitializer; | ||
import net.minecraft.block.Block; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class Leavesly implements ModInitializer { | ||
public static final String MOD_ID = "leavesly"; | ||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); | ||
|
||
@Override | ||
public void onInitialize() { | ||
|
||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/com/ishikyoo/leavesly/LeaveslyBlockRegistry.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,54 @@ | ||
package com.ishikyoo.leavesly; | ||
|
||
import net.minecraft.block.Block; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.*; | ||
|
||
public final class LeaveslyBlockRegistry { | ||
public static final Logger LOGGER = LoggerFactory.getLogger("Leavesly"); | ||
|
||
static HashSet<String> preregistrationblockClassNamesHashSet = new HashSet<>(); | ||
static final HashMap<String, String> blockIdsCompatibilityHashMap = new HashMap<>(Map.of( | ||
"grass", "short_grass" | ||
)); | ||
|
||
static HashMap<String, Block> blocksHashMap = new HashMap<>(); | ||
|
||
public static Block getBlock(String mod, String id) { | ||
Block block = blocksHashMap.get(mod + ":" + id); | ||
if (block == null) | ||
LOGGER.warn("Trying to get unregistered block (Mod: {}, Id: {})", mod, id); | ||
return block; | ||
} | ||
|
||
public static boolean isRegisteredBlock(Block block) { | ||
return blocksHashMap.containsValue(block) || preregistrationblockClassNamesHashSet.contains(block.getClass().getName()); | ||
} | ||
public static boolean isRegisteredBlock(String mod, String id) { | ||
return blocksHashMap.containsKey(mod + ":" + id); | ||
} | ||
|
||
public static void register(String mod, String id, Block block) { | ||
String blockId = mod + ":" + getCompatibilityBlockId(id); | ||
if (!blocksHashMap.containsKey(blockId)) { | ||
blocksHashMap.put(blockId, block); | ||
LOGGER.info("Registered block (Mod: {}, Id: {}, Class: {}).", mod, id, block.getClass().getSimpleName()); | ||
} else { | ||
LOGGER.warn("Trying to register already registered block (Mod: {}, Id: {}, Class: {}).", mod, id, block.getClass().getSimpleName()); | ||
} | ||
} | ||
|
||
public static void preregister(String mod, String blockClassName) { | ||
preregistrationblockClassNamesHashSet.add(blockClassName); | ||
LOGGER.info("Block class ready to be preregistered (Mod: {}, Class: {}).", mod, blockClassName); | ||
} | ||
|
||
static String getCompatibilityBlockId(String id) { | ||
String cId = blockIdsCompatibilityHashMap.get(id); | ||
if (cId != null) | ||
return cId; | ||
return id; | ||
} | ||
} |
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,16 @@ | ||
package com.ishikyoo.leavesly; | ||
|
||
import net.fabricmc.api.ClientModInitializer; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class LeaveslyClient implements ClientModInitializer { | ||
public static final Logger LOGGER = LoggerFactory.getLogger(Leavesly.MOD_ID); | ||
|
||
@Override | ||
public void onInitializeClient() { | ||
LeaveslyColorProvider.initialize(); | ||
} | ||
} | ||
|
111 changes: 111 additions & 0 deletions
111
src/main/java/com/ishikyoo/leavesly/LeaveslyColorProvider.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,111 @@ | ||
package com.ishikyoo.leavesly; | ||
|
||
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.client.color.world.BiomeColors; | ||
import net.minecraft.state.property.IntProperty; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.BlockRenderView; | ||
import net.minecraft.world.biome.FoliageColors; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.HashMap; | ||
|
||
public class LeaveslyColorProvider { | ||
public enum TintMode { | ||
Foliage, | ||
Grass | ||
} | ||
|
||
public static final Logger LOGGER = LoggerFactory.getLogger("Leavesly"); | ||
|
||
static final IntProperty SNOW_LAYER = SnowLayerLogic.SNOW_LAYER; | ||
static final HashMap<Block, Integer> blockStaticColorsHashMap = new HashMap<>(); | ||
static final HashMap<Block, Double> blockColorBrightnesssHashMap = new HashMap<>(); | ||
|
||
public static void register(String mod, String id, int brightness) { | ||
Block block = LeaveslyBlockRegistry.getBlock(mod, id); | ||
if (block != null) { | ||
blockStaticColorsHashMap.put(block, brightness); | ||
ColorProviderRegistry.BLOCK.register(LeaveslyColorProvider::getBlockSnowLayeredStaticColor, block); | ||
LOGGER.info("Registered color (Mod: {}, Id: {}, Tint: {}).", mod, id, "static"); | ||
} | ||
} | ||
|
||
public static void register(String mod, String id, TintMode tint, double brightness) { | ||
Block block = LeaveslyBlockRegistry.getBlock(mod, id); | ||
if (block != null) { | ||
switch (tint) { | ||
case Foliage: | ||
blockColorBrightnesssHashMap.put(block, brightness); | ||
ColorProviderRegistry.BLOCK.register(LeaveslyColorProvider::getBlockSnowLayeredFoliageColor, block); | ||
LOGGER.info("Registered color (Mod: {}, Id: {}, Tint: {}).", mod, id, "foliage"); | ||
break; | ||
case Grass: | ||
blockColorBrightnesssHashMap.put(block, brightness); | ||
ColorProviderRegistry.BLOCK.register(LeaveslyColorProvider::getBlockSnowLayeredGrassColor, block); | ||
LOGGER.info("Registered color (Mod: {}, Id: {}, Tint: {}).", mod, id, "grass"); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
public static void initialize() { | ||
register("minecraft", "birch_leaves", getBrightenedColor(FoliageColors.getBirchColor(), 0.72549019607)); | ||
register("minecraft", "mangrove_leaves", getBrightenedColor(FoliageColors.getMangroveColor(), 0.70980392156)); | ||
register("minecraft", "spruce_leaves", getBrightenedColor(FoliageColors.getSpruceColor(), 0.60392156862)); | ||
register("minecraft", "azalea_leaves", getBrightenedColor(0xC4FF4F, 0.5725490196)); | ||
register("minecraft", "cherry_leaves", getBrightenedColor(0xDEFF4C, 0.6)); | ||
register("minecraft", "flowering_azalea_leaves", getBrightenedColor(0xC4FF4F, 0.5725490196)); | ||
register("minecraft", "dark_oak_leaves", TintMode.Foliage, 0.72549019607); | ||
register("minecraft", "jungle_leaves", TintMode.Foliage, 0.85490196078); | ||
register("minecraft", "oak_leaves", TintMode.Foliage, 0.73725490196); | ||
register("minecraft", "vine", TintMode.Foliage, 0.66666666666); | ||
register("minecraft", "short_grass", TintMode.Grass, 0.72156862745); | ||
register("minecraft", "tall_grass", TintMode.Grass, 0.67450980392); | ||
register("minecraft", "fern", TintMode.Grass, 0.64705882352); | ||
register("minecraft", "large_fern", TintMode.Grass, 0.67450980392); | ||
} | ||
|
||
static int getBlockSnowLayeredStaticColor(BlockState state, BlockRenderView world, BlockPos position, int index) { | ||
Block block = state.getBlock(); | ||
int color = blockStaticColorsHashMap.get(block); | ||
int snowLayer = state.get(SNOW_LAYER); | ||
double leavesSnowLayerMask = (double) snowLayer / SNOW_LAYER.getValues().size(); | ||
return getSnowLayeredColor(color, leavesSnowLayerMask); | ||
} | ||
|
||
static int getBlockSnowLayeredFoliageColor(BlockState state, BlockRenderView world, BlockPos position, int index) { | ||
Block block = state.getBlock(); | ||
int color = getBrightenedColor(BiomeColors.getFoliageColor(world, position), blockColorBrightnesssHashMap.get(block)); | ||
int snowLayer = state.get(SNOW_LAYER); | ||
double leavesSnowLayerMask = (double) snowLayer / SNOW_LAYER.getValues().size(); | ||
return getSnowLayeredColor(color, leavesSnowLayerMask); | ||
} | ||
|
||
static int getBlockSnowLayeredGrassColor(BlockState state, BlockRenderView world, BlockPos position, int index) { | ||
Block block = state.getBlock(); | ||
int color = getBrightenedColor(BiomeColors.getGrassColor(world, position), blockColorBrightnesssHashMap.get(block)); | ||
int snowLayer = state.get(SNOW_LAYER); | ||
double leavesSnowLayerMask = (double) snowLayer / SNOW_LAYER.getValues().size(); | ||
return getSnowLayeredColor(color, leavesSnowLayerMask); | ||
} | ||
|
||
static int getBrightenedColor(int color, double brightness) { | ||
int r = (int) Math.round((color >> 16 & 0xff) * brightness); | ||
int g = (int) Math.round((color >> 8 & 0xff) * brightness); | ||
int b = (int) Math.round((color & 0xff) * brightness); | ||
return r << 16 | g << 8 | b; | ||
} | ||
static int getSnowLayeredColor(int color, double mask) { | ||
int r = (color >> 16 & 0xff); | ||
int g = (color >> 8 & 0xff); | ||
int b = (color & 0xff); | ||
r += (int) Math.round((0xff - r) * mask); | ||
g += (int) Math.round((0xff - g) * mask); | ||
b += (int) Math.round((0xff - b) * mask); | ||
return r << 16 | g << 8 | b; | ||
} | ||
} |
Oops, something went wrong.