Skip to content

Commit 4698998

Browse files
committed
Mob spleefing
1 parent 15f2b97 commit 4698998

File tree

5 files changed

+57
-6
lines changed

5 files changed

+57
-6
lines changed

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
value("Expected State", expectedState)
9696
value("Sneak", sneak)
9797
value("Inside Block", insideBlock)
98-
value("Current Dir Is Invalid", currentDirIsValid)
98+
value("Current Dir Is Valid", currentDirIsValid)
9999
}
100100
}
101101
}

src/main/kotlin/com/lambda/interaction/construction/result/PlaceResult.kt

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ import baritone.api.pathing.goals.GoalInverted
2222
import com.lambda.context.Automated
2323
import com.lambda.graphics.renderer.esp.ShapeBuilder
2424
import com.lambda.interaction.construction.context.PlaceContext
25+
import com.lambda.interaction.construction.verify.TargetState
26+
import com.lambda.task.Task
2527
import com.lambda.task.tasks.BuildTask.Companion.breakBlock
28+
import com.lambda.task.tasks.BuildTask.Companion.build
2629
import net.minecraft.block.BlockState
30+
import net.minecraft.entity.Entity
2731
import net.minecraft.item.ItemPlacementContext
2832
import net.minecraft.item.ItemStack
2933
import net.minecraft.util.math.BlockPos
@@ -83,18 +87,38 @@ sealed class PlaceResult : BuildResult() {
8387
}
8488
}
8589

90+
/**
91+
* Represents a scenario where block placement is obstructed by the player itself.
92+
*
93+
* @property blockPos The position of the block that was attempted to be placed.
94+
*/
95+
data class BlockedBySelf(
96+
override val blockPos: BlockPos
97+
) : Drawable, Navigable, PlaceResult() {
98+
override val rank = Rank.PLACE_BLOCKED_BY_PLAYER
99+
private val color = Color(252, 3, 3, 100)
100+
override val goal = GoalInverted(GoalBlock(blockPos))
101+
102+
override fun ShapeBuilder.buildRenderer() {
103+
box(blockPos, color, color)
104+
}
105+
}
106+
86107
/**
87108
* Represents a scenario where block placement is obstructed by an entity.
88109
*
89110
* @property blockPos The position of the block that was attempted to be placed.
90111
*/
91112
data class BlockedByEntity(
92113
override val blockPos: BlockPos,
93-
) : Navigable, PlaceResult() {
94-
override val rank = Rank.PLACE_BLOCKED_BY_PLAYER
114+
val entities: List<Entity>
115+
) : Drawable, PlaceResult() {
116+
override val rank = Rank.PLACE_BLOCKED_BY_ENTITY
117+
private val color = Color(252, 3, 3, 100)
95118

96-
// ToDo: check what type of entity. player -> leave box, other entity -> kill?
97-
override val goal = GoalInverted(GoalBlock(blockPos))
119+
override fun ShapeBuilder.buildRenderer() {
120+
entities.forEach { box(it, color) }
121+
}
98122
}
99123

