-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a hook for blocks to suppress a neighboring fluid overlay (#1690)
- Loading branch information
Showing
7 changed files
with
154 additions
and
2 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
7 changes: 7 additions & 0 deletions
7
...ated/resources/assets/neotests_test_water_glass_face_removal/blockstates/water_glass.json
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,7 @@ | ||
{ | ||
"variants": { | ||
"": { | ||
"model": "neotests_test_water_glass_face_removal:block/water_glass" | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
tests/src/generated/resources/assets/neotests_test_water_glass_face_removal/lang/en_us.json
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,3 @@ | ||
{ | ||
"block.neotests_test_water_glass_face_removal.water_glass": "Water Glass" | ||
} |
7 changes: 7 additions & 0 deletions
7
...ted/resources/assets/neotests_test_water_glass_face_removal/models/block/water_glass.json
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,7 @@ | ||
{ | ||
"parent": "minecraft:block/cube_all", | ||
"render_type": "minecraft:cutout", | ||
"textures": { | ||
"all": "minecraft:block/glass" | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
tests/src/main/java/net/neoforged/neoforge/debug/fluid/ClientFluidTests.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,72 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.debug.fluid; | ||
|
||
import net.minecraft.client.renderer.block.LiquidBlockRenderer; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.gametest.framework.GameTest; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.TransparentBlock; | ||
import net.minecraft.world.level.block.state.BlockBehaviour; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.material.FluidState; | ||
import net.minecraft.world.level.material.Fluids; | ||
import net.neoforged.api.distmarker.Dist; | ||
import net.neoforged.neoforge.client.model.generators.BlockStateProvider; | ||
import net.neoforged.testframework.DynamicTest; | ||
import net.neoforged.testframework.annotation.ForEachTest; | ||
import net.neoforged.testframework.annotation.TestHolder; | ||
import net.neoforged.testframework.gametest.EmptyTemplate; | ||
import net.neoforged.testframework.registration.RegistrationHelper; | ||
|
||
@ForEachTest(groups = ClientFluidTests.GROUP, side = Dist.CLIENT) | ||
public class ClientFluidTests { | ||
public static final String GROUP = "level.fluid.client"; | ||
|
||
static class WaterGlassBlock extends TransparentBlock { | ||
private static final Direction HIDE_DIRECTION = Direction.NORTH; | ||
|
||
public WaterGlassBlock(Properties p_309186_) { | ||
super(p_309186_); | ||
} | ||
|
||
@Override | ||
public boolean shouldHideAdjacentFluidFace(BlockState state, Direction selfFace, FluidState adjacentFluid) { | ||
if (selfFace == HIDE_DIRECTION) { | ||
return adjacentFluid.getFluidType() == Fluids.WATER.getFluidType(); | ||
} else { | ||
return super.shouldHideAdjacentFluidFace(state, selfFace, adjacentFluid); | ||
} | ||
} | ||
} | ||
|
||
@GameTest | ||
@EmptyTemplate | ||
@TestHolder(description = "Tests if blocks can prevent neighboring fluids from rendering against them") | ||
static void testWaterGlassFaceRemoval(final DynamicTest test, final RegistrationHelper reg) { | ||
final var glass = reg.blocks().registerBlock("water_glass", WaterGlassBlock::new, BlockBehaviour.Properties.ofFullCopy(Blocks.GLASS)).withLang("Water Glass").withBlockItem(); | ||
reg.provider(BlockStateProvider.class, prov -> prov.simpleBlock(glass.get(), prov.models() | ||
.cubeAll("water_glass", ResourceLocation.withDefaultNamespace("block/glass")) | ||
.renderType("cutout"))); | ||
final var waterPosition = new BlockPos(1, 1, 2); | ||
final var glassDirection = WaterGlassBlock.HIDE_DIRECTION.getOpposite(); | ||
final var glassPosition = waterPosition.relative(glassDirection); | ||
test.onGameTest(helper -> helper.startSequence() | ||
.thenExecute(() -> helper.setBlock(glassPosition, glass.get().defaultBlockState())) | ||
.thenExecute(() -> helper.setBlock(waterPosition, Blocks.WATER.defaultBlockState())) | ||
// Check that the north side of the water is not rendered | ||
.thenExecute(() -> helper.assertFalse( | ||
LiquidBlockRenderer.shouldRenderFace( | ||
helper.getBlockState(waterPosition).getFluidState(), | ||
helper.getBlockState(waterPosition), | ||
glassDirection, | ||
helper.getBlockState(glassPosition)), | ||
"Fluid face rendering is not skipped")) | ||
.thenSucceed()); | ||
} | ||
} |