Skip to content

Commit

Permalink
#28, #27 Added support for minecraft 1.20.6.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shynixn committed May 17, 2024
1 parent 38b3b37 commit cb9e7bb
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import com.github.shynixn.mcutils.common.chat.ChatMessageService
import com.github.shynixn.mcutils.common.command.CommandService
import com.github.shynixn.mcutils.common.command.CommandServiceImpl
import com.github.shynixn.mcutils.common.item.ItemService
import com.github.shynixn.mcutils.common.item.ItemServiceImpl
import com.github.shynixn.mcutils.common.physic.PhysicObjectDispatcher
import com.github.shynixn.mcutils.common.physic.PhysicObjectDispatcherImpl
import com.github.shynixn.mcutils.common.physic.PhysicObjectService
Expand All @@ -29,14 +28,12 @@ import com.github.shynixn.mcutils.guice.DependencyInjectionModule
import com.github.shynixn.mcutils.packet.api.EntityService
import com.github.shynixn.mcutils.packet.api.PacketService
import com.github.shynixn.mcutils.packet.api.RayTracingService
import com.github.shynixn.mcutils.packet.impl.service.ChatMessageServiceImpl
import com.github.shynixn.mcutils.packet.impl.service.EntityServiceImpl
import com.github.shynixn.mcutils.packet.impl.service.PacketServiceImpl
import com.github.shynixn.mcutils.packet.impl.service.RayTracingServiceImpl
import com.github.shynixn.mcutils.packet.impl.service.*
import com.github.shynixn.mcutils.sign.SignService
import com.github.shynixn.mcutils.sign.SignServiceImpl
import org.bukkit.Bukkit
import org.bukkit.plugin.Plugin
import java.util.concurrent.Executor
import java.util.logging.Level

class MCTennisDependencyInjectionModule(private val plugin: Plugin) : DependencyInjectionModule() {
Expand Down Expand Up @@ -79,7 +76,8 @@ class MCTennisDependencyInjectionModule(private val plugin: Plugin) : Dependency
addService<PhysicObjectDispatcher>(PhysicObjectDispatcherImpl(plugin))
addService<ConfigurationService>(ConfigurationServiceImpl(plugin))
addService<SoundService>(SoundServiceImpl(plugin))
addService<PacketService>(PacketServiceImpl(plugin))
addService<PacketService>(PacketServiceImpl(plugin
) { command -> plugin.server.scheduler.runTask(plugin, command) })
addService<ItemService>(ItemServiceImpl())
addService<EntityService, EntityServiceImpl>()
addService<ChatMessageService, ChatMessageServiceImpl>()
Expand Down
9 changes: 5 additions & 4 deletions src/main/kotlin/com/github/shynixn/mctennis/MCTennisPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,25 @@ class MCTennisPlugin : JavaPlugin() {
Version.VERSION_1_19_R3,
Version.VERSION_1_20_R1,
Version.VERSION_1_20_R2,
Version.VERSION_1_20_R3
Version.VERSION_1_20_R3,
Version.VERSION_1_20_R4
)
} else {
listOf(Version.VERSION_1_20_R3)
listOf(Version.VERSION_1_20_R4)
}

if (!Version.serverVersion.isCompatible(*versions.toTypedArray())) {
logger.log(Level.SEVERE, "================================================")
logger.log(Level.SEVERE, "MCTennis does not support your server version")
logger.log(Level.SEVERE, "Install v" + versions[0].id + " - v" + versions[versions.size - 1].id)
logger.log(Level.SEVERE, "Install v" + versions[0].from + " - v" + versions[versions.size - 1].to)
logger.log(Level.SEVERE, "Need support for a particular version? Go to https://www.patreon.com/Shynixn")
logger.log(Level.SEVERE, "Plugin gets now disabled!")
logger.log(Level.SEVERE, "================================================")
Bukkit.getPluginManager().disablePlugin(this)
return
}

logger.log(Level.INFO, "Loaded NMS version ${Version.serverVersion.bukkitId}.")
logger.log(Level.INFO, "Loaded NMS version ${Version.serverVersion}.")

// Guice
this.module = MCTennisDependencyInjectionModule(this).build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@ package com.github.shynixn.mctennis.entity
import com.github.shynixn.mctennis.enumeration.VisibilityType
import com.github.shynixn.mcutils.common.EffectTargetType
import com.github.shynixn.mcutils.common.command.CommandMeta
import com.github.shynixn.mcutils.common.item.Item
import com.github.shynixn.mcutils.common.sound.SoundMeta