100124
/**

src/main/kotlin/com/lambda/interaction/construction/result/Rank.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ enum class Rank {
2727
PLACE_BLOCKED_BY_PLAYER,
2828
NOT_VISIBLE,
2929
OUT_OF_REACH,
30+
PLACE_BLOCKED_BY_ENTITY,
3031
BREAK_NOT_EXPOSED,
3132
CHUNK_NOT_LOADED,
3233
PLACE_CANT_REPLACE,

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import com.lambda.util.BlockUtils.calcItemBlockBreakingDelta
5252
import com.lambda.util.BlockUtils.hasFluid
5353
import com.lambda.util.BlockUtils.instantBreakable
5454
import com.lambda.util.BlockUtils.isNotEmpty
55+
import com.lambda.util.Communication.info
5556
import com.lambda.util.Communication.warn
5657
import com.lambda.util.math.distSq
5758
import com.lambda.util.math.vec3d
@@ -67,11 +68,13 @@ import kotlinx.coroutines.runBlocking
6768
import net.minecraft.block.BlockState
6869
import net.minecraft.block.FallingBlock
6970
import net.minecraft.block.OperatorBlock
71+
import net.minecraft.block.ShapeContext
7072
import net.minecraft.block.SlabBlock
7173
import net.minecraft.block.Waterloggable
7274
import net.minecraft.block.enums.SlabType
7375
import net.minecraft.block.pattern.CachedBlockPosition
7476
import net.minecraft.enchantment.Enchantments
77+
import net.minecraft.entity.Entity
7578
import net.minecraft.fluid.FlowableFluid
7679
import net.minecraft.fluid.LavaFluid
7780
import net.minecraft.fluid.WaterFluid
@@ -80,6 +83,7 @@ import net.minecraft.item.Item
8083
import net.minecraft.item.ItemPlacementContext
8184
import net.minecraft.item.ItemStack
8285
import net.minecraft.item.ItemUsageContext
86+
import net.minecraft.predicate.entity.EntityPredicates
8387
import net.minecraft.registry.tag.ItemTags.DIAMOND_TOOL_MATERIALS
8488
import net.minecraft.registry.tag.ItemTags.GOLD_TOOL_MATERIALS
8589
import net.minecraft.registry.tag.ItemTags.IRON_TOOL_MATERIALS
@@ -90,6 +94,7 @@ import net.minecraft.state.property.Properties
9094
import net.minecraft.util.Hand
9195
import net.minecraft.util.hit.BlockHitResult
9296
import net.minecraft.util.math.BlockPos
97+
import net.minecraft.util.math.Box
9398
import net.minecraft.util.math.Direction
9499
import net.minecraft.util.math.Vec3d
95100
import net.minecraft.util.shape.VoxelShapes
@@ -510,7 +515,26 @@ object BuildSimulator {
510515

511516
val simulatePlaceState = placeState@{
512517
resultState = blockItem.getPlacementState(context)
513-
?: return@placeState PlaceResult.BlockedByEntity(pos)
518+
?: run {
519+
val theoreticalState = blockItem.block.getPlacementState(context)
520+
?: return@placeState PlaceResult.BlockedBySelf(pos)
521+
val shapeContext = ShapeContext.ofPlacement(player)
522+
val collisionShape = theoreticalState.getCollisionShape(world, context.blockPos, shapeContext)
523+
.offset(context.blockPos)
524+
val collidingEntities = collisionShape.boundingBoxes.flatMap { box ->
525+
world.entities.filter { it.boundingBox.intersects(box) }
526+
}
527+
if (collidingEntities.isNotEmpty()) {
528+
collidingEntities
529+
.mapNotNull { it.supportingBlockPos.orElse(null) }
530+
.forEach { support ->
531+
acc.addAll(checkBreakResults(support, eye, preProcessing))
532+
}
533+
return@placeState PlaceResult.BlockedByEntity(pos, collidingEntities)
534+
} else {
535+
return@placeState PlaceResult.BlockedBySelf(pos)
536+
}
537+
}
514538

515539
return@placeState if (!nextTargetState.matches(resultState, pos, world, preProcessing.ignore))
516540
PlaceResult.NoIntegrity(

src/main/kotlin/com/lambda/task/tasks/BuildTask.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import com.lambda.interaction.request.placing.PlaceRequest
5050
import com.lambda.task.Task
5151
import com.lambda.task.tasks.EatTask.Companion.eat
5252
import com.lambda.threading.runSafeAutomated
53+
import com.lambda.util.Communication.info
5354
import com.lambda.util.Formatting.string
5455
import com.lambda.util.extension.Structure
5556
import com.lambda.util.extension.inventorySlots
@@ -118,6 +119,7 @@ class BuildTask private constructor(
118119
val bestResult = resultsNotBlocked.firstOrNull() ?: return@listen
119120
if (bestResult !is BuildResult.Contextual && pendingInteractions.isNotEmpty())
120121
return@listen
122+
info("Best result: $bestResult")
121123
when (bestResult) {
122124
is BuildResult.Done,
123125
is BuildResult.Ignored,

0 commit comments

Comments
 (0)