Skip to content

Commit

Permalink
feat(coremod): AHCoreModHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
WakelessSloth56 committed Feb 13, 2024
1 parent 43fdbfa commit 08bcb42
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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 <code>coremod: arnicalib.cross_bow_item.shoot_projectile<code/>
*/
public static void preCrossbowRelease(LivingEntity living, ItemStack weapon, Projectile projectile) {
AHServerEventFactory.preProjectileWeaponRelease(living, weapon, projectile);
}

/**
* @see <code>coremod: arnicalib.fishing_rod_item.use<code/>
*/
public static FishingRodCastEvent preFishingRodCast(Player player, ItemStack fishingRod, int speedBonus, int luckBonus) {
return AHServerEventFactory.preFishingRodCast(player, fishingRod, speedBonus, luckBonus);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -67,14 +68,14 @@ public static boolean onServerLogin(final ClientIntentionPacket packet, final Co

/**
* @see org.auioc.mcmod.arnicalib.mod.mixin.server.MixinBowItem#releaseUsing
* @see <code>coremod: arnicalib.cross_bow_item.shoot_projectile<code/>
* @see AHCoreModHandler#preCrossbowRelease
*/
public static void preProjectileWeaponRelease(LivingEntity living, ItemStack weapon, Projectile projectile) {
BUS.post(new ProjectileWeaponReleaseEvent(living, weapon, projectile));
}

/**
* @see <code>coremod: arnicalib.fishing_rod_item.use<code/>
* @see AHCoreModHandler#preFishingRodCast
*/
public static FishingRodCastEvent preFishingRodCast(Player player, ItemStack fishingRod, int speedBonus, int luckBonus) {
var event = new FishingRodCastEvent((ServerPlayer) player, fishingRod, speedBonus, luckBonus);
Expand Down
14 changes: 7 additions & 7 deletions src/main/resources/coremods/cross_bow_item.shoot_projectile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
)
Expand All @@ -45,8 +45,8 @@ function initializeCoreMod() {

// print(ASMAPI.methodNodeToString(methodNode));
return methodNode;
},
},
}
}
};
}

Expand All @@ -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);
//_...
}
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/main/resources/coremods/fishing_rod_item.use.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -87,8 +87,8 @@ function initializeCoreMod() {

// print(ASMAPI.methodNodeToString(methodNode));
return methodNode;
},
},
}
}
};
}

Expand All @@ -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));
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 08bcb42

Please sign in to comment.