42 lines
No EOL
1.3 KiB
Kotlin
42 lines
No EOL
1.3 KiB
Kotlin
package moe.lava.cartloader.impl
|
|
|
|
import moe.lava.cartloader.accessor.AccessorAbstractMinecartEntity
|
|
import net.minecraft.entity.Entity
|
|
import net.minecraft.entity.ItemEntity
|
|
import net.minecraft.entity.player.PlayerEntity
|
|
import net.minecraft.entity.vehicle.AbstractMinecartEntity
|
|
import net.minecraft.item.Items
|
|
import net.minecraft.util.ActionResult
|
|
import net.minecraft.util.Hand
|
|
|
|
class MixinPlayerEntityImpl {
|
|
private var linking: AbstractMinecartEntity? = null
|
|
fun interact(minecart: Entity, player: PlayerEntity, hand: Hand): ActionResult? {
|
|
if (minecart !is AbstractMinecartEntity)
|
|
return null
|
|
|
|
if (minecart !is AccessorAbstractMinecartEntity)
|
|
return null;
|
|
|
|
if (!player.getStackInHand(hand).isOf(Items.CHAIN))
|
|
return null
|
|
|
|
val target = linking
|
|
if (target == null) {
|
|
linking = minecart
|
|
return ActionResult.SUCCESS
|
|
}
|
|
if (target !is AccessorAbstractMinecartEntity)
|
|
return null
|
|
|
|
linking = null
|
|
if (!target.isAlive)
|
|
return ActionResult.FAIL
|
|
|
|
if (!minecart.boundingBox.expand(0.1).intersects(target.boundingBox))
|
|
return ActionResult.FAIL
|
|
|
|
target.`cartloader$getImpl`().linkTo(minecart)
|
|
return ActionResult.SUCCESS
|
|
}
|
|
} |