Skip to content

Commit 0a03313

Browse files
pupnewfsterDrullkus
authored andcommitted
Use the passed in block state for purposes of checking the connection state
1 parent f9dfbd6 commit 0a03313

File tree

11 files changed

+68
-49
lines changed

11 files changed

+68
-49
lines changed

src/main/java/team/chisel/ctm/client/newctm/ConnectionCheck.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,18 @@ public class ConnectionCheck {
3333
* The world the positions are in.
3434
* @param current
3535
* The position of your block.
36+
* @param currentState
37+
* The current state of your block.
3638
* @param connection
3739
* The position of the block to check against.
3840
* @param dir
3941
* The {@link Direction side} of the block to check for connection status. This is <i>not</i> the direction to check in.
4042
* @return True if the given block can connect to the given location on the given side.
4143
*/
42-
public final boolean isConnected(BlockAndTintGetter world, BlockPos current, BlockPos connection, Direction dir) {
44+
public final boolean isConnected(BlockAndTintGetter world, BlockPos current, BlockState currentState, BlockPos connection, Direction dir) {
4345

44-
BlockState state = getConnectionState(world, current, dir, connection);
45-
return isConnected(world, current, connection, dir, state);
46+
BlockState state = getConnectionState(world, current, currentState, dir, connection, world.getBlockState(connection));
47+
return isConnected(world, current, currentState, connection, dir, state);
4648
}
4749

4850
/**
@@ -61,19 +63,19 @@ public final boolean isConnected(BlockAndTintGetter world, BlockPos current, Blo
6163
* @return True if the given block can connect to the given location on the given side.
6264
*/
6365
@SuppressWarnings({ "unused", "null" })
64-
public boolean isConnected(BlockAndTintGetter world, BlockPos current, BlockPos connection, Direction dir, BlockState state) {
66+
public boolean isConnected(BlockAndTintGetter world, BlockPos current, BlockState currentState, BlockPos connection, Direction dir, BlockState state) {
6567

6668
// if (CTMLib.chiselLoaded() && connectionBlocked(world, x, y, z, dir.ordinal())) {
6769
// return false;
6870
// }
6971

70-
BlockState con = getConnectionState(world, connection, dir, current);
72+
BlockState con = getConnectionState(world, connection, world.getBlockState(connection), dir, current, currentState);
7173
BlockState obscuring;
7274
if (disableObscuredFaceCheck.orElseGet(Configurations::connectInsideCTM)) {
7375
obscuring = null;
7476
} else {
7577
BlockPos obscuringPos = connection.relative(dir);
76-
obscuring = getConnectionState(world, obscuringPos, dir, current);
78+
obscuring = getConnectionState(world, obscuringPos, world.getBlockState(obscuringPos), dir, current, currentState);
7779
}
7880

7981
// bad API user
@@ -106,10 +108,14 @@ public boolean stateComparator(BlockState from, BlockState to, Direction dir) {
106108
// return false;
107109
// }
108110

109-
public BlockState getConnectionState(BlockAndTintGetter world, BlockPos pos, @Nullable Direction side, BlockPos connection) {
110-
BlockState state = world.getBlockState(pos);
111+
public BlockState getConnectionState(BlockAndTintGetter world, BlockPos pos, @Nullable Direction side, BlockPos connection, BlockState connectionState) {
112+
return getConnectionState(world, pos, world.getBlockState(pos), side, connection, connectionState);
113+
}
114+
115+
public BlockState getConnectionState(BlockAndTintGetter world, BlockPos pos, BlockState state, @Nullable Direction side, BlockPos connection,
116+
BlockState connectionState) {
111117
if (side != null) {
112-
return state.getAppearance(world, pos, side, world.getBlockState(connection), connection);
118+
return state.getAppearance(world, pos, side, connectionState, connection);
113119
}
114120
return state;
115121
}

src/main/java/team/chisel/ctm/client/newctm/CustomCTMLogic.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import net.minecraft.core.BlockPos;
1212
import net.minecraft.core.Direction;
1313
import net.minecraft.world.level.BlockAndTintGetter;
14+
import net.minecraft.world.level.block.state.BlockState;
1415
import org.jetbrains.annotations.Nullable;
1516
import team.chisel.ctm.api.texture.ISubmap;
1617
import team.chisel.ctm.client.newctm.CTMLogicBakery.OutputFace;
@@ -55,8 +56,8 @@ public long serialized() {
5556
}
5657

5758
@Override
58-
public void buildConnectionMap(BlockAndTintGetter world, BlockPos pos, Direction side) {
59-
this.cachedSubmapIds = CustomCTMLogic.this.getSubmapIds(world, pos, side, connectionCheckOverride);
59+
public void buildConnectionMap(BlockAndTintGetter world, BlockPos pos, BlockState state, Direction side) {
60+
this.cachedSubmapIds = CustomCTMLogic.this.getSubmapIds(world, pos, state, side, connectionCheckOverride);
6061
//Manually call with the computed submap ids to avoid having to calculate them a second type
6162
// like getSubmaps(BlockAndTintGetter, BlockPos, Direction) needs to do, and allows us to use
6263
// data that is based on our connection check override
@@ -65,14 +66,14 @@ public void buildConnectionMap(BlockAndTintGetter world, BlockPos pos, Direction
6566
}
6667

6768
@Override
68-
public int[] getSubmapIds(BlockAndTintGetter world, BlockPos pos, Direction side) {
69-
return getSubmapIds(world, pos, side, connectionCheck);
69+
public int[] getSubmapIds(BlockAndTintGetter world, BlockPos pos, BlockState state, Direction side) {
70+
return getSubmapIds(world, pos, state, side, connectionCheck);
7071
}
7172

72-
private int[] getSubmapIds(BlockAndTintGetter world, BlockPos pos, Direction side, ConnectionCheck connectionCheck) {
73+
private int[] getSubmapIds(BlockAndTintGetter world, BlockPos pos, BlockState state, Direction side, ConnectionCheck connectionCheck) {
7374
int key = 0;
7475
for (int i = 0; i < directions.length; i++) {
75-
boolean isConnected = directions[i].isConnected(connectionCheck, world, pos, side);
76+
boolean isConnected = directions[i].isConnected(connectionCheck, world, pos, state, side);
7677
key |= (isConnected ? 1 : 0) << i;
7778
}
7879
if (key >= lookups.length || lookups[key] == null) {
@@ -82,8 +83,8 @@ private int[] getSubmapIds(BlockAndTintGetter world, BlockPos pos, Direction sid
8283
}
8384

8485
@Override
85-
public OutputFace[] getSubmaps(BlockAndTintGetter world, BlockPos pos, Direction side) {
86-
var tileIds = getSubmapIds(world, pos, side);
86+
public OutputFace[] getSubmaps(BlockAndTintGetter world, BlockPos pos, BlockState state, Direction side) {
87+
var tileIds = getSubmapIds(world, pos, state, side);
8788
return getSubmaps(tileIds);
8889
}
8990

src/main/java/team/chisel/ctm/client/newctm/ICTMLogic.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
import net.minecraft.core.BlockPos;
66
import net.minecraft.core.Direction;
77
import net.minecraft.world.level.BlockAndTintGetter;
8+
import net.minecraft.world.level.block.state.BlockState;
89
import org.jetbrains.annotations.Nullable;
910
import team.chisel.ctm.api.texture.ISubmap;
1011
import team.chisel.ctm.client.newctm.CTMLogicBakery.OutputFace;
1112
import team.chisel.ctm.client.util.Submap;
1213

1314
public interface ICTMLogic {
1415

15-
int[] getSubmapIds(BlockAndTintGetter world, BlockPos pos, Direction side);
16+
int[] getSubmapIds(BlockAndTintGetter world, BlockPos pos, BlockState state, Direction side);
1617

17-
OutputFace[] getSubmaps(BlockAndTintGetter world, BlockPos pos, Direction side);
18+
OutputFace[] getSubmaps(BlockAndTintGetter world, BlockPos pos, BlockState state, Direction side);
1819

1920
ILogicCache cached(@Nullable ConnectionCheck connectionCheck);
2021

src/main/java/team/chisel/ctm/client/newctm/ILogicCache.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.minecraft.core.BlockPos;
44
import net.minecraft.core.Direction;
55
import net.minecraft.world.level.BlockAndTintGetter;
6+
import net.minecraft.world.level.block.state.BlockState;
67
import team.chisel.ctm.client.newctm.CTMLogicBakery.OutputFace;
78

89
public interface ILogicCache {
@@ -14,5 +15,5 @@ public interface ILogicCache {
1415
/**
1516
* Builds the connection map and stores it in this CTM instance.
1617
*/
17-
void buildConnectionMap(BlockAndTintGetter world, BlockPos pos, Direction side);
18+
void buildConnectionMap(BlockAndTintGetter world, BlockPos pos, BlockState state, Direction side);
1819
}

src/main/java/team/chisel/ctm/client/newctm/LocalDirection.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ public interface LocalDirection {
1616
* The world the block is in.
1717
* @param pos
1818
* The position of your block.
19+
* @param state
20+
* The state of your block.
1921
* @param side
2022
* The side of the current face.
2123
* @return True if the block is connected in the given Dir, false otherwise.
2224
*/
23-
boolean isConnected(ConnectionCheck ctm, BlockAndTintGetter world, BlockPos pos, Direction side);
25+
boolean isConnected(ConnectionCheck ctm, BlockAndTintGetter world, BlockPos pos, BlockState state, Direction side);
2426

2527
/**
2628
* Finds if this block is connected for the given side in this Dir.
@@ -31,13 +33,15 @@ public interface LocalDirection {
3133
* The world the block is in.
3234
* @param pos
3335
* The position of your block.
36+
* @param state
37+
* The state of your block.
3438
* @param side
3539
* The side of the current face.
36-
* @param state
40+
* @param connectionState
3741
* The state to check for connection with.
3842
* @return True if the block is connected in the given Dir, false otherwise.
3943
*/
40-
boolean isConnected(ConnectionCheck ctm, BlockAndTintGetter world, BlockPos pos, Direction side, BlockState state);
44+
boolean isConnected(ConnectionCheck ctm, BlockAndTintGetter world, BlockPos pos, BlockState state, Direction side, BlockState connectionState);
4145

4246
LocalDirection relativize(Direction normal);
4347

src/main/java/team/chisel/ctm/client/newctm/TextureContextCustomCTM.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public TextureContextCustomCTM(@NotNull BlockState state, BlockAndTintGetter wor
3030

3131
for (Direction face : Direction.values()) {
3232
ILogicCache ctm = createCTM(state, connectionCheckOverride);
33-
ctm.buildConnectionMap(world, pos, face);
33+
ctm.buildConnectionMap(world, pos, state, face);
3434
ctmData.put(face, ctm);
3535
this.data |= ctm.serialized() << (face.ordinal() * 10);
3636
}

src/main/java/team/chisel/ctm/client/texture/ctx/TextureContextCTM.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public TextureContextCTM(@NotNull BlockState state, BlockAndTintGetter world, Bl
2424

2525
for (Direction face : Direction.values()) {
2626
CTMLogic ctm = createCTM(state);
27-
ctm.getSubmapIds(world, pos, face);
27+
ctm.getSubmapIds(world, pos, state, face);
2828
ctmData.put(face, ctm);
2929
this.data |= ctm.serialized() << (face.ordinal() * 10);
3030
}

src/main/java/team/chisel/ctm/client/texture/type/TextureTypeEdges.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,18 @@ public static class ConnectionCheckEdges extends ConnectionCheck {
6060
private boolean obscured;
6161

6262
@Override
63-
public boolean isConnected(BlockAndTintGetter world, BlockPos current, BlockPos connection, Direction dir, BlockState state) {
63+
public boolean isConnected(BlockAndTintGetter world, BlockPos current, BlockState currentState, BlockPos connection, Direction dir, BlockState state) {
6464
if (isObscured()) {
6565
return false;
6666
}
67-
BlockState obscuring = getConnectionState(world, current.relative(dir), dir, current);
67+
BlockState obscuring = getConnectionState(world, current.relative(dir), dir, current, currentState);
6868
if (stateComparator(state, obscuring, dir)) {
6969
setObscured(true);
7070
return false;
7171
}
7272

73-
BlockState con = getConnectionState(world, connection, dir, current);
74-
BlockState obscuringcon = getConnectionState(world, connection.relative(dir), dir, current);
73+
BlockState con = getConnectionState(world, connection, dir, current, currentState);
74+
BlockState obscuringcon = getConnectionState(world, connection.relative(dir), dir, current, currentState);
7575

7676
if (stateComparator(state, con, dir) || stateComparator(state, obscuringcon, dir)) {
7777
Vec3 difference = Vec3.atLowerCornerOf(connection.subtract(current));
@@ -91,8 +91,8 @@ public boolean isConnected(BlockAndTintGetter world, BlockPos current, BlockPos
9191
}
9292
BlockPos posA = BlockPos.containing(vA).offset(current);
9393
BlockPos posB = BlockPos.containing(vB).offset(current);
94-
return (getConnectionState(world, posA, dir, current) == state && !stateComparator(state, getConnectionState(world, posA.relative(dir), dir, current), dir))
95-
|| (getConnectionState(world, posB, dir, current) == state && !stateComparator(state, getConnectionState(world, posB.relative(dir), dir, current), dir));
94+
return (getConnectionState(world, posA, dir, current, currentState) == state && !stateComparator(state, getConnectionState(world, posA.relative(dir), dir, current, currentState), dir))
95+
|| (getConnectionState(world, posB, dir, current, currentState) == state && !stateComparator(state, getConnectionState(world, posB.relative(dir), dir, current, currentState), dir));
9696
} else {
9797
return true;
9898
}

src/main/java/team/chisel/ctm/client/util/CTMLogic.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ public static CTMLogic getInstance() {
148148
* Indeces are in counter-clockwise order starting at bottom left.
149149
*/
150150
@Override
151-
public int[] getSubmapIds(@Nullable BlockAndTintGetter world, BlockPos pos, Direction side) {
151+
public int[] getSubmapIds(@Nullable BlockAndTintGetter world, BlockPos pos, BlockState state, Direction side) {
152152
if (world == null) {
153153
return submapCache;
154154
}
155155

156-
buildConnectionMap(world, pos, side);
156+
buildConnectionMap(world, pos, state, side);
157157

158158
// Map connections to submap indeces
159159
for (int i = 0; i < 4; i++) {
@@ -205,7 +205,7 @@ private static byte setConnectedState(byte map, LocalDirection dir, boolean conn
205205
* Builds the connection map and stores it in this CTM instance. The {@link #connected(Dir)}, {@link #connectedAnd(Dir...)}, and {@link #connectedOr(Dir...)} methods can be used to access it.
206206
*/
207207
@Override
208-
public void buildConnectionMap(BlockAndTintGetter world, BlockPos pos, Direction side) {
208+
public void buildConnectionMap(BlockAndTintGetter world, BlockPos pos, BlockState state, Direction side) {
209209
//BlockState state = connectionCheck.getConnectionState(world, pos, side, pos);
210210
// TODO this naive check doesn't work for models that have unculled faces.
211211
// Perhaps a smarter optimization could be done eventually?
@@ -214,7 +214,7 @@ public void buildConnectionMap(BlockAndTintGetter world, BlockPos pos, Direction
214214
//Note: We can't cache the state that we are checking about connection for as we want to ensure that
215215
// we can take into account the side of the block we want to know the "state" of as if the block is
216216
// a facade of some sort it might return different results based on where it is being queried from
217-
setConnectedState(dir, dir.isConnected(connectionCheck, world, pos, side));
217+
setConnectedState(dir, dir.isConnected(connectionCheck, world, pos, state, side));
218218
}
219219
// }
220220
}
@@ -318,7 +318,7 @@ public OutputFace[] getCachedSubmaps() {
318318

319319
@Override
320320
@Deprecated
321-
public OutputFace[] getSubmaps(BlockAndTintGetter world, BlockPos pos, Direction side) {
321+
public OutputFace[] getSubmaps(BlockAndTintGetter world, BlockPos pos, BlockState state, Direction side) {
322322
return new OutputFace[0];
323323
}
324324

src/main/java/team/chisel/ctm/client/util/Dir.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,15 @@ private void buildCaches() {
118118
* The world the block is in.
119119
* @param pos
120120
* The position of your block.
121+
* @param state
122+
* The state of your block.
121123
* @param side
122124
* The side of the current face.
123125
* @return True if the block is connected in the given Dir, false otherwise.
124126
*/
125127
@Override
126-
public boolean isConnected(ConnectionCheck ctm, BlockAndTintGetter world, BlockPos pos, Direction side) {
127-
return ctm.isConnected(world, pos, applyConnection(pos, side), side);
128+
public boolean isConnected(ConnectionCheck ctm, BlockAndTintGetter world, BlockPos pos, BlockState state, Direction side) {
129+
return ctm.isConnected(world, pos, state, applyConnection(pos, side), side);
128130
}
129131

130132
/**
@@ -136,15 +138,17 @@ public boolean isConnected(ConnectionCheck ctm, BlockAndTintGetter world, BlockP
136138
* The world the block is in.
137139
* @param pos
138140
* The position of your block.
141+
* @param state
142+
* The state of your block.
139143
* @param side
140144
* The side of the current face.
141-
* @param state
145+
* @param connectionState
142146
* The state to check for connection with.
143147
* @return True if the block is connected in the given Dir, false otherwise.
144148
*/
145149
@Override
146-
public boolean isConnected(ConnectionCheck ctm, BlockAndTintGetter world, BlockPos pos, Direction side, BlockState state) {
147-
return ctm.isConnected(world, pos, applyConnection(pos, side), side, state);
150+
public boolean isConnected(ConnectionCheck ctm, BlockAndTintGetter world, BlockPos pos, BlockState state, Direction side, BlockState connectionState) {
151+
return ctm.isConnected(world, pos, state, applyConnection(pos, side), side, connectionState);
148152
}
149153

150154
/**

0 commit comments

Comments
 (0)