Plasma projectiles tests and fixes

This commit is contained in:
DBotThePony 2022-05-10 19:32:41 +07:00
parent 426b0085d4
commit 40f56e110b
Signed by: DBot
GPG Key ID: DCC23B5715498507
5 changed files with 123 additions and 18 deletions

View File

@ -28,8 +28,10 @@ class PlasmaProjectileRenderer(context: EntityRendererProvider.Context) : Entity
) {
super.render(entity, p_114486_, p_114487_, pose, buffer, p_114490_)
pose.scale(0.1f, 0.1f, 0.1f)
pose.rotateAroundPoint(pose.translation(), Angle(roll = entity.xRot.toDouble(), yaw = entity.yRot.toDouble(), pitch = PI))
pose.pushPose()
pose.scale(0.03f, 0.03f, 0.03f)
pose.rotateAroundPoint(pose.translation(), Angle.deg(roll = entity.xRot.toDouble(), yaw = entity.yRot.toDouble(), pitch = 180.0))
font.drawAligned(pose, "PLASMA", TextAlign.CENTER_CENTER, 0f, 0f, 0xFFFFFF)
pose.popPose()
}
}

View File

@ -240,7 +240,7 @@ data class Angle(override val pitch: Double = 0.0, override val yaw: Double = 0.
const val PI_HALF = Math.PI / 2.0
fun deg(pitch: Double, yaw: Double, roll: Double): Angle {
return Angle(Math.toDegrees(pitch), Math.toDegrees(yaw), Math.toDegrees(roll))
return Angle(Math.toRadians(pitch), Math.toRadians(yaw), Math.toRadians(roll))
}
@JvmField val ZERO = Angle()
@ -256,7 +256,7 @@ data class Angle(override val pitch: Double = 0.0, override val yaw: Double = 0.
data class MutableAngle(override var pitch: Double = 0.0, override var yaw: Double = 0.0, override var roll: Double = 0.0) : IAngle {
companion object {
fun deg(pitch: Double, yaw: Double, roll: Double): MutableAngle {
return MutableAngle(Math.toDegrees(pitch), Math.toDegrees(yaw), Math.toDegrees(roll))
return MutableAngle(Math.toRadians(pitch), Math.toRadians(yaw), Math.toRadians(roll))
}
}
}

View File

@ -21,10 +21,6 @@ class PlasmaProjectile(level: Level) : Projectile(MEntityTypes.PLASMA as EntityT
var damage = 6.0f
var ttl = 200
init {
deltaMovement = Vector(1.0, 0.0, 0.0)
}
override fun defineSynchedData() {
}

View File

@ -1,13 +1,125 @@
package ru.dbotthepony.mc.otm.item.weapon
import net.minecraft.util.Mth
import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.player.Player
import net.minecraft.world.entity.projectile.Arrow
import net.minecraft.world.item.ItemStack
import net.minecraft.world.phys.Vec3
import ru.dbotthepony.kvector.vector.Angle3f
import ru.dbotthepony.kvector.vector.ndouble.Vector3d
import ru.dbotthepony.mc.otm.core.ImpreciseFraction
import ru.dbotthepony.mc.otm.core.plus
import ru.dbotthepony.mc.otm.core.times
import ru.dbotthepony.mc.otm.entity.PlasmaProjectile
import ru.dbotthepony.mc.otm.position
import java.util.*
import kotlin.math.PI
import kotlin.math.cos
import kotlin.math.sin
private val random = Random()
private const val DEGS = PI / 180.0
class VelocityCalculation(
xRot: Double,
yRot: Double,
zRot: Double = 0.0,
force: Double,
deviation: Double = 0.0,
owner: Entity? = null,
) {
constructor(
xRot: Float,
yRot: Float,
zRot: Float = 0f,
force: Double,
deviation: Double = 0.0,
owner: Entity? = null,
) : this(xRot.toDouble(), yRot.toDouble(), zRot.toDouble(), force, deviation, owner)
constructor(
xRot: Float,
yRot: Float,
zRot: Float = 0f,
force: Float,
deviation: Double = 0.0,
owner: Entity? = null,
) : this(xRot.toDouble(), yRot.toDouble(), zRot.toDouble(), force.toDouble(), deviation, owner)
constructor(
xRot: Float,
yRot: Float,
zRot: Float = 0f,
force: Float,
deviation: Float,
owner: Entity? = null,
) : this(xRot.toDouble(), yRot.toDouble(), zRot.toDouble(), force.toDouble(), deviation.toDouble(), owner)
constructor(
owner: Entity,
force: Float,
deviation: Float,
) : this(owner.xRot.toDouble() - 4.5 * (1 / force), owner.yRot.toDouble(), 0.0, force.toDouble(), deviation.toDouble(), owner)
constructor(
owner: Entity,
force: Double,
deviation: Float,
) : this(owner.xRot.toDouble() - 4.5 * (1 / force), owner.yRot.toDouble(), 0.0, force, deviation.toDouble(), owner)
constructor(
owner: Entity,
force: Double,
deviation: Double,
) : this(owner.xRot.toDouble() - 4.5 * (1 / force), owner.yRot.toDouble(), 0.0, force, deviation, owner)
val xVelocity = -sin(yRot * DEGS) * cos(xRot * (PI / 180.0))
val yVelocity = -sin((xRot + zRot) * DEGS)
val zVelocity = cos(yRot * DEGS) * cos(xRot * DEGS)
val velocity: Vec3
init {
var velocity = Vec3(
xVelocity,
yVelocity,
zVelocity
).normalize()
velocity += Vec3(
random.nextGaussian() * 0.0075 * deviation,
random.nextGaussian() * 0.0075 * deviation,
random.nextGaussian() * 0.0075 * deviation,
)
velocity *= force
if (owner != null) {
val ownerVel = owner.deltaMovement
if (owner.isOnGround) {
velocity += ownerVel
} else {
velocity += Vec3(ownerVel.x, 0.0, ownerVel.z)
}
}
this.velocity = velocity
}
val yRotation = Mth.atan2(velocity.x, velocity.z).toFloat() * (180f / Math.PI.toFloat())
val xRotation = Mth.atan2(velocity.y, velocity.horizontalDistance()).toFloat() * (180f / Math.PI.toFloat())
fun load(onto: Entity, withRotation: Boolean = true) {
if (withRotation) {
onto.xRot = xRotation
onto.yRot = yRotation
}
onto.deltaMovement = velocity
}
}
class PlasmaRifleItem : PlasmaWeaponItem<WeaponDataTable>(WeaponDataTable::class, ImpreciseFraction(200_000)) {
override val roundsPerMinute: Int = 400
@ -22,18 +134,13 @@ class PlasmaRifleItem : PlasmaWeaponItem<WeaponDataTable>(WeaponDataTable::class
get() = Angle3f(-0.02f,0f,0f)
override fun primaryFire(itemStack: ItemStack, player: Player, dt: WeaponDataTable): Boolean {
println("FIER! ${Thread.currentThread()}")
if (!player.level.isClientSide) {
//val arrow = Arrow(player.level, player)
//arrow.shootFromRotation(player, player.xRot, player.yRot, 0f, 2f, 0f)
//player.level.addFreshEntity(arrow)
val arrow = PlasmaProjectile(player.level)
arrow.position = player.eyePosition
arrow.xRot = player.xRot
arrow.yRot = player.yRot
//arrow.deltaMovement = arrow.rotationVector
val calc = VelocityCalculation(player, force = 4.0, deviation = 0.3)
calc.load(arrow)
player.level.addFreshEntity(arrow)
}

View File

@ -17,7 +17,7 @@ object MEntityTypes {
private val registry: DeferredRegister<EntityType<*>> = DeferredRegister.create(ForgeRegistries.ENTITIES, OverdriveThatMatters.MOD_ID)
val PLASMA: EntityType<*> by registry.register(MNames.PLASMA) {
EntityType.Builder.of<PlasmaProjectile>({ _, level -> PlasmaProjectile(level) }, MobCategory.MISC).build(MNames.PLASMA)
EntityType.Builder.of<PlasmaProjectile>({ _, level -> PlasmaProjectile(level) }, MobCategory.MISC).sized(0.4f, 0.4f).build(MNames.PLASMA)
}
internal fun register() {