Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: laser angle offsets #95

Open
wants to merge 4 commits into
base: 1.20.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/io/sc3/plethora/api/method/ArgumentExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ object ArgumentExt {

fun IArguments.optHand(index: Int): Hand {
return when (val hand = optString(index, "main")!!.lowercase()) {
"main", "mainhand", "right" -> Hand.MAIN_HAND
"off", "offhand", "left" -> Hand.OFF_HAND
"main", "mainhand" -> Hand.MAIN_HAND
"off", "offhand" -> Hand.OFF_HAND
else -> throw LuaException("Unknown hand '$hand', expected 'main' or 'off'")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import io.sc3.plethora.util.Helpers
import io.sc3.plethora.util.PlayerHelpers
import net.minecraft.block.entity.BlockEntity
import net.minecraft.entity.Entity
import net.minecraft.util.math.MathHelper
import net.minecraft.util.math.Vec3d
import java.lang.Math.PI
import java.util.concurrent.Callable
Expand Down Expand Up @@ -55,24 +56,12 @@ object LaserMethods {
laser.setShooter(entity, profile)

if (ctx.hasContext(BlockEntity::class.java) || ctx.hasContext(ITurtleAccess::class.java)) {
val vOff = 0.3 // The laser is 0.25 high, so we add a little more.

// Offset positions to be around the edge of the manipulator. Avoids breaking the manipulator and the
// block below/above in most cases.
// Also offset to be just above/below the manipulator, depending on the pitch.

val offset = if (pitch < -60) {
Vec3d(0.0, 0.5 + vOff, 0.0)
} else if (pitch > 60) {
Vec3d(0.0, -0.5 - vOff, 0.0)
} else {
// The laser is 0.25 wide, the offset from the centre is 0.5.
val hOff = 0.9
val length = sqrt(motionX * motionX + motionZ * motionZ)
Vec3d(motionX / length * hOff, 0.0, motionZ / length * hOff)
}

laser.setPosition(pos.add(offset))
laser.setPosition(pos.add(Vec3d(0.5, 0.5, 0.5)))
laser.setPosition(pos.add(Vec3d(
MathHelper.clamp(motionX * 1.25, -0.75, 0.75),
MathHelper.clamp(motionY * 1.25, -0.75, 0.75),
MathHelper.clamp(motionZ * 1.25, -0.75, 0.75)
)))
} else if (ctx.hasContext(Entity::class.java)) {
val entity = ctx.getContext(Entity::class.java)
val vector = entity.pos
Expand Down