Skip to content

Commit

Permalink
refactor: code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
UltimatChamp committed Feb 28, 2025
1 parent fc30737 commit 8a3f3f4
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.llamalad7.mixinextras.sugar.Local;
import com.mojang.blaze3d.systems.VertexSorter;
import dev.ultimatchamp.bettergrass.model.BetterGrassifyBakedModel;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.block.BlockRenderManager;
Expand Down Expand Up @@ -49,18 +48,17 @@ public class SectionBuilderMixin {
/*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) {
Block snowNeighbour = BetterGrassifyBakedModel.snowNeighbour(renderRegion, blockPos.up());
BlockState layerNeighbour = BetterGrassifyBakedModel.getLayerNeighbour(renderRegion, blockPos.up());

if (snowNeighbour != null) {
if (BetterGrassifyBakedModel.canHaveSnowLayer(renderRegion, blockPos.up())) {
if (layerNeighbour != null) {
if (BetterGrassifyBakedModel.canHaveGhostLayer(renderRegion, blockPos.up())) {
matrixStack.push();
matrixStack.translate(0, 1, 0);
blockRenderManager.renderBlock(snowNeighbour.getDefaultState(), blockPos.up(), renderRegion,
blockRenderManager.renderBlock(layerNeighbour, blockPos.up(), renderRegion,
matrixStack, bufferBuilder, true, random);
matrixStack.pop();
}
Expand All @@ -75,9 +73,9 @@ public class SectionBuilderMixin {
private BlockState bettergrass$setGrassState(BlockState state, @Local(ordinal = 2) BlockPos blockPos,
@Local(argsOnly = true) ChunkRendererRegion renderRegion) {
if (state.getOrEmpty(Properties.SNOWY).isEmpty()) return state;
if (BetterGrassifyBakedModel.isNeighbourSnow(renderRegion, blockPos.up())) return state;
if (!BetterGrassifyBakedModel.isLayerNeighbourSnow(renderRegion, blockPos.up())) return state;

if (BetterGrassifyBakedModel.canHaveSnowLayer(renderRegion, blockPos.up()))
if (BetterGrassifyBakedModel.canHaveGhostLayer(renderRegion, blockPos.up()))
return state.with(Properties.SNOWY, true);

return state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.llamalad7.mixinextras.sugar.Local;
import dev.ultimatchamp.bettergrass.model.BetterGrassifyBakedModel;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.state.property.Properties;
Expand Down Expand Up @@ -37,19 +36,18 @@ public class ChunkBuilderMeshingTaskMixin {
@Local(ordinal = 0) BlockPos.Mutable pos,
@Local(ordinal = 1) BlockPos.Mutable modelOffset,
@Local LocalRef<BlockState> blockState) {
Block snowNeighbour = BetterGrassifyBakedModel.snowNeighbour(slice, pos.up());
BlockState layerNeighbour = BetterGrassifyBakedModel.getLayerNeighbour(slice, pos.up());

if (snowNeighbour != null) {
if (BetterGrassifyBakedModel.canHaveSnowLayer(slice, pos.up())) {
if (snowNeighbour == Blocks.SNOW) {
if (layerNeighbour != null) {
if (BetterGrassifyBakedModel.canHaveGhostLayer(slice, pos.up())) {
if (layerNeighbour.isOf(Blocks.SNOW)) {
if (blockState.get().getOrEmpty(Properties.SNOWY).isPresent()) {
blockState.set(blockState.get().with(Properties.SNOWY, true));
}
}

BlockState state = snowNeighbour.getDefaultState();
BakedModel model = cache.getBlockModels().getModel(state);
cache.getBlockRenderer().renderModel(model, state, pos.up(), modelOffset.up());
BakedModel model = cache.getBlockModels().getModel(layerNeighbour);
cache.getBlockRenderer().renderModel(model, layerNeighbour, pos.up(), modelOffset.up());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ public void betterGrassify(MutableQuadView quad, BlockRenderView world, BlockSta
if (isSnowy(world, pos)) {
spriteBake(quad, world.getBlockState(pos.up()), randomSupplier);
return;
} else if (canHaveSnowLayer(world, pos.up()) && isNeighbourSnow(world, pos.up())) {
} else if (canHaveGhostSnowLayer(world, pos.up())) {
if (!BetterGrassifyConfig.load().snowy) return; // Better Snow Mode check, as block has ghost snow
spriteBake(quad, snowNeighbour(world, pos.up()).getDefaultState(), randomSupplier);
spriteBake(quad, getLayerNeighbour(world, pos.up()), randomSupplier);
return;
}

Expand All @@ -119,18 +119,16 @@ public void betterSnowyGrass(MutableQuadView quad, BlockRenderView world, BlockP
Direction face = quad.nominalFace();
BlockPos adjacentPos = pos.offset(face);

if (isSnowy(world, pos) && canHaveSnowLayer(world, adjacentPos) && isNeighbourSnow(world, adjacentPos)) {
if (isSnowy(world, pos) && canHaveGhostSnowLayer(world, adjacentPos)) {
// Self: Snowy Grass | Below: Ghost Snow
spriteBake(quad, world.getBlockState(pos.up()), randomSupplier);
} else if (canHaveSnowLayer(world, pos.up()) && isNeighbourSnow(world, pos.up()) &&
isSnowy(world, adjacentPos.down())) {
} else if (canHaveGhostSnowLayer(world, pos.up()) && isSnowy(world, adjacentPos.down())) {
// Self: Ghost Snow | Below: Snowy Grass
spriteBake(quad, world.getBlockState(adjacentPos), randomSupplier);
} else if (canHaveSnowLayer(world, pos.up()) && isNeighbourSnow(world, pos.up()) &&
canHaveSnowLayer(world, adjacentPos) && isNeighbourSnow(world, adjacentPos)) {
} else if (canHaveGhostSnowLayer(world, pos.up()) && canHaveGhostSnowLayer(world, adjacentPos)) {
// Self: Ghost Snow | Below: Ghost Snow
if (!BetterGrassifyConfig.load().snowy) return; // Better Snow Mode check, as both self and below have ghost snow
spriteBake(quad, snowNeighbour(world, pos.up()).getDefaultState(), randomSupplier);
spriteBake(quad, getLayerNeighbour(world, pos.up()), randomSupplier);
}
}

Expand Down Expand Up @@ -182,7 +180,7 @@ private static boolean isSnowy(BlockRenderView world, BlockPos selfPos) {
return self.getOrEmpty(Properties.SNOWY).orElse(false) && !world.getBlockState(selfPos.up()).isAir();
}

public static Block snowNeighbour(BlockRenderView world, BlockPos selfPos) {
public static BlockState getLayerNeighbour(BlockRenderView world, BlockPos selfPos) {
for (String id : BetterGrassifyConfig.load().snowLayers) {
Identifier identifier = Identifier.tryParse(id);

Expand Down Expand Up @@ -211,17 +209,27 @@ public static Block snowNeighbour(BlockRenderView world, BlockPos selfPos) {
default -> false;
};

if (layerCheck) return layer.get();
if (!layerCheck) continue;

for (BlockPos direction : directions) {
BlockState state = world.getBlockState(direction);
if (state.isOf(layer.get()) || (id.equals("snow") &&
(state.isOf(Blocks.SNOW_BLOCK) || state.isOf(Blocks.POWDER_SNOW)))) return state;
}
}

return null;
}

public static boolean isNeighbourSnow(BlockRenderView world, BlockPos selfPos) {
return snowNeighbour(world, selfPos) == Blocks.SNOW;
public static boolean isLayerNeighbourSnow(BlockRenderView world, BlockPos selfPos) {
return getLayerNeighbour(world, selfPos).isOf(Blocks.SNOW);
}

public static boolean canHaveGhostSnowLayer(BlockRenderView world, BlockPos selfPos) {
return canHaveGhostLayer(world, selfPos) && isLayerNeighbourSnow(world, selfPos);
}

public static boolean canHaveSnowLayer(BlockRenderView world, BlockPos selfPos) {
public static boolean canHaveGhostLayer(BlockRenderView world, BlockPos selfPos) {
if (BetterGrassifyConfig.load().betterSnowMode == BetterGrassifyConfig.BetterSnowMode.OFF) return false;

BlockState self = world.getBlockState(selfPos);
Expand All @@ -233,7 +241,7 @@ public static boolean canHaveSnowLayer(BlockRenderView world, BlockPos selfPos)
!world.getBlockState(selfPos.down()).isOpaqueFullCube(/*? if <1.21.3 {*//*world, selfPos.down()*//*?}*/)
) return false;

