From 26ca3826bf9c13d30b697df0994231bb4b89b535 Mon Sep 17 00:00:00 2001 From: opekope2 Date: Thu, 25 Jan 2024 20:36:06 +0100 Subject: [PATCH 1/3] Add basic lightning rod functionality --- .../staff_item_handler/LightningRodHandler.kt | 76 +++++++++++++++++++ .../VanillaStaffItemHandlers.kt | 2 + 2 files changed, 78 insertions(+) create mode 100644 StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/LightningRodHandler.kt diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/LightningRodHandler.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/LightningRodHandler.kt new file mode 100644 index 000000000..7d9315b29 --- /dev/null +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/LightningRodHandler.kt @@ -0,0 +1,76 @@ +/* + * AvM Staff Mod + * Copyright (c) 2024 opekope2 + * + * This mod is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This mod is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this mod. If not, see . + */ + +package opekope2.avm_staff.internal.staff_item_handler + +import net.minecraft.block.BlockState +import net.minecraft.block.Blocks +import net.minecraft.entity.EntityType +import net.minecraft.entity.LivingEntity +import net.minecraft.item.ItemStack +import net.minecraft.util.ActionResult +import net.minecraft.util.Hand +import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.Direction +import net.minecraft.world.World +import opekope2.avm_staff.api.item.StaffItemHandler +import opekope2.avm_staff.api.item.renderer.IStaffItemRenderer +import opekope2.avm_staff.api.item.renderer.InsideStaffBlockStateRenderer +import opekope2.avm_staff.api.item.renderer.StaffBlockStateRenderer +import org.joml.Vector3f + +class LightningRodHandler : StaffItemHandler() { + override val staffItemRenderer: IStaffItemRenderer = LightningRodRenderer() + + override fun useOnBlock( + staffStack: ItemStack, + world: World, + user: LivingEntity, + target: BlockPos, + side: Direction, + hand: Hand + ): ActionResult { + if (!EntityType.LIGHTNING_BOLT.isEnabled(world.enabledFeatures)) return ActionResult.FAIL + + val thunder = world.isThundering + val lightningPos = target.offset(side) + val skylit = world.isSkyVisible(lightningPos) + + if (world.isClient) { + return if (thunder && skylit) ActionResult.SUCCESS + else ActionResult.CONSUME + } + + if (!thunder) return ActionResult.FAIL + if (!skylit) return ActionResult.FAIL + + val lightning = EntityType.LIGHTNING_BOLT.create(world) ?: return ActionResult.FAIL + lightning.refreshPositionAfterTeleport(lightningPos.toCenterPos()) + world.spawnEntity(lightning) + + return ActionResult.SUCCESS + } + + private class LightningRodRenderer : StaffBlockStateRenderer() { + override val scale: Float + get() = InsideStaffBlockStateRenderer.SCALE + override val offset: Vector3f = InsideStaffBlockStateRenderer.OFFSET.add(0f, 10f / 16f, 0f, Vector3f()) + + override fun getBlockState(staffStack: ItemStack): BlockState = Blocks.LIGHTNING_ROD.defaultState + } +} diff --git a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/VanillaStaffItemHandlers.kt b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/VanillaStaffItemHandlers.kt index eac8aa0f5..e321e8f6b 100644 --- a/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/VanillaStaffItemHandlers.kt +++ b/StaffMod/src/main/kotlin/opekope2/avm_staff/internal/staff_item_handler/VanillaStaffItemHandlers.kt @@ -50,6 +50,8 @@ fun register() { FurnaceHandler(SMOKER as BlockItem, RecipeType.SMOKING, SoundEvents.BLOCK_SMOKER_SMOKE) ) + LIGHTNING_ROD.registerHandler(LightningRodHandler()) + MAGMA_BLOCK.registerHandler(MagmaBlockHandler()) SNOW_BLOCK.registerHandler(SnowBlockHandler()) From 18a4e3844275a30a3ab9fb1a8ac9d6dd32554835 Mon Sep 17 00:00:00 2001 From: opekope2 Date: Thu, 25 Jan 2024 20:55:11 +0100 Subject: [PATCH 2/3] Fix GitHub stars style --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 55eeddb77..a46a8ab08 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/opekope2/StaffMod?include_prereleases&label=Download+from+GitHub&logo=github)](https://github.com/opekope2/StaffMod/releases) [![Modrinth Version](https://img.shields.io/modrinth/v/avm-staff?label=Download+from+Modrinth&logo=modrinth)](https://modrinth.com/mod/avm-staff/versions) [![CurseForge Download](https://img.shields.io/badge/Download_from_CurseForge-uhh..._latest_I_guess%3F-E04E14?logo=curseforge)](https://www.curseforge.com/minecraft/mc-mods/avm-staff/files) -[![GitHub Repo stars](https://img.shields.io/github/stars/opekope2/StaffMod?label=⭐+GitHub+stars&color=ffff00)](https://github.com/opekope2/StaffMod/stargazers) +[![GitHub Repo stars](https://img.shields.io/github/stars/opekope2/StaffMod?label=⭐+GitHub+stars&color=ffff00&style=flat)](https://github.com/opekope2/StaffMod/stargazers) ![GitHub top language](https://img.shields.io/github/languages/top/opekope2/StaffMod?color=7F52FF&logo=kotlin) [![Buy me a coffee](https://img.shields.io/badge/Buy%20me%20a%20coffe-Ko--fi-f16061?logo=ko-fi)](https://ko-fi.com/opekope2) From e8e5b5013327fff09d49c2a5b7e4228561521a4c Mon Sep 17 00:00:00 2001 From: opekope2 Date: Thu, 25 Jan 2024 20:56:29 +0100 Subject: [PATCH 3/3] Bump version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 7b60c9a45..850b6e99e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ loader_version=0.15.3 java_version=17 ########################################################################## # Mod Properties -mod_version=0.8.0-beta +mod_version=0.9.0-beta maven_group=opekope2.avm_staff ########################################################################## # Kotlin Dependencies