Skip to content

Commit 4de6e07

Browse files
committed
Fix ShapeDSL issues
1 parent f583918 commit 4de6e07

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

src/main/kotlin/com/lambda/graphics/renderer/esp/ShapeDsl.kt

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import com.lambda.util.extension.outlineShape
2727
import net.minecraft.block.BlockState
2828
import net.minecraft.block.entity.BlockEntity
2929
import net.minecraft.entity.Entity
30+
import net.minecraft.util.math.BlockBox
3031
import net.minecraft.util.math.BlockPos
3132
import net.minecraft.util.math.Box
3233
import net.minecraft.util.shape.VoxelShape
@@ -104,30 +105,28 @@ class ShapeBuilder(
104105
color : Color,
105106
sides : Int = DirectionMask.ALL,
106107
) = runSafe { faces.apply {
107-
val shape = state.getOutlineShape(world, pos)
108-
filled(shape, color, sides)
108+
val shape = outlineShape(state, pos)
109+
if (shape.isEmpty) {
110+
filled(Box(pos), color, sides)
111+
} else {
112+
filled(shape, color, sides)
113+
}
109114
} }
110115

111116
@ShapeDsl
112117
fun filled(
113118
pos : BlockPos,
114119
color : Color,
115120
sides : Int = DirectionMask.ALL,
116-
) = runSafe { faces.apply {
117-
val shape = blockState(pos).getOutlineShape(world, pos)
118-
filled(shape, color, sides)
119-
} }
121+
) = runSafe { faces.apply { filled(pos, blockState(pos), color, sides) } }
120122

121123
@ShapeDsl
122124
fun filled(
123125
pos : BlockPos,
124126
entity : BlockEntity,
125127
color : Color,
126128
sides : Int = DirectionMask.ALL,
127-
) = runSafe {
128-
val shape = outlineShape(entity.cachedState, pos)
129-
filled(shape, color, sides)
130-
}
129+
) = filled(pos, entity.cachedState, color, sides)
131130

132131
@ShapeDsl
133132
fun filled(
@@ -243,8 +242,12 @@ class ShapeBuilder(
243242
sides : Int = DirectionMask.ALL,
244243
mode : DirectionMask.OutlineMode = DirectionMask.OutlineMode.OR,
245244
) = runSafe {
246-
val shape = state.getOutlineShape(world, pos)
247-
outline(shape, color, sides, mode)
245+
val shape = outlineShape(state, pos)
246+
if (shape.isEmpty) {
247+
outline(Box(pos), color, sides, mode)
248+
} else {
249+
outline(shape, color, sides, mode)
250+
}
248251
}
249252

250253
@ShapeDsl
@@ -253,10 +256,7 @@ class ShapeBuilder(
253256
color : Color,
254257
sides : Int = DirectionMask.ALL,
255258
mode : DirectionMask.OutlineMode = DirectionMask.OutlineMode.OR,
256-
) = runSafe {
257-
val shape = blockState(pos).getOutlineShape(world, pos)
258-
outline(shape, color, sides, mode)
259-
}
259+
) = runSafe { outline(pos, blockState(pos), color, sides, mode) }
260260

261261
@ShapeDsl
262262
fun outline(
@@ -265,10 +265,7 @@ class ShapeBuilder(
265265
color : Color,
266266
sides : Int = DirectionMask.ALL,
267267
mode : DirectionMask.OutlineMode = DirectionMask.OutlineMode.OR,
268-
) = runSafe {
269-
val shape = outlineShape(entity.cachedState, pos)
270-
outline(shape, color, sides, mode)
271-
}
268+
) = runSafe { outline(pos, entity.cachedState, color, sides, mode) }
272269

273270
@ShapeDsl
274271
fun outline(
@@ -300,9 +297,8 @@ class ShapeBuilder(
300297
sides : Int = DirectionMask.ALL,
301298
mode : DirectionMask.OutlineMode = DirectionMask.OutlineMode.OR,
302299
) = runSafe {
303-
val shape = state.getOutlineShape(world, pos)
304-
filled(shape, filled, sides)
305-
outline(shape, outline, sides, mode)
300+
filled(pos, state, filled, sides)
301+
outline(pos, state, outline, sides, mode)
306302
}
307303

308304
@ShapeDsl

src/main/kotlin/com/lambda/util/extension/World.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ val World?.dimensionName: String
4848
}
4949

5050
fun SafeContext.collisionShape(state: BlockState, pos: BlockPos): VoxelShape =
51-
state.getCollisionShape(world, pos).offset(pos.x.toDouble(), pos.y.toDouble(), pos.z.toDouble())
51+
state.getCollisionShape(world, pos).offset(pos)
5252

53-
fun SafeContext.outlineShape(state: BlockState, pos: BlockPos): VoxelShape =
54-
state.getOutlineShape(world, pos).offset(pos.x.toDouble(), pos.y.toDouble(), pos.z.toDouble())
53+
fun SafeContext.outlineShape(state: BlockState, pos: BlockPos) =
54+
state.getOutlineShape(world, pos).offset(pos)
5555

5656
fun SafeContext.blockColor(state: BlockState, pos: BlockPos) =
5757
Color(state.getMapColor(world, pos).color)

0 commit comments

Comments
 (0)