Skip to content

Commit b0ccf8e

Browse files
committed
Refactor BlockPos.blockState(world) to SafeContext.blockState(pos)
1 parent a6a3bcf commit b0ccf8e

File tree

15 files changed

+37
-37
lines changed

15 files changed

+37
-37
lines changed

common/src/main/kotlin/com/lambda/graphics/renderer/esp/builders/StaticESPBuilders.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fun StaticESPRenderer.ofShape(
3737
sides: Int = DirectionMask.ALL,
3838
outlineMode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.OR
3939
) = runSafe {
40-
val shape = pos.blockState(world).getOutlineShape(world, pos)
40+
val shape = blockState(pos).getOutlineShape(world, pos)
4141
ofShape(pos, shape, filledColor, outlineColor, sides, outlineMode)
4242
}
4343

@@ -92,7 +92,7 @@ fun StaticESPRenderer.buildFilledShape(
9292
color: Color,
9393
sides: Int = DirectionMask.ALL,
9494
) = runSafe {
95-
val shape = pos.blockState(world).getOutlineShape(world, pos)
95+
val shape = blockState(pos).getOutlineShape(world, pos)
9696
buildFilledShape(shape, color, sides)
9797
}
9898

@@ -129,7 +129,7 @@ fun StaticESPRenderer.buildOutlineShape(
129129
sides: Int = DirectionMask.ALL,
130130
outlineMode: DirectionMask.OutlineMode = DirectionMask.OutlineMode.OR
131131
) = runSafe {
132-
val shape = pos.blockState(world).getOutlineShape(world, pos)
132+
val shape = blockState(pos).getOutlineShape(world, pos)
133133
buildOutlineShape(shape, color, sides, outlineMode)
134134
}
135135

