feat: lost items
This commit is contained in:
parent
b1f44ff2db
commit
88dcf52a57
@ -0,0 +1,27 @@
|
||||
package quaedam.projection.swarm.ai
|
||||
|
||||
import net.minecraft.world.entity.LivingEntity
|
||||
import net.minecraft.world.entity.ai.behavior.OneShot
|
||||
import net.minecraft.world.entity.ai.behavior.declarative.BehaviorBuilder
|
||||
import net.minecraft.world.entity.ai.behavior.declarative.Trigger
|
||||
import net.minecraft.world.entity.npc.InventoryCarrier
|
||||
import net.minecraft.world.entity.schedule.Activity
|
||||
import net.minecraft.world.level.block.Block
|
||||
|
||||
@Suppress("FunctionName")
|
||||
fun <E> LostItem(chance: Int): OneShot<E>
|
||||
where E : LivingEntity, E : InventoryCarrier = BehaviorBuilder.create { instance ->
|
||||
instance.point(Trigger { level, entity: E, l: Long ->
|
||||
if (entity.brain.isActive(Activity.REST)) return@Trigger false
|
||||
if (level.random.nextInt(chance) != 0) return@Trigger false
|
||||
val inventory = entity.inventory
|
||||
val item = inventory.getItem(level.random.nextInt(inventory.containerSize))
|
||||
if (!item.isEmpty) {
|
||||
val count = level.random.nextInt(item.count)
|
||||
item.shrink(count)
|
||||
inventory.setChanged()
|
||||
Block.popResource(level, entity.blockPosition(), item.copyWithCount(count))
|
||||
}
|
||||
return@Trigger true
|
||||
})
|
||||
}
|
@ -101,6 +101,7 @@ object ProjectedPersonAI {
|
||||
3 weight LookAtTargetSink(40, 70),
|
||||
3 weight MoveToTargetSink(),
|
||||
3 weight InteractWithDoor.create(),
|
||||
3 weight LostItem(400),
|
||||
10 weight GoToWantedItem.create(1.2f, false, 7),
|
||||
)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user