Skip to content

Commit

Permalink
feat: big changes to better snow
Browse files Browse the repository at this point in the history
* better snow can now be applied, by default, with snow, moss carpet and pale moss carpet
* you can now add more blocks to better snow
* better snow can now, also be applied on non-grass blocks
* better snow support for neo, without sodium

---

* target from 1.21.2 -> 1.21.3
* fix various issues with wilder wild (by disabling some features if the mod is detected)
* also visually disable disabled-features
* better-grassify "sculk catalyst" by default, as an example for adding more grass blocks
* slightly compress logo (very slightly)
* code formatting (i guess i'm now addicted to switch statements)
  • Loading branch information
UltimatChamp committed Oct 30, 2024
1 parent 2c1d164 commit 623deaf
Show file tree
Hide file tree
Showing 33 changed files with 285 additions and 207 deletions.
36 changes: 17 additions & 19 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -139,35 +139,33 @@ processResources {
}

def packFormat
if (project.property("deps.minecraft_version") == "1.20.1") {
packFormat = 15
} else if (project.property("deps.minecraft_version") == "1.20.6") {
packFormat = 32
} else if (project.property("deps.minecraft_version") == "1.21.1") {
packFormat = 34
} else {
packFormat = 42
switch (project.property("deps.minecraft_version")) {
case "1.20.1":
packFormat = 15;
break;
case "1.20.6":
packFormat = 32;
break;
case "1.21.1":
packFormat = 34;
break;
default:
packFormat = 42;
}

filesMatching("pack.mcmeta") {
expand("pack_format": packFormat)
}
}

def targetJavaVersion = 21
if (project.property("deps.minecraft_version") == "1.20.1") {
targetJavaVersion = 17
}

tasks.withType(JavaCompile).configureEach {
it.options.release = targetJavaVersion
}

java {
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
def java = stonecutter.eval(project.property("deps.minecraft_version"), ">=1.20.5")
? JavaVersion.VERSION_21 : JavaVersion.VERSION_17

sourceCompatibility = java
targetCompatibility = java
}

jar {
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
org.gradle.jvmargs=-Xmx2G
org.gradle.parallel=true
org.gradle.caching=true

# Mod Properties
mod_id=bettergrass
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
12 changes: 6 additions & 6 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ plugins {

stonecutter {
shared {
vers("1.20.1-fabric", "1.20.1")
vers("1.20.1-forge", "1.20.1")

vers("1.20.6-fabric", "1.20.6")
vers("1.21.3-fabric", "1.21.3")

vers("1.21.1-fabric", "1.21.1")
vers("1.21.1-neo", "1.21.1")

vers("1.21.2-fabric", "1.21.2")
vers("1.20.6-fabric", "1.20.6")

vers("1.20.1-fabric", "1.20.1")
vers("1.20.1-forge", "1.20.1")

vcsVersion = "1.21.2-fabric"
vcsVersion = "1.21.3-fabric"
}

create rootProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ public Text getDisplayName() {
public boolean warpedNylium = true;

@SerialEntry
public List<String> moreBlocks = Lists.newArrayList();
public List<String> moreBlocks = Lists.newArrayList(
"minecraft:sculk_catalyst" // Example
);

@SerialEntry(comment = "\nBetter Snow\nOFF/OPTIFINE/LAMBDA (default: OPTIFINE)")
public BetterSnowMode betterSnowMode = BetterSnowMode.OPTIFINE;
Expand All @@ -86,6 +88,13 @@ public Text getDisplayName() {
}
}

@SerialEntry
public List<String> snowLayers = Lists.newArrayList(
"snow",
"moss_carpet",
"pale_moss_carpet"
);

@SerialEntry
public List<String> excludedTags = Lists.newArrayList(
"leaves",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.isxander.yacl3.api.*;
import dev.isxander.yacl3.api.controller.*;
import dev.isxander.yacl3.gui.controllers.cycling.EnumController;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -51,6 +52,7 @@ public static Screen createConfigScreen(Screen parent) {
() -> config.snowy,
(value) -> config.snowy = value
)
.available(!FabricLoader.getInstance().isModLoaded("wilderwild"))
.controller(TickBoxControllerBuilder::create)
.build())
.option(Option.<Boolean>createBuilder()
Expand Down Expand Up @@ -152,8 +154,24 @@ public static Screen createConfigScreen(Screen parent) {
() -> config.betterSnowMode,
(value) -> config.betterSnowMode = value
)
//? if >1.20.6 {
.available(!FabricLoader.getInstance().isModLoaded("wilderwild"))
//?} else {
/*.available(!(!FabricLoader.getInstance().isModLoaded("sodium") || FabricLoader.getInstance().isModLoaded("wilderwild")))
*///?}
.customController(opt -> new EnumController<>(opt, BetterGrassifyConfig.BetterSnowMode.class))
.build())
.group(ListOption.<String>createBuilder()
.name(Text.translatable("bettergrass.snowLayers"))
.binding(
defaults.snowLayers,
() -> config.snowLayers,
val -> config.snowLayers = val
)
.controller(StringControllerBuilder::create)
.initial("")
.insertEntriesAtEnd(true)
.build())
.group(ListOption.<String>createBuilder()
.name(Text.translatable("bettergrass.excludedTags"))
.binding(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@

import dev.ultimatchamp.bettergrass.config.BetterGrassifyConfig;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

//? if <1.21 {
/*import net.fabricmc.loader.api.FabricLoader;
*///?}

public class BetterGrassifyFabric implements ClientModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("bettergrass");

Expand All @@ -25,9 +22,16 @@ public void onInitializeClient() {

//? if <1.21 {
/*if (!FabricLoader.getInstance().isModLoaded("sodium")) {
BetterGrassifyConfig.instance().betterSnowMode = BetterGrassifyConfig.BetterSnowMode.OFF;
LOGGER.warn("[BetterGrassify] Sodium is not installed. 'Better Snow' feature has been disabled.");
}
*///?}

if (FabricLoader.getInstance().isModLoaded("wilderwild")) {
BetterGrassifyConfig.instance().snowy = false;
BetterGrassifyConfig.instance().betterSnowMode = BetterGrassifyConfig.BetterSnowMode.OFF;
LOGGER.warn("[BetterGrassify] WilderWild detected. 'Better Snowy Grass' and 'Better Snow' features have been disabled.");
}
}
}
//?}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@ private void onClientSetup(FMLClientSetupEvent event) {
}
if (!FabricLoader.getInstance().isModLoaded("embeddium")) {
BetterGrassifyConfig.instance().betterSnowMode = BetterGrassifyConfig.BetterSnowMode.OFF;
LOGGER.warn("[BetterGrassify] Embeddium is not installed. 'Better Snow' feature has been disabled.");
}
if (FabricLoader.getInstance().isModLoaded("wilderwild")) {
BetterGrassifyConfig.instance().snowy = false;
BetterGrassifyConfig.instance().betterSnowMode = BetterGrassifyConfig.BetterSnowMode.OFF;
LOGGER.warn("[BetterGrassify] WilderWild detected. 'Better Snowy Grass' and 'Better Snow' features have been disabled.");
}
}
}
*///?}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ private void onClientSetup(FMLClientSetupEvent event) {
LOGGER.info("[BetterGrassify] [{}] Gamers can finally touch grass!?", BetterGrassifyConfig.instance().betterGrassMode.toString());
}
if (!FabricLoader.getInstance().isModLoaded("sodium")) {
LOGGER.warn("[BetterGrassify] Sodium is not installed. 'Better Snow' feature has been disabled.");
if (FabricLoader.getInstance().isModLoaded("wilderwild")) {
BetterGrassifyConfig.instance().snowy = false;
BetterGrassifyConfig.instance().betterSnowMode = BetterGrassifyConfig.BetterSnowMode.OFF;
LOGGER.warn("[BetterGrassify] WilderWild detected. 'Better Snowy Grass' and 'Better Snow' features have been disabled.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
^///?}
@Mixin(ModelLoader.class)
public class BetterGrassifyModelLoaderMixin {
public class ModelLoaderMixin {
@Shadow
@Final
//? if >1.20.6 {
Expand All @@ -36,26 +36,24 @@ public class BetterGrassifyModelLoaderMixin {
//? if >1.20.6 {
@Inject(method = "addModelToBake", at = @At("HEAD"), cancellable = true)
private void onAddModelToBake(ModelIdentifier id, UnbakedModel unbakedModel, CallbackInfo ci) {
private void bettergrass$onAddModelToBake(ModelIdentifier id, UnbakedModel unbakedModel, CallbackInfo ci) {
//?} else {
/^@Inject(method = "putModel", at = @At("HEAD"), cancellable = true)
private void onPutModel(Identifier id, UnbakedModel unbakedModel, CallbackInfo ci) {
private void bettergrass$onPutModel(Identifier id, UnbakedModel unbakedModel, CallbackInfo ci) {
^///?}
if (id instanceof ModelIdentifier modelId) {
if (!modelId.getVariant().equals("inventory")) {
for (String path : BetterGrassifyConfig.instance().moreBlocks) {
if (BetterGrassifyConfig.instance().snowy) {
if (modelId.toString().startsWith(path) && modelId.toString().contains("snowy=true")) {
var newModel = new BetterGrassifyUnbakedModel(unbakedModel);
//? if >1.20.6 {
this.modelsToBake.put(id, newModel);
//?} else {
/^this.unbakedModels.put(id, newModel);
this.modelsToLoad.addAll(newModel.getModelDependencies());
^///?}
ci.cancel();
}
} else if (modelId.toString().startsWith(path) && !modelId.toString().contains("snowy=true")) {
if (modelId.toString().startsWith(path) && !modelId.toString().contains("snowy=true")) {
var newModel = new BetterGrassifyUnbakedModel(unbakedModel);
//? if >1.20.6 {
this.modelsToBake.put(id, newModel);
//?} else {
/^this.unbakedModels.put(id, newModel);
this.modelsToLoad.addAll(newModel.getModelDependencies());
^///?}
ci.cancel();
} if (modelId.toString().startsWith(path) && modelId.toString().contains("snowy=true") && BetterGrassifyConfig.instance().snowy) {
var newModel = new BetterGrassifyUnbakedModel(unbakedModel);
//? if >1.20.6 {
this.modelsToBake.put(id, newModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
@Mixin(ReferencedModelsCollector.class)
public class ReferencedModelsCollectorMixin {
@ModifyVariable(method = "addTopLevelModel", at = @At("HEAD"), argsOnly = true)
private UnbakedModel onAddTopLevelModel(UnbakedModel model, ModelIdentifier modelId) {
private UnbakedModel bettergrass$onAddTopLevelModel(UnbakedModel model, ModelIdentifier modelId) {
if (!modelId.getVariant().equals("inventory")) {
for (String path : BetterGrassifyConfig.instance().moreBlocks) {
if (BetterGrassifyConfig.instance().snowy) {
if (modelId.toString().startsWith(path) && modelId.toString().contains("snowy=true")) {
return new BetterGrassifyUnbakedModel(model);
}
} else if (modelId.toString().startsWith(path) && !modelId.toString().contains("snowy=true")) {
if (modelId.toString().startsWith(path) && !modelId.toString().contains("snowy=true")) {
return new BetterGrassifyUnbakedModel(model);
} else if (modelId.toString().startsWith(path) && modelId.toString().contains("snowy=true") && BetterGrassifyConfig.instance().snowy) {
return new BetterGrassifyUnbakedModel(model);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
//? if >1.20.6 && fabric {
//? if >1.20.6 {
package dev.ultimatchamp.bettergrass.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import com.mojang.blaze3d.systems.VertexSorter;
import dev.ultimatchamp.bettergrass.model.BetterGrassifyBakedModel;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.block.BlockRenderManager;
import net.minecraft.client.render.chunk.BlockBufferAllocatorStorage;
Expand All @@ -25,44 +24,58 @@
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

//? if neo {
/*import net.neoforged.neoforge.client.event.AddSectionGeometryEvent;
import java.util.List;
*///?}

@Mixin(value = SectionBuilder.class)
public class SectionBuilderMixin {
@Shadow
@Final
private BlockRenderManager blockRenderManager;

//? if fabric {
@Inject(method = "build", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/block/BlockRenderManager;renderBlock(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZLnet/minecraft/util/math/random/Random;)V"))
private void render(ChunkSectionPos sectionPos,
//?} else if neo {
/*@Inject(method = "compile", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/block/BlockRenderManager;renderBatched(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZLnet/minecraft/util/math/random/Random;Lnet/neoforged/neoforge/client/model/data/ModelData;Lnet/minecraft/client/render/RenderLayer;)V"))
*///?}
private void bettergrass$render(ChunkSectionPos sectionPos,
ChunkRendererRegion renderRegion,
VertexSorter vertexSorter,
BlockBufferAllocatorStorage allocatorStorage,
//? if neo {
/*List<AddSectionGeometryEvent.AdditionalSectionRenderer> additionalRenderers,
*///?}
CallbackInfoReturnable<SectionBuilder.RenderData> cir,
@Local BlockState blockState,
@Local(ordinal = 2) BlockPos blockPos,
@Local MatrixStack matrixStack,
@Local BufferBuilder bufferBuilder,
@Local Random random) {
var hasSnowNeighbour = BetterGrassifyBakedModel.hasSnowNeighbour(renderRegion, blockPos.up());
var snowNeighbour = BetterGrassifyBakedModel.snowNeighbour(renderRegion, blockPos.up());

if (hasSnowNeighbour) {
if (snowNeighbour != null) {
if (BetterGrassifyBakedModel.canHaveSnowLayer(renderRegion, blockPos.up())) {
matrixStack.push();
matrixStack.translate(0, 1, 0);
blockRenderManager.renderBlock(Blocks.SNOW.getDefaultState(), blockPos.up(), renderRegion, matrixStack, bufferBuilder, true, random);
blockRenderManager.renderBlock(snowNeighbour.getDefaultState(), blockPos.up(), renderRegion, matrixStack, bufferBuilder, true, random);
matrixStack.pop();
}
}
}

//? if fabric {
@ModifyVariable(method = "build", at = @At("STORE"), ordinal = 0)
private BlockState setGrassState(BlockState state, @Local(ordinal = 2) BlockPos blockPos) {
var world = MinecraftClient.getInstance().world;

if (world != null) {
var hasSnowNeighbour = BetterGrassifyBakedModel.hasSnowNeighbour(world, blockPos.up());
//?} else if neo {
/*@ModifyVariable(method = "compile", at = @At("STORE"), ordinal = 0)
*///?}
private BlockState bettergrass$setGrassState(BlockState state, @Local(ordinal = 2) BlockPos blockPos, @Local(argsOnly = true) ChunkRendererRegion renderRegion) {
var snowNeighbour = BetterGrassifyBakedModel.snowNeighbour(renderRegion, blockPos.up());

if (hasSnowNeighbour) {
if (BetterGrassifyBakedModel.canHaveSnowLayer(world, blockPos.up())) {
if (snowNeighbour == Blocks.SNOW) {
if (BetterGrassifyBakedModel.canHaveSnowLayer(renderRegion, blockPos.up())) {
if (state.getOrEmpty(Properties.SNOWY).isPresent()) {
return state.with(Properties.SNOWY, true);
}
}
Expand Down
Loading

0 comments on commit 623deaf

Please sign in to comment.