From 08bcb4266e1063ad31d8927cb0e946a9d0170dd5 Mon Sep 17 00:00:00 2001 From: WakelessSloth56 Date: Tue, 13 Feb 2024 20:10:51 +0800 Subject: [PATCH] feat(coremod): AHCoreModHandler --- .../mod/coremod/AHCoreModHandler.java | 46 +++++++++++++++++++ .../server/event/AHServerEventFactory.java | 5 +- .../cross_bow_item.shoot_projectile.js | 14 +++--- .../coremods/fishing_rod_item.use.js | 12 ++--- 4 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 src/main/java/org/auioc/mcmod/arnicalib/mod/coremod/AHCoreModHandler.java diff --git a/src/main/java/org/auioc/mcmod/arnicalib/mod/coremod/AHCoreModHandler.java b/src/main/java/org/auioc/mcmod/arnicalib/mod/coremod/AHCoreModHandler.java new file mode 100644 index 0000000..dddaaaa --- /dev/null +++ b/src/main/java/org/auioc/mcmod/arnicalib/mod/coremod/AHCoreModHandler.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2024 AUIOC.ORG + * + * This file is part of ArnicaLib, a mod made for Minecraft. + * + * ArnicaLib is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * This program 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +package org.auioc.mcmod.arnicalib.mod.coremod; + +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.projectile.Projectile; +import net.minecraft.world.item.ItemStack; +import org.auioc.mcmod.arnicalib.game.event.server.FishingRodCastEvent; +import org.auioc.mcmod.arnicalib.mod.server.event.AHServerEventFactory; + +public class AHCoreModHandler { + + /** + * @see coremod: arnicalib.cross_bow_item.shoot_projectile + */ + public static void preCrossbowRelease(LivingEntity living, ItemStack weapon, Projectile projectile) { + AHServerEventFactory.preProjectileWeaponRelease(living, weapon, projectile); + } + + /** + * @see coremod: arnicalib.fishing_rod_item.use + */ + public static FishingRodCastEvent preFishingRodCast(Player player, ItemStack fishingRod, int speedBonus, int luckBonus) { + return AHServerEventFactory.preFishingRodCast(player, fishingRod, speedBonus, luckBonus); + } + + +} diff --git a/src/main/java/org/auioc/mcmod/arnicalib/mod/server/event/AHServerEventFactory.java b/src/main/java/org/auioc/mcmod/arnicalib/mod/server/event/AHServerEventFactory.java index 58c5520..c013d6a 100644 --- a/src/main/java/org/auioc/mcmod/arnicalib/mod/server/event/AHServerEventFactory.java +++ b/src/main/java/org/auioc/mcmod/arnicalib/mod/server/event/AHServerEventFactory.java @@ -35,6 +35,7 @@ import org.auioc.mcmod.arnicalib.game.event.server.FishingRodCastEvent; import org.auioc.mcmod.arnicalib.game.event.server.ProjectileWeaponReleaseEvent; import org.auioc.mcmod.arnicalib.game.event.server.ServerLoginEvent; +import org.auioc.mcmod.arnicalib.mod.coremod.AHCoreModHandler; import static org.auioc.mcmod.arnicalib.ArnicaLib.LOGGER; @@ -67,14 +68,14 @@ public static boolean onServerLogin(final ClientIntentionPacket packet, final Co /** * @see org.auioc.mcmod.arnicalib.mod.mixin.server.MixinBowItem#releaseUsing - * @see coremod: arnicalib.cross_bow_item.shoot_projectile + * @see AHCoreModHandler#preCrossbowRelease */ public static void preProjectileWeaponRelease(LivingEntity living, ItemStack weapon, Projectile projectile) { BUS.post(new ProjectileWeaponReleaseEvent(living, weapon, projectile)); } /** - * @see coremod: arnicalib.fishing_rod_item.use + * @see AHCoreModHandler#preFishingRodCast */ public static FishingRodCastEvent preFishingRodCast(Player player, ItemStack fishingRod, int speedBonus, int luckBonus) { var event = new FishingRodCastEvent((ServerPlayer) player, fishingRod, speedBonus, luckBonus); diff --git a/src/main/resources/coremods/cross_bow_item.shoot_projectile.js b/src/main/resources/coremods/cross_bow_item.shoot_projectile.js index 57b5088..ed2adba 100644 --- a/src/main/resources/coremods/cross_bow_item.shoot_projectile.js +++ b/src/main/resources/coremods/cross_bow_item.shoot_projectile.js @@ -11,7 +11,7 @@ function initializeCoreMod() { type: 'METHOD', class: 'net.minecraft.world.item.CrossbowItem', methodName: 'shootProjectile', - methodDesc: '(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/item/ItemStack;FZFFF)V', + methodDesc: '(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/item/ItemStack;FZFFF)V' }, transformer: function (methodNode) { var toInject = new InsnList(); @@ -22,8 +22,8 @@ function initializeCoreMod() { toInject.add( new MethodInsnNode( Opcodes.INVOKESTATIC, - 'org/auioc/mcmod/arnicalib/mod/server/event/AHServerEventFactory', - 'preProjectileWeaponRelease', + 'org/auioc/mcmod/arnicalib/mod/coremod/AHCoreModHandler', + 'preCrossbowRelease', '(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/entity/projectile/Projectile;)V', false ) @@ -45,8 +45,8 @@ function initializeCoreMod() { // print(ASMAPI.methodNodeToString(methodNode)); return methodNode; - }, - }, + } + } }; } @@ -68,7 +68,7 @@ function initializeCoreMod() { //_... Projectile projectile; //_... -+ org.auioc.mcmod.arnicalib.mod.server.event.AHServerEventFactory.preProjectileWeaponRelease(pShooter, pCrossbowStack, projectile); ++ org.auioc.mcmod.arnicalib.mod.coremod.AHCoreModHandler.preCrossbowRelease(pShooter, pCrossbowStack, projectile); pLevel.addFreshEntity(projectile); //_... } @@ -80,7 +80,7 @@ function initializeCoreMod() { + ALOAD 1 + ALOAD 3 + ALOAD 11 -+ INVOKESTATIC org/auioc/mcmod/arnicalib/mod/server/event/AHServerEventFactory.preCrossbowRelease (Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/entity/projectile/Projectile;)V ++ INVOKESTATIC org/auioc/mcmod/arnicalib/mod/coremod/AHCoreModHandler.preCrossbowRelease (Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/entity/projectile/Projectile;)V ALOAD 0 ALOAD 11 INVOKEVIRTUAL net/minecraft/world/level/Level.addFreshEntity (Lnet/minecraft/world/entity/Entity;)Z diff --git a/src/main/resources/coremods/fishing_rod_item.use.js b/src/main/resources/coremods/fishing_rod_item.use.js index 5f283aa..d539958 100644 --- a/src/main/resources/coremods/fishing_rod_item.use.js +++ b/src/main/resources/coremods/fishing_rod_item.use.js @@ -13,7 +13,7 @@ function initializeCoreMod() { type: 'METHOD', class: 'net.minecraft.world.item.FishingRodItem', methodName: 'use', - methodDesc: '(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/InteractionResultHolder;', + methodDesc: '(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/InteractionResultHolder;' }, transformer: function (methodNode) { var toInject = new InsnList(); @@ -40,7 +40,7 @@ function initializeCoreMod() { toInject.add( new MethodInsnNode( Opcodes.INVOKESTATIC, - 'org/auioc/mcmod/arnicalib/mod/server/event/AHServerEventFactory', + 'org/auioc/mcmod/arnicalib/mod/coremod/AHCoreModHandler', 'preFishingRodCast', '(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/item/ItemStack;II)Lorg/auioc/mcmod/arnicalib/game/event/server/FishingRodCastEvent;', false @@ -87,8 +87,8 @@ function initializeCoreMod() { // print(ASMAPI.methodNodeToString(methodNode)); return methodNode; - }, - }, + } + } }; } @@ -114,7 +114,7 @@ function initializeCoreMod() { if (!pLevel.isClientSide) { int k = EnchantmentHelper.getFishingSpeedBonus(itemstack); int j = EnchantmentHelper.getFishingLuckBonus(itemstack); -+ var event = org.auioc.mcmod.arnicalib.mod.server.event.AHServerEventFactory.preFishingRodCast(pPlayer, itemstack, k, j); ++ var event = org.auioc.mcmod.arnicalib.mod.coremod.AHCoreModHandler.preFishingRodCast(pPlayer, itemstack, k, j); + k = event.getSpeedBonus(); + j = event.getLuckBonus(); pLevel.addFreshEntity(new FishingHook(pPlayer, pLevel, j, k)); @@ -142,7 +142,7 @@ function initializeCoreMod() { + ALOAD 4 + ILOAD 5 + ILOAD 6 -+ INVOKESTATIC org/auioc/mcmod/arnicalib/mod/server/event/AHServerEventFactory.preFishingRodCast (Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/item/ItemStack;II)Lorg/auioc/mcmod/arnicalib/game/event/server/FishingRodCastEvent; ++ INVOKESTATIC org/auioc/mcmod/arnicalib/mod/coremod/AHCoreModHandler.preFishingRodCast (Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/item/ItemStack;II)Lorg/auioc/mcmod/arnicalib/game/event/server/FishingRodCastEvent; + ASTORE 7 + ALOAD 7 + INVOKEVIRTUAL org/auioc/mcmod/arnicalib/game/event/server/FishingRodCastEvent.getSpeedBonus ()I