common/src/main/kotlin/com/lambda/interaction/blockplace/PlaceFinder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class PlaceFinder(
8686
val distSq = eyes distSq hitVec
8787

8888
if (distSq > rangeSq) return null
89-
if (clickPos.blockState(world).isClickable) return null
89+
if (blockState(clickPos).isClickable) return null
9090

9191
if (visibleCheck) {
9292
val box = Box(clickPos)

common/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ data class PlaceContext(
9595

9696
override fun SafeContext.buildRenderer() {
9797
withState(expectedState, expectedPos, baseColor, DirectionMask.ALL.exclude(result.side.opposite))
98-
withState(result.blockPos.blockState(world), result.blockPos, sideColor, result.side)
98+
withState(blockState(result.blockPos), result.blockPos, sideColor, result.side)
9999
}
100100

101101
override fun shouldRotate(config: BuildConfig) = config.rotateForPlace

common/src/main/kotlin/com/lambda/interaction/construction/result/BuildResult.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ abstract class BuildResult : ComparableResult<Rank>, Nameable {
209209
.transfer(MainHandContainer, inventory) ?: MaterialContainer.FailureTask("Couldn't find ${neededItem.name.string} anywhere.")
210210

211211
override fun SafeContext.buildRenderer() {
212-
if (blockPos.blockState(world).isAir) {
212+
if (blockState(blockPos).isAir) {
213213
withBox(Box(blockPos), color)
214214
} else {
215215
withPos(blockPos, color)
@@ -246,7 +246,7 @@ abstract class BuildResult : ComparableResult<Rank>, Nameable {
246246
.transfer(MainHandContainer, inventory) ?: MaterialContainer.FailureTask("Couldn't find ${neededStack.item.name.string} anywhere.")
247247

248248
override fun SafeContext.buildRenderer() {
249-
if (blockPos.blockState(world).isAir) {
249+
if (blockState(blockPos).isAir) {
250250
withBox(Box(blockPos), color)
251251
} else {
252252
withPos(blockPos, color)

common/src/main/kotlin/com/lambda/interaction/construction/result/Drawable.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ interface Drawable {
5151
}
5252

5353
fun SafeContext.withPos(blockPos: BlockPos, color: Color, mask: Int = DirectionMask.ALL) {
54-
val shape = blockPos.blockState(world).getOutlineShape(world, blockPos)
54+
val shape = blockState(blockPos).getOutlineShape(world, blockPos)
5555
withShape(shape, blockPos, color, mask)
5656
}
5757

common/src/main/kotlin/com/lambda/interaction/construction/simulation/BuildSimulator.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ object BuildSimulator {
100100
return BuildResult.ChunkNotLoaded(pos)
101101
}
102102

103-
val state = pos.blockState(world)
103+
val state = blockState(pos)
104104

105105
/* block is already in the correct state */
106106
if (target.matches(state, pos, world)) {
@@ -144,7 +144,7 @@ object BuildSimulator {
144144
inventory: InventoryConfig
145145
): Set<BuildResult> {
146146
val acc = mutableSetOf<BuildResult>()
147-
val targetPosState = pos.blockState(world)
147+
val targetPosState = blockState(pos)
148148

149149
if (target.isAir() || !targetPosState.isReplaceable) return acc
150150

@@ -154,7 +154,7 @@ object BuildSimulator {
154154
val hitPos = if (targetPosState.isAir || targetPosState.isLiquid) pos.offset(neighbor) else pos
155155
val hitSide = neighbor.opposite
156156

157-
val voxelShape = hitPos.blockState(world).getOutlineShape(world, hitPos)
157+
val voxelShape = blockState(hitPos).getOutlineShape(world, hitPos)
158158
if (voxelShape.isEmpty) return@forEach
159159

160160
val boxes = voxelShape.boundingBoxes.map { it.offset(hitPos) }
@@ -278,7 +278,7 @@ object BuildSimulator {
278278
}
279279

280280
val blockHit = checkedResult.blockResult ?: return@forEach
281-
val hitBlock = blockHit.blockPos.blockState(world).block
281+
val hitBlock = blockState(blockHit.blockPos).block
282282
val shouldSneak = hitBlock::class in BlockUtils.interactionClasses
283283

284284
val primeDirection =
@@ -290,7 +290,7 @@ object BuildSimulator {
290290
RotationRequest(lookAt(checkedHit.targetRotation, 0.001), rotation),
291291
eye.distanceTo(blockHit.pos),
292292
resultState,
293-
blockHit.blockPos.blockState(world),
293+
blockState(blockHit.blockPos),
294294
Hand.MAIN_HAND,
295295
context.blockPos,
296296
target,
@@ -326,7 +326,7 @@ object BuildSimulator {
326326
build: BuildConfig
327327
): Set<BuildResult> {
328328
val acc = mutableSetOf<BuildResult>()
329-
val state = pos.blockState(world)
329+
val state = blockState(pos)
330330

331331
/* is a block that will be destroyed by breaking adjacent blocks */
332332
if (build.breakWeakBlocks && state.block.hardness == 0f && !state.isAir) {
@@ -339,7 +339,7 @@ object BuildSimulator {
339339
val aabb = Box(pBox.minX, pBox.minY - 1.0E-6, pBox.minZ, pBox.maxX, pBox.minY, pBox.maxZ)
340340
world.findSupportingBlockPos(player, aabb).orElse(null)?.let { support ->
341341
if (support != pos) return@let
342-
val belowSupport = support.down().blockState(world)
342+
val belowSupport = blockState(support.down())
343343
if (belowSupport.isSolidSurface(world, support, player, Direction.UP)) return@let
344344
acc.add(BreakResult.PlayerOnTop(pos, state))
345345
return acc
@@ -354,14 +354,14 @@ object BuildSimulator {
354354
}
355355

356356
val adjacentLiquids = Direction.entries.filter {
357-
it != Direction.DOWN && !pos.offset(it).blockState(world).fluidState.isEmpty
357+
it != Direction.DOWN && !blockState(pos.offset(it)).fluidState.isEmpty
358358
}.map { pos.offset(it) }
359359

360360
/* block has liquids next to it that will leak when broken */
361361
if (adjacentLiquids.isNotEmpty()) {
362362
acc.add(BreakResult.BlockedByLiquid(pos, state))
363363
adjacentLiquids.forEach { liquidPos ->
364-
val submerge = if (liquidPos.blockState(world).isReplaceable) {
364+
val submerge = if (blockState(liquidPos).isReplaceable) {
365365
checkPlaceResults(liquidPos, TargetState.Solid, eye, interact, rotation, inventory)
366366
} else {
367367
checkBreakResults(liquidPos, eye, interact, rotation, inventory, build)

common/src/main/kotlin/com/lambda/interaction/construction/simulation/Simulation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ data class Simulation(
5858
runSafe {
5959
if (isOutOfBounds && isTooFar) return@getOrPut emptySet()
6060
val blockPos = pos.toBlockPos()
61-
val isWalkable = blockPos.down().blockState(world).isSideSolidFullSquare(world, blockPos, Direction.UP)
61+
val isWalkable = blockState(blockPos.down()).isSideSolidFullSquare(world, blockPos, Direction.UP)
6262
if (!isWalkable) return@getOrPut emptySet()
6363
if (!playerFitsIn(blockPos)) return@getOrPut emptySet()
6464
}

common/src/main/kotlin/com/lambda/interaction/construction/verify/TargetState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ sealed class TargetState(val type: Type) : StateMatcher {
6565
override fun toString() = "Support for ${direction.name}"
6666

6767
override fun matches(state: BlockState, pos: BlockPos, world: ClientWorld) =
68-
pos.offset(direction).blockState(world).isSolidBlock(world, pos.offset(direction))
68+
world.getBlockState(pos.offset(direction)).isSolidBlock(world, pos.offset(direction))
6969
|| state.isSolidBlock(world, pos)
7070

7171
override fun getStack(world: ClientWorld, pos: BlockPos) =

common/src/main/kotlin/com/lambda/interaction/material/container/ContainerManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ object ContainerManager : Loadable {
5757

5858
init {
5959
listen<PlayerEvent.Interact.Block> {
60-
lastInteractedBlockEntity = it.blockHitResult.blockPos.blockEntity(world)
60+
lastInteractedBlockEntity = blockEntity(it.blockHitResult.blockPos)
6161
}
6262

6363
listen<InventoryEvent.Close> { event ->

common/src/main/kotlin/com/lambda/interaction/request/rotation/visibilty/RequestedHit.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ abstract class RequestedHit {
104104
override val reach: Double
105105
) : RequestedHit() {
106106
override fun getBoundingBoxes(): List<Box> = runSafe {
107-
val state = blockPos.blockState(world)
107+
val state = blockState(blockPos)
108108
val voxelShape = state.getOutlineShape(world, blockPos)
109109
voxelShape.boundingBoxes.map { it.offset(blockPos) }
110110
} ?: listOf(Box(blockPos))

0 commit comments

Comments
 (0)