Skip to content

Commit

Permalink
Merge Staff Mod 0.9.0-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
opekope2 authored Jan 25, 2024
2 parents f79ad57 + e8e5b50 commit 867c538
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 867c538

Please sign in to comment.