Skip to content

Commit

Permalink
Fixed lightneing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
RealYusufIsmail committed Oct 18, 2023
1 parent 93d5270 commit b66cbfc
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.1 2023-10-17T21:36:16.1265363 Languages: en_us
30f8301afe214a9b79f7ec8c1d188b4103bb79b0 assets/armourandtoolsmod/lang/en_us.json
// 1.20.1 2023-10-18T21:49:31.0374931 Languages: en_us
dc4899b51a9ba3f1a123c05cc3c66fffe779b4b6 assets/armourandtoolsmod/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,6 @@
"item.minecraft.potion.effect.worthy_potion": "Worthy Potion",
"item.minecraft.splash_potion.effect.worthy_potion": "Worthy Potion",
"key.categories.armourandtoolsmod": "Armour and Item Mod",
"key.get_mjolnir": "Get Mjölnir"
"key.get_mjolnir": "Get Mjölnir",
"key.strike_lightning": "Strike Lightning"
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class ArmourAndToolsMod {
// register click event
FORGE_BUS.addListener(ClientEvents::rightClickBlock)
FORGE_BUS.addListener(ClientEvents::rightClickEmpty)
FORGE_BUS.addListener(ClientEvents::onEntityInteract)
// register key input event
bus.addListener(ClientEvents::onKeyRegister)
FORGE_BUS.addListener(ClientEvents::onKeyInput)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,12 @@ object ClientEvents {
val effects = player.activeEffectsMap

if (effects.contains(MobEffectsInit.WORTHY_EFFECT.get())) {
val lightningbolt = EntityType.LIGHTNING_BOLT.create(player.level())
if (lightningbolt != null) {}
}
}
}
}

fun onEntityInteract(event: PlayerInteractEvent.EntityInteract) {
if (event.entity is ServerPlayer) {
val player = event.entity as ServerPlayer
val effects = player.activeEffectsMap

if (effects.contains(MobEffectsInit.WORTHY_EFFECT.get())) {
if (event.target is LivingEntity) {
val lightningbolt = EntityType.LIGHTNING_BOLT.create(player.level())
if (lightningbolt != null) {

Check warning on line 169 in src/main/kotlin/io/github/realyusufismail/armourandtoolsmod/client/ClientEvents.kt

View workflow job for this annotation

GitHub Actions / qodana

Constant conditions

Condition 'lightningbolt != null' is always true
fireLightningBolt(event, lightningbolt)
lightningbolt.moveTo(Vec3.atBottomCenterOf(player.blockPosition()))
lightningbolt.cause = if (player is ServerPlayer) player else null
player.level().addFreshEntity(lightningbolt)
player.playSound(SoundEvents.LIGHTNING_BOLT_THUNDER, 1.0f, 1.0f)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ class MjolnirItemRendererISTER : ArmourAndToolsModBlockEntityWithoutLevelRendere
}

fun getModelResourceLocation(): ModelResourceLocation {
return ModelResourceLocation(ArmourAndToolsMod.getModIdAndName("mjolnir"), "inventory")
return ModelResourceLocation(
ArmourAndToolsMod.getModIdAndName("aqumarine_trident"), "inventory")
}

fun getTextureLocation(): ResourceLocation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package io.github.realyusufismail.armourandtoolsmod.common.entity

import io.github.realyusufismail.armourandtoolsmod.ArmourAndToolsMod
import net.minecraft.nbt.CompoundTag
import net.minecraft.nbt.Tag
import net.minecraft.network.protocol.Packet
Expand Down Expand Up @@ -48,6 +47,7 @@ abstract class ArmourToolsModTridentEntity : AbstractArrow {
var tridentItem: ItemStack? = null
private var dealtDamage = false
var returningTicks = 0
var allowToTriggerThunderWithoutEnchantment = false

constructor(type: EntityType<ArmourToolsModTridentEntity>, world: Level) : super(type, world)

Expand Down Expand Up @@ -152,16 +152,33 @@ abstract class ArmourToolsModTridentEntity : AbstractArrow {

deltaMovement = deltaMovement.multiply(-0.01, -0.1, -0.01)
var f1 = 1.0f
if (level() is ServerLevel && level().isThundering && isChanneling()) {
val blockpos = entity.blockPosition()
if (level().canSeeSky(blockpos)) {
val lightningbolt = EntityType.LIGHTNING_BOLT.create(level())
if (lightningbolt != null) {
lightningbolt.moveTo(Vec3.atBottomCenterOf(blockpos))
lightningbolt.cause = if (shooter is ServerPlayer) shooter else null
level().addFreshEntity(lightningbolt)
soundEvent = SoundEvents.TRIDENT_THUNDER
f1 = 5.0f

if (!allowToTriggerThunderWithoutEnchantment) {
if (level() is ServerLevel && level().isThundering && isChanneling()) {
val blockpos = entity.blockPosition()
if (level().canSeeSky(blockpos)) {
val lightningbolt = EntityType.LIGHTNING_BOLT.create(level())
if (lightningbolt != null) {
lightningbolt.moveTo(Vec3.atBottomCenterOf(blockpos))
lightningbolt.cause = if (shooter is ServerPlayer) shooter else null
level().addFreshEntity(lightningbolt)
soundEvent = SoundEvents.TRIDENT_THUNDER
f1 = 5.0f
}
}
}
} else {
if (level() is ServerLevel) {
val blockpos = entity.blockPosition()
if (level().canSeeSky(blockpos)) {
val lightningbolt = EntityType.LIGHTNING_BOLT.create(level())
if (lightningbolt != null) {
lightningbolt.moveTo(Vec3.atBottomCenterOf(blockpos))
lightningbolt.cause = if (shooter is ServerPlayer) shooter else null

Check warning on line 177 in src/main/kotlin/io/github/realyusufismail/armourandtoolsmod/common/entity/ArmourToolsModTridentEntity.kt

View workflow job for this annotation

GitHub Actions / qodana

Constant conditions

Condition 'shooter is ServerPlayer' is always true
level().addFreshEntity(lightningbolt)
soundEvent = SoundEvents.LIGHTNING_BOLT_THUNDER
f1 = 5.0f
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ open class MjolnirEntity : ArmourToolsModTridentEntity {

constructor(type: EntityType<ArmourToolsModTridentEntity>, world: Level) : super(type, world) {
this.tridentItem = ItemStack(ItemInit.MJOLNIR.get())
this.entityData.define(ID_LOYALTY, 1.toByte())
this.entityData.set(ID_LOYALTY, 1.toByte())
this.allowToTriggerThunderWithoutEnchantment = true
}

constructor(
level: Level,
thrower: LivingEntity,
stack: ItemStack
) : super(EntityTypeInit.MJOLNIR_THROWN_TRIDENT.get(), level, thrower, stack) {
this.entityData.define(ID_LOYALTY, 1.toByte())
this.entityData.set(ID_LOYALTY, 1.toByte())
this.allowToTriggerThunderWithoutEnchantment = true
}

override fun getBaseDamage(): Double {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ object KeyBinding {
KEY_STRIKE_LIGHTNING,
KeyConflictContext.IN_GAME,
InputConstants.Type.KEYSYM,
GLFW.GLFW_KEY_L,
GLFW.GLFW_KEY_Z,
KEY_CATEGORY_ARMOUR_AND_TOOLS_MOD)
}

0 comments on commit b66cbfc

Please sign in to comment.