rename raycastHit to target

This commit is contained in:
Bixilon 2021-12-24 15:09:54 +01:00
parent 7393705984
commit 02a87b9680
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 27 additions and 27 deletions

View File

@ -123,9 +123,9 @@ class TargetHandler(
} }
if (entities) { if (entities) {
val entityRaycastHit = raycastEntity(origin, direction) ?: return target val entityTarget = raycastEntity(origin, direction) ?: return target
target ?: return null target ?: return null
return (entityRaycastHit.distance < target.distance).decide(entityRaycastHit, target) return (entityTarget.distance < target.distance).decide(entityTarget, target)
} }
return target return target

View File

@ -98,20 +98,20 @@ class BreakInteractionHandler(
cancelDigging() cancelDigging()
return false return false
} }
val raycastHit = renderWindow.camera.targetHandler.target val target = renderWindow.camera.targetHandler.target
if (raycastHit !is BlockTarget) { if (target !is BlockTarget) {
cancelDigging() cancelDigging()
return false return false
} }
if (raycastHit.distance >= connection.player.reachDistance) { if (target.distance >= connection.player.reachDistance) {
cancelDigging() cancelDigging()
return false return false
} }
// check if we look at another block or our inventory changed // check if we look at another block or our inventory changed
if (breakPosition != raycastHit.blockPosition || breakBlockState != raycastHit.blockState || breakSelectedSlot != connection.player.selectedHotbarSlot) { if (breakPosition != target.blockPosition || breakBlockState != target.blockState || breakSelectedSlot != connection.player.selectedHotbarSlot) {
cancelDigging() cancelDigging()
} }
@ -120,22 +120,22 @@ class BreakInteractionHandler(
if (breakPosition != null) { if (breakPosition != null) {
return return
} }
connection.sendPacket(PlayerActionC2SP(PlayerActionC2SP.Actions.START_DIGGING, raycastHit.blockPosition, raycastHit.direction)) connection.sendPacket(PlayerActionC2SP(PlayerActionC2SP.Actions.START_DIGGING, target.blockPosition, target.direction))
breakPosition = raycastHit.blockPosition breakPosition = target.blockPosition
breakBlockState = raycastHit.blockState breakBlockState = target.blockState
breakProgress = 0.0 breakProgress = 0.0
breakSelectedSlot = connection.player.selectedHotbarSlot breakSelectedSlot = connection.player.selectedHotbarSlot
} }
fun finishDigging() { fun finishDigging() {
connection.sendPacket(PlayerActionC2SP(PlayerActionC2SP.Actions.FINISHED_DIGGING, raycastHit.blockPosition, raycastHit.direction)) connection.sendPacket(PlayerActionC2SP(PlayerActionC2SP.Actions.FINISHED_DIGGING, target.blockPosition, target.direction))
clearDigging() clearDigging()
connection.world.setBlockState(raycastHit.blockPosition, null) connection.world.setBlockState(target.blockPosition, null)
raycastHit.blockState.breakSoundEvent?.let { target.blockState.breakSoundEvent?.let {
connection.world.playSoundEvent(it, raycastHit.blockPosition, volume = raycastHit.blockState.soundEventVolume, pitch = raycastHit.blockState.soundEventPitch) connection.world.playSoundEvent(it, target.blockPosition, volume = target.blockState.soundEventVolume, pitch = target.blockState.soundEventPitch)
} }
} }
@ -176,14 +176,14 @@ class BreakInteractionHandler(
val isToolEffective = breakItemInHand?.item?.let { val isToolEffective = breakItemInHand?.item?.let {
return@let if (it is MiningToolItem) { return@let if (it is MiningToolItem) {
it.isEffectiveOn(connection, raycastHit.blockState) it.isEffectiveOn(connection, target.blockState)
} else { } else {
false false
} }
} ?: false } ?: false
val isBestTool = !raycastHit.blockState.requiresTool || isToolEffective val isBestTool = !target.blockState.requiresTool || isToolEffective
var speedMultiplier = breakItemInHand?.let { it.item.getMiningSpeedMultiplier(connection, raycastHit.blockState, it) } ?: 1.0f var speedMultiplier = breakItemInHand?.let { it.item.getMiningSpeedMultiplier(connection, target.blockState, it) } ?: 1.0f
if (isToolEffective) { if (isToolEffective) {
breakItemInHand?.enchantments?.get(efficiencyEnchantment)?.let { breakItemInHand?.enchantments?.get(efficiencyEnchantment)?.let {
@ -212,7 +212,7 @@ class BreakInteractionHandler(
speedMultiplier /= 5.0f speedMultiplier /= 5.0f
} }
var damage = speedMultiplier / raycastHit.blockState.hardness var damage = speedMultiplier / target.blockState.hardness
damage /= if (isBestTool) { damage /= if (isBestTool) {
30 30

View File

@ -82,28 +82,28 @@ class BlockOutlineRenderer(
} }
override fun prepareDraw() { override fun prepareDraw() {
val raycastHit = renderWindow.camera.targetHandler.target.nullCast<BlockTarget>() val target = renderWindow.camera.targetHandler.target.nullCast<BlockTarget>()
var currentMesh = currentMesh var currentMesh = currentMesh
if (raycastHit == null) { if (target == null) {
unload() unload()
return return
} }
if (raycastHit.distance >= connection.player.reachDistance) { if (target.distance >= connection.player.reachDistance) {
unload() unload()
return return
} }
if (connection.player.gamemode == Gamemodes.ADVENTURE || connection.player.gamemode == Gamemodes.SPECTATOR) { if (connection.player.gamemode == Gamemodes.ADVENTURE || connection.player.gamemode == Gamemodes.SPECTATOR) {
if (raycastHit.blockState.block.blockEntityType == null) { if (target.blockState.block.blockEntityType == null) {
unload() unload()
return return
} }
} }
if (raycastHit.blockPosition == currentOutlinePosition && raycastHit.blockState == currentOutlineBlockState && !reload) { if (target.blockPosition == currentOutlinePosition && target.blockState == currentOutlineBlockState && !reload) {
return return
} }
@ -114,20 +114,20 @@ class BlockOutlineRenderer(
currentMesh?.unload() currentMesh?.unload()
currentMesh = LineMesh(renderWindow) currentMesh = LineMesh(renderWindow)
val blockOffset = raycastHit.blockPosition.toVec3d + raycastHit.blockPosition.getWorldOffset(raycastHit.blockState.block) val blockOffset = target.blockPosition.toVec3d + target.blockPosition.getWorldOffset(target.blockState.block)
currentMesh.drawVoxelShape(raycastHit.blockState.outlineShape, blockOffset, RenderConstants.DEFAULT_LINE_WIDTH, profile.outlineColor) currentMesh.drawVoxelShape(target.blockState.outlineShape, blockOffset, RenderConstants.DEFAULT_LINE_WIDTH, profile.outlineColor)
if (profile.showCollisionBoxes) { if (profile.showCollisionBoxes) {
currentMesh.drawVoxelShape(raycastHit.blockState.collisionShape, blockOffset, RenderConstants.DEFAULT_LINE_WIDTH, profile.collisionColor, 0.005f) currentMesh.drawVoxelShape(target.blockState.collisionShape, blockOffset, RenderConstants.DEFAULT_LINE_WIDTH, profile.collisionColor, 0.005f)
} }
currentMesh.load() currentMesh.load()
this.currentOutlinePosition = raycastHit.blockPosition this.currentOutlinePosition = target.blockPosition
this.currentOutlineBlockState = raycastHit.blockState this.currentOutlineBlockState = target.blockState
this.currentMesh = currentMesh this.currentMesh = currentMesh
this.reload = false this.reload = false
} }