Skip to content

Commit

Permalink
Add attack particle effect
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoDog896 committed Mar 27, 2022
1 parent 5f75df1 commit 78c340d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
15 changes: 12 additions & 3 deletions build.gradle.kts
Expand Up @@ -32,19 +32,22 @@ dependencies {
compileOnly(kotlin("reflect"))

// Use the JUpiter test library.
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")

// Compile Minestom into project
compileOnly("com.github.Minestom", "Minestom", "4ee5cbe424")

// implement KStom
compileOnly("com.github.Project-Cepi:KStom:05b5e1f2a1")
compileOnly("com.github.Project-Cepi:KStom:15bab227a2")

// add energy
compileOnly("com.github.Project-Cepi:EnergyExtension:f2bcdfc79e")

// import kotlinx serialization
compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.1")
compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")

// Add MiniMessage
compileOnly("net.kyori:adventure-text-minimessage:4.2.0-SNAPSHOT")

// Add Kepi
compileOnly("com.github.Project-Cepi:Kepi:071b288ed0")
Expand All @@ -61,6 +64,12 @@ dependencies {
// Add actions
compileOnly("com.github.Project-Cepi:Actions:3cccca74c8")

// Add Particable
compileOnly("com.github.Project-Cepi:Particable:9ab0e20842")

// Add MinestomPVP
compileOnly("com.github.Project-Cepi:MinestomPVP:b9cb14d4bf")

// Add canvas
implementation("com.mattworzala:canvas:1.1.5")
}
Expand Down
Expand Up @@ -49,7 +49,7 @@ object TargetHandler {
// Check if the ray has hit an entity
if (result.hitType == HitType.ENTITY) {

val target = result.hitEntity!!
val target = result.hitEntity!! as? LivingEntity ?: return@forEach

// Ignore if the entity hit is a player
if (target is Player) {
Expand Down
@@ -1,5 +1,6 @@
package world.cepi.itemextension.combat.events

import io.github.bloepiloepi.pvp.events.FinalAttackEvent
import net.kyori.adventure.sound.Sound
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.NamedTextColor
Expand All @@ -25,6 +26,13 @@ import world.cepi.itemextension.item.cepiItem
import world.cepi.itemextension.item.checkIsItem
import world.cepi.itemextension.item.traits.list.*
import world.cepi.kstom.Manager
import world.cepi.kstom.raycast.RayCast
import world.cepi.kstom.util.eyePosition
import world.cepi.particle.Particle
import world.cepi.particle.ParticleType
import world.cepi.particle.data.OffsetAndSpeed
import world.cepi.particle.renderer.Renderer
import world.cepi.particle.renderer.render
import java.text.NumberFormat

object CombatHandler {
Expand Down Expand Up @@ -146,7 +154,7 @@ object CombatHandler {
ImmunityHandler.triggerImmune(entity)
}

fun registerDamageByEntity(event: EntityAttackEvent) = with(event) {
fun registerDamageByEntity(event: FinalAttackEvent) = with(event) {
if (!canDamageEntities(entity)) {
return
}
Expand Down Expand Up @@ -174,6 +182,17 @@ object CombatHandler {
cepiItem?.get<LevelTrait>()?.let {
if ((entity as Player).level < it.level) return
}

val centerTarget = RayCast.castRay(
instance,
entity,
entity.eyePosition(),
entity.position.direction(),
stepLength = 0.5
).finalPosition

Renderer.fixedLine(centerTarget, centerTarget.add(entity.position.direction().mul(2.0)))
.render(Particle.particle(ParticleType.CRIT, 1, OffsetAndSpeed()), target.viewersAsAudience)
}

if (cepiItem?.hasTrait<DurabilityTrait>() == true) {
Expand Down Expand Up @@ -204,9 +223,6 @@ object CombatHandler {
}
}
}
//
// if (entity is EquipmentHandler)
// entity.useAttackSpeed((entity as EquipmentHandler).itemInMainHand)

}

Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/META-INF/extension.json
Expand Up @@ -8,7 +8,9 @@
"MobExtension",
"Projectiles",
"Actions",
"Gooey"
"Gooey",
"Particable",
"PvpExtension"
],
"meta": {
"downloadURL": "https://github.com/Project-Cepi/ItemExtension/releases/download/latest/ItemExtension-1.0.0-all.jar"
Expand Down

0 comments on commit 78c340d

Please sign in to comment.