boolean isLayer = snowNeighbour(world, selfPos) != null;
boolean isLayer = getLayerNeighbour(world, selfPos) != null;
if (!isLayer) return false;

boolean isExcludedBlock = isBlockExcluded(self);
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/assets/bettergrass/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@
"bettergrass.snowLayers": "Weitere schneeartige Schichten",
"bettergrass.excludedTags": "Ausgeschlossene Schlagwörter",
"bettergrass.excludedBlocks": "Ausgeschlossene Blöcke",
"bettergrass.noconfig.warn": "§cBetterGrassify für (Neo)Forge 1.20.1 ist aufgrund einer Einschränkung in Forge nicht in der Lage, einen Konfigurationsbildschirm anzuzeigen. Bitte verwende stattdessen die Konfigurationsdatei. Entschuldigung für die Unannehmlichkeiten!§r\n\nWenn Embeddium verwendet wird, können die meisten Einstellungen im \"Grafik Einstellungs-Menü\" geändert werden.",
"bettergrass.noyacl.warn": "§cBetterGrassify kann keinen Konfigurationsbildschirm anzeigen, da die YetAnotherConfigLib Mod nicht installiert ist. Bitte verwende stattdessen die Konfigurationsdatei. Entschuldigung für die Unannehmlichkeiten!§r\n\nWenn Sodium verwendet wird, können die meisten Einstellungen im \"Grafik Einstellungs-Menü\" geändert werden."
}
1 change: 0 additions & 1 deletion src/main/resources/assets/bettergrass/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@
"bettergrass.snowLayers": "More Snow-like Layers",
"bettergrass.excludedTags": "Excluded Tags",
"bettergrass.excludedBlocks": "Excluded Blocks",
"bettergrass.noconfig.warn": "§cBetterGrassify for (Neo)Forge 1.20.1 is unable to display a configuration screen due to a limitation in Forge. Please use the configuration file instead. Sorry for the inconvenience!§r\n\nIf you're using Embeddium, you can change most of the configurations in the \"Video Settings Menu\".",
"bettergrass.noyacl.warn": "§cBetterGrassify is unable to display a configuration screen because YetAnotherConfigLib mod is not installed. Please use the configuration file instead. Sorry for the inconvenience!§r\n\nIf you're using Sodium, you can change most of the configurations in the \"Video Settings Menu\"."
}
1 change: 0 additions & 1 deletion src/main/resources/assets/bettergrass/lang/et_ee.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@
"bettergrass.snowLayers": "More Snow-like Layers",
"bettergrass.excludedTags": "Excluded Tags",
"bettergrass.excludedBlocks": "Excluded Blocks",
"bettergrass.noconfig.warn": "§cBetterGrassify for (Neo)Forge 1.20.1 is unable to display a configuration screen due to a limitation in Forge. Please use the configuration file instead. Sorry for the inconvenience!§r\n\nIf you're using Embeddium, you can change most of the configurations in the \"Video Settings Menu\".",
"bettergrass.noyacl.warn": "§cBetterGrassify is unable to display a configuration screen because YetAnotherConfigLib mod is not installed. Please use the configuration file instead. Sorry for the inconvenience!§r\n\nIf you're using Sodium, you can change most of the configurations in the \"Video Settings Menu\"."
}
1 change: 0 additions & 1 deletion src/main/resources/assets/bettergrass/lang/it_it.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@
"bettergrass.snowLayers": "Altri strati simili alla neve",
"bettergrass.excludedTags": "Tag Esclusi",
"bettergrass.excludedBlocks": "Blocchi Esclusi",
"bettergrass.noconfig.warn": "§cBetterGrassify per (Neo)Forge 1.20.1 non è in grado di visualizzare una schermata di configurazione a causa di una limitazione in Forge. Utilizzare invece il file di configurazione. Ci scusiamo per l'inconveniente!§r\n\nSe utilizzi Embeddium, puoi modificare la maggior parte delle configurazioni nel \"Menu Impostazioni video\".",
"bettergrass.noyacl.warn": "§cBetterGrassify non è in grado di visualizzare una schermata di configurazione perché la mod YetAnotherConfigLib non è installata. Si prega di utilizzare il file di configurazione. Ci scusiamo per l'inconveniente!§r\n\nSe utilizzi Sodium, puoi modificare la maggior parte delle configurazioni nel \"Menu Impostazioni video\"."
}
1 change: 0 additions & 1 deletion src/main/resources/assets/bettergrass/lang/pt_br.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@
"bettergrass.snowLayers": "Mais camadas semelhantes à neve",
"bettergrass.excludedTags": "Tags excluídas",
"bettergrass.excludedBlocks": "Blocos excluídos",
"bettergrass.noconfig.warn": "§cBetterGrassify para (Neo)Forge 1.20.1 está indisponivel para mostrar a tela de configuração devido à uma limitação no Forge. Por favor, utilize os arquivos de configuração no lugar. Desculpe pela inconveniência!§r\n\n Se estiver usando o Embeddium, você poderá alterar a maioria das configurações na seção \"Menu de Configurações de Vídeo\".",
"bettergrass.noyacl.warn": "§cO BetterGrassify não pode exibir uma tela de configuração porque o mod YetAnotherConfigLib não está instalado. Em vez disso, use o arquivo de configuração. Desculpe pelo incômodo!§r\n\nSe estiver usando o Sodium, você poderá alterar a maioria das configurações no arquivo \"Menu de Configurações de Vídeo\"."
}
1 change: 0 additions & 1 deletion src/main/resources/assets/bettergrass/lang/ru_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@
"bettergrass.snowLayers": "More Snow-like Layers",
"bettergrass.excludedTags": "Excluded Tags",
"bettergrass.excludedBlocks": "Excluded Blocks",
"bettergrass.noconfig.warn": "§cBetterGrassify for (Neo)Forge 1.20.1 is unable to display a configuration screen due to a limitation in Forge. Please use the configuration file instead. Sorry for the inconvenience!§r\n\nIf you're using Embeddium, you can change most of the configurations in the \"Video Settings Menu\".",
"bettergrass.noyacl.warn": "§cBetterGrassify is unable to display a configuration screen because YetAnotherConfigLib mod is not installed. Please use the configuration file instead. Sorry for the inconvenience!§r\n\nIf you're using Sodium, you can change most of the configurations in the \"Video Settings Menu\"."
}
1 change: 0 additions & 1 deletion src/main/resources/assets/bettergrass/lang/tr_tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@
"bettergrass.snowLayers": "Daha Fazla Kar-benzeri tabaka",
"bettergrass.excludedTags": "Dışlanan Etiketler",
"bettergrass.excludedBlocks": "Dışlanan Bloklar",
"bettergrass.noconfig.warn": "§cBetterGrassify (Neo)Forge 1.20.1 için Forge'daki bir sınırlama nedeniyle bir konfigürasyon ekranı görüntülenemiyor. Lütfen bunun yerine konfigürasyon dosyasını kullanın. Rahatsızlık için özür dileriz!§r\n\nEğer Embeddium kullanıyorsanız, konfigürasyonların çoğunu \"Video Ayarları Menüsü\" üzerinden değiştirebilirsiniz.",
"bettergrass.noyacl.warn": "§cBetterGrassify, YetAnotherConfigLib modu yüklü olmadığı için bir konfigürasyon ekranı görüntüleyemiyor. Lütfen bunun yerine konfigürasyon dosyasını kullanın. Rahatsızlık için özür dileriz!§r\n\nEğer Sodium kullanıyorsanız, konfigürasyonların çoğunu \"Video Ayarları Menüsü\" üzerinden değiştirebilirsiniz."
}
1 change: 0 additions & 1 deletion src/main/resources/assets/bettergrass/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@
"bettergrass.snowLayers": "More Snow-like Layers",
"bettergrass.excludedTags": "Excluded Tags",
"bettergrass.excludedBlocks": "Excluded Blocks",
"bettergrass.noconfig.warn": "§c由于Forge中的限制,BetterGrassify 的 (Neo)Forge 1.20.1 版本无法显示配置屏幕,请改用配置文件Config,为您带来不便敬请谅解!§r\n\n但如果您使用的是Embeddium,则可以在\"视频设置\"中更改大多数设置",
"bettergrass.noyacl.warn": "§cBetterGrassify is unable to display a configuration screen because YetAnotherConfigLib mod is not installed. Please use the configuration file instead. Sorry for the inconvenience!§r\n\n但如果您使用的是Sodium,则可以在\"视频设置\"中更改大多数设置"
}
1 change: 0 additions & 1 deletion src/main/resources/assets/bettergrass/lang/zh_tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@
"bettergrass.snowLayers": "更多類雪層",
"bettergrass.excludedTags": "排除標籤",
"bettergrass.excludedBlocks": "排除方塊",
"bettergrass.noconfig.warn": "§c由於 Forge 的限制,(Neo)Forge 1.20.1 的 BetterGrassify 無法顯示設定畫面。請改用設定檔。很抱歉造成不便!§r\n\n如果你正在使用 Embeddium,你可以在「顯示設定」中變更大部分的設定。",
"bettergrass.noyacl.warn": "§cBetterGrassify 無法顯示設定畫面,因為缺少 YetAnotherConfigLib 模組。請改用設定檔。很抱歉造成不便!§r\n\n如果你正在使用 Sodium,你可以在「顯示設定」中變更大部分的設定。"
}
6 changes: 4 additions & 2 deletions stonecutter.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ plugins.apply "dev.kikugie.stonecutter"
stonecutter.active "1.21.4-fabric" /* [SC] DO NOT EDIT */

stonecutter.parameters {
def loader = property("loom.platform")
consts(loader, "fabric", "neoforge")
def current = property("loom.platform")
def loaders = ["fabric", "neoforge"]

consts(current, loaders)
}

stonecutter.registerChiseled tasks.register("chiseledBuild", stonecutter.chiseled) {
Expand Down

0 comments on commit 8a3f3f4

Please sign in to comment.