|
| 1 | +/* |
| 2 | + * Copyright (c) 2019-2025 Wurst-Imperium and contributors. |
| 3 | + * |
| 4 | + * This source code is subject to the terms of the GNU General Public |
| 5 | + * License, version 3. If a copy of the GPL was not distributed with this |
| 6 | + * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt |
| 7 | + */ |
| 8 | +package net.wurstclient.glass.test; |
| 9 | + |
| 10 | +import static net.wurstclient.glass.test.WiModsTestHelper.*; |
| 11 | + |
| 12 | +import java.time.Duration; |
| 13 | + |
| 14 | +import net.minecraft.block.Block; |
| 15 | +import net.minecraft.block.BlockState; |
| 16 | +import net.minecraft.block.Blocks; |
| 17 | +import net.minecraft.block.SlabBlock; |
| 18 | +import net.minecraft.block.StairsBlock; |
| 19 | +import net.minecraft.block.enums.BlockHalf; |
| 20 | +import net.minecraft.block.enums.SlabType; |
| 21 | +import net.minecraft.block.enums.StairShape; |
| 22 | +import net.minecraft.util.DyeColor; |
| 23 | +import net.minecraft.util.math.BlockPos; |
| 24 | +import net.minecraft.util.math.Direction; |
| 25 | +import net.wurstclient.glass.MoGlassBlocks; |
| 26 | + |
| 27 | +public enum GlassPieceConnectionTest |
| 28 | +{ |
| 29 | + ; |
| 30 | + |
| 31 | + public static void testGlassPiecesConnectCorrectly() |
| 32 | + { |
| 33 | + System.out.println("Testing if glass pieces connect correctly..."); |
| 34 | + BlockPos pos = submitAndGet(mc -> mc.player.getBlockPos()); |
| 35 | + |
| 36 | + BlockState[][] blocksWithFullyCoveredNorthSide = new BlockState[][]{ |
| 37 | + blocks(), slabs(SlabType.DOUBLE), |
| 38 | + stairs(Direction.NORTH, BlockHalf.BOTTOM, StairShape.STRAIGHT), |
| 39 | + stairs(Direction.NORTH, BlockHalf.TOP, StairShape.STRAIGHT), |
| 40 | + stairs(Direction.NORTH, BlockHalf.BOTTOM, StairShape.INNER_LEFT), |
| 41 | + stairs(Direction.EAST, BlockHalf.BOTTOM, StairShape.INNER_LEFT), |
| 42 | + stairs(Direction.EAST, BlockHalf.TOP, StairShape.INNER_LEFT), |
| 43 | + stairs(Direction.NORTH, BlockHalf.TOP, StairShape.INNER_RIGHT), |
| 44 | + stairs(Direction.NORTH, BlockHalf.BOTTOM, StairShape.INNER_RIGHT), |
| 45 | + stairs(Direction.WEST, BlockHalf.BOTTOM, StairShape.INNER_RIGHT), |
| 46 | + stairs(Direction.NORTH, BlockHalf.TOP, StairShape.INNER_LEFT), |
| 47 | + stairs(Direction.WEST, BlockHalf.TOP, StairShape.INNER_RIGHT)}; |
| 48 | + |
| 49 | + for(BlockState[] back : blocksWithFullyCoveredNorthSide) |
| 50 | + { |
| 51 | + test(pos, back, blocks(), true, true); |
| 52 | + test(pos, back, slabs(SlabType.BOTTOM), false, true); |
| 53 | + test(pos, back, slabs(SlabType.TOP), false, true); |
| 54 | + test(pos, back, slabs(SlabType.DOUBLE), true, true); |
| 55 | + for(Direction dir : Direction.Type.HORIZONTAL) |
| 56 | + for(BlockHalf half : BlockHalf.values()) |
| 57 | + { |
| 58 | + test(pos, back, stairs(dir, half, StairShape.STRAIGHT), |
| 59 | + dir == Direction.SOUTH, true); |
| 60 | + test(pos, back, stairs(dir, half, StairShape.INNER_LEFT), |
| 61 | + dir == Direction.SOUTH || dir == Direction.WEST, true); |
| 62 | + test(pos, back, stairs(dir, half, StairShape.INNER_RIGHT), |
| 63 | + dir == Direction.SOUTH || dir == Direction.EAST, true); |
| 64 | + test(pos, back, stairs(dir, half, StairShape.OUTER_LEFT), |
| 65 | + false, true); |
| 66 | + test(pos, back, stairs(dir, half, StairShape.OUTER_RIGHT), |
| 67 | + false, true); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + // Clean up |
| 72 | + runChatCommand("fill ~-7 ~ ~-4 ~7 ~30 ~10 air"); |
| 73 | + clearChat(); |
| 74 | + } |
| 75 | + |
| 76 | + private static void test(BlockPos pos, BlockState[] backBlocks, |
| 77 | + BlockState[] frontBlocks, boolean frontSeamless, boolean backSeamless) |
| 78 | + { |
| 79 | + BlockPos back1 = pos.add(2, 0, 5); |
| 80 | + BlockPos back2 = pos.add(0, 0, 5); |
| 81 | + BlockPos back3 = pos.add(-2, 0, 5); |
| 82 | + BlockPos front1 = pos.add(2, 0, 4); |
| 83 | + BlockPos front2 = pos.add(0, 0, 4); |
| 84 | + BlockPos front3 = pos.add(-2, 0, 4); |
| 85 | + |
| 86 | + setBlock(back1, backBlocks[0]); |
| 87 | + setBlock(back2, backBlocks[1]); |
| 88 | + setBlock(back3, backBlocks[2]); |
| 89 | + setBlock(front1, frontBlocks[0]); |
| 90 | + setBlock(front2, frontBlocks[1]); |
| 91 | + setBlock(front3, frontBlocks[2]); |
| 92 | + |
| 93 | + waitUntil("blocks are placed", mc -> { |
| 94 | + return mc.world.getBlockState(back1) == backBlocks[0] |
| 95 | + && mc.world.getBlockState(back2) == backBlocks[1] |
| 96 | + && mc.world.getBlockState(back3) == backBlocks[2] |
| 97 | + && mc.world.getBlockState(front1) == frontBlocks[0] |
| 98 | + && mc.world.getBlockState(front2) == frontBlocks[1] |
| 99 | + && mc.world.getBlockState(front3) == frontBlocks[2]; |
| 100 | + }); |
| 101 | + |
| 102 | + assertConnection(back1, Direction.NORTH, frontSeamless); |
| 103 | + assertConnection(back2, Direction.NORTH, frontSeamless); |
| 104 | + assertConnection(back3, Direction.NORTH, frontSeamless); |
| 105 | + assertConnection(front1, Direction.SOUTH, backSeamless); |
| 106 | + assertConnection(front2, Direction.SOUTH, backSeamless); |
| 107 | + assertConnection(front3, Direction.SOUTH, backSeamless); |
| 108 | + } |
| 109 | + |
| 110 | + private static void assertConnection(BlockPos pos, Direction dir, |
| 111 | + boolean connected) |
| 112 | + { |
| 113 | + RuntimeException e = submitAndGet(mc -> { |
| 114 | + BlockState state = mc.world.getBlockState(pos); |
| 115 | + BlockState state2 = mc.world.getBlockState(pos.offset(dir)); |
| 116 | + if(Block.shouldDrawSide(state, state2, dir) != connected) |
| 117 | + return null; |
| 118 | + |
| 119 | + if(connected) |
| 120 | + return new RuntimeException( |
| 121 | + "Block " + state + " did not connect to " + state2); |
| 122 | + else |
| 123 | + return new RuntimeException( |
| 124 | + "Block " + state + " connected to " + state2); |
| 125 | + }); |
| 126 | + |
| 127 | + if(e == null) |
| 128 | + return; |
| 129 | + |
| 130 | + setBlock(pos.up(2), Blocks.RED_CONCRETE.getDefaultState()); |
| 131 | + if(dir == Direction.SOUTH) |
| 132 | + runChatCommand("tp @s ~ ~ ~9 180 0"); |
| 133 | + clearChat(); |
| 134 | + takeScreenshot("FAILED_TEST_glass_connected_incorrectly", |
| 135 | + Duration.ofMillis(250)); |
| 136 | + throw e; |
| 137 | + } |
| 138 | + |
| 139 | + private static BlockState[] blocks() |
| 140 | + { |
| 141 | + return new BlockState[]{Blocks.GLASS.getDefaultState(), |
| 142 | + Blocks.WHITE_STAINED_GLASS.getDefaultState(), |
| 143 | + Blocks.TINTED_GLASS.getDefaultState()}; |
| 144 | + } |
| 145 | + |
| 146 | + private static BlockState[] slabs(SlabType type) |
| 147 | + { |
| 148 | + return new BlockState[]{ |
| 149 | + MoGlassBlocks.GLASS_SLAB.getDefaultState().with(SlabBlock.TYPE, |
| 150 | + type), |
| 151 | + MoGlassBlocks.STAINED_GLASS_SLABS.get(DyeColor.WHITE.ordinal()) |
| 152 | + .getDefaultState().with(SlabBlock.TYPE, type), |
| 153 | + MoGlassBlocks.TINTED_GLASS_SLAB.getDefaultState() |
| 154 | + .with(SlabBlock.TYPE, type)}; |
| 155 | + } |
| 156 | + |
| 157 | + private static BlockState[] stairs(Direction facing, BlockHalf half, |
| 158 | + StairShape shape) |
| 159 | + { |
| 160 | + return new BlockState[]{ |
| 161 | + MoGlassBlocks.GLASS_STAIRS.getDefaultState() |
| 162 | + .with(StairsBlock.FACING, facing).with(StairsBlock.HALF, half) |
| 163 | + .with(StairsBlock.SHAPE, shape), |
| 164 | + MoGlassBlocks.STAINED_GLASS_STAIRS.get(DyeColor.WHITE.ordinal()) |
| 165 | + .getDefaultState().with(StairsBlock.FACING, facing) |
| 166 | + .with(StairsBlock.HALF, half).with(StairsBlock.SHAPE, shape), |
| 167 | + MoGlassBlocks.TINTED_GLASS_STAIRS.getDefaultState() |
| 168 | + .with(StairsBlock.FACING, facing).with(StairsBlock.HALF, half) |
| 169 | + .with(StairsBlock.SHAPE, shape)}; |
| 170 | + } |
| 171 | +} |
0 commit comments