Skip to content

Commit

Permalink
Release: 1.1.0 (Sapling)
Browse files Browse the repository at this point in the history
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
ishikyoo committed Oct 23, 2024
1 parent 90c4ed5 commit 15b637e
Show file tree
Hide file tree
Showing 59 changed files with 2,429 additions and 351 deletions.
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
# Leavesly
# Leavesly: Sapling

In Bedrock Edition, there is an exclusive feature that turns some of the leaves white when it is snowing. Leavesly brings this feature to Java Edition with some enhancements, such as:
- Snow will affect all leaves.
- Vines are also affected by snow.
- There are different levels of coverage depending on the exposure of the leaves to the snow.
- Flowers and fruits from the leaves are not affected by the snow.
- Jungle leaves now have cocoa pods.
- Jungle leaves now have cocoa pods (`Podded Jungle Leaves` resource pack).
- Short grass, fern, tall grass and large fern are also affected by snow.

## Support
This branch support `Minecraft` versions from `1.19.4` to `1.21.1`.

## Installation
You can install Leavesly by downloading it from the following:
- ### Leavesly

[![GitHub Downloads](https://img.shields.io/github/downloads/ishikyoo/leavesly/total?style=for-the-badge&logo=github&color=F5F5F5)](/~https://github.com/ishikyoo/leavesly/releases)
You can install `Leavesly` by downloading it from the following:

[![GitHub Downloads](https://img.shields.io/github/downloads/ishikyoo/leavesly/total?style=for-the-badge&logo=github&color=F5F5F5)](/~https://github.com/ishikyoo/leavesly)
[![Modrinth Downloads](https://img.shields.io/modrinth/dt/leavesly?style=for-the-badge&logo=modrinth&color=00AD5B)](https://modrinth.com/mod/leavesly)
[![CurseForge Downloads](https://img.shields.io/curseforge/dt/1109585?style=for-the-badge&logo=curseforge&color=F16436&)](https://www.curseforge.com/minecraft/mc-mods/leavesly)

Simply place the mod file `leavesly-1.0.2+1.21.1.jar` in your `.minecraft\mods` folder, and load Minecraft using [Fabric](https://fabricmc.net/use/installer) or [Quilt](https://quiltmc.org/en/install).
Simply place the mod file `leavesly-1.1.0+sapling.jar` in your `.minecraft\mods` folder, and load Minecraft using [Fabric](https://fabricmc.net/use/installer) or [Quilt](https://quiltmc.org/en/install).
You will need Fabric API or Quilted Fabric API.

You can also install it using [Prism Launcher](https://prismlauncher.org), or any other mod manager you like.
- ### Podded Jungle Leaves

You can install `Podded Jungle Leaves` by downloading it from the following:

[![GitHub Downloads](https://img.shields.io/github/downloads/ishikyoo/podded-jungle-leaves/total?style=for-the-badge&logo=github&color=F5F5F5)](/~https://github.com/ishikyoo/podded-jungle-leaves)
[![Modrinth Downloads](https://img.shields.io/modrinth/dt/podded-jungle-leaves?style=for-the-badge&logo=modrinth&color=00AD5B)](https://modrinth.com/resourcepack/podded-jungle-leaves)
[![CurseForge Downloads](https://img.shields.io/curseforge/dt/1126856?style=for-the-badge&logo=curseforge&color=F16436&)](https://www.curseforge.com/minecraft/texture-packs/podded-jungle-leaves)

Simply place the resource pack file `PoddedJungleLeaves.zip` in your `.minecraft\resourcepacks` folder. You will require to install `Leavesly`.

You can also install them using [Prism Launcher](https://prismlauncher.org), or any other mod manager you like.

## Compiling from Source

Expand Down
9 changes: 3 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ dependencies {

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

}

processResources {
inputs.property "version", project.version
filteringCharset "UTF-8"

filesMatching("fabric.mod.json") {
filesMatching("*.mod.json") {
expand "version": project.version
}
}
Expand All @@ -42,9 +42,6 @@ tasks.withType(JavaCompile).configureEach {
}

java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_17
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ org.gradle.parallel=true
# check these on https://fabricmc.net/develop
minecraft_version=1.21.1
yarn_mappings=1.21.1+build.3
loader_version=0.16.5
loader_version=0.16.7

# Mod Properties
mod_version=1.0.2+1.21.1
maven_group=net.ishikyoo.leavesly
mod_version=1.1.0+sapling
maven_group=com.ishikyoo.leavesly
archives_base_name=leavesly

# Dependencies
fabric_version=0.104.0+1.21.1
fabric_version=0.106.0+1.21.1
16 changes: 16 additions & 0 deletions src/main/java/com/ishikyoo/leavesly/Leavesly.java
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 src/main/java/com/ishikyoo/leavesly/LeaveslyBlockRegistry.java
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;
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/ishikyoo/leavesly/LeaveslyClient.java
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 src/main/java/com/ishikyoo/leavesly/LeaveslyColorProvider.java
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;
}
}
Loading

0 comments on commit 15b637e

Please sign in to comment.