Skip to content

Commit

Permalink
Merge Staff Mod 0.16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
opekope2 authored Jul 10, 2024
2 parents 5073b31 + 6f34522 commit a236737
Show file tree
Hide file tree
Showing 92 changed files with 2,597 additions and 1,007 deletions.
1 change: 1 addition & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,4 @@ jobs:
uses: mhausenblas/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}
REQUIREMENTS: requirements.txt
4 changes: 0 additions & 4 deletions FabricMod/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ dependencies {
modImplementation(libs.fabric.language.kotlin)
}

loom {
accessWidenerPath = project(":StaffMod").loom.accessWidenerPath
}

tasks {
jar {
archiveClassifier = "dev"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand;
import net.minecraft.world.World;
import opekope2.avm_staff.api.StaffMod;
import opekope2.avm_staff.api.staff.StaffHandler;
import opekope2.avm_staff.util.StaffUtil;
import opekope2.avm_staff.api.item.StaffItem;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -50,30 +47,20 @@ private LivingEntityMixin(EntityType<?> type, World world) {
@Inject(method = "disablesShield", at = @At("HEAD"), cancellable = true)
public void disableShield(CallbackInfoReturnable<Boolean> cir) {
ItemStack mainHandStack = getMainHandStack();
if (!mainHandStack.isIn(StaffMod.getStaffsTag())) return;

Item itemInStaff = StaffUtil.getItemInStaff(mainHandStack);
if (itemInStaff == null) return;

StaffHandler handlerOfItem = StaffUtil.getStaffHandlerOrDefault(itemInStaff);
if (handlerOfItem.disablesShield()) {
cir.setReturnValue(true);
if (mainHandStack.getItem() instanceof StaffItem staffItem) {
if (staffItem.disablesShield(mainHandStack, getEntityWorld(), (LivingEntity) (Object) this, Hand.MAIN_HAND)) {
cir.setReturnValue(true);
}
}
}

@SuppressWarnings("UnreachableCode") // Calm down IDEA, this is not what it looks like. Literally
@Inject(method = "swingHand(Lnet/minecraft/util/Hand;Z)V", at = @At("HEAD"), cancellable = true)
public void swingHand(Hand hand, boolean fromServerPlayer, CallbackInfo ci) {
ItemStack stackInHand = getStackInHand(hand);
if (stackInHand.isEmpty()) return;
if (!stackInHand.isIn(StaffMod.getStaffsTag())) return;

Item itemInStaff = StaffUtil.getItemInStaff(stackInHand);
if (itemInStaff == null) return;

StaffHandler handlerOfItem = StaffUtil.getStaffHandlerOrDefault(itemInStaff);
if (!handlerOfItem.canSwingHand(stackInHand, getEntityWorld(), (LivingEntity) (Object) this, hand)) {
ci.cancel();
if (stackInHand.getItem() instanceof StaffItem staffItem) {
if (!staffItem.canSwingHand(stackInHand, getEntityWorld(), (LivingEntity) (Object) this, hand)) {
ci.cancel();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,55 @@

package opekope2.avm_staff.internal.fabric

import net.fabricmc.api.EnvType
import net.fabricmc.api.ModInitializer
import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry
import net.fabricmc.fabric.api.event.player.AttackEntityCallback
import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes
import net.fabricmc.loader.api.FabricLoader
import net.minecraft.block.Block
import net.minecraft.entity.Entity
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.item.Item
import net.minecraft.particle.SimpleParticleType
import net.minecraft.util.ActionResult
import net.minecraft.util.Hand
import net.minecraft.util.hit.EntityHitResult
import net.minecraft.world.World
import opekope2.avm_staff.api.staffsTag
import opekope2.avm_staff.util.contains
import opekope2.avm_staff.util.itemInStaff
import opekope2.avm_staff.util.staffHandler
import opekope2.avm_staff.api.IStaffModPlatform
import opekope2.avm_staff.api.item.CrownItem
import opekope2.avm_staff.api.item.StaffItem
import opekope2.avm_staff.api.item.renderer.StaffRenderer
import opekope2.avm_staff.internal.fabric.item.FabricStaffItem

@Suppress("unused")
object StaffMod : ModInitializer {
object StaffMod : ModInitializer, IStaffModPlatform {
override fun onInitialize() {
AttackEntityCallback.EVENT.register(::handleEntityAttackEvent)
AttackEntityCallback.EVENT.register(::dispatchStaffEntityAttack)
}

@Suppress("UNUSED_PARAMETER")
private fun handleEntityAttackEvent(
player: PlayerEntity,
world: World,
hand: Hand,
target: Entity,
hit: EntityHitResult?
private fun dispatchStaffEntityAttack(
player: PlayerEntity, world: World, hand: Hand, target: Entity, hit: EntityHitResult?
): ActionResult {
val itemStack = player.getStackInHand(hand)
if (itemStack !in staffsTag) return ActionResult.PASS
val staffStack = player.getStackInHand(hand)
val staffItem = staffStack.item as? StaffItem ?: return ActionResult.PASS
val result = staffItem.attackEntity(staffStack, world, player, target, hand)

val itemInStaff = itemStack.itemInStaff ?: return ActionResult.PASS
val staffHandler = itemInStaff.staffHandler ?: return ActionResult.PASS

val result = staffHandler.attackEntity(itemStack, world, player, target, hand)
return if (result.interruptsFurtherEvaluation()) ActionResult.SUCCESS
else ActionResult.PASS
}

override fun staffItem(settings: Item.Settings) = FabricStaffItem(settings)

override fun itemWithStaffRenderer(settings: Item.Settings) = Item(settings).also { item ->
if (FabricLoader.getInstance().environmentType == EnvType.CLIENT) {
BuiltinItemRendererRegistry.INSTANCE.register(item, StaffRenderer::renderStaff)
}
}

override fun crownItem(groundBlock: Block, wallBlock: Block, settings: Item.Settings) =
CrownItem(groundBlock, wallBlock, settings)

override fun simpleParticleType(alwaysShow: Boolean): SimpleParticleType = FabricParticleTypes.simple(alwaysShow)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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/>.
*/

@file: JvmName("StaffModPlatformHolderImpl")
@file: Suppress("unused")

package opekope2.avm_staff.internal.fabric

import opekope2.avm_staff.api.IStaffModPlatform

val staffModPlatform: IStaffModPlatform
get() = StaffMod

This file was deleted.

32 changes: 27 additions & 5 deletions FabricMod/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,33 @@
"name": "Staff Mod (Animation vs Minecraft)",
"description": "AvM Staff Mod is a fan-made, mostly canonically accurate, and close to vanilla mod adding staffs from Animation vs Minecraft series to the latest version of Minecraft: Java Edition",
"authors": [
"opekope2"
{
"name": "opekope2",
"contact": {
"homepage": "https://opekope2.dev",
"github": "https://github.com/opekope2"
}
}
],
"contributors": [
"Brother_Oliviär",
"Ink&Soul"
{
"name": "Alan Becker",
"contact": {
"youtube": "https://www.youtube.com/@alanbecker"
}
},
{
"name": "Brother_Oliviär"
},
{
"name": "Ink&Soul",
"contact": {
"github": "https://github.com/MBYL-InkAndSoul"
}
},
{
"name": "MoonWolf"
}
],
"contact": {
"homepage": "https://opekope2.dev/StaffMod",
Expand Down Expand Up @@ -39,7 +61,7 @@
},
{
"adapter": "kotlin",
"value": "opekope2.avm_staff.internal.staff_handler.VanillaStaffHandlersKt::registerVanillaStaffHandlers"
"value": "opekope2.avm_staff.internal.staff.handler.VanillaStaffHandlersKt::registerVanillaStaffHandlers"
}
],
"client": [
Expand All @@ -61,7 +83,7 @@
},
{
"adapter": "kotlin",
"value": "opekope2.avm_staff.internal.staff_handler.VanillaStaffHandlersKt::registerVanillaStaffItemRenderers"
"value": "opekope2.avm_staff.internal.staff.handler.VanillaStaffHandlersKt::registerVanillaStaffItemRenderers"
}
]
},
Expand Down
5 changes: 0 additions & 5 deletions NeoForgeMod/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ dependencies {
implementation(libs.kotlinforforge.neoforge)
}

loom {
accessWidenerPath = project(":StaffMod").loom.accessWidenerPath
}

tasks {
jar {
archiveClassifier = "dev"
Expand Down Expand Up @@ -106,7 +102,6 @@ tasks {
inputFile = shadowJar.get().archiveFile
injectAccessWidener = true
archiveClassifier = null
atAccessWideners.add(loom.accessWidenerPath.get().asFile.name)

from(rootDir.resolve("COPYING"))
from(rootDir.resolve("COPYING.LESSER"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,27 @@

package opekope2.avm_staff.internal.neoforge

import net.minecraft.block.Block
import net.minecraft.item.Item
import net.minecraft.particle.SimpleParticleType
import net.neoforged.api.distmarker.Dist
import net.neoforged.fml.common.Mod
import net.neoforged.neoforge.event.entity.living.LivingDropsEvent
import opekope2.avm_staff.api.IStaffModPlatform
import opekope2.avm_staff.internal.initializeNetworking
import opekope2.avm_staff.internal.neoforge.item.NeoForgeCrownItem
import opekope2.avm_staff.internal.neoforge.item.NeoForgeStaffItem
import opekope2.avm_staff.internal.neoforge.item.NeoForgeStaffRendererItem
import opekope2.avm_staff.internal.registerContent
import opekope2.avm_staff.internal.staff_handler.registerVanillaStaffHandlers
import opekope2.avm_staff.internal.staff.handler.registerVanillaStaffHandlers
import opekope2.avm_staff.internal.stopUsingStaffWhenDropped
import opekope2.avm_staff.internal.subscribeToEvents
import opekope2.avm_staff.util.MOD_ID
import thedarkcolour.kotlinforforge.neoforge.forge.FORGE_BUS
import thedarkcolour.kotlinforforge.neoforge.forge.runWhenOn

@Mod(MOD_ID)
object StaffMod {
object StaffMod : IStaffModPlatform {
init {
registerContent()
initializeNetworking()
Expand All @@ -50,4 +57,13 @@ object StaffMod {
stopUsingStaffWhenDropped(event.entity, item)
}
}

override fun staffItem(settings: Item.Settings) = NeoForgeStaffItem(settings)

override fun itemWithStaffRenderer(settings: Item.Settings) = NeoForgeStaffRendererItem(settings)

override fun crownItem(groundBlock: Block, wallBlock: Block, settings: Item.Settings) =
NeoForgeCrownItem(groundBlock, wallBlock, settings)

override fun simpleParticleType(alwaysShow: Boolean) = SimpleParticleType(alwaysShow)
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import opekope2.avm_staff.api.soulFlamethrowerParticleType
import opekope2.avm_staff.internal.model.registerModelPredicateProviders
import opekope2.avm_staff.internal.registerClientContent
import opekope2.avm_staff.internal.registerSmithingTableTextures
import opekope2.avm_staff.internal.staff_handler.registerVanillaStaffItemRenderers
import opekope2.avm_staff.internal.staff.handler.registerVanillaStaffItemRenderers
import opekope2.avm_staff.internal.subscribeToClientEvents
import thedarkcolour.kotlinforforge.neoforge.forge.MOD_BUS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,12 @@
* along with this mod. If not, see <https://www.gnu.org/licenses/>.
*/

@file: JvmName("StaffModPlatformImpl")
@file: JvmName("StaffModPlatformHolderImpl")
@file: Suppress("unused")

package opekope2.avm_staff.internal.neoforge

import net.minecraft.item.Item
import opekope2.avm_staff.api.item.CrownItem
import opekope2.avm_staff.api.item.StaffItem
import opekope2.avm_staff.internal.neoforge.item.NeoForgeCrownItem
import opekope2.avm_staff.internal.neoforge.item.NeoForgeStaffItem
import opekope2.avm_staff.internal.neoforge.item.NeoForgeStaffRendererItem
import opekope2.avm_staff.api.IStaffModPlatform

fun createStaffItem(settings: Item.Settings): StaffItem = NeoForgeStaffItem(settings)

fun createStaffRendererItem(settings: Item.Settings): Item = NeoForgeStaffRendererItem(settings)

fun createCrownItem(settings: Item.Settings): CrownItem = NeoForgeCrownItem(settings)
val staffModPlatform: IStaffModPlatform
get() = StaffMod
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

package opekope2.avm_staff.internal.neoforge.item

import net.minecraft.block.Block
import net.minecraft.entity.LivingEntity
import net.minecraft.item.Item
import net.minecraft.item.ItemStack
import net.neoforged.neoforge.common.extensions.IItemExtension
import opekope2.avm_staff.api.item.CrownItem

class NeoForgeCrownItem(settings: Item.Settings) : CrownItem(settings), IItemExtension {
class NeoForgeCrownItem(groundBlock: Block, wallBlock: Block, settings: Item.Settings) :
CrownItem(groundBlock, wallBlock, settings), IItemExtension {
override fun isRepairable(arg: ItemStack) = false

override fun makesPiglinsNeutral(stack: ItemStack, wearer: LivingEntity) = stack.item is CrownItem
Expand Down
Loading

0 comments on commit a236737

Please sign in to comment.