generated from SmushyTaco/Example-Mod
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
216 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,14 +21,14 @@ jobs: | |
needs: build | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
uses: actions/checkout@v4.1.1 | ||
- name: Download Fabric jars | ||
uses: actions/download-artifact@v3 | ||
uses: actions/download-artifact@v4.1.4 | ||
with: | ||
name: fabric-jars | ||
path: dist/fabric | ||
- name: Download Forge jars | ||
uses: actions/download-artifact@v3 | ||
uses: actions/download-artifact@v4.1.4 | ||
with: | ||
name: forge-jars | ||
path: dist/forge | ||
|
@@ -102,7 +102,7 @@ jobs: | |
dist/forge/*-@(dev|sources|javadoc).jar | ||
changelog-file: CHANGELOG.g.md | ||
- name: Delete build output | ||
uses: geekyeggo/delete-artifact@v2 | ||
uses: geekyeggo/delete-artifact@v5.0.0 | ||
with: | ||
name: | | ||
fabric-jars | ||
|
@@ -118,7 +118,7 @@ jobs: | |
VERSION: ${{ github.ref_name }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
uses: actions/checkout@v4.1.1 | ||
with: | ||
fetch-depth: 0 | ||
ref: docs | ||
|
@@ -127,12 +127,12 @@ jobs: | |
git config user.email "[email protected]" | ||
git config user.name "github-actions[bot]" | ||
- name: Download Kotlin documentation | ||
uses: actions/download-artifact@v3 | ||
uses: actions/download-artifact@v4.1.4 | ||
with: | ||
name: kdoc | ||
path: docs/kdoc/${{ github.ref_name }} | ||
- name: Download Java documentation | ||
uses: actions/download-artifact@v3 | ||
uses: actions/download-artifact@v4.1.4 | ||
with: | ||
name: javadoc | ||
path: docs/javadoc/${{ github.ref_name }} | ||
|
@@ -155,11 +155,11 @@ jobs: | |
git add docs | ||
git commit -a -m "Add documentation for $VERSION" | ||
- name: Push documentation | ||
uses: ad-m/github-push-action@master | ||
uses: ad-m/github-push-action@v0.8.0 | ||
with: | ||
branch: docs | ||
- name: Delete documentation artifacts | ||
uses: geekyeggo/delete-artifact@v2 | ||
uses: geekyeggo/delete-artifact@v5.0.0 | ||
with: | ||
name: | | ||
kdoc | ||
|
@@ -173,14 +173,14 @@ jobs: | |
needs: push-docs | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
uses: actions/checkout@v4.1.1 | ||
with: | ||
ref: docs | ||
- name: Configure git | ||
run: | | ||
git config user.email "[email protected]" | ||
git config user.name "github-actions[bot]" | ||
- name: Publish documentation | ||
uses: mhausenblas/mkdocs-deploy-gh-pages@master | ||
uses: mhausenblas/mkdocs-deploy-gh-pages@1.26 | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
184 changes: 184 additions & 0 deletions
184
.../main/kotlin/opekope2/avm_staff/internal/staff_item_handler/WitherSkeletonSkullHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
/* | ||
* 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.fabricmc.api.EnvType | ||
import net.fabricmc.api.Environment | ||
import net.minecraft.client.render.entity.model.SkullEntityModel | ||
import net.minecraft.client.render.model.* | ||
import net.minecraft.client.render.model.json.ModelOverrideList | ||
import net.minecraft.client.render.model.json.ModelTransformation | ||
import net.minecraft.client.render.model.json.Transformation | ||
import net.minecraft.client.texture.Sprite | ||
import net.minecraft.client.texture.SpriteAtlasTexture | ||
import net.minecraft.client.util.SpriteIdentifier | ||
import net.minecraft.entity.Entity | ||
import net.minecraft.entity.LivingEntity | ||
import net.minecraft.entity.effect.StatusEffectInstance | ||
import net.minecraft.entity.effect.StatusEffects | ||
import net.minecraft.entity.player.PlayerEntity | ||
import net.minecraft.entity.projectile.WitherSkullEntity | ||
import net.minecraft.item.ItemStack | ||
import net.minecraft.util.ActionResult | ||
import net.minecraft.util.Hand | ||
import net.minecraft.util.Identifier | ||
import net.minecraft.util.TypedActionResult | ||
import net.minecraft.util.math.Direction | ||
import net.minecraft.world.Difficulty | ||
import net.minecraft.world.World | ||
import net.minecraft.world.WorldEvents | ||
import opekope2.avm_staff.api.item.StaffItemHandler | ||
import opekope2.avm_staff.api.item.model.IStaffItemBakedModel | ||
import opekope2.avm_staff.api.item.model.IStaffItemUnbakedModel | ||
import opekope2.avm_staff.api.item.model.StaffItemBakedModel | ||
import opekope2.avm_staff.util.* | ||
import org.joml.Vector3f | ||
import java.util.function.Function | ||
import java.util.function.Supplier | ||
|
||
class WitherSkeletonSkullHandler : StaffItemHandler() { | ||
override val maxUseTime = 20 | ||
|
||
override fun use( | ||
staffStack: ItemStack, | ||
world: World, | ||
user: PlayerEntity, | ||
hand: Hand | ||
): TypedActionResult<ItemStack> { | ||
user.setCurrentHand(hand) | ||
return TypedActionResult.pass(staffStack) | ||
} | ||
|
||
override fun usageTick(staffStack: ItemStack, world: World, user: LivingEntity, remainingUseTicks: Int) { | ||
if ((remainingUseTicks and 1) == 0) { | ||
shootSkull(world, user, Math.random() < 0.1f) // TODO ratio | ||
} | ||
} | ||
|
||
override fun attack(staffStack: ItemStack, world: World, attacker: LivingEntity, hand: Hand): ActionResult { | ||
if (attacker is PlayerEntity && attacker.itemCooldownManager.isCoolingDown(staffStack.item)) return ActionResult.FAIL | ||
|
||
shootSkull(world, attacker, false) | ||
(attacker as? PlayerEntity)?.resetLastAttackedTicks() | ||
return ActionResult.SUCCESS | ||
} | ||
|
||
private fun shootSkull(world: World, user: LivingEntity, charged: Boolean) { | ||
if (!user.canUseStaff) return | ||
if (user is PlayerEntity && user.isAttackCoolingDown) return | ||
|
||
world.syncWorldEvent(null, WorldEvents.WITHER_SHOOTS, user.blockPos, 0) | ||
|
||
if (world.isClient) return | ||
|
||
val (x, y, z) = user.rotationVector | ||
world.spawnEntity(WitherSkullEntity(world, user, x, y, z).apply { | ||
isCharged = charged | ||
setPosition(user.approximateStaffTipPosition) | ||
}) | ||
} | ||
|
||
override fun attackEntity( | ||
staffStack: ItemStack, | ||
world: World, | ||
attacker: LivingEntity, | ||
target: Entity, | ||
hand: Hand | ||
): ActionResult { | ||
if (!world.isClient) { | ||
if (world.difficulty.id >= Difficulty.NORMAL.id) { | ||
if (target is LivingEntity && !target.isInvulnerableTo(world.damageSources.wither())) { | ||
val amplifier = if (world.difficulty == Difficulty.HARD) 1 else 0 | ||
target.addStatusEffect(StatusEffectInstance(StatusEffects.WITHER, 5 * 20, amplifier)) | ||
} | ||
} | ||
} | ||
|
||
return super.attackEntity(staffStack, world, attacker, target, hand) | ||
} | ||
|
||
override fun onStoppedUsing(staffStack: ItemStack, world: World, user: LivingEntity, remainingUseTicks: Int) { | ||
(user as? PlayerEntity)?.itemCooldownManager?.set(staffStack.item, 4 * (maxUseTime - remainingUseTicks)) | ||
} | ||
|
||
override fun finishUsing(staffStack: ItemStack, world: World, user: LivingEntity): ItemStack { | ||
onStoppedUsing(staffStack, world, user, 0) | ||
return staffStack | ||
} | ||
|
||
@Environment(EnvType.CLIENT) | ||
private class WitherSkeletonSkullUnbakedModel : IStaffItemUnbakedModel { | ||
override fun getModelDependencies() = setOf<Identifier>() | ||
|
||
override fun setParents(modelLoader: Function<Identifier, UnbakedModel>?) { | ||
} | ||
|
||
override fun bake( | ||
baker: Baker, | ||
textureGetter: Function<SpriteIdentifier, Sprite>, | ||
rotationContainer: ModelBakeSettings, | ||
modelId: Identifier, | ||
transformation: Transformation | ||
): IStaffItemBakedModel { | ||
val skullSprite = textureGetter.apply(WITHER_SKELETON_SKULL_TEXTURE) | ||
val skullModel = SkullEntityModel.getSkullTexturedModelData().createModel().getChild("head") | ||
val quads = skullModel.getBakedQuads(skullSprite, skullTransformation) | ||
val baked = BasicBakedModel( | ||
quads, | ||
createEmptyFaceQuads(), | ||
true, | ||
false, | ||
false, | ||
skullSprite, | ||
ModelTransformation.NONE, | ||
ModelOverrideList.EMPTY | ||
) | ||
|
||
return StaffItemBakedModel(baked.transform(null, transformation, textureGetter)) | ||
} | ||
|
||
private companion object { | ||
private val WITHER_SKELETON_SKULL_TEXTURE = SpriteIdentifier( | ||
SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, | ||
Identifier("entity/skeleton/wither_skeleton") | ||
) | ||
|
||
private val skullTransformation = Transformation( | ||
Vector3f(0f, 0f, 180f), | ||
Vector3f(.5f, 0f, .5f), | ||
Vector3f(2f) | ||
) | ||
|
||
private fun createEmptyFaceQuads(): Map<Direction, List<BakedQuad>> = mapOf( | ||
Direction.DOWN to listOf(), | ||
Direction.UP to listOf(), | ||
Direction.NORTH to listOf(), | ||
Direction.SOUTH to listOf(), | ||
Direction.WEST to listOf(), | ||
Direction.EAST to listOf(), | ||
) | ||
} | ||
} | ||
|
||
companion object { | ||
val modelSupplierFactory: Supplier<Supplier<out IStaffItemUnbakedModel>> = Supplier { | ||
Supplier(::WitherSkeletonSkullUnbakedModel) | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
StaffMod/src/main/resources/assets/minecraft/atlases/blocks.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"sources": [ | ||
{ | ||
"type": "single", | ||
"resource": "entity/skeleton/wither_skeleton" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters