From d8d8cd93c564f4fe0dad4c1956dafe1f570b287d Mon Sep 17 00:00:00 2001 From: jss2a98aj Date: Sun, 5 May 2024 14:30:40 -0400 Subject: [PATCH] Leaf render mode edge case handling --- .../thaumcraft/MixinBlockMagicalLeaves.java | 23 ++-- .../twilightforest/MixinBlockTFLeaves.java | 17 +-- .../twilightforest/MixinBlockTFLeaves3.java | 17 +-- .../MixinBlockTFMagicLeaves.java | 23 +--- .../witchery/MixinBlockWitchLeaves.java | 16 +-- .../java/jss/notfine/util/ILeafBlock.java | 38 +----- .../java/jss/notfine/util/LeafRenderUtil.java | 119 +++++++++--------- 7 files changed, 83 insertions(+), 170 deletions(-) diff --git a/src/main/java/com/gtnewhorizons/angelica/mixins/late/notfine/leaves/thaumcraft/MixinBlockMagicalLeaves.java b/src/main/java/com/gtnewhorizons/angelica/mixins/late/notfine/leaves/thaumcraft/MixinBlockMagicalLeaves.java index ca8ce93fe..e66b09dbf 100644 --- a/src/main/java/com/gtnewhorizons/angelica/mixins/late/notfine/leaves/thaumcraft/MixinBlockMagicalLeaves.java +++ b/src/main/java/com/gtnewhorizons/angelica/mixins/late/notfine/leaves/thaumcraft/MixinBlockMagicalLeaves.java @@ -1,13 +1,10 @@ package com.gtnewhorizons.angelica.mixins.late.notfine.leaves.thaumcraft; -import jss.notfine.gui.options.named.LeavesQuality; +import jss.notfine.util.IFaceObstructionCheckHelper; import jss.notfine.util.ILeafBlock; -import jss.notfine.core.Settings; -import jss.notfine.core.SettingsManager; import jss.notfine.util.LeafRenderUtil; import net.minecraft.block.Block; import net.minecraft.block.material.Material; -import net.minecraft.util.Facing; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import org.spongepowered.asm.mixin.Mixin; @@ -16,21 +13,12 @@ import org.spongepowered.asm.mixin.Shadow; import thaumcraft.common.blocks.BlockMagicalLeaves; @Mixin(value = BlockMagicalLeaves.class) -public abstract class MixinBlockMagicalLeaves extends Block implements ILeafBlock { +public abstract class MixinBlockMagicalLeaves extends Block implements IFaceObstructionCheckHelper, ILeafBlock { @Override public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { int maskedMeta = world.getBlockMetadata(x, y, z) & 3; - int renderMode; - if(Settings.MODE_LEAVES.option.getStore() == LeavesQuality.SHELLED_FAST) { - renderMode = world.getBlock( - x + Facing.offsetsXForSide[side], - y + Facing.offsetsYForSide[side], - z + Facing.offsetsZForSide[side] - ) instanceof ILeafBlock ? 1 : 0; - } else { - renderMode = SettingsManager.leavesOpaque ? 1 : 0; - } + final int renderMode = LeafRenderUtil.selectRenderMode(world, x, y, z, side) ? 1 : 0; maskedMeta = maskedMeta > 1 ? 0 : maskedMeta; return icon[renderMode + maskedMeta * 2]; } @@ -44,6 +32,11 @@ public abstract class MixinBlockMagicalLeaves extends Block implements ILeafBloc return LeafRenderUtil.shouldSideBeRendered(world, x, y, z, side); } + @Override() + public boolean isFaceNonObstructing(IBlockAccess world, int x, int y, int z, int side, double otherMinX, double otherMinY, double otherMinZ, double otherMaxX, double otherMaxY, double otherMaxZ) { + return LeafRenderUtil.isFaceNonObstructing(world, x, y, z); + } + private MixinBlockMagicalLeaves(Material material) { super(material); } diff --git a/src/main/java/com/gtnewhorizons/angelica/mixins/late/notfine/leaves/twilightforest/MixinBlockTFLeaves.java b/src/main/java/com/gtnewhorizons/angelica/mixins/late/notfine/leaves/twilightforest/MixinBlockTFLeaves.java index 834a2e6c5..59342c1ce 100644 --- a/src/main/java/com/gtnewhorizons/angelica/mixins/late/notfine/leaves/twilightforest/MixinBlockTFLeaves.java +++ b/src/main/java/com/gtnewhorizons/angelica/mixins/late/notfine/leaves/twilightforest/MixinBlockTFLeaves.java @@ -1,12 +1,8 @@ package com.gtnewhorizons.angelica.mixins.late.notfine.leaves.twilightforest; -import jss.notfine.core.Settings; -import jss.notfine.core.SettingsManager; -import jss.notfine.gui.options.named.LeavesQuality; -import jss.notfine.util.ILeafBlock; +import jss.notfine.util.LeafRenderUtil; import net.minecraft.block.BlockLeaves; import net.minecraft.init.Blocks; -import net.minecraft.util.Facing; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import org.spongepowered.asm.mixin.Mixin; @@ -18,16 +14,7 @@ public abstract class MixinBlockTFLeaves extends BlockLeaves { @Override public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { int maskedMeta = world.getBlockMetadata(x, y, z) & 3; - int renderMode; - if(Settings.MODE_LEAVES.option.getStore() == LeavesQuality.SHELLED_FAST) { - renderMode = world.getBlock( - x + Facing.offsetsXForSide[side], - y + Facing.offsetsYForSide[side], - z + Facing.offsetsZForSide[side] - ) instanceof ILeafBlock ? 1 : 0; - } else { - renderMode = SettingsManager.leavesOpaque ? 1 : 0; - } + int renderMode = LeafRenderUtil.selectRenderMode(world, x, y, z, side) ? 1 : 0; maskedMeta = maskedMeta > 1 ? 0 : maskedMeta; return Blocks.leaves.field_150129_M[renderMode][maskedMeta]; } diff --git a/src/main/java/com/gtnewhorizons/angelica/mixins/late/notfine/leaves/twilightforest/MixinBlockTFLeaves3.java b/src/main/java/com/gtnewhorizons/angelica/mixins/late/notfine/leaves/twilightforest/MixinBlockTFLeaves3.java index f48b639db..53c7b0018 100644 --- a/src/main/java/com/gtnewhorizons/angelica/mixins/late/notfine/leaves/twilightforest/MixinBlockTFLeaves3.java +++ b/src/main/java/com/gtnewhorizons/angelica/mixins/late/notfine/leaves/twilightforest/MixinBlockTFLeaves3.java @@ -1,12 +1,8 @@ package com.gtnewhorizons.angelica.mixins.late.notfine.leaves.twilightforest; -import jss.notfine.core.Settings; -import jss.notfine.core.SettingsManager; -import jss.notfine.gui.options.named.LeavesQuality; -import jss.notfine.util.ILeafBlock; +import jss.notfine.util.LeafRenderUtil; import net.minecraft.block.BlockLeaves; import net.minecraft.init.Blocks; -import net.minecraft.util.Facing; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import org.spongepowered.asm.mixin.Mixin; @@ -17,16 +13,7 @@ public abstract class MixinBlockTFLeaves3 extends BlockLeaves { @Override public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { - int renderMode; - if(Settings.MODE_LEAVES.option.getStore() == LeavesQuality.SHELLED_FAST) { - renderMode = world.getBlock( - x + Facing.offsetsXForSide[side], - y + Facing.offsetsYForSide[side], - z + Facing.offsetsZForSide[side] - ) instanceof ILeafBlock ? 1 : 0; - } else { - renderMode = SettingsManager.leavesOpaque ? 1 : 0; - } + final int renderMode = LeafRenderUtil.selectRenderMode(world, x, y, z, side) ? 1 : 0; return Blocks.leaves.field_150129_M[renderMode][0]; } diff --git a/src/main/java/com/gtnewhorizons/angelica/mixins/late/notfine/leaves/twilightforest/MixinBlockTFMagicLeaves.java b/src/main/java/com/gtnewhorizons/angelica/mixins/late/notfine/leaves/twilightforest/MixinBlockTFMagicLeaves.java index 185e4f797..e5cb86667 100644 --- a/src/main/java/com/gtnewhorizons/angelica/mixins/late/notfine/leaves/twilightforest/MixinBlockTFMagicLeaves.java +++ b/src/main/java/com/gtnewhorizons/angelica/mixins/late/notfine/leaves/twilightforest/MixinBlockTFMagicLeaves.java @@ -1,11 +1,7 @@ package com.gtnewhorizons.angelica.mixins.late.notfine.leaves.twilightforest; -import jss.notfine.core.Settings; -import jss.notfine.core.SettingsManager; -import jss.notfine.gui.options.named.LeavesQuality; -import jss.notfine.util.ILeafBlock; +import jss.notfine.util.LeafRenderUtil; import net.minecraft.block.BlockLeaves; -import net.minecraft.util.Facing; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import org.spongepowered.asm.mixin.Mixin; @@ -17,21 +13,12 @@ public abstract class MixinBlockTFMagicLeaves extends BlockLeaves { @Override public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { int maskedMeta = world.getBlockMetadata(x, y, z) & 3; - int renderMode; - if(Settings.MODE_LEAVES.option.getStore() == LeavesQuality.SHELLED_FAST) { - renderMode = world.getBlock( - x + Facing.offsetsXForSide[side], - y + Facing.offsetsYForSide[side], - z + Facing.offsetsZForSide[side] - ) instanceof ILeafBlock ? 1 : 0; - } else { - renderMode = SettingsManager.leavesOpaque ? 1 : 0; - } + final boolean renderMode = LeafRenderUtil.selectRenderMode(world, x, y, z, side); maskedMeta = maskedMeta > 1 ? 0 : maskedMeta; return switch (maskedMeta) { - case 1 -> renderMode == 1 ? SPR_TRANSLEAVES_OPAQUE : SPR_TRANSLEAVES; - case 3 -> renderMode == 1 ? SPR_SORTLEAVES_OPAQUE : SPR_SORTLEAVES; - default -> renderMode == 1 ? SPR_TIMELEAVES_OPAQUE : SPR_TIMELEAVES; + case 1 -> renderMode ? SPR_TRANSLEAVES_OPAQUE : SPR_TRANSLEAVES; + case 3 -> renderMode ? SPR_SORTLEAVES_OPAQUE : SPR_SORTLEAVES; + default -> renderMode ? SPR_TIMELEAVES_OPAQUE : SPR_TIMELEAVES; }; } diff --git a/src/main/java/com/gtnewhorizons/angelica/mixins/late/notfine/leaves/witchery/MixinBlockWitchLeaves.java b/src/main/java/com/gtnewhorizons/angelica/mixins/late/notfine/leaves/witchery/MixinBlockWitchLeaves.java index 17a82f5b3..4fccfe841 100644 --- a/src/main/java/com/gtnewhorizons/angelica/mixins/late/notfine/leaves/witchery/MixinBlockWitchLeaves.java +++ b/src/main/java/com/gtnewhorizons/angelica/mixins/late/notfine/leaves/witchery/MixinBlockWitchLeaves.java @@ -1,13 +1,10 @@ package com.gtnewhorizons.angelica.mixins.late.notfine.leaves.witchery; import com.emoniph.witchery.blocks.BlockWitchLeaves; -import jss.notfine.core.Settings; import jss.notfine.core.SettingsManager; -import jss.notfine.gui.options.named.LeavesQuality; -import jss.notfine.util.ILeafBlock; +import jss.notfine.util.LeafRenderUtil; import net.minecraft.block.BlockLeavesBase; import net.minecraft.block.material.Material; -import net.minecraft.util.Facing; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import org.spongepowered.asm.mixin.Mixin; @@ -29,16 +26,7 @@ public abstract class MixinBlockWitchLeaves extends BlockLeavesBase { @Override public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { int maskedMeta = world.getBlockMetadata(x, y, z) & 3; - int renderMode; - if(Settings.MODE_LEAVES.option.getStore() == LeavesQuality.SHELLED_FAST) { - renderMode = world.getBlock( - x + Facing.offsetsXForSide[side], - y + Facing.offsetsYForSide[side], - z + Facing.offsetsZForSide[side] - ) instanceof ILeafBlock ? 1 : 0; - } else { - renderMode = SettingsManager.leavesOpaque ? 1 : 0; - } + final int renderMode = LeafRenderUtil.selectRenderMode(world, x, y, z, side) ? 1 : 0; maskedMeta = maskedMeta > 1 ? 0 : maskedMeta; return iconsForModes[renderMode][maskedMeta]; } diff --git a/src/main/java/jss/notfine/util/ILeafBlock.java b/src/main/java/jss/notfine/util/ILeafBlock.java index 8c88e2c10..5e971eba4 100644 --- a/src/main/java/jss/notfine/util/ILeafBlock.java +++ b/src/main/java/jss/notfine/util/ILeafBlock.java @@ -1,43 +1,11 @@ package jss.notfine.util; -import jss.notfine.core.Settings; -import jss.notfine.core.SettingsManager; -import jss.notfine.gui.options.named.LeavesQuality; -import net.minecraft.block.Block; import net.minecraft.world.IBlockAccess; -public interface ILeafBlock extends IFaceObstructionCheckHelper { +public interface ILeafBlock { - @Override() - default boolean isFaceNonObstructing(IBlockAccess worldIn, int x, int y, int z, int side, double otherMinX, double otherMinY, double otherMinZ, double otherMaxX, double otherMaxY, double otherMaxZ) { - - if(Settings.MODE_LEAVES.option.getStore() == LeavesQuality.SHELLED_FAST) { - Block otherBlock; - otherBlock = worldIn.getBlock(x + 1, y, z); - if(!(otherBlock instanceof ILeafBlock || otherBlock.isOpaqueCube())) { - return true; - } - otherBlock = worldIn.getBlock(x - 1, y, z); - if(!(otherBlock instanceof ILeafBlock || otherBlock.isOpaqueCube())) { - return true; - } - otherBlock = worldIn.getBlock(x, y + 1, z); - if(!(otherBlock instanceof ILeafBlock || otherBlock.isOpaqueCube())) { - return true; - } - otherBlock = worldIn.getBlock(x, y - 1, z); - if(!(otherBlock instanceof ILeafBlock || otherBlock.isOpaqueCube())) { - return true; - } - otherBlock = worldIn.getBlock(x, y, z + 1); - if(!(otherBlock instanceof ILeafBlock || otherBlock.isOpaqueCube())) { - return true; - } - otherBlock = worldIn.getBlock(x, y, z - 1); - return !(otherBlock instanceof ILeafBlock || otherBlock.isOpaqueCube()); - } else { - return !SettingsManager.leavesOpaque; - } + default boolean isFullLeaf(IBlockAccess world, int x, int y, int z) { + return true; } } diff --git a/src/main/java/jss/notfine/util/LeafRenderUtil.java b/src/main/java/jss/notfine/util/LeafRenderUtil.java index 2820abe10..cc48a2f6b 100644 --- a/src/main/java/jss/notfine/util/LeafRenderUtil.java +++ b/src/main/java/jss/notfine/util/LeafRenderUtil.java @@ -25,12 +25,12 @@ public class LeafRenderUtil { 5, 4, 1, 0, 3, 2 }; - public static boolean shouldSideBeRendered(IBlockAccess worldIn, int x, int y, int z, int side) { - Block otherBlock = worldIn.getBlock(x, y, z); + public static boolean shouldSideBeRendered(IBlockAccess world, int x, int y, int z, int side) { + final Block otherBlock = world.getBlock(x, y, z); if(otherBlock.isOpaqueCube()) { return false; } - if(otherBlock instanceof ILeafBlock) { + if(otherBlock instanceof ILeafBlock otherLeaf && otherLeaf.isFullLeaf(world, x, y, z)) { switch ((LeavesQuality)Settings.MODE_LEAVES.option.getStore()) { case FAST, SMART -> { return false; @@ -40,76 +40,33 @@ public class LeafRenderUtil { y -= Facing.offsetsYForSide[side]; z -= Facing.offsetsZForSide[side]; int renderCheck = 0; - otherBlock = worldIn.getBlock(x + 1, y, z); - if(otherBlock instanceof ILeafBlock || otherBlock.isOpaqueCube()) { - renderCheck++; - } - otherBlock = worldIn.getBlock(x - 1, y, z); - if(otherBlock instanceof ILeafBlock || otherBlock.isOpaqueCube()) { - renderCheck++; - } - otherBlock = worldIn.getBlock(x, y + 1, z); - if(otherBlock instanceof ILeafBlock || otherBlock.isOpaqueCube()) { - renderCheck++; - } - otherBlock = worldIn.getBlock(x, y - 1, z); - if(otherBlock instanceof ILeafBlock || otherBlock.isOpaqueCube()) { - renderCheck++; - } - otherBlock = worldIn.getBlock(x, y, z + 1); - if(otherBlock instanceof ILeafBlock || otherBlock.isOpaqueCube()) { - renderCheck++; - } - otherBlock = worldIn.getBlock(x, y, z - 1); - if(otherBlock instanceof ILeafBlock || otherBlock.isOpaqueCube()) { - renderCheck++; - } + renderCheck += ignoreWhenCulling(world, x + 1, y, z) ? 0 : 1; + renderCheck += ignoreWhenCulling(world, x - 1, y, z) ? 0 : 1; + renderCheck += ignoreWhenCulling(world, x, y + 1, z) ? 0 : 1; + renderCheck += ignoreWhenCulling(world, x, y - 1, z) ? 0 : 1; + renderCheck += ignoreWhenCulling(world, x, y, z + 1) ? 0 : 1; + renderCheck += ignoreWhenCulling(world, x, y, z - 1) ? 0 : 1; boolean renderSide = renderCheck == 6; if (renderSide) { x += 2 * Facing.offsetsXForSide[side]; y += 2 * Facing.offsetsYForSide[side]; z += 2 * Facing.offsetsZForSide[side]; - otherBlock = worldIn.getBlock(x, y, z); - if(otherBlock instanceof ILeafBlock || otherBlock.isOpaqueCube()) { + if(!ignoreWhenCulling(world, x, y, z)) { renderSide = false; } x -= Facing.offsetsXForSide[side]; y -= Facing.offsetsYForSide[side]; z -= Facing.offsetsZForSide[side]; - int nextSide = relativeADirections[side]; - otherBlock = worldIn.getBlock( - x + Facing.offsetsXForSide[nextSide], - y + Facing.offsetsYForSide[nextSide], - z + Facing.offsetsZForSide[nextSide] - ); - if(!(otherBlock instanceof ILeafBlock || otherBlock.isOpaqueCube())) { + if(ignoreWhenCulling(world, x, y, z, relativeADirections[side])) { return true; } - nextSide = relativeBDirections[side]; - otherBlock = worldIn.getBlock( - x + Facing.offsetsXForSide[nextSide], - y + Facing.offsetsYForSide[nextSide], - z + Facing.offsetsZForSide[nextSide] - ); - if(!(otherBlock instanceof ILeafBlock || otherBlock.isOpaqueCube())) { + if(ignoreWhenCulling(world, x, y, z, relativeBDirections[side])) { return true; } - nextSide = relativeCDirections[side]; - otherBlock = worldIn.getBlock( - x + Facing.offsetsXForSide[nextSide], - y + Facing.offsetsYForSide[nextSide], - z + Facing.offsetsZForSide[nextSide] - ); - if(!(otherBlock instanceof ILeafBlock || otherBlock.isOpaqueCube())) { + if(ignoreWhenCulling(world, x, y, z, relativeCDirections[side])) { return true; } - nextSide = relativeDDirections[side]; - otherBlock = worldIn.getBlock( - x + Facing.offsetsXForSide[nextSide], - y + Facing.offsetsYForSide[nextSide], - z + Facing.offsetsZForSide[nextSide] - ); - if(!(otherBlock instanceof ILeafBlock || otherBlock.isOpaqueCube())) { + if(ignoreWhenCulling(world, x, y, z, relativeDDirections[side])) { return true; } } @@ -122,9 +79,55 @@ public class LeafRenderUtil { } //Check for IFaceObstructionCheckHelper if(otherBlock instanceof IFaceObstructionCheckHelper target) { - return target.isFaceNonObstructing(worldIn, x, y, z, side, 0D, 0D, 0D, 1D, 1D, 1D); + return target.isFaceNonObstructing(world, x, y, z, side, 0D, 0D, 0D, 1D, 1D, 1D); } return true; } + public static boolean isFaceNonObstructing(IBlockAccess world, int x, int y, int z) { + if(Settings.MODE_LEAVES.option.getStore() != LeavesQuality.SHELLED_FAST) { + return !SettingsManager.leavesOpaque; + } + if(ignoreWhenCulling(world, x + 1, y, z)) { + return true; + } + if(ignoreWhenCulling(world, x - 1, y, z)) { + return true; + } + if(ignoreWhenCulling(world, x, y + 1, z)) { + return true; + } + if(ignoreWhenCulling(world, x, y - 1, z)) { + return true; + } + if(ignoreWhenCulling(world, x, y, z + 1)) { + return true; + } + return ignoreWhenCulling(world, x, y, z - 1); + } + + public static boolean ignoreWhenCulling(IBlockAccess world, int x, int y, int z) { + Block otherBlock = world.getBlock(x, y, z); + return !(otherBlock instanceof ILeafBlock leafBlock && leafBlock.isFullLeaf(world, x, y, z) || otherBlock.isOpaqueCube()); + } + + public static boolean ignoreWhenCulling(IBlockAccess world, int x, int y, int z, int side) { + x += Facing.offsetsXForSide[side]; + y += Facing.offsetsYForSide[side]; + z += Facing.offsetsZForSide[side]; + final Block otherBlock = world.getBlock(x, y, z); + return !(otherBlock instanceof ILeafBlock leafBlock && leafBlock.isFullLeaf(world, x, y, z) || otherBlock.isOpaqueCube()); + } + + public static boolean selectRenderMode(IBlockAccess world, int x, int y, int z, int side) { + if(Settings.MODE_LEAVES.option.getStore() == LeavesQuality.SHELLED_FAST) { + x += Facing.offsetsXForSide[side]; + y += Facing.offsetsYForSide[side]; + z += Facing.offsetsZForSide[side]; + final Block otherBlock = world.getBlock(x, y, z); + return otherBlock instanceof ILeafBlock leafBlock && leafBlock.isFullLeaf(world, x, y, z); + } + return SettingsManager.leavesOpaque; + } + }