package net.mcreator.creategunaddition; import net.minecraft.world.entity.player.Player; import net.minecraft.world.InteractionHand; import net.minecraft.world.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.mcreator.creategunaddition.init.CreateGunAdditionModItems; @Mod.EventBusSubscriber(modid = CreateGunAdditionMod.MODID, value = Dist.CLIENT) public class PlayerTickEventHandler { @SubscribeEvent public static void onPlayerTick(TickEvent.PlayerTickEvent event) { if (event.phase == TickEvent.Phase.START && event.side.isClient()) { Player player = event.player; ItemStack mainHandItem = player.getMainHandItem(); if (mainHandItem.getItem() == CreateGunAdditionModItems.BOLT.get()) { if (player.swingingArm == InteractionHand.MAIN_HAND) { if (player.swingTime > 0) { player.swingTime = Math.max(1, player.swingTime - 1); } else { player.swingingArm = null; } } if (player.swingingArm == InteractionHand.OFF_HAND) { player.swingTime = Math.max(1, player.swingTime - 1); } else { player.swingingArm = null; } } if ((mainHandItem.getItem() == CreateGunAdditionModItems.BOLT.get())) { player.stopUsingItem(); } } } }