Skip to content

Commit

Permalink
Attempted to fix lightningbolt key pressed issue
Browse files Browse the repository at this point in the history
  • Loading branch information
RealYusufIsmail committed Oct 18, 2023
1 parent b66cbfc commit 9be1876
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## [1.20.1-1.0.7] - UNRELEASED

### Added thors hammer. This is a work in progress and will be updated in the future. currently when thrown it will be rendered as a trident.
### Pressing M while having tne effect 'worthy' will allow you to get the hammer.
### Pressing T while having the effect 'worthy' will allow you to strike lightning.

## [1.20.1-1.0.6] - 2023-10-13

### Added Ingot Fusion Enchanter (been in the works for a month with more than two rewrites) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ class ArmourAndToolsMod {
bus.addListener(ArmourAndToolsModTridentItemRendererProvider::init)
// register entity renderers
bus.addListener(ClientEvents::registerEntityRenders)
// register click event
FORGE_BUS.addListener(ClientEvents::rightClickBlock)
FORGE_BUS.addListener(ClientEvents::rightClickEmpty)
// 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 @@ -32,16 +32,14 @@ import net.minecraft.client.renderer.item.ItemProperties
import net.minecraft.resources.ResourceLocation
import net.minecraft.server.level.ServerPlayer
import net.minecraft.sounds.SoundEvents
import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.EntityType
import net.minecraft.world.entity.LightningBolt
import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.item.ItemStack
import net.minecraft.world.phys.Vec3
import net.minecraftforge.client.event.EntityRenderersEvent
import net.minecraftforge.client.event.InputEvent
import net.minecraftforge.client.event.RegisterKeyMappingsEvent
import net.minecraftforge.event.entity.player.PlayerInteractEvent
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickEmpty
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent

object ClientEvents {
Expand Down Expand Up @@ -133,10 +131,6 @@ object ClientEvents {
EntityTypeInit.MJOLNIR_THROWN_TRIDENT.get(), ::MjolnirItemRenderer)
}

fun rightClickBlock(event: PlayerInteractEvent.RightClickBlock) {}

fun rightClickEmpty(event: PlayerInteractEvent.RightClickEmpty) {}

fun onKeyRegister(event: RegisterKeyMappingsEvent) {
event.register(KeyBinding.GET_MJOLNIR)
event.register(KeyBinding.STRIKE_LIGHTNING)
Expand Down Expand Up @@ -165,23 +159,31 @@ object ClientEvents {
val effects = player.activeEffectsMap

if (effects.contains(MobEffectsInit.WORTHY_EFFECT.get())) {
val lightningbolt = EntityType.LIGHTNING_BOLT.create(player.level())
if (lightningbolt != null) {
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)
val entity =
player
.level()
.getEntities(player, player.boundingBox.inflate(10.0)) { entity: Entity?
->
entity != player && entity?.isAlive ?: false
}
.minByOrNull { player.distanceToSqr(it) }

val level = player.level()
if (entity != null) {

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

View workflow job for this annotation

GitHub Actions / qodana

Constant conditions

Condition 'entity != null' is always true
val blockpos = entity.blockPosition()

if (level.canSeeSky(blockpos)) {
val lightningbolt = EntityType.LIGHTNING_BOLT.create(level)
if (lightningbolt != null) {

Check warning on line 177 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
lightningbolt.moveTo(Vec3.atBottomCenterOf(blockpos))
lightningbolt.cause = if (entity is ServerPlayer) entity else null

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

View workflow job for this annotation

GitHub Actions / qodana

Constant conditions

Condition 'entity is ServerPlayer' is always true
level.addFreshEntity(lightningbolt)
entity.playSound(SoundEvents.LIGHTNING_BOLT_THUNDER, 1.0f, 1.0f)
}
}
}
}
}
}
}

private fun fireLightningBolt(event: PlayerInteractEvent, lightningbolt: LightningBolt) {
lightningbolt.moveTo(Vec3.atBottomCenterOf(event.pos))
lightningbolt.cause =
if (event.entity is ServerPlayer) event.entity as ServerPlayer else null
event.level.addFreshEntity(lightningbolt)
event.entity.playSound(SoundEvents.LIGHTNING_BOLT_THUNDER, 1.0f, 1.0f)
}
}

0 comments on commit 9be1876

Please sign in to comment.