class TennisBallSettings {
/**
* Item.
*/
var item: Item = Item().also {
it.typeName = "PLAYER_HEAD,397"
it.durability = 3
it.skinBase64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjZkYThhNzk3N2VjOTIxNGM1YjcwMWY5YWU3ZTE1NWI4ZWIyMWQxZDM3MTU5OGUxYjk4NzVjNGM4NWM2NWFlNiJ9fX0="
}

// Ground
var horizontalBaseMultiplier: Double = 0.4

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class TennisGameImpl(
val teamMetaData = getTeamMetaFromTeam(team)
// Spawnpoint 0 is always serving.
val spawnpoint = teamMetaData.spawnpoints[0]
val ballspawnpoint = spawnpoint.clone().addRelativeFront(2.0).addRelativeUp(0.5)
val ballspawnpoint = spawnpoint.copy().addRelativeFront(2.0).addRelativeUp(0.5)

ball = tennisBallFactory.createTennisBall(ballspawnpoint.toLocation(), arena.ballSettings, this)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.shynixn.mctennis.impl.physic

import com.github.shynixn.mctennis.entity.TennisBallSettings
import com.github.shynixn.mcutils.common.*
import com.github.shynixn.mcutils.common.item.ItemService
import com.github.shynixn.mcutils.common.physic.PhysicComponent
import com.github.shynixn.mcutils.packet.api.*
import com.github.shynixn.mcutils.packet.api.meta.enumeration.ArmorSlotType
Expand All @@ -14,6 +16,8 @@ class ArmorstandEntityComponent(
physicsComponent: MathComponent,
private val packetService: PacketService,
private val playerComponent: PlayerComponent,
private val itemService: ItemService,
private val ballSettings: TennisBallSettings,
val entityId: Int,
private var filteredPlayers: HashSet<Player>,
private val renderOffsetY : Double
Expand All @@ -37,12 +41,7 @@ class ArmorstandEntityComponent(
it.target = location.toVector3d().addRelativeUp(renderOffsetY).toLocation()
})

val itemStack = item {
this.typeName = "PLAYER_HEAD,397"
this.durability = 3
this.nbt =
"{SkullOwner:{Name:\"MCTennis\",Properties:{textures:[{Value:\"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjZkYThhNzk3N2VjOTIxNGM1YjcwMWY5YWU3ZTE1NWI4ZWIyMWQxZDM3MTU5OGUxYjk4NzVjNGM4NWM2NWFlNiJ9fX0=\"}]}}}"
}.toItemStack()
val itemStack = itemService.toItemStack(ballSettings.item)

packetService.sendPacketOutEntityEquipment(player, PacketOutEntityEquipment().also {
it.entityId = this.entityId
Expand Down Expand Up @@ -82,7 +81,7 @@ class ArmorstandEntityComponent(

packetService.sendPacketOutEntityTeleport(player, PacketOutEntityTeleport().also {
it.entityId = this.entityId
it.target = position.clone().addRelativeUp(renderOffsetY).toLocation()
it.target = position.copy().addRelativeUp(renderOffsetY).toLocation()
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.github.shynixn.mctennis.impl.physic

import com.github.shynixn.mcutils.common.Vector3d
import com.github.shynixn.mcutils.common.physic.PhysicComponent
import com.github.shynixn.mcutils.common.vector
import com.github.shynixn.mcutils.packet.api.meta.enumeration.BlockDirection

class BounceComponent(
Expand Down Expand Up @@ -78,38 +77,38 @@ class BounceComponent(
): Vector3d {
val normalVector = when (blockDirection) {
BlockDirection.WEST -> {
vector {
x = -1.0
Vector3d().also {
it.x = -1.0
}
}
BlockDirection.EAST -> {
vector {
x = 1.0
Vector3d().also {
it.x = 1.0
}
}
BlockDirection.NORTH -> {
vector {
z = -1.0
Vector3d().also{
it.z = -1.0
}
}
BlockDirection.SOUTH -> {
vector {
z = 1.0
Vector3d().also {
it.z = 1.0
}
}
else -> if (blockDirection == BlockDirection.DOWN) {
vector {
y = -1.0
Vector3d().also{
it.y = -1.0
}
} else {
vector {
y = 1.0
Vector3d().also {
it.y = 1.0
}
}.normalize()
}

val radianAngle = 2 * incomingVector.dot(normalVector)
val outgoingVector = incomingVector.clone().subtract(normalVector.multiply(radianAngle))
val outgoingVector = incomingVector.copy().subtract(normalVector.multiply(radianAngle))

if (blockDirection == BlockDirection.UP) {
outgoingVector.y = outgoingVector.y * groundBouncing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.github.shynixn.mcutils.common.Vector3d
import com.github.shynixn.mcutils.common.physic.PhysicComponent
import com.github.shynixn.mcutils.common.toLocation
import com.github.shynixn.mcutils.common.toVector
import com.github.shynixn.mcutils.common.vector
import com.github.shynixn.mcutils.packet.api.RayTraceResult
import com.github.shynixn.mcutils.packet.api.RayTracingService
import com.github.shynixn.mcutils.packet.api.meta.enumeration.BlockDirection
Expand All @@ -29,10 +28,10 @@ class MathComponent(
/**
* Origin coordinate to make relative rotations in the world.
*/
private val origin = vector {
x = 0.0
y = 0.0
z = -1.0
private val origin = Vector3d().also {
it.x = 0.0
it.y = 0.0
it.z = -1.0
}.normalize()
var motion: Vector3d = Vector3d(null, 0.0, 0.0, 0.0)

Expand All @@ -50,7 +49,7 @@ class MathComponent(
*/
fun setVelocity(vector: Vector3d) {
// Motion per step is the new motion.
this.motion = vector.clone()
this.motion = vector.copy()
// Move the object a little up otherwise wallcollision of ground immediately cancel movement.
// this.position.y += 0.25
// Correct the yaw of the object after bouncing.
Expand Down Expand Up @@ -154,7 +153,7 @@ class MathComponent(
* Fixes the yaw value after a motion change.
*/
fun fixYawMotion() {
this.position.yaw = getYawFromVector(origin, this.motion.clone().normalize()) * -1
this.position.yaw = getYawFromVector(origin, this.motion.copy().normalize()) * -1
this.position.pitch = 0.0
}

Expand All @@ -173,7 +172,7 @@ class MathComponent(
this.motion = this.motion.multiply(settings.airResistanceRelative)

// Reduces the motion absolute by a negative normalized value.
val reductionVector = this.motion.clone().normalize().multiply(settings.airResistanceAbsolute)
val reductionVector = this.motion.copy().normalize().multiply(settings.airResistanceAbsolute)
reduceVectorIfBiggerZero(this.motion, reductionVector)
fixMotionFloatingPoints()

Expand All @@ -198,7 +197,7 @@ class MathComponent(
this.motion = this.motion.multiply(settings.groundResistanceRelative)

// Reduces the motion absolute by a negative normalized value.
val reductionVector = this.motion.clone().normalize().multiply(settings.groundResistanceAbsolute)
val reductionVector = this.motion.copy().normalize().multiply(settings.groundResistanceAbsolute)
reduceVectorIfBiggerZero(this.motion, reductionVector)
fixMotionFloatingPoints()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.github.shynixn.mctennis.impl.physic

import com.github.shynixn.mcutils.common.Vector3d
import com.github.shynixn.mcutils.common.physic.PhysicComponent
import com.github.shynixn.mcutils.common.vector
import kotlin.math.abs
import kotlin.math.atan2
import kotlin.math.cos
Expand Down Expand Up @@ -56,15 +55,15 @@ class SpinComponent(
return
}

val addVector = vector {
this.x = -motion.z
this.z = motion.x
val addVector = Vector3d().also {
it.x = -motion.z
it.z = motion.x
}.multiply(angularVelocity)

this.physicComponent.motion = vector {
x = motion.x + addVector.x
y = motion.y
z = motion.z + addVector.z
this.physicComponent.motion = Vector3d().also {
it.x = motion.x + addVector.x
it.y = motion.y
it.z = motion.z + addVector.z
}

angularVelocity /= 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.github.shynixn.mctennis.enumeration.VisibilityType
import com.github.shynixn.mctennis.impl.TennisBallImpl
import com.github.shynixn.mctennis.entity.MathSettings
import com.github.shynixn.mctennis.impl.physic.*
import com.github.shynixn.mcutils.common.item.ItemService
import com.github.shynixn.mcutils.common.physic.PhysicObjectService
import com.github.shynixn.mcutils.common.sound.SoundService
import com.github.shynixn.mcutils.common.toVector3d
Expand All @@ -24,6 +25,7 @@ class TennisBallFactoryImpl @Inject constructor(
private val bedrockService: BedrockService,
private val packetService: PacketService,
private val rayTracingService: RayTracingService,
private val itemService: ItemService
) :
TennisBallFactory {

Expand Down Expand Up @@ -65,6 +67,8 @@ class TennisBallFactoryImpl @Inject constructor(
mathPhysicComponent,
packetService,
playerComponent,
itemService,
settings,
armorStandEntityId,
bedrockService.javaPlayers,
settings.renderYOffset
Expand All @@ -75,6 +79,8 @@ class TennisBallFactoryImpl @Inject constructor(
mathPhysicComponent,
packetService,
playerComponent,
itemService,
settings,
armorStandEntityId,
bedrockService.bedRockPlayers,
settings.renderYOffset
Expand All @@ -85,6 +91,8 @@ class TennisBallFactoryImpl @Inject constructor(
mathPhysicComponent,
packetService,
playerComponent,
itemService,
settings,
armorStandEntityId,
hashSetOf(),
settings.renderYOffset
Expand Down

0 comments on commit cb9e7bb

Please sign in to comment.