Skip to content

Commit df63466

Browse files
Further optimize TintedGlassLightBlockingTest
1 parent c0a92a2 commit df63466

File tree

1 file changed

+72
-106
lines changed

1 file changed

+72
-106
lines changed

src/main/java/net/wurstclient/glass/test/TintedGlassLightBlockingTest.java

Lines changed: 72 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -9,149 +9,115 @@
99

1010
import static net.wurstclient.glass.test.WiModsTestHelper.*;
1111

12+
import net.minecraft.block.Block;
13+
import net.minecraft.block.BlockState;
14+
import net.minecraft.block.Blocks;
15+
import net.minecraft.block.SlabBlock;
16+
import net.minecraft.block.StairsBlock;
17+
import net.minecraft.block.enums.BlockHalf;
18+
import net.minecraft.block.enums.SlabType;
19+
import net.minecraft.block.enums.StairShape;
20+
import net.minecraft.util.math.BlockPos;
21+
import net.minecraft.util.math.Direction;
22+
import net.minecraft.world.World;
23+
import net.wurstclient.glass.MoGlassBlocks;
24+
1225
public enum TintedGlassLightBlockingTest
1326
{
1427
;
1528

1629
public static void testTintedGlassBlocksLightCorrectly()
1730
{
1831
System.out.println("Testing tinted glass light blocking...");
19-
String top = "~ ~1 ~4";
20-
String front = "~ ~ ~3";
32+
BlockPos playerPos = submitAndGet(mc -> mc.player.getBlockPos());
33+
BlockPos top = playerPos.add(0, 1, 4);
34+
BlockPos front = playerPos.add(0, 0, 3);
2135

2236
// Build test rig
2337
runChatCommand("fill ~-1 ~ ~3 ~1 ~1 ~5 tinted_glass");
2438
runChatCommand("setblock ~ ~ ~4 air");
39+
clearChat();
2540

2641
// Slab on top - should always block light
27-
testSlab(top, "bottom", 0);
28-
testSlab(top, "top", 0);
29-
testSlab(top, "double", 0);
42+
for(SlabType type : SlabType.values())
43+
testSlab(top, type, 0);
3044

3145
// Slab in front - depends on type
32-
testSlab(front, "bottom", 13);
33-
testSlab(front, "top", 13);
34-
testSlab(front, "double", 0);
46+
testSlab(front, SlabType.BOTTOM, 13);
47+
testSlab(front, SlabType.TOP, 13);
48+
testSlab(front, SlabType.DOUBLE, 0);
3549

3650
// Stairs on top - should always block light
37-
testStairs(top, "south", "bottom", "straight", 0);
38-
testStairs(top, "east", "bottom", "straight", 0);
39-
testStairs(top, "north", "bottom", "straight", 0);
40-
testStairs(top, "west", "bottom", "straight", 0);
41-
testStairs(top, "south", "top", "straight", 0);
42-
testStairs(top, "east", "top", "straight", 0);
43-
testStairs(top, "north", "top", "straight", 0);
44-
testStairs(top, "west", "top", "straight", 0);
45-
testStairs(top, "south", "bottom", "outer_left", 0);
46-
testStairs(top, "east", "bottom", "outer_left", 0);
47-
testStairs(top, "north", "bottom", "outer_left", 0);
48-
testStairs(top, "west", "bottom", "outer_left", 0);
49-
testStairs(top, "south", "top", "outer_left", 0);
50-
testStairs(top, "east", "top", "outer_left", 0);
51-
testStairs(top, "north", "top", "outer_left", 0);
52-
testStairs(top, "west", "top", "outer_left", 0);
53-
testStairs(top, "south", "bottom", "outer_right", 0);
54-
testStairs(top, "east", "bottom", "outer_right", 0);
55-
testStairs(top, "north", "bottom", "outer_right", 0);
56-
testStairs(top, "west", "bottom", "outer_right", 0);
57-
testStairs(top, "south", "top", "outer_right", 0);
58-
testStairs(top, "east", "top", "outer_right", 0);
59-
testStairs(top, "north", "top", "outer_right", 0);
60-
testStairs(top, "west", "top", "outer_right", 0);
61-
testStairs(top, "south", "bottom", "inner_left", 0);
62-
testStairs(top, "east", "bottom", "inner_left", 0);
63-
testStairs(top, "north", "bottom", "inner_left", 0);
64-
testStairs(top, "west", "bottom", "inner_left", 0);
65-
testStairs(top, "south", "top", "inner_left", 0);
66-
testStairs(top, "east", "top", "inner_left", 0);
67-
testStairs(top, "north", "top", "inner_left", 0);
68-
testStairs(top, "west", "top", "inner_left", 0);
69-
testStairs(top, "south", "bottom", "inner_right", 0);
70-
testStairs(top, "east", "bottom", "inner_right", 0);
71-
testStairs(top, "north", "bottom", "inner_right", 0);
72-
testStairs(top, "west", "bottom", "inner_right", 0);
73-
testStairs(top, "south", "top", "inner_right", 0);
74-
testStairs(top, "east", "top", "inner_right", 0);
75-
testStairs(top, "north", "top", "inner_right", 0);
76-
testStairs(top, "west", "top", "inner_right", 0);
77-
78-
// Straight stairs in front - depends on facing
79-
testStairs(front, "south", "bottom", "straight", 0);
80-
testStairs(front, "east", "bottom", "straight", 13);
81-
testStairs(front, "north", "bottom", "straight", 0);
82-
testStairs(front, "west", "bottom", "straight", 13);
83-
testStairs(front, "south", "top", "straight", 0);
84-
testStairs(front, "east", "top", "straight", 13);
85-
testStairs(front, "north", "top", "straight", 0);
86-
testStairs(front, "west", "top", "straight", 13);
51+
for(Direction dir : Direction.Type.HORIZONTAL)
52+
for(BlockHalf half : BlockHalf.values())
53+
for(StairShape shape : StairShape.values())
54+
testStairs(top, dir, half, shape, 0);
55+
56+
// Straight stairs in front - depends on direction
57+
for(Direction dir : Direction.Type.HORIZONTAL)
58+
{
59+
int light = dir.getAxis() == Direction.Axis.X ? 13 : 0;
60+
for(BlockHalf half : BlockHalf.values())
61+
testStairs(front, dir, half, StairShape.STRAIGHT, light);
62+
}
8763

88-
// Outer stairs in front - should always let light through
89-
testStairs(front, "south", "bottom", "outer_left", 13);
90-
testStairs(front, "east", "bottom", "outer_left", 13);
91-
testStairs(front, "north", "bottom", "outer_left", 13);
92-
testStairs(front, "west", "bottom", "outer_left", 13);
93-
testStairs(front, "south", "top", "outer_left", 13);
94-
testStairs(front, "east", "top", "outer_left", 13);
95-
testStairs(front, "north", "top", "outer_left", 13);
96-
testStairs(front, "west", "top", "outer_left", 13);
97-
testStairs(front, "south", "bottom", "outer_right", 13);
98-
testStairs(front, "east", "bottom", "outer_right", 13);
99-
testStairs(front, "north", "bottom", "outer_right", 13);
100-
testStairs(front, "west", "bottom", "outer_right", 13);
101-
testStairs(front, "south", "top", "outer_right", 13);
102-
testStairs(front, "east", "top", "outer_right", 13);
103-
testStairs(front, "north", "top", "outer_right", 13);
104-
testStairs(front, "west", "top", "outer_right", 13);
105-
106-
// Inner stairs in front - should always block light
107-
testStairs(front, "south", "bottom", "inner_left", 0);
108-
testStairs(front, "east", "bottom", "inner_left", 0);
109-
testStairs(front, "north", "bottom", "inner_left", 0);
110-
testStairs(front, "west", "bottom", "inner_left", 0);
111-
testStairs(front, "south", "top", "inner_left", 0);
112-
testStairs(front, "east", "top", "inner_left", 0);
113-
testStairs(front, "north", "top", "inner_left", 0);
114-
testStairs(front, "west", "top", "inner_left", 0);
115-
testStairs(front, "south", "bottom", "inner_right", 0);
116-
testStairs(front, "east", "bottom", "inner_right", 0);
117-
testStairs(front, "north", "bottom", "inner_right", 0);
118-
testStairs(front, "west", "bottom", "inner_right", 0);
119-
testStairs(front, "south", "top", "inner_right", 0);
120-
testStairs(front, "east", "top", "inner_right", 0);
121-
testStairs(front, "north", "top", "inner_right", 0);
122-
testStairs(front, "west", "top", "inner_right", 0);
64+
// Curved stairs in front - depends on curve type
65+
for(Direction dir : Direction.Type.HORIZONTAL)
66+
for(BlockHalf half : BlockHalf.values())
67+
{
68+
testStairs(front, dir, half, StairShape.INNER_LEFT, 0);
69+
testStairs(front, dir, half, StairShape.INNER_RIGHT, 0);
70+
testStairs(front, dir, half, StairShape.OUTER_LEFT, 13);
71+
testStairs(front, dir, half, StairShape.OUTER_RIGHT, 13);
72+
}
12373

12474
// Clean up
12575
runChatCommand("fill ~-1 ~ ~3 ~1 ~1 ~5 air");
12676
clearChat();
12777
}
12878

129-
private static void testSlab(String position, String type, int light)
79+
private static void testSlab(BlockPos pos, SlabType type, int light)
13080
{
131-
testConfiguration(position, "tinted_glass_slab[type=" + type + "]",
132-
light);
81+
testConfiguration(pos, MoGlassBlocks.TINTED_GLASS_SLAB.getDefaultState()
82+
.with(SlabBlock.TYPE, type), light);
13383
}
13484

135-
private static void testStairs(String position, String facing, String half,
136-
String shape, int light)
85+
private static void testStairs(BlockPos pos, Direction facing,
86+
BlockHalf half, StairShape shape, int light)
13787
{
138-
testConfiguration(position, "tinted_glass_stairs[facing=" + facing
139-
+ ",half=" + half + ",shape=" + shape + "]", light);
88+
testConfiguration(pos,
89+
MoGlassBlocks.TINTED_GLASS_STAIRS.getDefaultState()
90+
.with(StairsBlock.FACING, facing).with(StairsBlock.HALF, half)
91+
.with(StairsBlock.SHAPE, shape),
92+
light);
14093
}
14194

142-
private static void testConfiguration(String position, String block,
95+
private static void testConfiguration(BlockPos pos, BlockState state,
14396
int expectedLightLevel)
14497
{
145-
runChatCommand("setblock " + position + " mo_glass:" + block);
146-
clearChat();
98+
setBlock(pos, state);
99+
waitUntil("block " + state + " is placed at " + pos, mc -> {
100+
return mc.world.getBlockState(pos) == state;
101+
});
147102
assertLightLevel(0, 0, 4, expectedLightLevel);
148-
runChatCommand("setblock " + position + " tinted_glass");
103+
setBlock(pos, Blocks.TINTED_GLASS.getDefaultState());
104+
}
105+
106+
private static void setBlock(BlockPos pos, BlockState state)
107+
{
108+
// Set the block without any chat commands or block updates
109+
submitAndWait(
110+
mc -> mc.getServer().getWorld(World.OVERWORLD).setBlockState(pos,
111+
state, Block.FORCE_STATE | Block.NOTIFY_LISTENERS));
149112
}
150113

151114
private static void assertLightLevel(int x, int y, int z, int expected)
152115
{
153-
int lightLevel = submitAndGet(
154-
mc -> mc.world.getLightLevel(mc.player.getBlockPos().add(x, y, z)));
116+
int lightLevel = submitAndGet(mc -> {
117+
BlockPos pos = mc.player.getBlockPos().add(x, y, z);
118+
mc.world.getLightingProvider().checkBlock(pos);
119+
return mc.world.getLightLevel(pos);
120+
});
155121

156122
if(lightLevel == expected)
157123
return;

0 commit comments

Comments
 (0)